示例#1
0
    ?>
</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');
        ?>

        <?php 
    } elseif (bp_get_max_thread_recipients_to_list() <= bp_get_thread_recipients_count()) {
        ?>

          <?php 
        printf(__('Conversation between %s recipients.', 'buddypress'), number_format_i18n(bp_get_thread_recipients_count()));
        ?>

        <?php 
    } else {
        ?>

          <?php 
        printf(__('Conversation between %s and you.', 'buddypress'), bp_get_thread_recipients_list());
        ?>

        <?php 
示例#2
0
 /**
  * Get a specific message
  *
  * @param WP_REST_Request $request
  * @return array|WP_Error
  */
 public function get_item($request)
 {
     global $thread_template;
     $id = $request['id'];
     if (bp_thread_has_messages(array('thread_id' => $id))) {
         $data = array();
         $data['thread_id'] = $id;
         $data['subject'] = bp_get_the_thread_subject();
         if (bp_is_active('messages', 'star')) {
             $data['star'] = strpos(bp_get_the_message_star_action_link(array('thread_id' => $id)), 'unstar') ? true : false;
         }
         if (bp_get_thread_recipients_count() <= 1) {
             $data['thread_title'] = __('You are alone in this conversation.', BP_API_PLUGIN_SLUG);
         } elseif (bp_get_max_thread_recipients_to_list() <= bp_get_thread_recipients_count()) {
             $data['thread_title'] = sprintf(__('Conversation between %s recipients.', BP_API_PLUGIN_SLUG), number_format_i18n(bp_get_thread_recipients_count()));
         } else {
             foreach ((array) $thread_template->thread->recipients as $recipient) {
                 if ((int) $recipient->user_id !== bp_loggedin_user_id()) {
                     $recipient_name = bp_core_get_user_displayname($recipient->user_id);
                     if (empty($recipient_name)) {
                         $recipient_name = __('Deleted User', BP_API_PLUGIN_SLUG);
                     }
                     $recipient_names[] = $recipient_name;
                 }
             }
             $data['thread_title'] = sprintf(__('Conversation between %s and you.'), implode(',', $recipient_names));
             $data['thread_msg'] = [];
             while (bp_thread_messages()) {
                 bp_thread_the_message();
                 $single_msg = (array) $thread_template->message;
                 $single_msg['sender_avatar'] = bp_core_fetch_avatar(array('item_id' => $thread_template->message->sender_id, 'width' => 25, 'height' => 25, 'html' => false));
                 $single_msg['sender_name'] = bp_get_the_thread_message_sender_name();
                 if (bp_is_active('messages', 'star')) {
                     $single_msg['star'] = bp_messages_is_message_starred($thread_template->message->id, bp_loggedin_user_id());
                 }
                 $data['thread_msg'][] = $single_msg;
             }
         }
     } else {
         return new WP_Error('bp_json_message', __('Message Not Found.', BP_API_PLUGIN_SLUG), array('status' => 404));
     }
     return new WP_REST_Response($data, 200);
 }