Skip to:
Content

BuddyPress.org


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

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

Also, adding several minor PHP changes.

See #8553

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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 ) {
Note: See TracChangeset for help on using the changeset viewer.