コード例 #1
1
ファイル: bp-api-messages.php プロジェクト: buddyboss/BP-API
 /**
  * Get all messages
  *
  * @param WP_REST_Request $request
  * @return array|WP_Error
  */
 public function get_items($request)
 {
     /* filter messages */
     $args = array();
     $args['box'] = $request['box'];
     if ($request['box'] == 'starred') {
         $args['meta_query'] = array(array('key' => 'starred_by_user', 'value' => bp_loggedin_user_id()));
     }
     if (isset($request['filter'])) {
         $args = array_merge($args, $request['filter']);
         unset($args['filter']);
     }
     global $messages_template;
     $data = array();
     if (bp_has_message_threads($args)) {
         while (bp_message_threads()) {
             bp_message_thread();
             $single_msg = array('thread_id' => $messages_template->thread->thread_id, 'read' => bp_message_thread_has_unread() ? false : true, 'total_messages' => bp_get_message_thread_total_count($messages_template->thread->thread_id), 'unread_messages' => bp_get_message_thread_unread_count($messages_template->thread->thread_id), 'avatar' => bp_core_fetch_avatar(array('item_id' => $messages_template->thread->last_sender_id, 'width' => 25, 'height' => 25, 'html' => false)), 'from' => bp_core_get_username($messages_template->thread->last_sender_id), 'from_id' => $messages_template->thread->last_sender_id, 'last_message_date' => $messages_template->thread->last_message_date, 'subject' => bp_get_message_thread_subject(), 'excerpt' => bp_get_message_thread_excerpt(), 'content' => bp_get_message_thread_content());
             if (bp_is_active('messages', 'star')) {
                 $single_msg['star'] = strpos(bp_get_the_message_star_action_link(array('thread_id' => bp_get_message_thread_id())), 'unstar') ? true : false;
             }
             if ($args['box'] == 'sentbox') {
                 foreach ($messages_template->thread->recipients as $user => $userdata) {
                     if ((int) $user !== bp_loggedin_user_id()) {
                         $single_msg['to'][$user]['name'] = bp_core_get_username($user);
                     }
                 }
             }
             $links['self'] = array('href' => rest_url(sprintf(BP_API_SLUG . '/messages/%d', $messages_template->thread->thread_id)));
             if ($args['box'] == 'sentbox') {
                 $links['collection'] = array('href' => rest_url(BP_API_SLUG . '/messages?box=sentbox'));
             } else {
                 $links['collection'] = array('href' => rest_url(BP_API_SLUG . '/messages/'));
             }
             $single_msg['_links'] = $links;
             $data[] = $single_msg;
         }
     } else {
         return new WP_Error('bp_json_messages', __('No Messages Found.', BP_API_PLUGIN_SLUG), array('status' => 200));
     }
     $data = apply_filters('bp_json_prepare_messages', $data);
     return new WP_REST_Response($data, 200);
 }
コード例 #2
0
/**
 * Output the thread's last message content.
 *
 * When viewing your Inbox, the last message is the most recent message in
 * the thread of which you are *not* the author.
 *
 * When viewing your Sentbox, last message is the most recent message in
 * the thread of which you *are* the member.
 *
 * @since 2.0.0
 */
function bp_message_thread_content()
{
    echo bp_get_message_thread_content();
}