Hello @akgt,
I am sorry about the delay but we’ve just pushed 2.0 online.
You can normally use the basic shortcodes to create a messages link for current user with unread count using:
<a href="[bbpm-messages-link]">Messages ([bbpm-unread-count])</a>
But to make the dynamic form I’d suggest you add this code to your custom plugin or child theme’s functions file:
add_shortcode('bbpm-new-message', 'shortcode_bbpm_new_message');
function shortcode_bbpm_new_message($atts) {
$atts = shortcode_atts(array(
'recipient' => 0
), $atts);
extract(array_map('intval', $atts));
if ( !$recipient )
return;
$m = bbpm_messages();
if ( !$m->current_user )
return;
$chat_id = $m->getPrivateSharedChat($recipient, $m->current_user);
if ( !$chat_id ) {
$m->set(
'chat_id',
$m->set('chat_id', null)->getOrGenerateChatId()
)->addChatRecipient(array($m->current_user, $recipient));
$chat_id = $m->get('chat_id');
}
if ( class_exists('\BBP_MESSAGES\Inc\Core\Redirect') ) {
if ( method_exists('\BBP_MESSAGES\Inc\Core\Redirect', 'parseNotices') ) {
\BBP_MESSAGES\Inc\Core\Redirect::parseNotices('bbpm_errors', 'bbpm_add_error');
bbpm_template_errors();
}
}
ob_start();
?>
<form method="post" action="<?php echo bbpm_messages_url('send', $m->current_user); ?>">
<p class="form-section<?php echo bbpm_has_errors('message') ? ' has-errors' : ''; ?>">
<label for="message"><?php _e('Type a message:', BBP_MESSAGES_DOMAIN); ?></label>
<?php echo bbpm_message_field(bbpm_old('message', true)); ?>
<?php if ( bbpm_has_errors('message') ) : ?>
<?php bbpm_print_error('message'); ?>
<?php endif; ?>
</p>
<p class="form-submit">
<?php wp_nonce_field('send_message', 'bbpm_nonce'); ?>
<input type="hidden" name="chat_id" value="<?php echo $chat_id; ?>" />
<input type="submit" name="send_message" value="<?php esc_attr_e('Send', BBP_MESSAGES_DOMAIN); ?>" />
<a href="<?php echo bbpm_messages_url(null, $m->current_user); ?>"><?php _e('Cancel', BBP_MESSAGES_DOMAIN); ?></a>
</p>
</form>
<?php
return ob_get_clean();
}
That will produce the [bbpm-new-message]
shortcode which you can use this way:
[bbpm-new-message recipient=5]
where 5 is the user whom current user will be sending messages to.
If you’re not sure about the recipient ID then just link current user to [bbpm-messages-link]new/
where they can search for recipients and compose a message.
Hope that helps, let me know how it goes.
Thanks
Best,
Samuel
-
This reply was modified 7 years, 9 months ago by Ismail.