/** * @group bp_messages_update_meta_cache * @group bp_thread_has_messages */ public function test_bp_messages_metadata_cache_in_message_loop() { $u1 = $this->factory->user->create(); $u2 = $this->factory->user->create(); // create the message and thread $m = $this->factory->message->create_and_get(array('sender_id' => $u1, 'recipients' => array($u2), 'subject' => 'Oy')); // add message cache bp_messages_update_meta($m->id, 'yolo', 'gah'); // prime meta cache in message loop bp_thread_has_messages(array('thread_id' => $m->thread_id, 'update_meta_cache' => true)); $this->assertNotEmpty(wp_cache_get($m->id, 'message_meta')); }
<div id="message-thread"> <?php /** * Fires before the display of a single member message thread content. * * @since BuddyPress (1.1.0) */ do_action('bp_before_message_thread_content'); ?> <?php if (bp_thread_has_messages()) { ?> <h3 id="message-subject"><?php bp_the_thread_subject(); ?> </h3> <p id="message-recipients"> <span class="highlight"> <?php if (bp_get_thread_recipients_count() <= 1) { ?> <?php _e('You are alone in this conversation.', 'buddypress'); ?>
/** * Send a private message reply to a thread via a POST request. * * @return string HTML * @since BuddyPress (1.2) */ function bp_legacy_theme_ajax_messages_send_reply() { // Bail if not a POST action if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) { return; } check_ajax_referer('messages_send_message'); $result = messages_new_message(array('thread_id' => (int) $_REQUEST['thread_id'], 'content' => $_REQUEST['content'])); if (!empty($result)) { // pretend we're in the message loop global $thread_template; bp_thread_has_messages(array('thread_id' => (int) $_REQUEST['thread_id'])); // set the current message to the 2nd last $thread_template->message = end($thread_template->thread->messages); $thread_template->message = prev($thread_template->thread->messages); // set current message to current key $thread_template->current_message = key($thread_template->thread->messages); // now manually iterate message like we're in the loop bp_thread_the_message(); // manually call oEmbed // this is needed because we're not at the beginning of the loop bp_messages_embed(); ?> <div class="message-box new-message <?php bp_the_thread_message_css_class(); ?> "> <div class="message-metadata"> <?php /** * Fires before the single message header is displayed. * * @since BuddyPress (1.1.0) */ do_action('bp_before_message_meta'); ?> <?php echo bp_loggedin_user_avatar('type=thumb&width=30&height=30'); ?> <strong><a href="<?php echo bp_loggedin_user_domain(); ?> "><?php bp_loggedin_user_fullname(); ?> </a> <span class="activity"><?php printf(__('Sent %s', 'buddypress'), bp_core_time_since(bp_core_current_time())); ?> </span></strong> <?php /** * Fires after the single message header is displayed. * * @since BuddyPress (1.1.0) */ do_action('bp_after_message_meta'); ?> </div> <?php /** * Fires before the message content for a private message. * * @since BuddyPress (1.1.0) */ do_action('bp_before_message_content'); ?> <div class="message-content"> <?php bp_the_thread_message_content(); ?> </div> <?php /** * Fires after the message content for a private message. * * @since BuddyPress (1.1.0) */ do_action('bp_after_message_content'); ?> <div class="clear"></div> </div> <?php // clean up the loop bp_thread_messages(); } else { echo "-1<div id='message' class='error'><p>" . __('There was a problem sending that reply. Please try again.', 'buddypress') . '</p></div>'; } exit; }
/** * Send a private message reply to a thread via a POST request. * * @return string HTML * @since BuddyPress (1.2) */ function bp_legacy_theme_ajax_messages_send_reply() { // Bail if not a POST action if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) { return; } check_ajax_referer('messages_send_message'); $result = messages_new_message(array('thread_id' => (int) $_REQUEST['thread_id'], 'content' => $_REQUEST['content'])); if (!empty($result)) { // Get the zebra line classes correct on ajax requests global $thread_template; bp_thread_has_messages(array('thread_id' => (int) $_REQUEST['thread_id'])); if ($thread_template->message_count % 2 == 1) { $class = 'odd'; } else { $class = 'even alt'; } ?> <div class="message-box new-message <?php echo $class; ?> "> <div class="message-metadata"> <?php do_action('bp_before_message_meta'); ?> <?php echo bp_loggedin_user_avatar('type=thumb&width=30&height=30'); ?> <strong><a href="<?php echo bp_loggedin_user_domain(); ?> "><?php bp_loggedin_user_fullname(); ?> </a> <span class="activity"><?php printf(__('Sent %s', 'buddypress'), bp_core_time_since(bp_core_current_time())); ?> </span></strong> <?php do_action('bp_after_message_meta'); ?> </div> <?php do_action('bp_before_message_content'); ?> <div class="message-content"> <?php echo stripslashes(apply_filters('bp_get_the_thread_message_content', $_REQUEST['content'])); ?> </div> <?php do_action('bp_after_message_content'); ?> <div class="clear"></div> </div> <?php } else { echo "-1<div id='message' class='error'><p>" . __('There was a problem sending that reply. Please try again.', 'buddypress') . '</p></div>'; } exit; }
/** * Send a private message reply to a thread via a POST request. * * @since 1.2.0 * * @return string HTML */ function bp_legacy_theme_ajax_messages_send_reply() { // Bail if not a POST action. if ('POST' !== strtoupper($_SERVER['REQUEST_METHOD'])) { return; } check_ajax_referer('messages_send_message'); $result = messages_new_message(array('thread_id' => (int) $_REQUEST['thread_id'], 'content' => $_REQUEST['content'])); if (!empty($result)) { // Pretend we're in the message loop. global $thread_template; bp_thread_has_messages(array('thread_id' => (int) $_REQUEST['thread_id'])); // Set the current message to the 2nd last. $thread_template->message = end($thread_template->thread->messages); $thread_template->message = prev($thread_template->thread->messages); // Set current message to current key. $thread_template->current_message = key($thread_template->thread->messages); // Now manually iterate message like we're in the loop. bp_thread_the_message(); // Manually call oEmbed // this is needed because we're not at the beginning of the loop. bp_messages_embed(); // Add new-message css class. add_filter('bp_get_the_thread_message_css_class', create_function('$retval', ' $retval[] = "new-message"; return $retval; ')); // Output single message template part. bp_get_template_part('members/single/messages/message'); // Clean up the loop. bp_thread_messages(); } else { echo "-1<div id='message' class='error'><p>" . __('There was a problem sending that reply. Please try again.', 'buddypress') . '</p></div>'; } exit; }
<div id="message-thread"> <?php do_action( 'bp_before_message_thread_content' ) ?> <?php if ( bp_thread_has_messages() ) : ?> <h3 id="message-subject"><?php bp_the_thread_subject() ?></h3> <p id="message-recipients"> <span class="highlight"> <?php printf( __('Sent between %s and %s', 'buddypress'), bp_get_the_thread_recipients(), '<a href="' . bp_get_loggedin_user_link() . '" title="' . bp_get_loggedin_user_fullname() . '">' . bp_get_loggedin_user_fullname() . '</a>' ) ?> </span> </p> <?php do_action( 'bp_before_message_thread_list' ) ?> <?php while ( bp_thread_messages() ) : bp_thread_the_message(); ?> <div class="message-box"> <div class="message-metadata"> <?php do_action( 'bp_before_message_meta' ) ?> <?php bp_the_thread_message_sender_avatar( 'type=thumb&width=30&height=30' ) ?> <strong><a href="<?php bp_the_thread_message_sender_link() ?>" title="<?php bp_the_thread_message_sender_name() ?>"><?php bp_the_thread_message_sender_name() ?></a> <span class="activity"><?php bp_the_thread_message_time_since() ?></span></strong> <?php do_action( 'bp_after_message_meta' ) ?> </div><!-- .message-metadata -->
/** * Delete a single message * * @param WP_REST_Request $request Full details about the request. * @return WP_Error|WP_REST_Response */ public function delete_item($request) { $id = (int) $request['id']; if (!bp_thread_has_messages(array('thread_id' => $id))) { return new WP_Error('bp_json_message', __('Message Not Found.', BP_API_PLUGIN_SLUG), array('status' => 404)); } $deleted = messages_delete_thread($id); if (!$deleted) { return new WP_Error('bp_json_message_cannot_be_deleted', __('The message cannot be deleted.', BP_API_PLUGIN_SLUG), array('status' => 500)); } return new WP_Error('bp_json_message_deleted', __('Message deleted successfully.', BP_API_PLUGIN_SLUG), array('status' => 200)); }