Skip to:
Content

BuddyPress.org

Changeset 9752


Ignore:
Timestamp:
04/15/2015 10:38:41 PM (4 years ago)
Author:
r-a-y
Message:

Messages: Add $thread_id parameter to BP_Messages_Thread::get_recipients().

Also added new static BP_Messages_Thread::get_recipients_for_thread()
method for convenience.

See #6221.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-messages/classes/class-bp_messages-thread.php

    r9714 r9752  
    207207     *
    208208     * @since BuddyPress (1.0.0)
    209      *
     209     * @since BuddyPress (2.3.0) Added $thread_id as a parameter.
     210     *
     211     * @param int $thread_id The thread ID
    210212     * @return array
    211213     */
    212     public function get_recipients() {
    213         global $wpdb;
    214 
    215         $recipients = wp_cache_get( 'thread_recipients_' . $this->thread_id, 'bp_messages' );
     214    public function get_recipients( $thread_id = 0 ) {
     215        global $wpdb;
     216
     217        if ( empty( $thread_id ) ) {
     218            $thread_id = $this->thread_id;
     219        }
     220
     221        $recipients = wp_cache_get( 'thread_recipients_' . $thread_id, 'bp_messages' );
    216222        if ( false === $recipients ) {
    217223            $bp = buddypress();
    218224
    219225            $recipients = array();
    220             $results    = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->messages->table_name_recipients} WHERE thread_id = %d", $this->thread_id ) );
     226            $results    = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$bp->messages->table_name_recipients} WHERE thread_id = %d", $thread_id ) );
    221227
    222228            foreach ( (array) $results as $recipient ) {
     
    224230            }
    225231
    226             wp_cache_set( 'thread_recipients_' . $this->thread_id, $recipients, 'bp_messages' );
     232            wp_cache_set( 'thread_recipients_' . $thread_id, $recipients, 'bp_messages' );
    227233        }
    228234
     
    235241         * @param int   $thread_id  ID of the current thread.
    236242         */
    237         return apply_filters( 'bp_messages_thread_get_recipients', $recipients, $this->thread_id );
     243        return apply_filters( 'bp_messages_thread_get_recipients', $recipients, $thread_id );
    238244    }
    239245
    240246    /** Static Functions ******************************************************/
     247
     248    /**
     249     * Static method to get message recipients by thread ID.
     250     *
     251     * @since BuddyPress (2.3.0)
     252     *
     253     * @param  int $thread_id The thread ID
     254     * @return array
     255     */
     256    public static function get_recipients_for_thread( $thread_id = 0 ) {
     257        $thread = new self( false );
     258        return $thread->get_recipients( $thread_id );
     259    }
    241260
    242261    /**
Note: See TracChangeset for help on using the changeset viewer.