Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to access other members messages ?


  • StefanBu
    Participant

    @stefanbu

    Hi, i tried to access unread messages from other users, but the following code gives me only access to the account messages, i am logged in with.

    Here is a part of the code. If i use another user ID then the current logged in account, i get no results.

    ...
          $aParams ['box'] = 'inbox';
          $aParams ['per_page'] = '99';
          $aParams ['user_id'] = $UID;
    
          if (bp_has_message_threads($aParams)) {
              while (bp_message_threads()) {
                  bp_message_thread();
    
                  $subject = bp_get_message_thread_subject();
                  $excerpt = bp_get_message_thread_excerpt();
                  $from = bp_get_message_thread_from();
                  $unread = bp_message_thread_has_unread();
                  if ($unread){
                  	$messages .= ' From: ' . $from . ' Subject: ' . $subject . ' Excerpt: ' . $excerpt;
                  }
                }
            } else {
                return array("message" => "no messages");
            }
            return array("all messages" => "$messages");
    ...
    

    I am using WordPress 4.2.2 and BB 2.3.1

Viewing 6 replies - 1 through 6 (of 6 total)

  • Henry Wright
    Moderator

    @henrywright

    Hi @stefanbu

    It isn’t clear from your post what you are trying to do. You should explain in detail your aim and any problems you’re facing.


    danbp
    Moderator

    @danbp

    By default, you have no access to others messages, even if site admin. Your request sounds like a privacy violation. Why would you access to others messages ? Please explain with more details what you want to do.


    shanebp
    Moderator

    @shanebp

    The problem may be that bp_message_thread_has_unread() is hard-coded to check based on the loggedin_user.
    See bp-messages\classes\class-bp_messages-thread.php

    If you remove your $unread conditional, you will see all the messages for $UID.

    To only get unread messages, you may need to use custom sql that starts with the bp_messages_recipients table and queries based on the unread_count field.


    StefanBu
    Participant

    @stefanbu

    Hi shanebp,

    thanks, that helps. Its a pity, that bp_message_thread_has_unread() only checks for the loggedin user.
    Do you think it would be possible to copy and modify this function in a custom.php ?


    @danbp
    and Henry Wright:
    For our project, we want to forward unread messages via JSON API to an external system, which has a central processing and provides these messages to external displays of users – outside WordPress. Therefore, we need a central access to all unread messages of all users.


    StefanBu
    Participant

    @stefanbu

    I found a solution for the unread problem:
    bp_has_message_threads() has a parameter ‘type’.
    So i added this to my params:
    $aParams ['type'] = 'unread';


    shanebp
    Moderator

    @shanebp

    Please use the code button when sharing code.

    Nice solution! $aParams [‘type’] = 'unread';

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How to access other members messages ?’ is closed to new replies.
Skip to toolbar