Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
12/19/2016 10:24:19 PM (8 years ago)
Author:
slaffik
Message:

Messages: new filter for get_recipients_ids()

Give ability to filter the array of recipients IDs. For BC we can't explicitly make it always return array, so if no usernames provided, false will be returned.

See #5193.

File:
1 edited

Legend:

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

    r11028 r11306  
    193193     *
    194194     * @param array $recipient_usernames Usernames of recipients.
    195      * @return array $recipient_ids Array of Recepient IDs.
     195     *
     196     * @return bool|array $recipient_ids Array of Recepient IDs.
    196197     */
    197198    public static function get_recipient_ids( $recipient_usernames ) {
    198         if ( !$recipient_usernames )
    199             return false;
     199        $recipient_ids = false;
     200
     201        if ( ! $recipient_usernames ) {
     202            return $recipient_ids;
     203        }
    200204
    201205        if ( is_array( $recipient_usernames ) ) {
    202             for ( $i = 0, $count = count( $recipient_usernames ); $i < $count; ++$i ) {
    203                 if ( $rid = bp_core_get_userid( trim($recipient_usernames[$i]) ) ) {
     206            $rec_un_count = count( $recipient_usernames );
     207
     208            for ( $i = 0, $count = $rec_un_count; $i < $count; ++ $i ) {
     209                if ( $rid = bp_core_get_userid( trim( $recipient_usernames[ $i ] ) ) ) {
    204210                    $recipient_ids[] = $rid;
    205211                }
     
    207213        }
    208214
    209         return $recipient_ids;
     215        /**
     216         * Filters the array of recipients IDs.
     217         *
     218         * @since 2.8.0
     219         *
     220         * @param array $recipient_ids Array of recipients IDs that were retrieved based on submitted usernames.
     221         * @param array $recipient_usernames Array of recipients usernames that were submitted by a user.
     222         */
     223        return apply_filters( 'messages_message_get_recipient_ids', $recipient_ids, $recipient_usernames );
    210224    }
    211225
Note: See TracChangeset for help on using the changeset viewer.