Skip to:
Content

BuddyPress.org

Changeset 13893


Ignore:
Timestamp:
06/02/2024 02:07:21 AM (2 years ago)
Author:
espellcaste
Message:

WPCS: Part VII: miscellaneous fixes for some of the files of the core component.

Follow-up to [13883], [13886], [13887], [13888], [13891], and [13892]

See #9164 and #7228

Location:
trunk/src/bp-core
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/bp-core-functions.php

    r13890 r13893  
    31853185                 * @since 2.5.0
    31863186                 *
    3187                  * @param string $value Email post type name.
     3187                 * @param string $email_post_type Email post type name.
    31883188                 */
    31893189                return apply_filters( 'bp_get_email_post_type', buddypress()->email_post_type );
  • trunk/src/bp-core/classes/class-bp-core-user.php

    r13890 r13893  
    131131         *
    132132         * @param integer $user_id         The ID for the user being queried.
    133          * @param bool    $populate_extras Whether to fetch extra information such as
     133         * @param bool    $populate_extras Optional. Whether to fetch extra information such as
    134134         *                                 group/friendship counts or not. Default: false.
    135135         */
    136136        public function __construct( $user_id, $populate_extras = false ) {
    137                 if ( !empty( $user_id ) ) {
     137                if ( ! empty( $user_id ) ) {
    138138                        $this->id = $user_id;
    139139                        $this->populate();
    140140
    141                         if ( !empty( $populate_extras ) ) {
     141                        if ( ! empty( $populate_extras ) ) {
    142142                                $this->populate_extras();
    143143                        }
     
    150150        public function populate() {
    151151
    152                 if ( bp_is_active( 'xprofile' ) )
     152                if ( bp_is_active( 'xprofile' ) ) {
    153153                        $this->profile_data = $this->get_profile_data();
    154 
    155                 if ( !empty( $this->profile_data ) ) {
     154                }
     155
     156                if ( ! empty( $this->profile_data ) ) {
    156157                        $full_name_field_name = bp_xprofile_fullname_field_name();
    157158
    158159                        $this->user_url  = bp_members_get_user_url( $this->id );
    159                         $this->fullname  = esc_attr( $this->profile_data[$full_name_field_name]['field_data'] );
     160                        $this->fullname  = esc_attr( $this->profile_data[ $full_name_field_name ]['field_data'] );
    160161                        $this->user_link = "<a href='{$this->user_url}'>{$this->fullname}</a>";
    161162                        $this->email     = esc_attr( $this->profile_data['user_email'] );
     
    175176                                        __( 'Profile photo of %s', 'buddypress' ),
    176177                                        $this->fullname
    177                                 )
     178                                ),
    178179                        )
    179180                );
     
    187188                                        __( 'Profile photo of %s', 'buddypress' ),
    188189                                        $this->fullname
    189                                 )
     190                                ),
    190191                        )
    191192                );
     
    201202                                ),
    202203                                'width'   => 30,
    203                                 'height'  => 30
     204                                'height'  => 30,
    204205                        )
    205206                );
     
    248249         *
    249250         * @deprecated 1.7.0 Use {@link BP_User_Query}.
     251         *
     252         * @global wpdb $wpdb WordPress database object.
    250253         *
    251254         * @see BP_User_Query for a description of parameters, most of which
     
    282285                $sql = array();
    283286
    284                 $sql['select_main'] = "SELECT DISTINCT u.ID as id, u.user_registered, u.user_nicename, u.user_login, u.display_name, u.user_email";
    285 
    286                 if ( 'active' == $type || 'online' == $type || 'newest' == $type ) {
    287                         $sql['select_active'] = ", um.meta_value as last_activity";
    288                 }
    289 
    290                 if ( 'popular' == $type ) {
    291                         $sql['select_popular'] = ", um.meta_value as total_friend_count";
    292                 }
    293 
    294                 if ( 'alphabetical' == $type ) {
    295                         $sql['select_alpha'] = ", pd.value as fullname";
     287                $sql['select_main'] = 'SELECT DISTINCT u.ID as id, u.user_registered, u.user_nicename, u.user_login, u.display_name, u.user_email';
     288
     289                if ( 'active' === $type || 'online' === $type || 'newest' === $type ) {
     290                        $sql['select_active'] = ', um.meta_value as last_activity';
     291                }
     292
     293                if ( 'popular' === $type ) {
     294                        $sql['select_popular'] = ', um.meta_value as total_friend_count';
     295                }
     296
     297                if ( 'alphabetical' === $type ) {
     298                        $sql['select_alpha'] = ', pd.value as fullname';
    296299                }
    297300
    298301                if ( $meta_key ) {
    299                         $sql['select_meta'] = ", umm.meta_key";
     302                        $sql['select_meta'] = ', umm.meta_key';
    300303
    301304                        if ( $meta_value ) {
    302                                 $sql['select_meta'] .= ", umm.meta_value";
     305                                $sql['select_meta'] .= ', umm.meta_value';
    303306                        }
    304307                }
     
    312315
    313316                // Alphabetical sorting is done by the xprofile Full Name field.
    314                 if ( 'alphabetical' == $type ) {
     317                if ( 'alphabetical' === $type ) {
    315318                        $sql['join_profiledata_alpha'] = "LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id";
    316319                }
     
    322325                $sql['where'] = 'WHERE ' . bp_core_get_status_sql( 'u.' );
    323326
    324                 if ( 'active' == $type || 'online' == $type || 'newest' == $type ) {
    325                         $sql['where_active'] = $wpdb->prepare( "AND um.meta_key = %s", bp_get_user_meta_key( 'last_activity' ) );
    326                 }
    327 
    328                 if ( 'popular' == $type ) {
    329                         $sql['where_popular'] = $wpdb->prepare( "AND um.meta_key = %s", bp_get_user_meta_key( 'total_friend_count' ) );
    330                 }
    331 
    332                 if ( 'online' == $type ) {
    333                         $sql['where_online'] = "AND DATE_ADD( um.meta_value, INTERVAL 5 MINUTE ) >= UTC_TIMESTAMP()";
    334                 }
    335 
    336                 if ( 'alphabetical' == $type ) {
    337                         $sql['where_alpha'] = "AND pd.field_id = 1";
    338                 }
    339 
    340                 if ( !empty( $exclude ) ) {
     327                if ( 'active' === $type || 'online' === $type || 'newest' === $type ) {
     328                        $sql['where_active'] = $wpdb->prepare( 'AND um.meta_key = %s', bp_get_user_meta_key( 'last_activity' ) );
     329                }
     330
     331                if ( 'popular' === $type ) {
     332                        $sql['where_popular'] = $wpdb->prepare( 'AND um.meta_key = %s', bp_get_user_meta_key( 'total_friend_count' ) );
     333                }
     334
     335                if ( 'online' === $type ) {
     336                        $sql['where_online'] = 'AND DATE_ADD( um.meta_value, INTERVAL 5 MINUTE ) >= UTC_TIMESTAMP()';
     337                }
     338
     339                if ( 'alphabetical' === $type ) {
     340                        $sql['where_alpha'] = 'AND pd.field_id = 1';
     341                }
     342
     343                if ( ! empty( $exclude ) ) {
    341344                        $exclude              = implode( ',', wp_parse_id_list( $exclude ) );
    342345                        $sql['where_exclude'] = "AND u.ID NOT IN ({$exclude})";
     
    346349                // returned. The default value of false will hit the 'else' clause.
    347350                if ( 0 === $include || '0' === $include ) {
    348                         $sql['where_users'] = "AND 0 = 1";
    349                 } else {
    350                         if ( !empty( $include ) ) {
    351                                 $include = implode( ',',  wp_parse_id_list( $include ) );
     351                        $sql['where_users'] = 'AND 0 = 1';
     352                } elseif ( ! empty( $include ) ) {
     353                                $include            = implode( ',', wp_parse_id_list( $include ) );
    352354                                $sql['where_users'] = "AND u.ID IN ({$include})";
    353                         } elseif ( !empty( $user_id ) && bp_is_active( 'friends' ) ) {
    354                                 $friend_ids = friends_get_friend_user_ids( $user_id );
    355 
    356                                 if ( !empty( $friend_ids ) ) {
    357                                         $friend_ids = implode( ',', wp_parse_id_list( $friend_ids ) );
    358                                         $sql['where_friends'] = "AND u.ID IN ({$friend_ids})";
     355                } elseif ( ! empty( $user_id ) && bp_is_active( 'friends' ) ) {
     356                        $friend_ids = friends_get_friend_user_ids( $user_id );
     357
     358                        if ( ! empty( $friend_ids ) ) {
     359                                $friend_ids          = implode( ',', wp_parse_id_list( $friend_ids ) );
     360                                $sql['where_friends'] = "AND u.ID IN ({$friend_ids})";
    359361
    360362                                // User has no friends, return false since there will be no users to fetch.
    361                                 } else {
    362                                         return false;
    363                                 }
    364                         }
    365                 }
    366 
    367                 if ( !empty( $search_terms ) && bp_is_active( 'xprofile' ) ) {
     363                        } else {
     364                                return false;
     365                        }
     366                }
     367
     368                if ( ! empty( $search_terms ) && bp_is_active( 'xprofile' ) ) {
    368369                        $search_terms_like        = '%' . bp_esc_like( $search_terms ) . '%';
    369                         $sql['where_searchterms'] = $wpdb->prepare( "AND spd.value LIKE %s", $search_terms_like );
    370                 }
    371 
    372                 if ( !empty( $meta_key ) ) {
    373                         $sql['where_meta'] = $wpdb->prepare( " AND umm.meta_key = %s", $meta_key );
     370                        $sql['where_searchterms'] = $wpdb->prepare( 'AND spd.value LIKE %s', $search_terms_like );
     371                }
     372
     373                if ( ! empty( $meta_key ) ) {
     374                        $sql['where_meta'] = $wpdb->prepare( ' AND umm.meta_key = %s', $meta_key );
    374375
    375376                        // If a meta value is provided, match it.
    376377                        if ( $meta_value ) {
    377                                 $sql['where_meta'] .= $wpdb->prepare( " AND umm.meta_value = %s", $meta_value );
     378                                $sql['where_meta'] .= $wpdb->prepare( ' AND umm.meta_value = %s', $meta_value );
    378379                        }
    379380                }
    380381
    381382                switch ( $type ) {
    382                         case 'active': case 'online': default:
    383                                 $sql[] = "ORDER BY um.meta_value DESC";
     383                        case 'active':
     384                        case 'online':
     385                        default:
     386                                        $sql[] = 'ORDER BY um.meta_value DESC';
    384387                                break;
    385388                        case 'newest':
    386                                 $sql[] = "ORDER BY u.ID DESC";
     389                                $sql[] = 'ORDER BY u.ID DESC';
    387390                                break;
    388391                        case 'alphabetical':
    389                                 $sql[] = "ORDER BY pd.value ASC";
     392                                $sql[] = 'ORDER BY pd.value ASC';
    390393                                break;
    391394                        case 'random':
    392                                 $sql[] = "ORDER BY rand()";
     395                                $sql[] = 'ORDER BY rand()';
    393396                                break;
    394397                        case 'popular':
    395                                 $sql[] = "ORDER BY CONVERT(um.meta_value, SIGNED) DESC";
     398                                $sql[] = 'ORDER BY CONVERT(um.meta_value, SIGNED) DESC';
    396399                                break;
    397400                }
    398401
    399                 if ( !empty( $limit ) && !empty( $page ) ) {
    400                         $sql['pagination'] = $wpdb->prepare( "LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
     402                if ( ! empty( $limit ) && ! empty( $page ) ) {
     403                        $sql['pagination'] = $wpdb->prepare( 'LIMIT %d, %d', intval( ( $page - 1 ) * $limit ), intval( $limit ) );
    401404                }
    402405
     
    415418                unset( $sql['select_main'] );
    416419
    417                 if ( !empty( $sql['select_active'] ) ) {
     420                if ( ! empty( $sql['select_active'] ) ) {
    418421                        unset( $sql['select_active'] );
    419422                }
    420423
    421                 if ( !empty( $sql['select_popular'] ) ) {
     424                if ( ! empty( $sql['select_popular'] ) ) {
    422425                        unset( $sql['select_popular'] );
    423426                }
    424427
    425                 if ( !empty( $sql['select_alpha'] ) ) {
     428                if ( ! empty( $sql['select_alpha'] ) ) {
    426429                        unset( $sql['select_alpha'] );
    427430                }
    428431
    429                 if ( !empty( $sql['pagination'] ) ) {
     432                if ( ! empty( $sql['pagination'] ) ) {
    430433                        unset( $sql['pagination'] );
    431434                }
    432435
    433                 array_unshift( $sql, "SELECT COUNT(u.ID)" );
     436                array_unshift( $sql, 'SELECT COUNT(u.ID)' );
    434437
    435438                /**
     
    448451                 * We can't add these to the main query above since only users who have this information will be returned (since the much of the data is in usermeta and won't support any type of directional join).
    449452                 */
    450                 if ( !empty( $populate_extras ) ) {
     453                if ( ! empty( $populate_extras ) ) {
    451454                        $user_ids = array();
    452455
     
    456459
    457460                        // Add additional data to the returned results.
    458                         $paged_users = BP_Core_User::get_user_extras( $paged_users, $user_ids, $type );
    459                 }
    460 
    461                 return array( 'users' => $paged_users, 'total' => $total_users );
    462         }
    463 
     461                        $paged_users = self::get_user_extras( $paged_users, $user_ids, $type );
     462                }
     463
     464                return array(
     465                        'users' => $paged_users,
     466                        'total' => $total_users,
     467                );
     468        }
    464469
    465470        /**
     
    482487                $pag_sql = '';
    483488                if ( $limit && $page ) {
    484                         $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
     489                        $pag_sql = $wpdb->prepare( ' LIMIT %d, %d', intval( ( $page - 1 ) * $limit ), intval( $limit ) );
    485490                }
    486491
    487492                // Multibyte compliance.
    488493                if ( function_exists( 'mb_strlen' ) ) {
    489                         if ( mb_strlen( $letter, 'UTF-8' ) > 1 || is_numeric( $letter ) || !$letter ) {
     494                        if ( mb_strlen( $letter, 'UTF-8' ) > 1 || is_numeric( $letter ) || ! $letter ) {
    490495                                return false;
    491496                        }
    492                 } else {
    493                         if ( strlen( $letter ) > 1 || is_numeric( $letter ) || !$letter ) {
    494                                 return false;
    495                         }
     497                } elseif ( strlen( $letter ) > 1 || is_numeric( $letter ) || ! $letter ) {
     498                        return false;
    496499                }
    497500
     
    501504                $status_sql  = bp_core_get_status_sql( 'u.' );
    502505
    503                 if ( !empty( $exclude ) ) {
     506                if ( ! empty( $exclude ) ) {
    504507                        $exclude     = implode( ',', wp_parse_id_list( $exclude ) );
    505508                        $exclude_sql = " AND u.id NOT IN ({$exclude})";
     
    524527                 * @param string $value SQL prepared statement for the user query.
    525528                 */
    526                 $paged_users_sql = apply_filters( 'bp_core_users_by_letter_sql',       $wpdb->prepare( "SELECT DISTINCT u.ID as id, u.user_registered, u.user_nicename, u.user_login, u.user_email FROM {$wpdb->users} u LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id LEFT JOIN {$bp->profile->table_name_fields} pf ON pd.field_id = pf.id WHERE {$status_sql} AND pf.name = %s {$exclude_sql} AND pd.value LIKE %s ORDER BY pd.value ASC{$pag_sql}", bp_xprofile_fullname_field_name(), $letter_like ) );
     529                $paged_users_sql = apply_filters( 'bp_core_users_by_letter_sql', $wpdb->prepare( "SELECT DISTINCT u.ID as id, u.user_registered, u.user_nicename, u.user_login, u.user_email FROM {$wpdb->users} u LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id LEFT JOIN {$bp->profile->table_name_fields} pf ON pd.field_id = pf.id WHERE {$status_sql} AND pf.name = %s {$exclude_sql} AND pd.value LIKE %s ORDER BY pd.value ASC{$pag_sql}", bp_xprofile_fullname_field_name(), $letter_like ) );
    527530
    528531                $total_users = $wpdb->get_var( $total_users_sql );
     
    537540                 */
    538541                $user_ids = array();
    539                 foreach ( (array) $paged_users as $user )
     542                foreach ( (array) $paged_users as $user ) {
    540543                        $user_ids[] = (int) $user->id;
     544                }
    541545
    542546                // Add additional data to the returned results.
    543547                if ( $populate_extras ) {
    544                         $paged_users = BP_Core_User::get_user_extras( $paged_users, $user_ids );
    545                 }
    546 
    547                 return array( 'users' => $paged_users, 'total' => $total_users );
     548                        $paged_users = self::get_user_extras( $paged_users, $user_ids );
     549                }
     550
     551                return array(
     552                        'users' => $paged_users,
     553                        'total' => $total_users,
     554                );
    548555        }
    549556
     
    566573
    567574                $pag_sql = '';
    568                 if ( $limit && $page )
    569                         $pag_sql = $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * $limit), intval( $limit ) );
     575                if ( $limit && $page ) {
     576                        $pag_sql = $wpdb->prepare( ' LIMIT %d, %d', intval( ( $page - 1 ) * $limit ), intval( $limit ) );
     577                }
    570578
    571579                $user_ids   = implode( ',', wp_parse_id_list( $user_ids ) );
     
    638646
    639647                // Add additional data to the returned results.
    640                 if ( !empty( $populate_extras ) ) {
    641                         $paged_users = BP_Core_User::get_user_extras( $paged_users, $user_ids );
    642                 }
    643 
    644                 return array( 'users' => $paged_users, 'total' => $total_users );
     648                if ( ! empty( $populate_extras ) ) {
     649                        $paged_users = self::get_user_extras( $paged_users, $user_ids );
     650                }
     651
     652                return array(
     653                        'users' => $paged_users,
     654                        'total' => $total_users,
     655                );
    645656        }
    646657
     
    663674
    664675                $user_ids = array();
    665                 $pag_sql  = $limit && $page ? $wpdb->prepare( " LIMIT %d, %d", intval( ( $page - 1 ) * intval( $limit ) ), intval( $limit ) ) : '';
     676                $pag_sql  = $limit && $page ? $wpdb->prepare( ' LIMIT %d, %d', intval( ( $page - 1 ) * intval( $limit ) ), intval( $limit ) ) : '';
    666677
    667678                $search_terms_like = '%' . bp_esc_like( $search_terms ) . '%';
     
    684695                 * @param string $value SQL statement for the searched users query.
    685696                 */
    686                 $paged_users_sql = apply_filters( 'bp_core_search_users_sql',       $wpdb->prepare( "SELECT DISTINCT u.ID as id, u.user_registered, u.user_nicename, u.user_login, u.user_email FROM {$wpdb->users} u LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id WHERE {$status_sql} AND pd.value LIKE %s ORDER BY pd.value ASC{$pag_sql}", $search_terms_like ), $search_terms, $pag_sql );
     697                $paged_users_sql = apply_filters( 'bp_core_search_users_sql', $wpdb->prepare( "SELECT DISTINCT u.ID as id, u.user_registered, u.user_nicename, u.user_login, u.user_email FROM {$wpdb->users} u LEFT JOIN {$bp->profile->table_name_data} pd ON u.ID = pd.user_id WHERE {$status_sql} AND pd.value LIKE %s ORDER BY pd.value ASC{$pag_sql}", $search_terms_like ), $search_terms, $pag_sql );
    687698
    688699                $total_users = $wpdb->get_var( $total_users_sql );
     
    693704                 * We can't add these to the main query above since only users who have this information will be returned (since the much of the data is in usermeta and won't support any type of directional join)
    694705                 */
    695                 foreach ( (array) $paged_users as $user )
     706                foreach ( (array) $paged_users as $user ) {
    696707                        $user_ids[] = $user->id;
     708                }
    697709
    698710                // Add additional data to the returned results.
    699                 if ( $populate_extras )
    700                         $paged_users = BP_Core_User::get_user_extras( $paged_users, $user_ids );
    701 
    702                 return array( 'users' => $paged_users, 'total' => $total_users );
     711                if ( $populate_extras ) {
     712                        $paged_users = self::get_user_extras( $paged_users, $user_ids );
     713                }
     714
     715                return array(
     716                        'users' => $paged_users,
     717                        'total' => $total_users,
     718                );
    703719        }
    704720
     
    720736                $bp = buddypress();
    721737
    722                 if ( empty( $user_ids ) )
     738                if ( empty( $user_ids ) ) {
    723739                        return $paged_users;
     740                }
    724741
    725742                // Sanitize user IDs.
     
    727744
    728745                // Fetch the user's full name.
    729                 if ( bp_is_active( 'xprofile' ) && 'alphabetical' != $type ) {
     746                if ( bp_is_active( 'xprofile' ) && 'alphabetical' !== $type ) {
    730747                        $names = $wpdb->get_results( $wpdb->prepare( "SELECT pd.user_id as id, pd.value as fullname FROM {$bp->profile->table_name_fields} pf, {$bp->profile->table_name_data} pd WHERE pf.id = pd.field_id AND pf.name = %s AND pd.user_id IN ( {$user_ids} )", bp_xprofile_fullname_field_name() ) );
    731748                        for ( $i = 0, $count = count( $paged_users ); $i < $count; ++$i ) {
    732749                                foreach ( (array) $names as $name ) {
    733                                         if ( $name->id == $paged_users[$i]->id )
    734                                                 $paged_users[$i]->fullname = $name->fullname;
     750                                        if ( $name->id === $paged_users[ $i ]->id ) {
     751                                                $paged_users[ $i ]->fullname = $name->fullname;
     752                                        }
    735753                                }
    736754                        }
     
    738756
    739757                // Fetch the user's total friend count.
    740                 if ( 'popular' != $type ) {
     758                if ( 'popular' !== $type ) {
    741759                        $friend_count = $wpdb->get_results( $wpdb->prepare( "SELECT user_id as id, meta_value as total_friend_count FROM {$wpdb->usermeta} WHERE meta_key = %s AND user_id IN ( {$user_ids} )", bp_get_user_meta_key( 'total_friend_count' ) ) );
    742760                        for ( $i = 0, $count = count( $paged_users ); $i < $count; ++$i ) {
    743761                                foreach ( (array) $friend_count as $fcount ) {
    744                                         if ( $fcount->id == $paged_users[$i]->id )
    745                                                 $paged_users[$i]->total_friend_count = (int) $fcount->total_friend_count;
     762                                        if ( $fcount->id === $paged_users[ $i ]->id ) {
     763                                                $paged_users[ $i ]->total_friend_count = (int) $fcount->total_friend_count;
     764                                        }
    746765                                }
    747766                        }
     
    753772                        for ( $i = 0, $count = count( $paged_users ); $i < $count; ++$i ) {
    754773                                foreach ( (array) $friend_status as $status ) {
    755                                         if ( $status->initiator_user_id == $paged_users[$i]->id || $status->friend_user_id == $paged_users[$i]->id )
    756                                                 $paged_users[$i]->is_friend = $status->is_confirmed;
     774                                        if ( $status->initiator_user_id === $paged_users[ $i ]->id || $status->friend_user_id === $paged_users[ $i ]->id ) {
     775                                                $paged_users[ $i ]->is_friend = $status->is_confirmed;
     776                                        }
    757777                                }
    758778                        }
     
    760780
    761781                // Fetch the user's last_activity.
    762                 if ( 'active' != $type ) {
     782                if ( 'active' !== $type ) {
    763783                        $user_activity = self::get_last_activity( $user_ids );
    764784                        for ( $i = 0, $count = count( $paged_users ); $i < $count; ++$i ) {
    765785                                foreach ( (array) $user_activity as $activity ) {
    766                                         if ( ! empty( $activity['user_id'] ) && (int) $activity['user_id'] === (int) $paged_users[$i]->id ) {
    767                                                 $paged_users[$i]->last_activity = $activity['date_recorded'];
     786                                        if ( ! empty( $activity['user_id'] ) && (int) $activity['user_id'] === (int) $paged_users[ $i ]->id ) {
     787                                                $paged_users[ $i ]->last_activity = $activity['date_recorded'];
    768788                                        }
    769789                                }
     
    775795                for ( $i = 0, $count = count( $paged_users ); $i < $count; ++$i ) {
    776796                        foreach ( (array) $user_update as $update ) {
    777                                 if ( $update->id == $paged_users[$i]->id )
    778                                         $paged_users[$i]->latest_update = $update->latest_update;
     797                                if ( $update->id === $paged_users[ $i ]->id ) {
     798                                        $paged_users[ $i ]->latest_update = $update->latest_update;
     799                                }
    779800                        }
    780801                }
     
    789810         *
    790811         * @param int $user_id User ID.
    791          * @return false|object WP_User if successful, false on failure.
     812         * @return false|object User object if successful, false on failure.
    792813         */
    793814        public static function get_core_userdata( $user_id ) {
     
    797818        /**
    798819         * Get last activity data for a user or set of users.
     820         *
     821         * @global wpdb $wpdb WordPress database object.
    799822         *
    800823         * @param int|array $user_id User IDs or multiple user IDs.
     
    821844
    822845                        foreach ( $last_activities as $last_activity ) {
    823                                 wp_cache_set( $last_activity->user_id, array(
    824                                         'user_id'       => $last_activity->user_id,
    825                                         'date_recorded' => $last_activity->date_recorded,
    826                                         'activity_id'   => $last_activity->id,
    827                                 ), 'bp_last_activity' );
     846                                wp_cache_set(
     847                                        $last_activity->user_id,
     848                                        array(
     849                                                'user_id'       => $last_activity->user_id,
     850                                                'date_recorded' => $last_activity->date_recorded,
     851                                                'activity_id'   => $last_activity->id,
     852                                        ),
     853                                        'bp_last_activity'
     854                                );
    828855                        }
    829856                }
     
    835862
    836863                        if ( isset( $retval['user_id'] ) ) {
    837                                 $retval[ $user_id ]['user_id']     = (int) $retval[ $user_id ]['user_id'];
     864                                $retval[ $user_id ]['user_id'] = (int) $retval[ $user_id ]['user_id'];
    838865                        }
    839866                        if ( isset( $retval['activity_id'] ) ) {
     
    852879         *
    853880         * @since 2.0.0
     881         *
     882         * @global wpdb $wpdb WordPress database object.
    854883         *
    855884         * @param int    $user_id ID of the user whose last_activity you are updating.
     
    867896                        $updated = $wpdb->update(
    868897                                $table_name,
    869 
    870898                                // Data to update.
    871899                                array(
    872900                                        'date_recorded' => $time,
    873901                                ),
    874 
    875902                                // WHERE.
    876903                                array(
    877904                                        'id' => $activity[ $user_id ]['activity_id'],
    878905                                ),
    879 
    880906                                // Data sanitization format.
    881907                                array(
    882908                                        '%s',
    883909                                ),
    884 
    885910                                // WHERE sanitization format.
    886911                                array(
     
    895920                        $updated = $wpdb->insert(
    896921                                $table_name,
    897 
    898922                                // Data.
    899923                                array(
     
    907931                                        'date_recorded' => $time,
    908932                                ),
    909 
    910933                                // Data sanitization format.
    911934                                array(
     
    923946                        // Set up activity array for caching.
    924947                        // View the foreach loop in the get_last_activity() method for format.
    925                         $activity = array();
     948                        $activity             = array();
    926949                        $activity[ $user_id ] = array(
    927950                                'user_id'       => $user_id,
     
    952975         * @since 2.0.0
    953976         *
     977         * @global wpdb $wpdb WordPress database object.
     978         *
    954979         * @param int $user_id ID of the user whose activity should be deleted.
    955980         * @return bool
     
    966991                $deleted = $wpdb->delete(
    967992                        buddypress()->members->table_name_last_activity,
    968 
    969993                        // WHERE.
    970994                        array(
    971995                                'id' => $existing[ $user_id ]['activity_id'],
    972996                        ),
    973 
    974997                        // WHERE sanitization format.
    975998                        array(
  • trunk/src/bp-core/classes/class-bp-core.php

    r13878 r13893  
    2525         *
    2626         * @since 1.5.0
    27          *
    2827         */
    2928        public function __construct() {
     
    4443         * @since 7.0.0
    4544         *
    46          * @param string $key
     45         * @param string $key The object var to get.
    4746         * @return mixed
    4847         */
    4948        public function __get( $key = '' ) {
    5049
    51                 // Backwards compatibility for the original Notifications table var
     50                // Backwards compatibility for the original Notifications table var.
    5251                if ( 'table_name_notifications' === $key ) {
    5352                        return bp_is_active( 'notifications' )
     
    5655                }
    5756
    58                 // Return object var if set, else null
     57                // Return object var if set, else null.
    5958                return isset( $this->{$key} )
    6059                        ? $this->{$key}
     
    9089                 * @since 1.5.0
    9190                 *
    92                  * @param array $value Array of included and optional components.
     91                 * @param array $optional_components Array of included and optional components.
    9392                 */
    9493                $bp->optional_components = apply_filters( 'bp_optional_components', array( 'activity', 'blogs', 'friends', 'groups', 'messages', 'notifications', 'settings', 'xprofile' ) );
     
    104103
    105104                // Get a list of activated components.
    106                 if ( $active_components = bp_get_option( 'bp-active-components' ) ) {
     105                $active_components = bp_get_option( 'bp-active-components' );
     106                if ( $active_components ) {
    107107
    108108                        /** This filter is documented in bp-core/admin/bp-core-admin-components.php */
    109                         $bp->active_components      = apply_filters( 'bp_active_components', $active_components );
     109                        $bp->active_components = apply_filters( 'bp_active_components', $active_components );
    110110
    111111                        /**
     
    118118                        $bp->deactivated_components = apply_filters( 'bp_deactivated_components', array_values( array_diff( array_values( array_merge( $bp->optional_components, $bp->required_components ) ), array_keys( $bp->active_components ) ) ) );
    119119
    120                 // Pre 1.5 Backwards compatibility.
     120                        // Pre 1.5 Backwards compatibility.
    121121                } elseif ( $deactivated_components = bp_get_option( 'bp-deactivated-components' ) ) {
    122122
     
    130130
    131131                        // Setup the active components.
    132                         $active_components     = array_fill_keys( array_diff( array_values( array_merge( $bp->optional_components, $bp->required_components ) ), array_values( $bp->deactivated_components ) ), '1' );
     132                        $active_components = array_fill_keys( array_diff( array_values( array_merge( $bp->optional_components, $bp->required_components ) ), array_values( $bp->deactivated_components ) ), '1' );
    133133
    134134                        /** This filter is documented in bp-core/admin/bp-core-admin-components.php */
    135135                        $bp->active_components = apply_filters( 'bp_active_components', $bp->active_components );
    136136
    137                 // Default to all components active.
     137                        // Default to all components active.
    138138                } else {
    139139
     
    142142
    143143                        // Setup the active components.
    144                         $active_components     = array_fill_keys( array_values( array_merge( $bp->optional_components, $bp->required_components ) ), '1' );
     144                        $active_components = array_fill_keys( array_values( array_merge( $bp->optional_components, $bp->required_components ) ), '1' );
    145145
    146146                        /** This filter is documented in bp-core/admin/bp-core-admin-components.php */
     
    151151                foreach ( $bp->optional_components as $component ) {
    152152                        if ( bp_is_active( $component ) && file_exists( $bp->plugin_dir . '/bp-' . $component . '/bp-' . $component . '-loader.php' ) ) {
    153                                 include( $bp->plugin_dir . '/bp-' . $component . '/bp-' . $component . '-loader.php' );
     153                                include $bp->plugin_dir . '/bp-' . $component . '/bp-' . $component . '-loader.php';
    154154                        }
    155155                }
     
    158158                foreach ( $bp->required_components as $component ) {
    159159                        if ( file_exists( $bp->plugin_dir . '/bp-' . $component . '/bp-' . $component . '-loader.php' ) ) {
    160                                 include( $bp->plugin_dir . '/bp-' . $component . '/bp-' . $component . '-loader.php' );
     160                                include $bp->plugin_dir . '/bp-' . $component . '/bp-' . $component . '-loader.php';
    161161                        }
    162162                }
     
    189189
    190190                $includes = array(
    191                         'admin'
     191                        'admin',
    192192                );
    193193
     
    237237
    238238                // Logged in user is the 'current_user'.
    239                 $current_user            = wp_get_current_user();
     239                $current_user = wp_get_current_user();
    240240
    241241                // The user ID of the user who is currently logged in.
    242                 $bp->loggedin_user       = new stdClass;
    243                 $bp->loggedin_user->id   = isset( $current_user->ID ) ? $current_user->ID : 0;
     242                $bp->loggedin_user     = new stdClass();
     243                $bp->loggedin_user->id = isset( $current_user->ID ) ? $current_user->ID : 0;
    244244
    245245                /** Avatars **********************************************************
     
    247247
    248248                // Fetches the default Gravatar image to use if the user/group/blog has no avatar or gravatar.
    249                 $bp->grav_default        = new stdClass;
     249                $bp->grav_default = new stdClass();
    250250
    251251                /**
     
    256256                 * @param string $value Default user Gravatar.
    257257                 */
    258                 $bp->grav_default->user  = apply_filters( 'bp_user_gravatar_default', $bp->site_options['avatar_default'] );
     258                $bp->grav_default->user = apply_filters( 'bp_user_gravatar_default', $bp->site_options['avatar_default'] );
    259259
    260260                /**
     
    272272                 * @since 1.1.0
    273273                 *
    274                  * @param string $value Default blog Gravatar.
    275                  */
    276                 $bp->grav_default->blog  = apply_filters( 'bp_blog_gravatar_default', $bp->grav_default->user );
     274                 * @param string $gravatar_default Default blog Gravatar.
     275                 */
     276                $bp->grav_default->blog = apply_filters( 'bp_blog_gravatar_default', $bp->grav_default->user );
    277277
    278278                // Only fully deprecate the legacy navigation globals if BP Classic is not active.
     
    325325
    326326                // Global groups.
    327                 wp_cache_add_global_groups( array(
    328                         'bp',
    329                         'bp_pages',
    330                         'bp_invitations',
    331                 ) );
     327                wp_cache_add_global_groups(
     328                        array(
     329                                'bp',
     330                                'bp_pages',
     331                                'bp_invitations',
     332                        )
     333                );
    332334
    333335                parent::setup_cache_groups();
     
    371373                        register_post_type(
    372374                                bp_get_email_post_type(),
    373                                 apply_filters( 'bp_register_email_post_type', array(
    374                                         'description'       => _x( 'BuddyPress emails', 'email post type description', 'buddypress' ),
    375                                         'capabilities'      => array(
    376                                                 'edit_posts'          => 'bp_moderate',
    377                                                 'edit_others_posts'   => 'bp_moderate',
    378                                                 'publish_posts'       => 'bp_moderate',
    379                                                 'read_private_posts'  => 'bp_moderate',
    380                                                 'delete_posts'        => 'bp_moderate',
    381                                                 'delete_others_posts' => 'bp_moderate',
    382                                         ),
    383                                         'map_meta_cap'      => true,
    384                                         'labels'            => bp_get_email_post_type_labels(),
    385                                         'menu_icon'         => 'dashicons-email',
    386                                         'public'            => false,
    387                                         'publicly_queryable' => bp_current_user_can( 'bp_moderate' ),
    388                                         'query_var'         => false,
    389                                         'rewrite'           => false,
    390                                         'show_in_admin_bar' => false,
    391                                         'show_ui'           => bp_current_user_can( 'bp_moderate' ),
    392                                         'supports'          => bp_get_email_post_type_supports(),
    393                                 ) )
     375                                apply_filters(
     376                                        'bp_register_email_post_type',
     377                                        array(
     378                                                'description'        => _x( 'BuddyPress emails', 'email post type description', 'buddypress' ),
     379                                                'capabilities'       => array(
     380                                                        'edit_posts'          => 'bp_moderate',
     381                                                        'edit_others_posts'   => 'bp_moderate',
     382                                                        'publish_posts'       => 'bp_moderate',
     383                                                        'read_private_posts'  => 'bp_moderate',
     384                                                        'delete_posts'        => 'bp_moderate',
     385                                                        'delete_others_posts' => 'bp_moderate',
     386                                                ),
     387                                                'map_meta_cap'       => true,
     388                                                'labels'             => bp_get_email_post_type_labels(),
     389                                                'menu_icon'          => 'dashicons-email',
     390                                                'public'             => false,
     391                                                'publicly_queryable' => bp_current_user_can( 'bp_moderate' ),
     392                                                'query_var'          => false,
     393                                                'rewrite'            => false,
     394                                                'show_in_admin_bar'  => false,
     395                                                'show_ui'            => bp_current_user_can( 'bp_moderate' ),
     396                                                'supports'           => bp_get_email_post_type_supports(),
     397                                        )
     398                                )
    394399                        );
    395400                }
  • trunk/src/bp-core/classes/class-bp-customizer-control-range.php

    r10475 r13893  
    1616 */
    1717class BP_Customizer_Control_Range extends WP_Customize_Control {
     18
    1819        /**
     20         * Control type.
     21         *
    1922         * @var string
    2023         */
     
    4750                        <?php endif; ?>
    4851
    49                         <input type="range" id="<?php echo esc_attr( "{$id}-range" ); ?>" <?php $this->link(); $this->input_attrs(); ?> value="<?php echo esc_attr( $this->value() ); ?>" />
     52                        <input type="range" id="<?php echo esc_attr( "{$id}-range" ); ?>"
     53                        <?php
     54                        $this->link();
     55                        $this->input_attrs();
     56                        ?>
     57                        value="<?php echo esc_attr( $this->value() ); ?>" />
    5058                        <output for="<?php echo esc_attr( "{$id}-range" ); ?>"><?php echo esc_html( $this->value() ); ?></output>
    5159
     
    5361                                <p><span class="description customize-control-description"><?php echo esc_html( $this->description ); ?></span></p>
    5462                        <?php endif; ?>
    55                 </li><?php
     63                </li>
     64                <?php
    5665        }
    5766}
  • trunk/src/bp-core/classes/class-bp-date-query.php

    r13184 r13893  
    1111defined( 'ABSPATH' ) || exit;
    1212
    13 if ( class_exists( 'WP_Date_Query' ) ) :
     13if ( ! class_exists( 'WP_Date_Query' ) ) {
     14        return;
     15}
    1416
    1517/**
     
    2628 */
    2729class BP_Date_Query extends WP_Date_Query {
     30
    2831        /**
    2932         * The column to query against. Can be changed via the query arguments.
     
    4649         *
    4750         * @since 2.1.0
    48          * @since 10.0.0 Added $prepend_and argument.
     51         * @since 10.0.0 Added `$prepend_and` argument.
     52         *
     53         * @see WP_Date_Query::__construct()
    4954         *
    5055         * @param array  $date_query  Date query arguments.
    5156         * @param string $column      The DB column to query against.
    5257         * @param bool   $prepend_and Whether to prepend the 'AND' operator to the WHERE SQL clause.
    53          *
    54          * @see WP_Date_Query::__construct()
    5558         */
    5659        public function __construct( $date_query, $column = '', $prepend_and = false ) {
     
    129132                if ( ! empty( $date_query ) && is_array( $date_query ) && ! empty( $column ) ) {
    130133                        $date_query = new self( $date_query, $column, $prepend_and );
    131                         $sql = $date_query->get_sql();
     134                        $sql        = $date_query->get_sql();
    132135                }
    133136
     
    135138        }
    136139}
    137 endif;
  • trunk/src/bp-core/classes/class-bp-media-extractor.php

    r13793 r13893  
    66 * @subpackage Core
    77 * @since 2.3.0
     8 *
     9 * @phpcs:disable Squiz.PHP.CommentedOutCode.Found
    810 */
    911
     
    4042 */
    4143class BP_Media_Extractor {
     44
    4245        /**
    4346         * Media type.
     
    5457        const AUDIO      = 32;
    5558        const VIDEOS     = 64;
    56 
    5759
    5860        /**
     
    132134                $plaintext = $this->strip_markup( $richtext );
    133135
    134 
    135136                // Extract links.
    136137                if ( self::LINKS & $what_to_extract ) {
     
    181182                return apply_filters( 'bp_media_extractor_extract', $media, $richtext, $what_to_extract, $extra_args, $plaintext );
    182183        }
    183 
    184184
    185185        /**
     
    209209         */
    210210        protected function extract_links( $richtext, $plaintext, $extra_args = array() ) {
    211                 $data = array( 'has' => array( 'links' => 0 ), 'links' => array() );
     211                $data = array(
     212                        'has'   => array( 'links' => 0 ),
     213                        'links' => array(),
     214                );
    212215
    213216                // Matches: href="text" and href='text'.
     
    269272         */
    270273        protected function extract_mentions( $richtext, $plaintext, $extra_args = array() ) {
    271                 $data     = array( 'has' => array( 'mentions' => 0 ), 'mentions' => array() );
     274                $data     = array(
     275                        'has'      => array( 'mentions' => 0 ),
     276                        'mentions' => array(),
     277                );
    272278                $mentions = array();
    273279
     
    279285                        }
    280286
    281                 // If the Activity component is disabled, instead do a basic parse.
    282                 } else {
    283                         if ( strpos( $plaintext, '@' ) !== false ) {
     287                        // If the Activity component is disabled, instead do a basic parse.
     288                } elseif ( strpos( $plaintext, '@' ) !== false ) {
    284289                                preg_match_all( '/[@]+([A-Za-z0-9-_\.@]+)\b/', $plaintext, $matches );
    285290
    286                                 if ( ! empty( $matches[1] ) ) {
    287                                         $mentions = array_unique( array_map( 'strtolower', $matches[1] ) );
    288                                 }
     291                        if ( ! empty( $matches[1] ) ) {
     292                                $mentions = array_unique( array_map( 'strtolower', $matches[1] ) );
    289293                        }
    290294                }
     
    343347         */
    344348        protected function extract_images( $richtext, $plaintext, $extra_args = array() ) {
    345                 $media = array( 'has' => array( 'images' => 0 ), 'images' => array() );
     349                $media = array(
     350                        'has'    => array( 'images' => 0 ),
     351                        'images' => array(),
     352                );
    346353
    347354                $featured_image = $this->extract_images_from_featured_images( $richtext, $plaintext, $extra_args );
    348355                $galleries      = $this->extract_images_from_galleries( $richtext, $plaintext, $extra_args );
    349 
    350356
    351357                // `<img src>` tags.
     
    421427                $media['has']['images'] = count( $media['images'] );
    422428
    423 
    424429                /**
    425430                 * Filters images extracted from text.
     
    461466         */
    462467        protected function extract_shortcodes( $richtext, $plaintext, $extra_args = array() ) {
    463                 $data = array( 'has' => array( 'shortcodes' => 0 ), 'shortcodes' => array() );
     468                $data = array(
     469                        'has'        => array( 'shortcodes' => 0 ),
     470                        'shortcodes' => array(),
     471                );
    464472
    465473                // Match any registered WordPress shortcodes.
     
    519527         */
    520528        protected function extract_embeds( $richtext, $plaintext, $extra_args = array() ) {
    521                 $data   = array( 'has' => array( 'embeds' => 0 ), 'embeds' => array() );
     529                $data = array(
     530                        'has'    => array( 'embeds' => 0 ),
     531                        'embeds' => array(),
     532                );
    522533
    523534                if ( ! function_exists( '_wp_oembed_get_object' ) ) {
    524                         require( ABSPATH . WPINC . '/class-oembed.php' );
    525                 }
    526 
     535                        require ABSPATH . WPINC . '/class-oembed.php';
     536                }
    527537
    528538                // Matches any links on their own lines. They may be oEmbeds.
     
    599609         */
    600610        protected function extract_audio( $richtext, $plaintext, $extra_args = array() ) {
    601                 $data   = array( 'has' => array( 'audio' => 0 ), 'audio' => array() );
     611                $data   = array(
     612                        'has'   => array( 'audio' => 0 ),
     613                        'audio' => array(),
     614                );
    602615                $audios = $this->extract_shortcodes( $richtext, $plaintext, $extra_args );
    603616                $links  = $this->extract_links( $richtext, $plaintext, $extra_args );
    604617
    605618                $audio_types = wp_get_audio_extensions();
    606 
    607619
    608620                // [audio]
     
    695707         */
    696708        protected function extract_video( $richtext, $plaintext, $extra_args = array() ) {
    697                 $data   = array( 'has' => array( 'videos' => 0 ), 'videos' => array() );
     709                $data   = array(
     710                        'has'    => array( 'videos' => 0 ),
     711                        'videos' => array(),
     712                );
    698713                $videos = $this->extract_shortcodes( $richtext, $plaintext, $extra_args );
    699714
    700715                $video_types = wp_get_video_extensions();
    701716
    702 
    703                 // [video]
     717                // [video].
    704718                $videos = wp_list_filter( $videos['shortcodes'], array( 'type' => 'video' ) );
    705719                foreach ( $videos as $video ) {
     
    787801                                        $image_size = $extra_args['width'];  // E.g. "thumb", "medium".
    788802                                }
    789 
    790803                        } else {
    791804                                $image_size = 'full';
     
    807820                                        $images = wp_parse_id_list( $gallery['ids'] );
    808821
    809                                 // Gallery post_parent variant.
     822                                        // Gallery post_parent variant.
    810823                                } elseif ( isset( $extra_args['post'] ) ) {
    811824                                        $images = wp_parse_id_list(
    812                                                 get_children( array(
    813                                                         'fields'         => 'ids',
    814                                                         'order'          => 'ASC',
    815                                                         'orderby'        => 'menu_order ID',
    816                                                         'post_mime_type' => 'image',
    817                                                         'post_parent'    => $extra_args['post']->ID,
    818                                                         'post_status'    => 'inherit',
    819                                                         'post_type'      => 'attachment',
    820                                                 ) )
     825                                                get_children(
     826                                                        array(
     827                                                                'fields'         => 'ids',
     828                                                                'order'          => 'ASC',
     829                                                                'orderby'        => 'menu_order ID',
     830                                                                'post_mime_type' => 'image',
     831                                                                'post_parent'    => $extra_args['post']->ID,
     832                                                                'post_status'    => 'inherit',
     833                                                                'post_type'      => 'attachment',
     834                                                        )
     835                                                )
    821836                                        );
    822837                                }
     
    824839                                // Extract the data we need from each image in this gallery.
    825840                                foreach ( $images as $image_id ) {
    826                                         $image  = wp_get_attachment_image_src( $image_id, $image_size );
     841                                        $image = wp_get_attachment_image_src( $image_id, $image_size );
    827842
    828843                                        $image_url    = isset( $image[0] ) ? $image[0] : '';
     
    831846
    832847                                        $data[] = array(
    833                                                 'url'    => $image_url,
    834                                                 'width'  => $image_width,
    835                                                 'height' => $image_height,
     848                                                'url'        => $image_url,
     849                                                'width'      => $image_width,
     850                                                'height'     => $image_height,
    836851
    837852                                                'gallery_id' => 1 + $gallery_id,
  • trunk/src/bp-core/classes/class-bp-theme-compat.php

    r13890 r13893  
    104104         */
    105105        public function __set( $property, $value ) {
    106                 return $this->_data[ $property ] = $value;
     106                $this->_data[ $property ] = $value;
     107
     108                return $this->_data[ $property ];
    107109        }
    108110
Note: See TracChangeset for help on using the changeset viewer.