Skip to:
Content

BuddyPress.org

Changeset 13092


Ignore:
Timestamp:
08/24/2021 04:16:17 AM (3 years ago)
Author:
espellcaste
Message:

Making PHPDoc Improvements to the BP Friends (component) files.

Also, adding several minor PHP changes.

See #8553

Location:
trunk/src/bp-friends
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-friends/actions/add-friend.php

    r11931 r13092  
    11<?php
    22/**
    3  * Friends: Add action
     3 * Friends: Add action.
    44 *
    55 * @package BuddyPress
     
    1414 */
    1515function friends_action_add_friend() {
    16     if ( !bp_is_friends_component() || !bp_is_current_action( 'add-friend' ) )
     16    if ( ! bp_is_friends_component() || ! bp_is_current_action( 'add-friend' ) ) {
    1717        return false;
     18    }
    1819
    19     if ( !$potential_friend_id = (int)bp_action_variable( 0 ) )
     20    $potential_friend_id = (int) bp_action_variable( 0 );
     21    if ( ! $potential_friend_id ) {
    2022        return false;
     23    }
    2124
    22     if ( $potential_friend_id == bp_loggedin_user_id() )
     25    if ( bp_loggedin_user_id() === $potential_friend_id ) {
    2326        return false;
     27    }
    2428
    2529    $friendship_status = BP_Friends_Friendship::check_is_friend( bp_loggedin_user_id(), $potential_friend_id );
    2630
    27     if ( 'not_friends' == $friendship_status ) {
     31    if ( 'not_friends' === $friendship_status ) {
    2832
    29         if ( !check_admin_referer( 'friends_add_friend' ) )
     33        if ( ! check_admin_referer( 'friends_add_friend' ) ) {
    3034            return false;
     35        }
    3136
    32         if ( !friends_add_friend( bp_loggedin_user_id(), $potential_friend_id ) ) {
     37        if ( ! friends_add_friend( bp_loggedin_user_id(), $potential_friend_id ) ) {
    3338            bp_core_add_message( __( 'Friendship could not be requested.', 'buddypress' ), 'error' );
    3439        } else {
    3540            bp_core_add_message( __( 'Friendship requested', 'buddypress' ) );
    3641        }
    37 
    38     } elseif ( 'is_friend' == $friendship_status ) {
     42    } elseif ( 'is_friend' === $friendship_status ) {
    3943        bp_core_add_message( __( 'You are already friends with this user', 'buddypress' ), 'error' );
    4044    } else {
  • trunk/src/bp-friends/actions/remove-friend.php

    r11931 r13092  
    11<?php
    22/**
    3  * Friends: Remove action
     3 * Friends: Remove action.
    44 *
    55 * @package BuddyPress
     
    1414 */
    1515function friends_action_remove_friend() {
    16     if ( !bp_is_friends_component() || !bp_is_current_action( 'remove-friend' ) )
     16    if ( ! bp_is_friends_component() || ! bp_is_current_action( 'remove-friend' ) ) {
    1717        return false;
     18    }
    1819
    19     if ( !$potential_friend_id = (int)bp_action_variable( 0 ) )
     20    $potential_friend_id = (int) bp_action_variable( 0 );
     21    if ( ! $potential_friend_id ) {
    2022        return false;
     23    }
    2124
    22     if ( $potential_friend_id == bp_loggedin_user_id() )
     25    if ( bp_loggedin_user_id() === $potential_friend_id ) {
    2326        return false;
     27    }
    2428
    2529    $friendship_status = BP_Friends_Friendship::check_is_friend( bp_loggedin_user_id(), $potential_friend_id );
    2630
    27     if ( 'is_friend' == $friendship_status ) {
     31    if ( 'is_friend' === $friendship_status ) {
    2832
    29         if ( !check_admin_referer( 'friends_remove_friend' ) )
     33        if ( ! check_admin_referer( 'friends_remove_friend' ) ) {
    3034            return false;
     35        }
    3136
    32         if ( !friends_remove_friend( bp_loggedin_user_id(), $potential_friend_id ) ) {
     37        if ( ! friends_remove_friend( bp_loggedin_user_id(), $potential_friend_id ) ) {
    3338            bp_core_add_message( __( 'Friendship could not be canceled.', 'buddypress' ), 'error' );
    3439        } else {
    3540            bp_core_add_message( __( 'Friendship canceled', 'buddypress' ) );
    3641        }
    37 
    38     } elseif ( 'not_friends' == $friendship_status ) {
     42    } elseif ( 'not_friends' === $friendship_status ) {
    3943        bp_core_add_message( __( 'You are not yet friends with this user', 'buddypress' ), 'error' );
    4044    } else {
  • trunk/src/bp-friends/bp-friends-activity.php

    r12602 r13092  
    5050        'secondary_item_id' => false,
    5151        'recorded_time'     => bp_core_current_time(),
    52         'hide_sitewide'     => false
     52        'hide_sitewide'     => false,
    5353    ) );
    5454
     
    7070 *     @type int    $user_id ID of the user associated with the activity item.
    7171 * }
    72  * @return bool True on success, false on failure.
    7372 */
    7473function friends_delete_activity( $args ) {
     
    8180        'item_id'   => $args['item_id'],
    8281        'type'      => $args['type'],
    83         'user_id'   => $args['user_id']
     82        'user_id'   => $args['user_id'],
    8483    ) );
    8584}
     
    8988 *
    9089 * @since 1.1.0
     90 *
     91 * @return bool False if activity component is not active.
    9192 */
    9293function friends_register_activity_actions() {
    9394
    94     if ( !bp_is_active( 'activity' ) ) {
     95    if ( ! bp_is_active( 'activity' ) ) {
    9596        return false;
    9697    }
     
    136137 * @param string $action   Activity action string.
    137138 * @param object $activity Activity data.
    138  * @return string $action Formatted activity action.
     139 * @return string Formatted activity action.
    139140 */
    140141function bp_friends_format_activity_action_friendship_accepted( $action, $activity ) {
     
    171172 * @param string $action   Static activity action.
    172173 * @param object $activity Activity data.
    173  * @return string $action Formatted activity action.
     174 * @return string Formatted activity action.
    174175 */
    175176function bp_friends_format_activity_action_friendship_created( $action, $activity ) {
     
    270271            'column'  => 'user_id',
    271272            'compare' => 'IN',
    272             'value'   => (array) $friends
     273            'value'   => (array) $friends,
    273274        ),
    274275
     
    276277        array(
    277278            'column' => 'hide_sitewide',
    278             'value'  => 0
     279            'value'  => 0,
    279280        ),
    280281
     
    282283        'override' => array(
    283284            'filter'      => array( 'user_id' => 0 ),
    284             'show_hidden' => true
     285            'show_hidden' => true,
    285286        ),
    286287    );
     
    355356                'value'  => $user_id,
    356357            ),
    357         )
     358        ),
    358359    );
    359360
     
    373374 * @since 1.9.0
    374375 *
    375  * @param int         $friendship_id       ID of the friendship.
    376  * @param int         $initiator_user_id   ID of friendship initiator.
    377  * @param int         $friend_user_id      ID of user whose friendship is requested.
    378  * @param object|bool $friendship Optional Friendship object.
    379  */
    380 function bp_friends_friendship_accepted_activity( $friendship_id, $initiator_user_id, $friend_user_id, $friendship = false ) {
     376 * @param int $friendship_id     ID of the friendship.
     377 * @param int $initiator_user_id ID of friendship initiator.
     378 * @param int $friend_user_id    ID of user whose friendship is requested.
     379 */
     380function bp_friends_friendship_accepted_activity( $friendship_id, $initiator_user_id, $friend_user_id ) {
    381381    if ( ! bp_is_active( 'activity' ) ) {
    382382        return;
     
    388388        'type'              => 'friendship_created',
    389389        'item_id'           => $friendship_id,
    390         'secondary_item_id' => $friend_user_id
     390        'secondary_item_id' => $friend_user_id,
    391391    ) );
    392392}
    393 add_action( 'friends_friendship_accepted', 'bp_friends_friendship_accepted_activity', 10, 4 );
     393add_action( 'friends_friendship_accepted', 'bp_friends_friendship_accepted_activity', 10, 3 );
    394394
    395395/**
     
    405405    }
    406406
    407     bp_activity_delete( array(
    408         'component'         => buddypress()->friends->id,
    409         'type'              => 'friendship_created',
    410         'secondary_item_id' => $user_id
    411     ) );
     407    bp_activity_delete(
     408        array(
     409            'component'         => buddypress()->friends->id,
     410            'type'              => 'friendship_created',
     411            'secondary_item_id' => $user_id,
     412        )
     413    );
    412414}
    413415add_action( 'friends_remove_data', 'bp_friends_delete_activity_on_user_delete' );
     
    421423 */
    422424function bp_friends_delete_activity_on_friendship_delete( $friendship_id ) {
    423     friends_delete_activity( array( 'item_id' => $friendship_id, 'type' => 'friendship_created', 'user_id' => 0 ) );
     425    friends_delete_activity(
     426        array(
     427            'item_id' => $friendship_id,
     428            'type'    => 'friendship_created',
     429            'user_id' => 0,
     430        )
     431    );
    424432}
    425433add_action( 'friends_friendship_deleted', 'bp_friends_delete_activity_on_friendship_delete' );
  • trunk/src/bp-friends/bp-friends-blocks.php

    r13004 r13092  
    99
    1010// Exit if accessed directly.
    11 if ( ! defined( 'ABSPATH' ) ) {
    12     exit;
    13 }
     11defined( 'ABSPATH' ) || exit;
    1412
    1513/**
  • trunk/src/bp-friends/bp-friends-cache.php

    r11949 r13092  
    2424 */
    2525function friends_clear_friend_object_cache( $friendship_id ) {
    26     if ( !$friendship = new BP_Friends_Friendship( $friendship_id ) )
     26    $friendship = new BP_Friends_Friendship( $friendship_id );
     27    if ( ! $friendship ) {
    2728        return false;
     29    }
    2830
    29     wp_cache_delete( 'friends_friend_ids_' .    $friendship->initiator_user_id, 'bp' );
    30     wp_cache_delete( 'friends_friend_ids_' .    $friendship->friend_user_id,    'bp' );
     31    wp_cache_delete( 'friends_friend_ids_' . $friendship->initiator_user_id, 'bp' );
     32    wp_cache_delete( 'friends_friend_ids_' . $friendship->friend_user_id, 'bp' );
    3133}
    3234
    3335// List actions to clear object caches on.
    3436add_action( 'friends_friendship_accepted', 'friends_clear_friend_object_cache' );
    35 add_action( 'friends_friendship_deleted',  'friends_clear_friend_object_cache' );
     37add_action( 'friends_friendship_deleted', 'friends_clear_friend_object_cache' );
    3638
    3739/**
     
    4345 * @param int $initiator_user_id ID of the first user.
    4446 * @param int $friend_user_id    ID of the second user.
    45  * @return bool
    4647 */
    4748function bp_friends_clear_bp_friends_friendships_cache( $friendship_id, $initiator_user_id, $friend_user_id ) {
    4849    // Clear friendship ID cache for each user.
    4950    wp_cache_delete( $initiator_user_id, 'bp_friends_friendships_for_user' );
    50     wp_cache_delete( $friend_user_id,    'bp_friends_friendships_for_user' );
     51    wp_cache_delete( $friend_user_id, 'bp_friends_friendships_for_user' );
    5152
    5253    // Clear the friendship object cache.
     
    6061}
    6162add_action( 'friends_friendship_requested', 'bp_friends_clear_bp_friends_friendships_cache', 10, 3 );
    62 add_action( 'friends_friendship_accepted',  'bp_friends_clear_bp_friends_friendships_cache', 10, 3 );
    63 add_action( 'friends_friendship_deleted',   'bp_friends_clear_bp_friends_friendships_cache', 10, 3 );
     63add_action( 'friends_friendship_accepted', 'bp_friends_clear_bp_friends_friendships_cache', 10, 3 );
     64add_action( 'friends_friendship_deleted', 'bp_friends_clear_bp_friends_friendships_cache', 10, 3 );
    6465
    6566/**
     
    6970 *
    7071 * @param int                   $friendship_id The friendship ID.
    71  * @param BP_Friends_Friendship $friendship Friendship object.
     72 * @param BP_Friends_Friendship $friendship    The friendship object.
    7273 */
    73 function bp_friends_clear_bp_friends_friendships_cache_remove( $friendship_id, BP_Friends_Friendship $friendship ) {
     74function bp_friends_clear_bp_friends_friendships_cache_remove( $friendship_id, $friendship ) {
    7475    // Clear friendship ID cache for each user.
    7576    wp_cache_delete( $friendship->initiator_user_id, 'bp_friends_friendships_for_user' );
    76     wp_cache_delete( $friendship->friend_user_id,    'bp_friends_friendships_for_user' );
     77    wp_cache_delete( $friendship->friend_user_id, 'bp_friends_friendships_for_user' );
    7778
    7879    // Clear the friendship object cache.
     
    8384}
    8485add_action( 'friends_friendship_withdrawn', 'bp_friends_clear_bp_friends_friendships_cache_remove', 10, 2 );
    85 add_action( 'friends_friendship_rejected',  'bp_friends_clear_bp_friends_friendships_cache_remove', 10, 2 );
     86add_action( 'friends_friendship_rejected', 'bp_friends_clear_bp_friends_friendships_cache_remove', 10, 2 );
    8687
    8788/**
     
    111112}
    112113add_action( 'friends_friendship_requested', 'bp_friends_clear_request_cache_on_save', 10, 3 );
    113 add_action( 'friends_friendship_accepted',  'bp_friends_clear_request_cache_on_save', 10, 3 );
     114add_action( 'friends_friendship_accepted', 'bp_friends_clear_request_cache_on_save', 10, 3 );
    114115
    115116/**
     
    121122 *
    122123 * @param int                   $friendship_id The friendship ID.
    123  * @param BP_Friends_Friendship $friendship Friendship object.
     124 * @param BP_Friends_Friendship $friendship    The friendship object.
    124125 */
    125 function bp_friends_clear_request_cache_on_remove( $friendship_id, BP_Friends_Friendship $friendship ) {
     126function bp_friends_clear_request_cache_on_remove( $friendship_id, $friendship ) {
    126127    bp_friends_clear_request_cache( $friendship->friend_user_id );
    127128}
    128129add_action( 'friends_friendship_withdrawn', 'bp_friends_clear_request_cache_on_remove', 10, 2 );
    129 add_action( 'friends_friendship_rejected',  'bp_friends_clear_request_cache_on_remove', 10, 2 );
     130add_action( 'friends_friendship_rejected', 'bp_friends_clear_request_cache_on_remove', 10, 2 );
    130131
    131132/**
     
    134135 * @since 3.0.0
    135136 *
    136  * @param BP_Friends_Friendship $friendship Friendship object.
     137 * @param BP_Friends_Friendship $friendship The friendship object.
    137138 */
    138139function bp_friends_delete_cached_friendships_on_friendship_save( $friendship ) {
  • trunk/src/bp-friends/bp-friends-cssjs.php

    r13002 r13092  
    99
    1010// Exit if accessed directly.
    11 if ( ! defined( 'ABSPATH' ) ) {
    12     exit;
    13 }
     11defined( 'ABSPATH' ) || exit;
    1412
    1513/**
  • trunk/src/bp-friends/bp-friends-filters.php

    r12670 r13092  
    1313// Format numerical output.
    1414add_filter( 'friends_get_total_friend_count', 'bp_core_number_format' );
    15 add_filter( 'bp_get_total_friend_count',      'bp_core_number_format' );
     15add_filter( 'bp_get_total_friend_count', 'bp_core_number_format' );
    1616
    1717/**
     
    2323 * @since 1.7.0
    2424 *
    25  * @global WPDB $wpdb WordPress database access object.
    26  *
    2725 * @param BP_User_Query $user_query   The BP_User_Query object.
    2826 * @param string        $user_ids_sql Comma-separated list of user IDs to fetch extra
    2927 *                                    data for, as determined by BP_User_Query.
    3028 */
    31 function bp_friends_filter_user_query_populate_extras( BP_User_Query $user_query, $user_ids_sql ) {
    32     global $wpdb;
     29function bp_friends_filter_user_query_populate_extras( $user_query, $user_ids_sql ) {
    3330
    3431    // Stop if user isn't logged in.
    35     if ( ! $user_id = bp_loggedin_user_id() ) {
     32    $user_id = bp_loggedin_user_id();
     33    if ( ! $user_id ) {
    3634        return;
    3735    }
     
    4543        $status = BP_Friends_Friendship::check_is_friend( $user_id, $friend_id );
    4644        $user_query->results[ $friend_id ]->friendship_status = $status;
    47         if ( 'is_friend' == $status ) {
     45        if ( 'is_friend' === $status ) {
    4846            $user_query->results[ $friend_id ]->is_friend = 1;
    4947        }
    5048    }
    51 
    5249}
    5350add_filter( 'bp_user_query_populate_extras', 'bp_friends_filter_user_query_populate_extras', 4, 2 );
  • trunk/src/bp-friends/bp-friends-functions.php

    r13086 r13092  
    3434
    3535    // You cannot be friends with yourself!
    36     if ( $initiator_userid == $friend_userid ) {
     36    if ( $initiator_userid === $friend_userid ) {
    3737        return false;
    3838    }
     
    7878     * @since 1.0.0
    7979     *
    80      * @param int    $id                ID of the pending friendship connection.
    81      * @param int    $initiator_user_id ID of the friendship initiator.
    82      * @param int    $friend_user_id    ID of the friend user.
    83      * @param object $friendship        BuddyPress Friendship Object.
     80     * @param int                   $id                ID of the pending friendship connection.
     81     * @param int                   $initiator_user_id ID of the friendship initiator.
     82     * @param int                   $friend_user_id    ID of the friend user.
     83     * @param BP_Friends_Friendship $friendship        The friendship object.
    8484     */
    8585    do_action( 'friends_friendship_' . $action, $friendship->id, $friendship->initiator_user_id, $friendship->friend_user_id, $friendship );
     
    175175         * @since 1.0.0
    176176         *
    177          * @param int    $id                ID of the pending friendship object.
    178          * @param int    $initiator_user_id ID of the friendship initiator.
    179          * @param int    $friend_user_id    ID of the user requested friendship with.
    180          * @param object $friendship        BuddyPress Friendship Object.
     177         * @param int                   $id                ID of the pending friendship object.
     178         * @param int                   $initiator_user_id ID of the friendship initiator.
     179         * @param int                   $friend_user_id    ID of the user requested friendship with.
     180         * @param BP_Friends_Friendship $friendship        The friendship object.
    181181         */
    182182        do_action( 'friends_friendship_accepted', $friendship->id, $friendship->initiator_user_id, $friendship->friend_user_id, $friendship );
     
    206206         * @since 1.0.0
    207207         *
    208          * @param int                   $friendship_id ID of the pending friendship.
    209          * @param BP_Friends_Friendship $friendships Friendship object. Passed by reference.
     208         * @param int                   $friendship_id ID of the friendship.
     209         * @param BP_Friends_Friendship $friendship    The friendship object. Passed by reference.
    210210         */
    211211        do_action_ref_array( 'friends_friendship_rejected', array( $friendship_id, &$friendship ) );
     212
    212213        return true;
    213214    }
     
    241242         *
    242243         * @param int                   $friendship_id ID of the friendship.
    243          * @param BP_Friends_Friendship $friendship    Friendship object. Passed by reference.
     244         * @param BP_Friends_Friendship $friendship    The friendship object. Passed by reference.
    244245         */
    245         do_action_ref_array( 'friends_friendship_withdrawn',  array( $friendship_id, &$friendship ) );
     246        do_action_ref_array( 'friends_friendship_withdrawn', array( $friendship_id, &$friendship ) );
    246247
    247248        return true;
     
    261262 */
    262263function friends_check_friendship( $user_id, $possible_friend_id ) {
    263 
    264     if ( 'is_friend' == BP_Friends_Friendship::check_is_friend( $user_id, $possible_friend_id ) )
    265         return true;
    266 
    267     return false;
     264    return ( 'is_friend' === BP_Friends_Friendship::check_is_friend( $user_id, $possible_friend_id ) );
    268265}
    269266
     
    274271 *
    275272 * @since 1.2.0
     273 *
     274 * @global object $friends_template
    276275 *
    277276 * @param int $user_id            ID of the first user.
     
    302301 */
    303302function friends_get_total_friend_count( $user_id = 0 ) {
    304     if ( empty( $user_id ) )
     303    if ( empty( $user_id ) ) {
    305304        $user_id = ( bp_displayed_user_id() ) ? bp_displayed_user_id() : bp_loggedin_user_id();
     305    }
    306306
    307307    $count = bp_get_user_meta( $user_id, 'total_friend_count', true );
    308     if ( empty( $count ) )
     308    if ( empty( $count ) ) {
    309309        $count = 0;
     310    }
    310311
    311312    /**
     
    316317     * @param int $count Total friend count for a given user.
    317318     */
    318     return apply_filters( 'friends_get_total_friend_count', $count );
     319    return apply_filters( 'friends_get_total_friend_count', (int) $count );
    319320}
    320321
     
    330331    $friend_count = friends_get_total_friend_count( $user_id );
    331332
    332     if ( empty( $friend_count ) )
     333    if ( empty( $friend_count ) ) {
    333334        return false;
    334 
    335     if ( !(int) $friend_count )
     335    }
     336
     337    if ( ! (int) $friend_count ) {
    336338        return false;
     339    }
    337340
    338341    return true;
     
    346349 * @param int $initiator_user_id ID of the first user.
    347350 * @param int $friend_user_id    ID of the second user.
    348  * @return int|null ID of the friendship if found, otherwise false.
     351 * @return int|null ID of the friendship if found, otherwise null.
    349352 */
    350353function friends_get_friendship_id( $initiator_user_id, $friend_user_id ) {
     
    407410 * @since 1.0.0
    408411 *
    409  * @see BP_Core_User::get_users() for a description of return value.
     412 * @see bp_core_get_users() for a description of return value.
    410413 *
    411414 * @param int    $user_id  ID of the user whose friends are being retrieved.
     
    445448 * @since 1.0.0
    446449 *
    447  * @see BP_Core_User::get_users() for a description of return value.
     450 * @see bp_core_get_users() for a description of return value.
    448451 *
    449452 * @param int    $user_id  ID of the user whose friends are being retrieved.
     
    483486 * @since 1.0.0
    484487 *
    485  * @see BP_Core_User::get_users() for a description of return value.
     488 * @see bp_core_get_users() for a description of return value.
    486489 *
    487490 * @param int    $user_id  ID of the user whose friends are being retrieved.
     
    525528 *
    526529 * @param array $friend_ids See BP_Friends_Friendship::get_bulk_last_active().
    527  * @return array $user_ids See BP_Friends_Friendship::get_bulk_last_active().
     530 * @return array See BP_Friends_Friendship::get_bulk_last_active().
    528531 */
    529532function friends_get_bulk_last_active( $friend_ids ) {
     
    547550
    548551    // Default to logged in user id.
    549     if ( empty( $user_id ) )
     552    if ( empty( $user_id ) ) {
    550553        $user_id = bp_loggedin_user_id();
     554    }
    551555
    552556    // Only group admins can invited previously banned users.
     
    561565     * @since 1.5.4
    562566     *
    563      * @param array $value Array of default parameters for invite list.
     567     * @param array $value {
     568     *     @type int    $user_id  User ID whose friends too see can be invited.
     569     *     @type string $type     Type of order to return a list of members.
     570     *     @type int    $per_page Number of friends per page.
     571     * }
    564572     */
    565     $args = apply_filters( 'bp_friends_pre_get_invite_list', array(
    566         'user_id'  => $user_id,
    567         'type'     => 'alphabetical',
    568         'per_page' => 0
    569     ) );
     573    $args = apply_filters(
     574        'bp_friends_pre_get_invite_list',
     575        array(
     576            'user_id'  => $user_id,
     577            'type'     => 'alphabetical',
     578            'per_page' => 0,
     579        )
     580    );
    570581
    571582    // User has friends.
     
    589600
    590601            // Skip friend if already in the group.
    591             if ( groups_is_user_member( $friend_user_id, $group_id ) )
     602            if ( groups_is_user_member( $friend_user_id, $group_id ) ) {
    592603                continue;
     604            }
    593605
    594606            // Skip friend if not group admin and user banned from group.
    595             if ( ( false === $user_is_admin ) && groups_is_user_banned( $friend_user_id, $group_id ) )
     607            if ( ( false === $user_is_admin ) && groups_is_user_banned( $friend_user_id, $group_id ) ) {
    596608                continue;
     609            }
    597610
    598611            // Friend is safe, so add it to the array of possible friends.
    599612            $friends[] = array(
    600613                'id'        => $friend_user_id,
    601                 'full_name' => bp_get_member_name()
     614                'full_name' => bp_get_member_name(),
    602615            );
    603616
     
    606619
    607620    // If no friends, explicitly set to false.
    608     if ( empty( $friends ) )
     621    if ( empty( $friends ) ) {
    609622        $friends = false;
     623    }
    610624
    611625    /**
     
    634648 * @param int $user_id  ID of the user whose friends are being counted.
    635649 * @param int $group_id ID of the group friends are being invited to.
    636  * @return int $invitable_count Eligible friend count.
     650 * @return int Eligible friend count.
    637651 */
    638652function friends_count_invitable_friends( $user_id, $group_id ) {
     
    667681 */
    668682function friends_search_users( $search_terms, $user_id, $pag_num = 0, $pag_page = 0 ) {
    669 
    670683    $user_ids = BP_Friends_Friendship::search_users( $search_terms, $user_id, $pag_num, $pag_page );
    671684
    672     if ( empty( $user_ids ) )
     685    if ( empty( $user_ids ) ) {
    673686        return false;
     687    }
    674688
    675689    $users = array();
    676     for ( $i = 0, $count = count( $user_ids ); $i < $count; ++$i )
    677         $users[] = new BP_Core_User( $user_ids[$i] );
    678 
    679     return array( 'users' => $users, 'count' => BP_Friends_Friendship::search_users_count( $search_terms ) );
     690    for ( $i = 0, $count = count( $user_ids ); $i < $count; ++$i ) {
     691        $users[] = new BP_Core_User( $user_ids[ $i ] );
     692    }
     693
     694    return array(
     695        'users' => $users,
     696        'count' => BP_Friends_Friendship::search_users_count( $search_terms ),
     697    );
    680698}
    681699
     
    690708function friends_is_friendship_confirmed( $friendship_id ) {
    691709    $friendship = new BP_Friends_Friendship( $friendship_id );
    692     return $friendship->is_confirmed;
     710    return (bool) $friendship->is_confirmed;
    693711}
    694712
     
    709727 */
    710728function friends_update_friend_totals( $initiator_user_id, $friend_user_id, $status = 'add' ) {
    711 
    712     if ( 'add' == $status ) {
    713         bp_update_user_meta( $initiator_user_id, 'total_friend_count', (int)bp_get_user_meta( $initiator_user_id, 'total_friend_count', true ) + 1 );
    714         bp_update_user_meta( $friend_user_id, 'total_friend_count', (int)bp_get_user_meta( $friend_user_id, 'total_friend_count', true ) + 1 );
     729    if ( 'add' === $status ) {
     730        bp_update_user_meta( $initiator_user_id, 'total_friend_count', (int) bp_get_user_meta( $initiator_user_id, 'total_friend_count', true ) + 1 );
     731        bp_update_user_meta( $friend_user_id, 'total_friend_count', (int) bp_get_user_meta( $friend_user_id, 'total_friend_count', true ) + 1 );
    715732    } else {
    716         bp_update_user_meta( $initiator_user_id, 'total_friend_count', (int)bp_get_user_meta( $initiator_user_id, 'total_friend_count', true ) - 1 );
    717         bp_update_user_meta( $friend_user_id, 'total_friend_count', (int)bp_get_user_meta( $friend_user_id, 'total_friend_count', true ) - 1 );
     733        bp_update_user_meta( $initiator_user_id, 'total_friend_count', (int) bp_get_user_meta( $initiator_user_id, 'total_friend_count', true ) - 1 );
     734        bp_update_user_meta( $friend_user_id, 'total_friend_count', (int) bp_get_user_meta( $friend_user_id, 'total_friend_count', true ) - 1 );
    718735    }
    719736}
     
    757774    do_action( 'friends_remove_data', $user_id );
    758775}
    759 add_action( 'wpmu_delete_user',  'friends_remove_data' );
     776add_action( 'wpmu_delete_user', 'friends_remove_data' );
    760777add_action( 'bp_make_spam_user', 'friends_remove_data' );
    761778
     
    806823
    807824    $friends_query = array(
    808         'count_total'     => '',                    // Prevents total count.
     825        'count_total'     => '', // Prevents total count.
    809826        'populate_extras' => false,
    810 
    811827        'type'            => 'alphabetical',
    812828        'user_id'         => get_current_user_id(),
     
    851867 */
    852868function friends_notification_new_request( $friendship_id, $initiator_id, $friend_id ) {
    853     if ( 'no' == bp_get_user_meta( (int) $friend_id, 'notification_friends_friendship_request', true ) ) {
     869    if ( 'no' === bp_get_user_meta( (int) $friend_id, 'notification_friends_friendship_request', true ) ) {
    854870        return;
    855871    }
     
    888904 */
    889905function friends_notification_accepted_request( $friendship_id, $initiator_id, $friend_id ) {
    890     if ( 'no' == bp_get_user_meta( (int) $initiator_id, 'notification_friends_friendship_accepted', true ) ) {
     906    if ( 'no' === bp_get_user_meta( (int) $initiator_id, 'notification_friends_friendship_accepted', true ) ) {
    891907        return;
    892908    }
     
    904920            'friendship.id'  => $friendship_id,
    905921            'initiator.id'   => $initiator_id,
    906             'unsubscribe'      => esc_url( bp_email_get_unsubscribe_link( $unsubscribe_args ) ),
     922            'unsubscribe'    => esc_url( bp_email_get_unsubscribe_link( $unsubscribe_args ) ),
    907923        ),
    908924    );
     
    921937 */
    922938function bp_friends_personal_data_exporter( $email_address, $page ) {
    923     $number = 50;
    924 
    925     $email_address = trim( $email_address );
    926 
     939    $number         = 50;
     940    $email_address  = trim( $email_address );
    927941    $data_to_export = array();
    928 
    929     $user = get_user_by( 'email', $email_address );
     942    $user           = get_user_by( 'email', $email_address );
    930943
    931944    if ( ! $user ) {
     
    941954        'per_page'     => $number,
    942955    ) );
    943 
    944     $user_data_to_export = array();
    945956
    946957    foreach ( $friendships as $friendship ) {
     
    9951006 */
    9961007function bp_friends_pending_sent_requests_personal_data_exporter( $email_address, $page ) {
    997     $number = 50;
    998 
    999     $email_address = trim( $email_address );
    1000 
     1008    $number         = 50;
     1009    $email_address  = trim( $email_address );
    10011010    $data_to_export = array();
    1002 
    1003     $user = get_user_by( 'email', $email_address );
     1011    $user           = get_user_by( 'email', $email_address );
    10041012
    10051013    if ( ! $user ) {
     
    10161024        'per_page'          => $number,
    10171025    ) );
    1018 
    1019     $user_data_to_export = array();
    10201026
    10211027    foreach ( $friendships as $friendship ) {
     
    10581064 */
    10591065function bp_friends_pending_received_requests_personal_data_exporter( $email_address, $page ) {
    1060     $number = 50;
    1061 
    1062     $email_address = trim( $email_address );
    1063 
     1066    $number         = 50;
     1067    $email_address  = trim( $email_address );
    10641068    $data_to_export = array();
    1065 
    1066     $user = get_user_by( 'email', $email_address );
     1069    $user           = get_user_by( 'email', $email_address );
    10671070
    10681071    if ( ! $user ) {
     
    10791082        'per_page'       => $number,
    10801083    ) );
    1081 
    1082     $user_data_to_export = array();
    10831084
    10841085    foreach ( $friendships as $friendship ) {
  • trunk/src/bp-friends/bp-friends-loader.php

    r11360 r13092  
    66 *
    77 * @package BuddyPress
    8  * @subpackage Friends
     8 * @subpackage FriendsLoader
    99 * @since 1.5.0
    1010 */
  • trunk/src/bp-friends/bp-friends-notifications.php

    r12597 r13092  
    4444            } else {
    4545                /* translators: %s: friend name */
    46                 $text = sprintf( __( '%s accepted your friendship request', 'buddypress' ),  bp_core_get_user_displayname( $item_id ) );
     46                $text = sprintf( __( '%s accepted your friendship request', 'buddypress' ), bp_core_get_user_displayname( $item_id ) );
    4747                $amount = 'single';
    4848            }
     
    6262            } else {
    6363                /* translators: %s: friend name */
    64                 $text = sprintf( __( 'You have a friendship request from %s', 'buddypress' ),  bp_core_get_user_displayname( $item_id ) );
     64                $text = sprintf( __( 'You have a friendship request from %s', 'buddypress' ), bp_core_get_user_displayname( $item_id ) );
    6565                $amount = 'single';
    6666            }
     
    7070
    7171    // Return either an HTML link or an array, depending on the requested format.
    72     if ( 'string' == $format ) {
     72    if ( 'string' === $format ) {
    7373
    7474        /**
     
    177177 * @since 1.9.0
    178178 *
    179  * @param int    $friendship_id Friendship ID (not used).
    180  * @param object $friendship    Friendship object.
     179 * @param int                   $friendship_id Friendship ID (not used).
     180 * @param BP_Friends_Friendship $friendship    The friendship object.
    181181 */
    182182function bp_friends_mark_friendship_rejected_notifications_by_item_id( $friendship_id, $friendship ) {
     
    216216 * @since 1.9.0
    217217 *
    218  * @param int    $friendship_id Friendship ID (not used).
    219  * @param object $friendship    Friendship Object.
     218 * @param int                   $friendship_id Friendship ID (not used).
     219 * @param BP_Friends_Friendship $friendship    The friendship object.
    220220 */
    221221function bp_friends_mark_friendship_withdrawn_notifications_by_item_id( $friendship_id, $friendship ) {
     
    243243function friends_screen_notification_settings() {
    244244
    245     if ( !$send_requests = bp_get_user_meta( bp_displayed_user_id(), 'notification_friends_friendship_request', true ) )
    246         $send_requests   = 'yes';
    247 
    248     if ( !$accept_requests = bp_get_user_meta( bp_displayed_user_id(), 'notification_friends_friendship_accepted', true ) )
     245    if ( ! $send_requests = bp_get_user_meta( bp_displayed_user_id(), 'notification_friends_friendship_request', true ) ) {
     246        $send_requests = 'yes';
     247    }
     248
     249    if ( ! $accept_requests = bp_get_user_meta( bp_displayed_user_id(), 'notification_friends_friendship_accepted', true ) )
    249250        $accept_requests = 'yes'; ?>
    250251
     
    253254            <tr>
    254255                <th class="icon"></th>
    255                 <th class="title"><?php _ex( 'Friends', 'Friend settings on notification settings page', 'buddypress' ) ?></th>
    256                 <th class="yes"><?php _e( 'Yes', 'buddypress' ) ?></th>
    257                 <th class="no"><?php _e( 'No', 'buddypress' )?></th>
     256                <th class="title"><?php _ex( 'Friends', 'Friend settings on notification settings page', 'buddypress' ); ?></th>
     257                <th class="yes"><?php esc_html_e( 'Yes', 'buddypress' ); ?></th>
     258                <th class="no"><?php esc_html_e( 'No', 'buddypress' ); ?></th>
    258259            </tr>
    259260        </thead>
     
    262263            <tr id="friends-notification-settings-request">
    263264                <td></td>
    264                 <td><?php _ex( 'A member sends you a friendship request', 'Friend settings on notification settings page', 'buddypress' ) ?></td>
     265                <td><?php _ex( 'A member sends you a friendship request', 'Friend settings on notification settings page', 'buddypress' ); ?></td>
    265266                <td class="yes"><input type="radio" name="notifications[notification_friends_friendship_request]" id="notification-friends-friendship-request-yes" value="yes" <?php checked( $send_requests, 'yes', true ) ?>/><label for="notification-friends-friendship-request-yes" class="bp-screen-reader-text"><?php
    266267                    /* translators: accessibility text */
    267                     _e( 'Yes, send email', 'buddypress' );
     268                    esc_html_e( 'Yes, send email', 'buddypress' );
    268269                ?></label></td>
    269270                <td class="no"><input type="radio" name="notifications[notification_friends_friendship_request]" id="notification-friends-friendship-request-no" value="no" <?php checked( $send_requests, 'no', true ) ?>/><label for="notification-friends-friendship-request-no" class="bp-screen-reader-text"><?php
    270271                    /* translators: accessibility text */
    271                     _e( 'No, do not send email', 'buddypress' );
     272                    esc_html_e( 'No, do not send email', 'buddypress' );
    272273                ?></label></td>
    273274            </tr>
     
    277278                <td class="yes"><input type="radio" name="notifications[notification_friends_friendship_accepted]" id="notification-friends-friendship-accepted-yes" value="yes" <?php checked( $accept_requests, 'yes', true ) ?>/><label for="notification-friends-friendship-accepted-yes" class="bp-screen-reader-text"><?php
    278279                    /* translators: accessibility text */
    279                     _e( 'Yes, send email', 'buddypress' );
     280                    esc_html_e( 'Yes, send email', 'buddypress' );
    280281                ?></label></td>
    281282                <td class="no"><input type="radio" name="notifications[notification_friends_friendship_accepted]" id="notification-friends-friendship-accepted-no" value="no" <?php checked( $accept_requests, 'no', true ) ?>/><label for="notification-friends-friendship-accepted-no" class="bp-screen-reader-text"><?php
    282283                    /* translators: accessibility text */
    283                     _e( 'No, do not send email', 'buddypress' );
     284                    esc_html_e( 'No, do not send email', 'buddypress' );
    284285                ?></label></td>
    285286            </tr>
  • trunk/src/bp-friends/bp-friends-template.php

    r12670 r13092  
    1515 *
    1616 * @since 1.5.0
    17  *
    1817 */
    1918function bp_friends_slug() {
     
    4342 *
    4443 * @since 1.5.0
    45  *
    4644 */
    4745function bp_friends_root_slug() {
     
    246244     * Return value is a string of the form "x friends".
    247245     *
     246     * @global object $members_template
     247     *
    248248     * @since 1.2.0
    249249     *
     
    296296        global $friends_template;
    297297
    298         if ( empty( $user_id ) && isset( $friends_template->friendship->friend ) )
     298        if ( empty( $user_id ) && isset( $friends_template->friendship->friend ) ) {
    299299            $user_id = $friends_template->friendship->friend->id;
    300         elseif ( empty( $user_id ) && !isset( $friends_template->friendship->friend ) )
     300        } elseif ( empty( $user_id ) && ! isset( $friends_template->friendship->friend ) ) {
    301301            $user_id = bp_displayed_user_id();
     302        }
    302303
    303304        /**
     
    320321 * @param int $user_id ID of the potential friend. Default: the value of
    321322 *                     {@link bp_get_potential_friend_id()}.
    322  * @return string 'is_friend', 'not_friends', or 'pending'.
     323 * @return bool|string 'is_friend', 'not_friends', or 'pending'.
    323324 */
    324325function bp_is_friend( $user_id = 0 ) {
    325326
    326     if ( !is_user_logged_in() )
     327    if ( ! is_user_logged_in() ) {
    327328        return false;
    328 
    329     if ( empty( $user_id ) )
     329    }
     330
     331    if ( empty( $user_id ) ) {
    330332        $user_id = bp_get_potential_friend_id( $user_id );
    331 
    332     if ( bp_loggedin_user_id() == $user_id )
     333    }
     334
     335    if ( bp_loggedin_user_id() === $user_id ) {
    333336        return false;
     337    }
    334338
    335339    /**
     
    338342     * @since 1.2.10
    339343     *
    340      * @param string $value String status of friendship. Possible values are 'is_friend', 'not_friends', 'pending'.
     344     * @param string $value   String status of friendship. Possible values are 'is_friend', 'not_friends', 'pending'.
     345     * @param int    $user_id ID of the potential friend.
    341346     */
    342347    return apply_filters( 'bp_is_friend', friends_check_friendship_status( bp_loggedin_user_id(), $user_id ), $user_id );
     
    364369     *                                  applies. Default: value of {@link bp_get_potential_friend_id()}.
    365370     * @param bool $friend_status       Not currently used.
    366      * @return false|string HTML for the Add Friend button.
     371     * @return bool|string HTML for the Add Friend button. False if already friends.
    367372     */
    368373    function bp_get_add_friend_button( $potential_friend_id = 0, $friend_status = false ) {
    369374
    370         if ( empty( $potential_friend_id ) )
     375        if ( empty( $potential_friend_id ) ) {
    371376            $potential_friend_id = bp_get_potential_friend_id( $potential_friend_id );
     377        }
    372378
    373379        $is_friend = bp_is_friend( $potential_friend_id );
    374380
    375         if ( empty( $is_friend ) )
     381        if ( empty( $is_friend ) ) {
    376382            return false;
     383        }
    377384
    378385        switch ( $is_friend ) {
    379             case 'pending' :
     386            case 'pending':
    380387                $button = array(
    381388                    'id'                => 'pending',
     
    389396                    'link_id'           => 'friend-' . $potential_friend_id,
    390397                    'link_rel'          => 'remove',
    391                     'link_class'        => 'friendship-button pending_friend requested'
     398                    'link_class'        => 'friendship-button pending_friend requested',
    392399                );
    393400                break;
    394401
    395             case 'awaiting_response' :
     402            case 'awaiting_response':
    396403                $button = array(
    397404                    'id'                => 'awaiting_response',
     
    405412                    'link_id'           => 'friend-' . $potential_friend_id,
    406413                    'link_rel'          => 'remove',
    407                     'link_class'        => 'friendship-button awaiting_response_friend requested'
     414                    'link_class'        => 'friendship-button awaiting_response_friend requested',
    408415                );
    409416                break;
    410417
    411             case 'is_friend' :
     418            case 'is_friend':
    412419                $button = array(
    413420                    'id'                => 'is_friend',
     
    421428                    'link_id'           => 'friend-' . $potential_friend_id,
    422429                    'link_rel'          => 'remove',
    423                     'link_class'        => 'friendship-button is_friend remove'
     430                    'link_class'        => 'friendship-button is_friend remove',
    424431                );
    425432                break;
     
    437444                    'link_id'           => 'friend-' . $potential_friend_id,
    438445                    'link_rel'          => 'add',
    439                     'link_class'        => 'friendship-button not_friends add'
     446                    'link_class'        => 'friendship-button not_friends add',
    440447                );
    441448                break;
     
    459466 * @param int $user_id Optional. Default: the displayed user's ID, or the
    460467 *                     logged-in user's ID.
    461  * @return false|string A comma-separated list of friend IDs if any are found,
     468 * @return bool|string A comma-separated list of friend IDs if any are found,
    462469 *                      otherwise false.
    463470 */
    464471function bp_get_friend_ids( $user_id = 0 ) {
    465472
    466     if ( empty( $user_id ) )
     473    if ( empty( $user_id ) ) {
    467474        $user_id = ( bp_displayed_user_id() ) ? bp_displayed_user_id() : bp_loggedin_user_id();
     475    }
    468476
    469477    $friend_ids = friends_get_friend_user_ids( $user_id );
    470478
    471     if ( empty( $friend_ids ) )
     479    if ( empty( $friend_ids ) ) {
    472480        return false;
     481    }
    473482
    474483    return implode( ',', friends_get_friend_user_ids( $user_id ) );
     
    488497 */
    489498function bp_get_friendship_requests( $user_id = 0 ) {
    490     if ( !$user_id ) {
     499    if ( ! $user_id ) {
    491500        $user_id = bp_displayed_user_id();
    492501    }
    493502
    494     if ( !$user_id ) {
     503    if ( ! $user_id ) {
    495504        return 0;
    496505    }
     
    498507    $requests = friends_get_friendship_request_user_ids( $user_id );
    499508
    500     if ( !empty( $requests ) ) {
     509    if ( ! empty( $requests ) ) {
    501510        $requests = implode( ',', (array) $requests );
    502511    } else {
     
    529538     * @since 1.2.0
    530539     *
     540     * @global object $members_template
     541     *
    531542     * @return int ID of the friendship.
    532543     */
     
    562573     * @since 1.0.0
    563574     *
     575     * @global object $members_template
     576     *
    564577     * @return string accept-friendship URL.
    565578     */
     
    597610     * @since 1.0.0
    598611     *
     612     * @global object $members_template
     613     *
    599614     * @return string reject-friendship URL.
    600615     */
     
    656671 * @since 1.2.0
    657672 *
    658  * @see bp_friend_get_total_requests_count() for description of arguments.
    659  *
    660  * @param int $user_id See {@link bp_friend_get_total_requests_count().
     673 * @param int $user_id ID of the user whose requests are being counted.
     674 *                     Default: ID of the logged-in user.
    661675 */
    662676function bp_friend_total_requests_count( $user_id = 0 ) {
     
    673687     */
    674688    function bp_friend_get_total_requests_count( $user_id = 0 ) {
    675         if ( empty( $user_id ) )
     689        if ( empty( $user_id ) ) {
    676690            $user_id = bp_loggedin_user_id();
     691        }
    677692
    678693        /**
  • trunk/src/bp-friends/bp-friends-widgets.php

    r11381 r13092  
    44 *
    55 * @package BuddyPress
    6  * @subpackage Friends
     6 * @subpackage FriendsWidgets
    77 * @since 1.9.0
    88 */
     
    2828    }
    2929
    30     add_action( 'widgets_init', function() { register_widget( 'BP_Core_Friends_Widget' ); } );
     30    add_action(
     31        'widgets_init',
     32        function() {
     33            register_widget( 'BP_Core_Friends_Widget' );
     34        }
     35    );
    3136}
    3237add_action( 'bp_register_widgets', 'bp_friends_register_widgets' );
     
    8792    <?php else: ?>
    8893        <?php echo "-1[[SPLIT]]<li>"; ?>
    89         <?php _e( 'There were no members found, please try another filter.', 'buddypress' ); ?>
     94        <?php esc_html_e( 'There were no members found, please try another filter.', 'buddypress' ); ?>
    9095        <?php echo "</li>"; ?>
    9196    <?php endif;
  • trunk/src/bp-friends/classes/class-bp-core-friends-widget.php

    r12997 r13092  
    44 *
    55 * @package BuddyPress
    6  * @subpackage Friends
     6 * @subpackage FriendsWidget
    77 * @since 1.9.0
    88 */
     
    2424     * @since 9.0.0 Adds the `show_instance_in_rest` property to Widget options.
    2525     */
    26     function __construct() {
     26    public function __construct() {
    2727        $widget_ops = array(
    2828            'description'                 => __( 'A dynamic list of recently active, popular, and newest Friends of the displayed member. Widget is only shown when viewing a member profile.', 'buddypress' ),
     
    5353     * @since 1.9.0
    5454     *
     55     * @global object $members_template
     56     *
    5557     * @param array $args Widget arguments.
    5658     * @param array $instance The widget settings, as saved by the user.
    5759     */
    58     function widget( $args, $instance ) {
     60    public function widget( $args, $instance ) {
    5961        global $members_template;
    6062
     
    6567        }
    6668
    67         $user_id = bp_displayed_user_id();
    68         $link = trailingslashit( bp_displayed_user_domain() . bp_get_friends_slug() );
     69        $user_id           = bp_displayed_user_id();
     70        $link              = trailingslashit( bp_displayed_user_domain() . bp_get_friends_slug() );
    6971        $instance['title'] = sprintf( __( "%s's Friends", 'buddypress' ), bp_get_displayed_user_fullname() );
    7072
     
    159161     * @return array $instance The processed settings to save.
    160162     */
    161     function update( $new_instance, $old_instance ) {
     163    public function update( $new_instance, $old_instance ) {
    162164        $instance = $old_instance;
    163165
     
    175177     *
    176178     * @param array $instance The saved widget settings.
    177      * @return void
    178      */
    179     function form( $instance ) {
     179     */
     180    public function form( $instance ) {
    180181        $defaults = array(
    181             'max_friends'   => 5,
     182            'max_friends'   => 5,
    182183            'friend_default' => 'active',
    183             'link_title'     => false
     184            'link_title'     => false,
    184185        );
    185         $instance = wp_parse_args( (array) $instance, $defaults );
    186 
    187         $max_friends    = $instance['max_friends'];
     186
     187        $instance       = wp_parse_args( (array) $instance, $defaults );
     188        $max_friends    = $instance['max_friends'];
    188189        $friend_default = $instance['friend_default'];
    189         $link_title = (bool) $instance['link_title'];
     190        $link_title     = (bool) $instance['link_title'];
    190191        ?>
    191192
    192193        <p><label for="<?php echo $this->get_field_id( 'link_title' ); ?>"><input type="checkbox" name="<?php echo $this->get_field_name('link_title'); ?>" id="<?php echo $this->get_field_id( 'link_title' ); ?>" value="1" <?php checked( $link_title ); ?> /> <?php _e( 'Link widget title to Members directory', 'buddypress' ); ?></label></p>
    193194
    194         <p><label for="<?php echo $this->get_field_id( 'max_friends' ); ?>"><?php _e( 'Max friends to show:', 'buddypress' ); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'max_friends' ); ?>" name="<?php echo $this->get_field_name( 'max_friends' ); ?>" type="text" value="<?php echo absint( $max_friends ); ?>" style="width: 30%" /></label></p>
     195        <p><label for="<?php echo $this->get_field_id( 'max_friends' ); ?>"><?php esc_html_e( 'Max friends to show:', 'buddypress' ); ?> <input class="widefat" id="<?php echo $this->get_field_id( 'max_friends' ); ?>" name="<?php echo $this->get_field_name( 'max_friends' ); ?>" type="text" value="<?php echo absint( $max_friends ); ?>" style="width: 30%" /></label></p>
    195196
    196197        <p>
    197             <label for="<?php echo $this->get_field_id( 'friend_default' ) ?>"><?php _e( 'Default friends to show:', 'buddypress' ); ?></label>
     198            <label for="<?php echo $this->get_field_id( 'friend_default' ) ?>"><?php esc_html_e( 'Default friends to show:', 'buddypress' ); ?></label>
    198199            <select name="<?php echo $this->get_field_name( 'friend_default' ); ?>" id="<?php echo $this->get_field_id( 'friend_default' ); ?>">
    199                 <option value="newest" <?php selected( $friend_default, 'newest' ); ?>><?php _e( 'Newest', 'buddypress' ); ?></option>
    200                 <option value="active" <?php selected( $friend_default, 'active' );?>><?php _e( 'Active', 'buddypress' ); ?></option>
    201                 <option value="popular"  <?php selected( $friend_default, 'popular' ); ?>><?php _e( 'Popular', 'buddypress' ); ?></option>
     200                <option value="newest" <?php selected( $friend_default, 'newest' ); ?>><?php esc_html_e( 'Newest', 'buddypress' ); ?></option>
     201                <option value="active" <?php selected( $friend_default, 'active' ); ?>><?php esc_html_e( 'Active', 'buddypress' ); ?></option>
     202                <option value="popular"  <?php selected( $friend_default, 'popular' ); ?>><?php esc_html_e( 'Popular', 'buddypress' ); ?></option>
    202203            </select>
    203204        </p>
    204 
    205205    <?php
    206206    }
  • trunk/src/bp-friends/classes/class-bp-friends-component.php

    r13002 r13092  
    66 *
    77 * @package BuddyPress
    8  * @subpackage Friends
     8 * @subpackage FriendsComponent
    99 * @since 1.5.0
    1010 */
     
    3131            buddypress()->plugin_dir,
    3232            array(
    33                 'adminbar_myaccount_order' => 60
     33                'adminbar_myaccount_order' => 60,
    3434            )
    3535        );
     
    104104     *
    105105     * @since 1.5.0
     106     *
     107     * @global BuddyPress $bp The one true BuddyPress instance.
    106108     *
    107109     * @see BP_Component::setup_globals() for description of parameters.
     
    194196            'screen_function'     => 'friends_screen_my_friends',
    195197            'default_subnav_slug' => 'my-friends',
    196             'item_css_id'         => $this->id
     198            'item_css_id'         => $this->id,
    197199        );
    198200
     
    205207            'screen_function' => 'friends_screen_my_friends',
    206208            'position'        => 10,
    207             'item_css_id'     => 'friends-my-friends'
     209            'item_css_id'     => 'friends-my-friends',
    208210        );
    209211
     
    215217            'screen_function' => 'friends_screen_requests',
    216218            'position'        => 20,
    217             'user_has_access' => $access
     219            'user_has_access' => $access,
    218220        );
    219221
     
    241243            // Pending friend requests.
    242244            $count = count( friends_get_friendship_request_user_ids( bp_loggedin_user_id() ) );
    243             if ( !empty( $count ) ) {
     245            if ( ! empty( $count ) ) {
    244246                $title = sprintf(
    245247                    /* translators: %s: Pending friend request count for the current user */
     
    253255                );
    254256            } else {
    255                 $title   = _x( 'Friends',            'My Account Friends menu',        'buddypress' );
    256                 $pending = _x( 'No Pending Requests','My Account Friends menu sub nav', 'buddypress' );
     257                $title   = _x( 'Friends', 'My Account Friends menu', 'buddypress' );
     258                $pending = _x( 'No Pending Requests', 'My Account Friends menu sub nav', 'buddypress' );
    257259            }
    258260
     
    262264                'id'     => 'my-account-' . $this->id,
    263265                'title'  => $title,
    264                 'href'   => $friends_link
     266                'href'   => $friends_link,
    265267            );
    266268
     
    271273                'title'    => _x( 'Friendships', 'My Account Friends menu sub nav', 'buddypress' ),
    272274                'href'     => $friends_link,
    273                 'position' => 10
     275                'position' => 10,
    274276            );
    275277
     
    280282                'title'    => $pending,
    281283                'href'     => trailingslashit( $friends_link . 'requests' ),
    282                 'position' => 20
     284                'position' => 20,
    283285            );
    284286        }
     
    291293     *
    292294     * @since 1.5.0
     295     *
     296     * @global BuddyPress $bp The one true BuddyPress instance.
    293297     */
    294298    public function setup_title() {
  • trunk/src/bp-friends/classes/class-bp-friends-friendship.php

    r13086 r13092  
    44 *
    55 * @package BuddyPress
    6  * @subpackage FriendsClasses
     6 * @subpackage FriendsFriendship
    77 * @since 1.0.0
    88 */
     
    132132     *
    133133     * @since 1.0.0
     134     *
     135     * @global BuddyPress $bp The one true BuddyPress instance.
     136     * @global wpdb $wpdb WordPress database object.
    134137     */
    135138    public function populate() {
     
    161164
    162165        if ( ! empty( $this->populate_friend_details ) ) {
    163             if ( $this->friend_user_id == bp_displayed_user_id() ) {
     166            if ( bp_displayed_user_id() === $this->friend_user_id ) {
    164167                $this->friend = new BP_Core_User( $this->initiator_user_id );
    165168            } else {
     
    174177     * @since 1.0.0
    175178     *
     179     * @global BuddyPress $bp The one true BuddyPress instance.
     180     * @global wpdb $wpdb WordPress database object.
     181     *
    176182     * @return bool True on success, false on failure.
    177183     */
     
    182188
    183189        $this->initiator_user_id = apply_filters( 'friends_friendship_initiator_user_id_before_save', $this->initiator_user_id, $this->id );
    184         $this->friend_user_id    = apply_filters( 'friends_friendship_friend_user_id_before_save',    $this->friend_user_id,    $this->id );
    185         $this->is_confirmed      = apply_filters( 'friends_friendship_is_confirmed_before_save',      $this->is_confirmed,      $this->id );
    186         $this->is_limited        = apply_filters( 'friends_friendship_is_limited_before_save',        $this->is_limited,        $this->id );
    187         $this->date_created      = apply_filters( 'friends_friendship_date_created_before_save',      $this->date_created,      $this->id );
     190        $this->friend_user_id    = apply_filters( 'friends_friendship_friend_user_id_before_save', $this->friend_user_id, $this->id );
     191        $this->is_confirmed      = apply_filters( 'friends_friendship_is_confirmed_before_save', $this->is_confirmed, $this->id );
     192        $this->is_limited        = apply_filters( 'friends_friendship_is_limited_before_save', $this->is_limited, $this->id );
     193        $this->date_created      = apply_filters( 'friends_friendship_date_created_before_save', $this->date_created, $this->id );
    188194
    189195        /**
     
    192198         * @since 1.0.0
    193199         *
    194          * @param BP_Friends_Friendship $value Current friendship request object.
     200         * @param BP_Friends_Friendship $value Current friendship object. Passed by reference.
    195201         */
    196202        do_action_ref_array( 'friends_friendship_before_save', array( &$this ) );
    197203
    198204        // Update.
    199         if (!empty( $this->id ) ) {
     205        if ( ! empty( $this->id ) ) {
    200206            $result = $wpdb->query( $wpdb->prepare( "UPDATE {$bp->friends->table_name} SET initiator_user_id = %d, friend_user_id = %d, is_confirmed = %d, is_limited = %d, date_created = %s WHERE id = %d", $this->initiator_user_id, $this->friend_user_id, $this->is_confirmed, $this->is_limited, $this->date_created, $this->id ) );
    201207
     
    211217         * @since 1.0.0
    212218         *
    213          * @param BP_Friends_Friendship $value Current friendship request object.
     219         * @param BP_Friends_Friendship $value Current friendship object. Passed by reference.
    214220         */
    215221        do_action_ref_array( 'friends_friendship_after_save', array( &$this ) );
     
    223229     * @since 1.0.0
    224230     *
     231     * @global BuddyPress $bp The one true BuddyPress instance.
     232     * @global wpdb $wpdb WordPress database object.
     233     *
    225234     * @return bool|int
    226235     */
     
    240249     * @since 2.6.0
    241250     *
    242      * @param int   $user_id              ID of the user whose friends are being retrieved.
    243      * @param array $args {
     251     * @param int    $user_id  ID of the user whose friends are being retrieved.
     252     * @param array  $args    {
    244253     *        Optional. Filter parameters.
    245254     *        @type int    $id                ID of specific friendship to retrieve.
     
    251260     *        @type string $sort_order        ASC or DESC. Default DESC.
    252261     * }
    253      * @param string $operator            Optional. Operator to use in `wp_list_filter()`.
     262     * @param string $operator Optional. Operator to use in `wp_list_filter()`.
    254263     *
    255264     * @return array $friendships Array of friendship objects.
     
    376385     * @since 2.7.0
    377386     *
     387     * @global BuddyPress $bp The one true BuddyPress instance.
     388     * @global wpdb $wpdb WordPress database object.
     389     *
    378390     * @param int $user_id ID of the user.
    379391     * @return array
     
    403415     */
    404416    public static function get_friend_user_ids( $user_id, $friend_requests_only = false, $assoc_arr = false ) {
    405         global $wpdb;
    406417
    407418        if ( ! empty( $friend_requests_only ) ) {
    408419            $args = array(
    409                 'is_confirmed' => 0,
    410                 'friend_user_id' => $user_id
     420                'is_confirmed'   => 0,
     421                'friend_user_id' => $user_id,
    411422            );
    412423        } else {
     
    443454
    444455        // Can't friend yourself.
    445         if ( $user_id == $friend_id ) {
     456        if ( $user_id === $friend_id ) {
    446457            return $friendship_id;
    447458        }
     
    453464        $args = array(
    454465            'initiator_user_id' => $friend_id,
    455             'friend_user_id'    => $friend_id
     466            'friend_user_id'    => $friend_id,
    456467        );
     468
    457469        $result = self::get_friendships( $user_id, $args, 'OR' );
    458470        if ( $result ) {
     
    469481     * @param int $user_id The ID of the user who has received the
    470482     *                     friendship requests.
    471      * @return array|bool An array of user IDs, or false if none are found.
     483     * @return array|bool An array of user IDs or false if none are found.
    472484     */
    473485    public static function get_friendship_request_user_ids( $user_id ) {
     
    499511     */
    500512    public static function total_friend_count( $user_id = 0 ) {
    501         global $wpdb;
    502513
    503514        if ( empty( $user_id ) ) {
     
    510521         */
    511522
    512         $args = array(
    513             'is_confirmed' => 1,
    514         );
     523        $args        = array( 'is_confirmed' => 1 );
    515524        $friendships = self::get_friendships( $user_id, $args );
    516525        $count       = count( $friendships );
     
    529538     * Search the friends of a user by a search string.
    530539     *
    531      * @since 1.0.0
     540     * @todo Optimize this function.
     541     *
     542     * @since 1.0.0
     543     *
     544     * @global BuddyPress $bp The one true BuddyPress instance.
     545     * @global wpdb $wpdb WordPress database object.
    532546     *
    533547     * @param string   $filter  The search string, matched against xprofile
     
    546560        global $wpdb;
    547561
    548         /*
    549          * TODO: Optimize this function.
    550          */
    551 
    552         if ( empty( $user_id ) )
     562        $bp = buddypress();
     563
     564        if ( empty( $user_id ) ) {
    553565            $user_id = bp_loggedin_user_id();
     566        }
    554567
    555568        // Only search for matching strings at the beginning of the
     
    558571
    559572        $pag_sql = '';
    560         if ( !empty( $limit ) && !empty( $page ) )
     573        if ( ! empty( $limit ) && ! empty( $page ) ) {
    561574            $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
    562 
    563         if ( !$friend_ids = BP_Friends_Friendship::get_friend_user_ids( $user_id ) )
     575        }
     576
     577        $friend_ids = self::get_friend_user_ids( $user_id );
     578        if ( ! $friend_ids ) {
    564579            return false;
     580        }
    565581
    566582        // Get all the user ids for the current user's friends.
    567583        $fids = implode( ',', wp_parse_id_list( $friend_ids ) );
    568584
    569         if ( empty( $fids ) )
     585        if ( empty( $fids ) ) {
    570586            return false;
    571 
    572         $bp = buddypress();
     587        }
    573588
    574589        // Filter the user_ids based on the search criteria.
     
    584599        $total_friend_ids    = $wpdb->get_var( $total_sql );
    585600
    586         if ( empty( $filtered_friend_ids ) )
     601        if ( empty( $filtered_friend_ids ) ) {
    587602            return false;
    588 
    589         return array( 'friends' => array_map( 'intval', $filtered_friend_ids ), 'total' => (int) $total_friend_ids );
     603        }
     604
     605        return array(
     606            'friends' => array_map( 'intval', $filtered_friend_ids ),
     607            'total'   => (int) $total_friend_ids,
     608        );
    590609    }
    591610
     
    608627     */
    609628    public static function check_is_friend( $initiator_userid, $possible_friend_userid ) {
    610         global $wpdb;
    611629
    612630        if ( empty( $initiator_userid ) || empty( $possible_friend_userid ) ) {
     
    615633
    616634        // Can't friend yourself.
    617         if ( $initiator_userid == $possible_friend_userid ) {
     635        if ( $initiator_userid === $possible_friend_userid ) {
    618636            return 'not_friends';
    619637        }
    620638
    621         BP_Friends_Friendship::update_bp_friends_cache( $initiator_userid, $possible_friend_userid );
     639        self::update_bp_friends_cache( $initiator_userid, $possible_friend_userid );
    622640
    623641        return bp_core_get_incremented_cache( $initiator_userid . ':' . $possible_friend_userid, 'bp_friends' );
    624642    }
    625643
    626 
    627644    /**
    628645     * Find uncached friendships between a user and one or more other users and cache them.
     
    630647     * @since 3.0.0
    631648     *
    632      * @param int $user_id                          The ID of the primary user for whom we want
     649     * @global BuddyPress $bp The one true BuddyPress instance.
     650     * @global wpdb $wpdb WordPress database object.
     651     *
     652     * @param int              $user_id             The ID of the primary user for whom we want
    633653     *                                              to check friendships statuses.
    634654     * @param int|array|string $possible_friend_ids The IDs of the one or more users
    635655     *                                              to check friendship status with primary user.
    636      * @return null
    637656     */
    638657    public static function update_bp_friends_cache( $user_id, $possible_friend_ids ) {
    639658        global $wpdb;
    640         $bp = buddypress();
     659
     660        $bp                  = buddypress();
    641661        $possible_friend_ids = wp_parse_id_list( $possible_friend_ids );
    642662
     
    649669            }
    650670        }
     671
    651672        if ( empty( $fetch ) ) {
    652673            return;
     
    695716     */
    696717    public static function get_bulk_last_active( $user_ids ) {
    697         global $wpdb;
    698 
    699718        $last_activities = BP_Core_User::get_last_activity( $user_ids );
    700719
    701720        // Sort and structure as expected in legacy function.
    702721        usort( $last_activities, function( $a, $b ) {
    703             if ( $a['date_recorded'] == $b['date_recorded'] ) {
     722            if ( $a['date_recorded'] === $b['date_recorded'] ) {
    704723                return 0;
    705724            }
     
    710729        $retval = array();
    711730        foreach ( $last_activities as $last_activity ) {
    712             $u = new stdClass;
     731            $u                = new stdClass();
    713732            $u->last_activity = $last_activity['date_recorded'];
    714733            $u->user_id       = $last_activity['user_id'];
     
    725744     * @since 1.0.0
    726745     *
     746     * @global BuddyPress $bp The one true BuddyPress instance.
     747     * @global wpdb $wpdb WordPress database object.
     748     *
    727749     * @param int $friendship_id ID of the friendship to be accepted.
    728750     * @return int Number of database rows updated.
    729751     */
    730     public static function accept($friendship_id) {
     752    public static function accept( $friendship_id ) {
    731753        global $wpdb;
    732754
     
    740762     *
    741763     * @since 1.6.0
     764     *
     765     * @global BuddyPress $bp The one true BuddyPress instance.
     766     * @global wpdb $wpdb WordPress database object.
    742767     *
    743768     * @param int $friendship_id ID of the friendship to be withdrawn.
    744769     * @return int Number of database rows deleted.
    745770     */
    746     public static function withdraw($friendship_id) {
     771    public static function withdraw( $friendship_id ) {
    747772        global $wpdb;
    748773
     
    756781     *
    757782     * @since 1.0.0
     783     *
     784     * @global BuddyPress $bp The one true BuddyPress instance.
     785     * @global wpdb $wpdb WordPress database object.
    758786     *
    759787     * @param int $friendship_id ID of the friendship to be rejected.
    760788     * @return int Number of database rows deleted.
    761789     */
    762     public static function reject($friendship_id) {
     790    public static function reject( $friendship_id ) {
    763791        global $wpdb;
    764792
     
    774802     *
    775803     * @since 1.0.0
     804     *
     805     * @global BuddyPress $bp The one true BuddyPress instance.
     806     * @global wpdb $wpdb WordPress database object.
    776807     *
    777808     * @param string   $filter  String to search by.
     
    793824
    794825        $pag_sql = '';
    795         if ( !empty( $limit ) && !empty( $page ) )
     826        if ( ! empty( $limit ) && ! empty( $page ) ) {
    796827            $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * intval( $limit ) ), intval( $limit ) );
     828        }
    797829
    798830        $bp = buddypress();
     
    805837        }
    806838
    807         $filtered_fids = $wpdb->get_col($sql);
    808 
    809         if ( empty( $filtered_fids ) )
     839        $filtered_fids = $wpdb->get_col( $sql );
     840
     841        if ( empty( $filtered_fids ) ) {
    810842            return false;
     843        }
    811844
    812845        return $filtered_fids;
     
    819852     *
    820853     * @since 1.0.0
     854     *
     855     * @global BuddyPress $bp The one true BuddyPress instance.
     856     * @global wpdb $wpdb WordPress database object.
    821857     *
    822858     * @param string $filter Search term.
     
    842878        }
    843879
    844         $user_count = $wpdb->get_col($sql);
    845 
    846         if ( empty( $user_count ) )
     880        $user_count = $wpdb->get_col( $sql );
     881
     882        if ( empty( $user_count ) ) {
    847883            return false;
     884        }
    848885
    849886        return $user_count[0];
     
    857894     * @since 1.0.0
    858895     *
     896     * @global BuddyPress $bp The one true BuddyPress instance.
     897     * @global wpdb $wpdb WordPress database object.
     898     *
    859899     * @param array $user_ids Array of user IDs.
    860      * @return array User IDs, sorted by the associated display names.
     900     * @return array|bool User IDs, sorted by the associated display names.
     901     *                    False if XProfile component is not active.
    861902     */
    862903    public static function sort_by_name( $user_ids ) {
    863904        global $wpdb;
    864905
    865         if ( !bp_is_active( 'xprofile' ) )
     906        if ( ! bp_is_active( 'xprofile' ) ) {
    866907            return false;
     908        }
    867909
    868910        $bp = buddypress();
     
    877919     *
    878920     * @since 1.0.0
     921     *
     922     * @global BuddyPress $bp The one true BuddyPress instance.
     923     * @global wpdb $wpdb WordPress database object.
    879924     *
    880925     * @param int $user_id       ID of the user whose friends are being retrieved.
     
    893938
    894939        for ( $i = 0, $count = count( $results ); $i < $count; ++$i ) {
    895             $fids[] = ( $results[$i]->friend_user_id == $user_id ) ? $results[$i]->initiator_user_id : $results[$i]->friend_user_id;
     940            $fids[] = ( $results[ $i ]->friend_user_id === $user_id ) ? $results[ $i ]->initiator_user_id : $results[ $i ]->friend_user_id;
    896941        }
    897942
    898943        // Remove duplicates.
    899         if ( count( $fids ) > 0 )
     944        if ( count( $fids ) > 0 ) {
    900945            return array_flip( array_flip( $fids ) );
    901         else
    902             return false;
     946        }
     947
     948        return false;
    903949    }
    904950
     
    912958     * - users who have been banned from the group
    913959     *
    914      * @since 1.0.0
    915960     * @todo Need to do a group component check before using group functions.
     961     *
     962     * @since 1.0.0
    916963     *
    917964     * @param int $user_id  ID of the user whose friends are being counted.
    918965     * @param int $group_id ID of the group friends are being invited to.
    919      * @return int $invitable_count Eligible friend count.
     966     * @return bool|int False if group component is not active, and friend count.
    920967     */
    921968    public static function get_invitable_friend_count( $user_id, $group_id ) {
     969
     970        if ( ! bp_is_active( 'group' ) ) {
     971            return false;
     972        }
    922973
    923974        // Setup some data we'll use below.
    924975        $is_group_admin  = groups_is_user_admin( $user_id, $group_id );
    925         $friend_ids      = BP_Friends_Friendship::get_friend_user_ids( $user_id );
     976        $friend_ids      = self::get_friend_user_ids( $user_id );
    926977        $invitable_count = 0;
    927978
     
    929980
    930981            // If already a member, they cannot be invited again.
    931             if ( groups_is_user_member( (int) $friend_ids[$i], $group_id ) ) {
     982            if ( groups_is_user_member( (int) $friend_ids[ $i ], $group_id ) ) {
    932983                continue;
    933984            }
    934985
    935986            // If user already has invite, they cannot be added.
    936             if ( groups_check_user_has_invite( (int) $friend_ids[$i], $group_id ) ) {
     987            if ( groups_check_user_has_invite( (int) $friend_ids[ $i ], $group_id ) ) {
    937988                continue;
    938989            }
    939990
    940991            // If user is not group admin and friend is banned, they cannot be invited.
    941             if ( ( false === $is_group_admin ) && groups_is_user_banned( (int) $friend_ids[$i], $group_id ) ) {
     992            if ( ( false === $is_group_admin ) && groups_is_user_banned( (int) $friend_ids[ $i ], $group_id ) ) {
    942993                continue;
    943994            }
     
    9531004     *
    9541005     * @since 2.7.0
     1006     *
     1007     * @global BuddyPress $bp The one true BuddyPress instance.
     1008     * @global wpdb $wpdb WordPress database object.
    9551009     *
    9561010     * @param int|string|array $friendship_ids Single friendship ID or comma-separated/array list of friendship IDs.
     
    9721026     *
    9731027     * @param int $friendship_id ID of the friendship.
    974      * @return null|stdClass friend_user_id and initiator_user_id.
     1028     * @return null|stdClass
    9751029     */
    9761030    public static function get_user_ids_for_friendship( $friendship_id ) {
    977 
    9781031        $friendship = new BP_Friends_Friendship( $friendship_id, false, false );
    9791032
     
    9821035        }
    9831036
    984         $retval = new StdClass;
    985         $retval->friend_user_id = $friendship->friend_user_id;
     1037        $retval                    = new StdClass();
     1038        $retval->friend_user_id    = $friendship->friend_user_id;
    9861039        $retval->initiator_user_id = $friendship->initiator_user_id;
    9871040
     
    9931046     *
    9941047     * @since 1.0.0
     1048     *
     1049     * @global BuddyPress $bp The one true BuddyPress instance.
     1050     * @global wpdb $wpdb WordPress database object.
    9951051     *
    9961052     * @param int $user_id ID of the user being expunged.
     
    10331089            // Delete cached friendships.
    10341090            wp_cache_delete( $friend_id, 'bp_friends_friendships_for_user' );
    1035             BP_Friends_Friendship::total_friend_count( $friend_id );
     1091
     1092            self::total_friend_count( $friend_id );
    10361093        }
    10371094
Note: See TracChangeset for help on using the changeset viewer.