Skip to:
Content

BuddyPress.org

Changeset 13887


Ignore:
Timestamp:
06/01/2024 10:19:51 PM (2 years ago)
Author:
espellcaste
Message:

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

Follow-up to [13883] and [13886]

See #9164 and #7228

Location:
trunk/src/bp-core/classes
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/classes/class-bp-recursive-query.php

    r12547 r13887  
    9999
    100100                                        $sql_chunks['join'] = array_merge( $sql_chunks['join'], $clause_sql['join'] );
    101                                 // This is a subquery.
     101                                        // This is a subquery.
    102102                                } else {
    103103                                        $clause_sql = $this->get_sql_for_query( $clause, $depth + 1 );
     
    157157                                continue;
    158158
    159                         // First-order clause.
     159                                // First-order clause.
    160160                        } elseif ( $this->is_first_order_clause( $query ) ) {
    161161                                if ( isset( $query['value'] ) && array() === $query['value'] ) {
     
    165165                                $clean_queries[] = $query;
    166166
    167                         // Otherwise, it's a nested query, so we recurse.
     167                                // Otherwise, it's a nested query, so we recurse.
    168168                        } else {
    169169                                $cleaned_query = $this->sanitize_query( $query );
     
    183183                        $clean_queries['relation'] = 'OR';
    184184
    185                 /*
    186                  * If there is only a single clause, call the relation 'OR'.
    187                  * This value will not actually be used to join clauses, but it
    188                  * simplifies the logic around combining key-only queries.
    189                  */
     185                        /*
     186                        * If there is only a single clause, call the relation 'OR'.
     187                        * This value will not actually be used to join clauses, but it
     188                        * simplifies the logic around combining key-only queries.
     189                        */
    190190                } elseif ( 1 === count( $clean_queries ) ) {
    191191                        $clean_queries['relation'] = 'OR';
    192192
    193                 // Default to AND.
     193                        // Default to AND.
    194194                } else {
    195195                        $clean_queries['relation'] = 'AND';
  • trunk/src/bp-core/classes/class-bp-theme-compat.php

    r13013 r13887  
    4040         *
    4141         * @since 1.7.0
     42         *
    4243         * @var array
    4344         */
     
    5152         * @param array $properties Array of properties for BP_Theme_Compat.
    5253         */
    53         public function __construct( Array $properties = array() ) {
     54        public function __construct( array $properties = array() ) {
    5455                $this->_data = $properties;
    5556        }
     
    103104         */
    104105        public function __set( $property, $value ) {
    105                 return $this->_data[$property] = $value;
     106                return $this->_data[ $property ] = $value;
    106107        }
    107108
     
    116117         */
    117118        public function __get( $property ) {
    118                 return array_key_exists( $property, $this->_data ) ? $this->_data[$property] : '';
     119                return array_key_exists( $property, $this->_data ) ? $this->_data[ $property ] : '';
    119120        }
    120121
  • trunk/src/bp-core/classes/class-bp-user-query.php

    r13395 r13887  
    1818 *
    1919 * @since 1.7.0
    20  * @since 10.0.0 Added $date_query parameter.
     20 * @since 10.0.0 Added `$date_query` parameter.
    2121 *
    2222 * @param array $query {
     
    4444 *     @type array|string      $member_type__in     Array or comma-separated list of member types to limit results to.
    4545 *     @type array|string      $member_type__not_in Array or comma-separated list of member types that will be
    46  *                                                                   excluded from results.
     46 *                                                       excluded from results.
    4747 *     @type string|bool       $meta_key            Limit results to users that have usermeta associated with this meta_key.
    4848 *                                                  Usually used with $meta_value. Default: false.
     
    7272         *
    7373         * @since 1.8.0
     74         *
    7475         * @var array
    7576         */
     
    8081         *
    8182         * @since 1.7.0
     83         *
    8284         * @var array
    8385         */
     
    8890         *
    8991         * @since 1.7.0
     92         *
    9093         * @var array
    9194         */
     
    9699         *
    97100         * @since 1.7.0
     101         *
    98102         * @var int
    99103         */
     
    104108         *
    105109         * @since 1.7.0
     110         *
    106111         * @var array
    107112         */
     
    112117         *
    113118         * @since 1.7.0
     119         *
    114120         * @var array
    115121         */
     
    120126         *
    121127         * @since 2.2.0
     128         *
    122129         * @var string
    123130         */
     
    128135         *
    129136         * @since 1.7.0
     137         *
    130138         * @var string
    131139         */
     
    136144         *
    137145         * @since 1.7.0
    138          * @var string
    139          */
    140         protected $no_results = array( 'join' => '', 'where' => '0 = 1' );
    141 
     146         *
     147         * @var array
     148         */
     149        protected $no_results = array(
     150                'join'  => '',
     151                'where' => '0 = 1',
     152        );
    142153
    143154        /** Methods ***************************************************************/
     
    233244         * Prepare the query for user_ids.
    234245         *
     246         * @global wpdb $wpdb WordPress database object.
     247         *
    235248         * @since 1.7.0
    236249         */
     
    256269                $sql = array(
    257270                        'select'  => '',
    258                         'where'   => array('1=1'),
     271                        'where'   => array( '1=1' ),
    259272                        'orderby' => '',
    260273                        'order'   => '',
    261                         'limit'   => ''
     274                        'limit'   => '',
    262275                );
    263276
     
    271284                        // Filter 'bp_user_query_online_interval' to modify the
    272285                        // number of minutes used as an interval.
    273                         case 'online' :
    274                                 $this->uid_name = 'user_id';
     286                        case 'online':
     287                                $this->uid_name  = 'user_id';
    275288                                $this->uid_table = $bp->members->table_name_last_activity;
    276                                 $sql['select']  = "SELECT u.{$this->uid_name} as id FROM {$this->uid_table} u";
    277                                 $sql['where'][] = $wpdb->prepare( "u.component = %s AND u.type = 'last_activity'", buddypress()->members->id );
     289                                $sql['select']   = "SELECT u.{$this->uid_name} as id FROM {$this->uid_table} u";
     290                                $sql['where'][]  = $wpdb->prepare( "u.component = %s AND u.type = 'last_activity'", buddypress()->members->id );
    278291
    279292                                /**
     
    284297                                 * @param int $value Amount of minutes for threshold. Default 15.
    285298                                 */
    286                                 $sql['where'][] = $wpdb->prepare( "u.date_recorded >= DATE_SUB( UTC_TIMESTAMP(), INTERVAL %d MINUTE )", apply_filters( 'bp_user_query_online_interval', 15 ) );
    287                                 $sql['orderby'] = "ORDER BY u.date_recorded";
    288                                 $sql['order']   = "DESC";
     299                                $sql['where'][] = $wpdb->prepare( 'u.date_recorded >= DATE_SUB( UTC_TIMESTAMP(), INTERVAL %d MINUTE )', apply_filters( 'bp_user_query_online_interval', 15 ) );
     300                                $sql['orderby'] = 'ORDER BY u.date_recorded';
     301                                $sql['order']   = 'DESC';
    289302
    290303                                // Date query.
     
    298311                        // 'active', 'newest', and 'random' queries
    299312                        // all happen against the last_activity usermeta key.
    300                         case 'active' :
    301                         case 'newest' :
    302                         case 'random' :
    303                                 $this->uid_name = 'user_id';
     313                        case 'active':
     314                        case 'newest':
     315                        case 'random':
     316                                $this->uid_name  = 'user_id';
    304317                                $this->uid_table = $bp->members->table_name_last_activity;
    305                                 $sql['select']  = "SELECT u.{$this->uid_name} as id FROM {$this->uid_table} u";
    306                                 $sql['where'][] = $wpdb->prepare( "u.component = %s AND u.type = 'last_activity'", buddypress()->members->id );
    307 
    308                                 if ( 'newest' == $type ) {
    309                                         $sql['orderby'] = "ORDER BY u.user_id";
    310                                         $sql['order'] = "DESC";
    311                                 } elseif ( 'random' == $type ) {
    312                                         $sql['orderby'] = "ORDER BY rand()";
     318                                $sql['select']   = "SELECT u.{$this->uid_name} as id FROM {$this->uid_table} u";
     319                                $sql['where'][]  = $wpdb->prepare( "u.component = %s AND u.type = 'last_activity'", buddypress()->members->id );
     320
     321                                if ( 'newest' === $type ) {
     322                                        $sql['orderby'] = 'ORDER BY u.user_id';
     323                                        $sql['order']   = 'DESC';
     324                                } elseif ( 'random' === $type ) {
     325                                        $sql['orderby'] = 'ORDER BY rand()';
    313326                                } else {
    314                                         $sql['orderby'] = "ORDER BY u.date_recorded";
    315                                         $sql['order'] = "DESC";
     327                                        $sql['orderby'] = 'ORDER BY u.date_recorded';
     328                                        $sql['order']   = 'DESC';
    316329                                }
    317330
     
    325338
    326339                        // 'popular' sorts by the 'total_friend_count' usermeta.
    327                         case 'popular' :
    328                                 $this->uid_name = 'user_id';
     340                        case 'popular':
     341                                $this->uid_name  = 'user_id';
    329342                                $this->uid_table = $wpdb->usermeta;
    330                                 $sql['select']  = "SELECT u.{$this->uid_name} as id FROM {$this->uid_table} u";
    331                                 $sql['where'][] = $wpdb->prepare( "u.meta_key = %s", bp_get_user_meta_key( 'total_friend_count' ) );
    332                                 $sql['orderby'] = "ORDER BY CONVERT(u.meta_value, SIGNED)";
    333                                 $sql['order']   = "DESC";
     343                                $sql['select']   = "SELECT u.{$this->uid_name} as id FROM {$this->uid_table} u";
     344                                $sql['where'][]  = $wpdb->prepare( 'u.meta_key = %s', bp_get_user_meta_key( 'total_friend_count' ) );
     345                                $sql['orderby']  = 'ORDER BY CONVERT(u.meta_value, SIGNED)';
     346                                $sql['order']    = 'DESC';
    334347
    335348                                break;
    336349
    337350                        // 'alphabetical' sorts depend on the xprofile setup.
    338                         case 'alphabetical' :
    339 
     351                        case 'alphabetical':
    340352                                // We prefer to do alphabetical sorts against the display_name field
    341353                                // of wp_users, because the table is smaller and better indexed. We
     
    344356                                // @todo remove need for bp_is_active() check.
    345357                                if ( ! bp_disable_profile_sync() || ! bp_is_active( 'xprofile' ) ) {
    346                                         $this->uid_name = 'ID';
     358                                        $this->uid_name  = 'ID';
    347359                                        $this->uid_table = $wpdb->users;
    348                                         $sql['select']  = "SELECT u.{$this->uid_name} as id FROM {$this->uid_table} u";
    349                                         $sql['orderby'] = "ORDER BY u.display_name";
    350                                         $sql['order']   = "ASC";
    351 
    352                                 // When profile sync is disabled, alphabetical sorts must happen against
    353                                 // the xprofile table.
     360                                        $sql['select']   = "SELECT u.{$this->uid_name} as id FROM {$this->uid_table} u";
     361                                        $sql['orderby']  = 'ORDER BY u.display_name';
     362                                        $sql['order']    = 'ASC';
     363
     364                                        // When profile sync is disabled, alphabetical sorts must happen against
     365                                        // the xprofile table.
    354366                                } else {
    355                                         $this->uid_name = 'user_id';
     367                                        $this->uid_name  = 'user_id';
    356368                                        $this->uid_table = $bp->profile->table_name_data;
    357                                         $sql['select']  = "SELECT u.{$this->uid_name} as id FROM {$this->uid_table} u";
    358                                         $sql['where'][] = $wpdb->prepare( "u.field_id = %d", bp_xprofile_fullname_field_id() );
    359                                         $sql['orderby'] = "ORDER BY u.value";
    360                                         $sql['order']   = "ASC";
     369                                        $sql['select']   = "SELECT u.{$this->uid_name} as id FROM {$this->uid_table} u";
     370                                        $sql['where'][]  = $wpdb->prepare( 'u.field_id = %d', bp_xprofile_fullname_field_id() );
     371                                        $sql['orderby']  = 'ORDER BY u.value';
     372                                        $sql['order']    = 'ASC';
    361373                                }
    362374
     
    364376                                // to infer spam/deleted/non-activated users. To ensure that these users
    365377                                // are filtered out, we add an appropriate sub-query.
    366                                 $sql['where'][] = "u.{$this->uid_name} IN ( SELECT ID FROM {$wpdb->users} WHERE " . bp_core_get_status_sql( '' ) . " )";
     378                                $sql['where'][] = "u.{$this->uid_name} IN ( SELECT ID FROM {$wpdb->users} WHERE " . bp_core_get_status_sql( '' ) . ' )';
    367379
    368380                                break;
    369381
    370382                        // Any other 'type' falls through.
    371                         default :
    372                                 $this->uid_name = 'ID';
     383                        default:
     384                                $this->uid_name  = 'ID';
    373385                                $this->uid_table = $wpdb->users;
    374                                 $sql['select']  = "SELECT u.{$this->uid_name} as id FROM {$this->uid_table} u";
     386                                $sql['select']   = "SELECT u.{$this->uid_name} as id FROM {$this->uid_table} u";
    375387
    376388                                // In this case, we assume that a plugin is
     
    387399
    388400                // An array containing nothing but 0 should always fail.
    389                 if ( 1 === count( $include_ids ) && 0 == reset( $include_ids ) ) {
     401                if ( 1 === count( $include_ids ) && 0 === reset( $include_ids ) ) {
    390402                        $sql['where'][] = $this->no_results['where'];
    391403                } elseif ( ! empty( $include_ids ) ) {
     
    409421                                $sql['where'][] = "u.{$this->uid_name} IN ({$friend_ids})";
    410422
    411                         // If the user has no friends, the query should always
    412                         // return no users.
     423                                // If the user has no friends, the query should always
     424                                // return no users.
    413425                        } else {
    414426                                $sql['where'][] = $this->no_results['where'];
     
    427439                                $search_terms_space   = '%' . $search_terms . ' %';
    428440                        } elseif ( $search_wildcard === 'right' ) {
    429                                 $search_terms_nospace =        $search_terms . '%';
     441                                $search_terms_nospace = $search_terms . '%';
    430442                                $search_terms_space   = '% ' . $search_terms . '%';
    431443                        } else {
     
    434446                        }
    435447
    436                         $matched_user_ids = $wpdb->get_col( $wpdb->prepare(
    437                                 "SELECT ID FROM {$wpdb->users} WHERE ( user_login LIKE %s OR user_login LIKE %s OR user_nicename LIKE %s OR user_nicename LIKE %s )",
    438                                 $search_terms_nospace,
    439                                 $search_terms_space,
    440                                 $search_terms_nospace,
    441                                 $search_terms_space
    442                         ) );
    443 
    444                         $match_in_clause = empty( $matched_user_ids) ? 'NULL' : implode( ',', $matched_user_ids );
     448                        $matched_user_ids = $wpdb->get_col(
     449                                $wpdb->prepare(
     450                                        "SELECT ID FROM {$wpdb->users} WHERE ( user_login LIKE %s OR user_login LIKE %s OR user_nicename LIKE %s OR user_nicename LIKE %s )",
     451                                        $search_terms_nospace,
     452                                        $search_terms_space,
     453                                        $search_terms_nospace,
     454                                        $search_terms_space
     455                                )
     456                        );
     457
     458                        $match_in_clause        = empty( $matched_user_ids ) ? 'NULL' : implode( ',', $matched_user_ids );
    445459                        $sql['where']['search'] = "u.{$this->uid_name} IN ({$match_in_clause})";
    446460                }
     
    455469                        $member_type_clause = $this->get_sql_clause_for_member_types( $member_type__not_in, 'NOT IN' );
    456470
    457                 // Member types to include.
     471                        // Member types to include.
    458472                } elseif ( ! empty( $member_type ) ) {
    459473                        $member_type_clause = $this->get_sql_clause_for_member_types( $member_type, 'IN' );
     
    470484
    471485                        if ( false !== $meta_value ) {
    472                                 $meta_sql .= $wpdb->prepare( " AND meta_value = %s", $meta_value );
     486                                $meta_sql .= $wpdb->prepare( ' AND meta_value = %s', $meta_value );
    473487                        }
    474488
     
    476490
    477491                        if ( ! empty( $found_user_ids ) ) {
    478                                 $sql['where'][] = "u.{$this->uid_name} IN (" . implode( ',', wp_parse_id_list( $found_user_ids ) ) . ")";
     492                                $sql['where'][] = "u.{$this->uid_name} IN (" . implode( ',', wp_parse_id_list( $found_user_ids ) ) . ')';
    479493                        } else {
    480494                                $sql['where'][] = '1 = 0';
     
    483497
    484498                // 'per_page', 'page' - handles LIMIT.
    485                 if ( !empty( $per_page ) && !empty( $page ) ) {
    486                         $sql['limit'] = $wpdb->prepare( "LIMIT %d, %d", intval( ( $page - 1 ) * $per_page ), intval( $per_page ) );
     499                if ( ! empty( $per_page ) && ! empty( $page ) ) {
     500                        $sql['limit'] = $wpdb->prepare( 'LIMIT %d, %d', intval( ( $page - 1 ) * $per_page ), intval( $per_page ) );
    487501                } else {
    488502                        $sql['limit'] = '';
     
    524538         * Also used to quickly perform user total counts.
    525539         *
     540         * @global wpdb $wpdb WordPress database object.
     541         *
    526542         * @since 1.7.0
    527543         */
     
    530546
    531547                // If counting using SQL_CALC_FOUND_ROWS, set it up here.
    532                 if ( 'sql_calc_found_rows' == $this->query_vars['count_total'] ) {
     548                if ( 'sql_calc_found_rows' === $this->query_vars['count_total'] ) {
    533549                        $this->uid_clauses['select'] = str_replace( 'SELECT', 'SELECT SQL_CALC_FOUND_ROWS', $this->uid_clauses['select'] );
    534550                }
     
    538554
    539555                // Get the total user count.
    540                 if ( 'sql_calc_found_rows' == $this->query_vars['count_total'] ) {
     556                if ( 'sql_calc_found_rows' === $this->query_vars['count_total'] ) {
    541557
    542558                        /**
     
    552568                         * @param BP_User_Query $user_query Current BP_User_Query instance.
    553569                         */
    554                         $this->total_users = $wpdb->get_var( apply_filters( 'bp_found_user_query', "SELECT FOUND_ROWS()", $this ) );
    555                 } elseif ( 'count_query' == $this->query_vars['count_total'] ) {
    556                         $count_select      = preg_replace( '/^SELECT.*?FROM (\S+) u/', "SELECT COUNT(u.{$this->uid_name}) FROM $1 u", $this->uid_clauses['select'] );
     570                        $this->total_users = $wpdb->get_var( apply_filters( 'bp_found_user_query', 'SELECT FOUND_ROWS()', $this ) );
     571                } elseif ( 'count_query' === $this->query_vars['count_total'] ) {
     572                        $count_select = preg_replace( '/^SELECT.*?FROM (\S+) u/', "SELECT COUNT(u.{$this->uid_name}) FROM $1 u", $this->uid_clauses['select'] );
    557573
    558574                        /** This filter is documented in bp-core/classes/class-bp-user-query.php */
     
    582598                 * @param BP_User_Query $user_query Current BP_User_Query instance.
    583599                 */
    584                 $wp_user_query = new WP_User_Query( apply_filters( 'bp_wp_user_query_args', array(
    585 
    586                         // Relevant.
    587                         'fields'      => $fields,
    588                         'include'     => $this->user_ids,
    589 
    590                         // Overrides
    591                         'blog_id'     => 0,    // BP does not require blog roles.
    592                         'count_total' => false // We already have a count.
    593 
    594                 ), $this ) );
     600                $wp_user_query = new WP_User_Query(
     601                        apply_filters(
     602                                'bp_wp_user_query_args',
     603                                array(
     604                                        // Relevant.
     605                                        'fields'      => $fields,
     606                                        'include'     => $this->user_ids,
     607
     608                                        // Overrides.
     609                                        'blog_id'     => 0,    // BP does not require blog roles.
     610                                        'count_total' => false, // We already have a count.
     611                                ),
     612                                $this
     613                        )
     614                );
    595615
    596616                /*
     
    613633                foreach ( $this->user_ids as $key => $uid ) {
    614634                        if ( isset( $r[ $uid ] ) ) {
    615                                 $r[ $uid ]->ID = (int) $uid;
     635                                $r[ $uid ]->ID          = (int) $uid;
    616636                                $r[ $uid ]->user_status = (int) $r[ $uid ]->user_status;
    617637
     
    622642                                $this->results[ $uid ]->id = (int) $uid;
    623643
    624                         // Remove user ID from original user_ids property.
     644                                // Remove user ID from original user_ids property.
    625645                        } else {
    626646                                unset( $this->user_ids[ $key ] );
     
    641661         * @since 1.8.0
    642662         *
    643          * @param array $include Sanitized array of user IDs, as passed to the 'include'
    644          *                       parameter of the class constructor.
     663         * @param array $include_ids Sanitized array of user IDs, as passed to the 'include'
     664         *                           parameter of the class constructor.
    645665         * @return array The list of users to which the main query should be
    646666         *               limited.
    647667         */
    648         public function get_include_ids( $include = array() ) {
    649                 return $include;
     668        public function get_include_ids( $include_ids = array() ) {
     669                return $include_ids;
    650670        }
    651671
     
    671691                // In the case of the 'popular' sort type, we force
    672692                // populate_extras to true, because we need the friend counts.
    673                 if ( 'popular' == $this->query_vars['type'] ) {
     693                if ( 'popular' === $this->query_vars['type'] ) {
    674694                        $this->query_vars['populate_extras'] = 1;
    675695                }
     
    707727                // Set a last_activity value for each user, even if it's empty.
    708728                foreach ( $this->results as $user_id => $user ) {
    709                         $user_last_activity = isset( $last_activities[ $user_id ]['date_recorded'] ) ? $last_activities[ $user_id ]['date_recorded'] : '';
     729                        $user_last_activity                       = isset( $last_activities[ $user_id ]['date_recorded'] ) ? $last_activities[ $user_id ]['date_recorded'] : '';
    710730                        $this->results[ $user_id ]->last_activity = $user_last_activity;
    711731                }
     
    716736                // - latest update.
    717737                $total_friend_count_key = bp_get_user_meta_key( 'total_friend_count' );
    718                 $bp_latest_update_key   = bp_get_user_meta_key( 'bp_latest_update'   );
     738                $bp_latest_update_key   = bp_get_user_meta_key( 'bp_latest_update' );
    719739
    720740                // Total_friend_count must be set for each user, even if its
    721741                // value is 0.
    722742                foreach ( $this->results as $uindex => $user ) {
    723                         $this->results[$uindex]->total_friend_count = 0;
     743                        $this->results[ $uindex ]->total_friend_count = 0;
    724744                }
    725745
     
    731751                foreach ( $user_metas as $user_meta ) {
    732752                        switch ( $user_meta->meta_key ) {
    733                                 case $total_friend_count_key :
     753                                case $total_friend_count_key:
    734754                                        $key = 'total_friend_count';
    735755                                        break;
    736756
    737                                 case $bp_latest_update_key :
     757                                case $bp_latest_update_key:
    738758                                        $key = 'latest_update';
    739759                                        break;
     
    749769                if ( ! empty( $this->query_vars['meta_key'] ) ) {
    750770                        $meta_sql = array(
    751                                 'select' => "SELECT user_id, meta_key, meta_value",
     771                                'select' => 'SELECT user_id, meta_key, meta_value',
    752772                                'from'   => "FROM $wpdb->usermeta",
    753                                 'where'  => $wpdb->prepare( "WHERE meta_key = %s", $this->query_vars['meta_key'] )
     773                                'where'  => $wpdb->prepare( 'WHERE meta_key = %s', $this->query_vars['meta_key'] ),
    754774                        );
    755775
    756776                        if ( false !== $this->query_vars['meta_value'] ) {
    757                                 $meta_sql['where'] .= $wpdb->prepare( " AND meta_value = %s", $this->query_vars['meta_value'] );
     777                                $meta_sql['where'] .= $wpdb->prepare( ' AND meta_value = %s', $this->query_vars['meta_value'] );
    758778                        }
    759779
     
    779799         * @since 2.4.0
    780800         *
     801         * @global wpdb $wpdb WordPress database object.
     802         *
    781803         * @param string|array $member_types Array or comma-separated list of member types.
    782804         * @param string       $operator     'IN' or 'NOT IN'.
     
    803825                }
    804826
    805                 $tax_query = new WP_Tax_Query( array(
     827                $tax_query = new WP_Tax_Query(
    806828                        array(
    807                                 'taxonomy' => bp_get_member_type_tax_name(),
    808                                 'field'    => 'name',
    809                                 'operator' => $operator,
    810                                 'terms'    => $types,
    811                         ),
    812                 ) );
     829                                array(
     830                                        'taxonomy' => bp_get_member_type_tax_name(),
     831                                        'field'    => 'name',
     832                                        'operator' => $operator,
     833                                        'terms'    => $types,
     834                                ),
     835                        )
     836                );
    813837
    814838                // Switch to the root blog, where member type taxonomies live.
     
    828852                        $clause = $this->no_results['where'];
    829853
    830                 // The tax_query clause generated for NOT IN can be used almost as-is. We just trim the leading 'AND'.
     854                        // The tax_query clause generated for NOT IN can be used almost as-is. We just trim the leading 'AND'.
    831855                } elseif ( 'NOT IN' === $operator ) {
    832856                        $clause = preg_replace( '/^\s*AND\s*/', '', $sql_clauses['where'] );
    833857
    834                 // IN clauses must be converted to a subquery.
     858                        // IN clauses must be converted to a subquery.
    835859                } elseif ( preg_match( '/' . $wpdb->term_relationships . '\.term_taxonomy_id IN \([0-9, ]+\)/', $sql_clauses['where'], $matches ) ) {
    836860                        $clause = "u.{$this->uid_name} IN ( SELECT object_id FROM $wpdb->term_relationships WHERE {$matches[0]} )";
  • trunk/src/bp-core/classes/class-bp-walker-category-checklist.php

    r10811 r13887  
    11<?php
     2/**
     3 * BP_Walker_Category_Checklist class.
     4 *
     5 * @package BuddyPress
     6 * @subpackage Core
     7 * @since 2.5.0
     8 */
     9
     10// Exit if accessed directly.
     11defined( 'ABSPATH' ) || exit;
     12
    213/**
    314 * Walker class to output an unordered list of category checkbox input elements.
     
    1021 */
    1122class BP_Walker_Category_Checklist extends Walker {
     23        /**
     24         * Tree type.
     25         *
     26         * @since 2.5.0
     27         *
     28         * @var string
     29         */
    1230        public $tree_type = 'category';
    13         public $db_fields = array( 'parent' => 'parent', 'id' => 'term_id' );
     31
     32        /**
     33         * DB Fields.
     34         *
     35         * @since 2.5.0
     36         *
     37         * @var array
     38         */
     39        public $db_fields = array(
     40                'parent' => 'parent',
     41                'id'     => 'term_id',
     42        );
    1443
    1544        /**
     
    3766         */
    3867        public function end_lvl( &$output, $depth = 0, $args = array() ) {
    39                 $indent = str_repeat( "\t", $depth );
     68                $indent  = str_repeat( "\t", $depth );
    4069                $output .= "$indent</ul>\n";
    4170        }
     
    5786                }
    5887
    59                 if ( $taxonomy == 'category' ) {
     88                if ( 'category' === $taxonomy ) {
    6089                        $name = 'post_category';
    6190                } else {
     
    6493
    6594                $args['popular_cats'] = empty( $args['popular_cats'] ) ? array() : $args['popular_cats'];
    66                 $class = in_array( $category->term_id, $args['popular_cats'] ) ? ' class="popular-category"' : '';
     95                $class                = in_array( $category->term_id, $args['popular_cats'], true ) ? ' class="popular-category"' : '';
    6796
    6897                $args['selected_cats'] = empty( $args['selected_cats'] ) ? array() : $args['selected_cats'];
     
    7099                if ( ! empty( $args['list_only'] ) ) {
    71100                        $aria_cheched = 'false';
    72                         $inner_class = 'category';
     101                        $inner_class  = 'category';
    73102
    74                         if ( in_array( $category->term_id, $args['selected_cats'] ) ) {
     103                        if ( in_array( $category->term_id, $args['selected_cats'], true ) ) {
    75104                                $inner_class .= ' selected';
    76105                                $aria_cheched = 'true';
     
    85114                        /** This filter is documented in wp-includes/category-template.php */
    86115                        $output .= "\n<li id='{$taxonomy}-{$category->term_id}'$class>" .
    87                                 '<label for="in-'.$taxonomy.'-' . $category->term_id . '" class="selectit"><input value="' . $category->slug . '" type="checkbox" name="'.$name.'[]" id="in-'.$taxonomy.'-' . $category->term_id . '"' .
    88                                 checked( in_array( $category->term_id, $args['selected_cats'] ), true, false ) .
     116                                '<label for="in-' . $taxonomy . '-' . $category->term_id . '" class="selectit"><input value="' . $category->slug . '" type="checkbox" name="' . $name . '[]" id="in-' . $taxonomy . '-' . $category->term_id . '"' .
     117                                checked( in_array( $category->term_id, $args['selected_cats'], true ), true, false ) .
    89118                                disabled( empty( $args['disabled'] ), false, false ) . ' /> ' .
    90119                                esc_html( apply_filters( 'the_category', $category->description ) ) . '</label>';
     
    102131         * @param object $category The current term object.
    103132         * @param int    $depth    Depth of the term in reference to parents. Default 0.
    104          * @param array  $args     An array of arguments. @see wp_terms_checklist()
     133         * @param array  $args     An array of arguments.
    105134         */
    106135        public function end_el( &$output, $category, $depth = 0, $args = array() ) {
  • trunk/src/bp-core/classes/class-bp-walker-nav-menu.php

    r12552 r13887  
    2121         *
    2222         * @since 1.7.0
     23         *
    2324         * @var array
    2425         */
    25         var $db_fields = array( 'id' => 'css_id', 'parent' => 'parent' );
     26        public $db_fields = array(
     27                'id'     => 'css_id',
     28                'parent' => 'parent',
     29        );
    2630
    2731        /**
     
    2933         *
    3034         * @since 1.7.0
     35         *
    3136         * @var string
    3237         */
    33         var $tree_type = array();
     38        public $tree_type = array();
    3439
    3540        /**
     
    5964                $output = '';
    6065
    61                 if ( $max_depth < -1 ) // Invalid parameter.
     66                if ( $max_depth < -1 ) { // Invalid parameter.
    6267                        return $output;
    63 
    64                 if ( empty( $elements ) ) // Nothing to walk.
     68                }
     69
     70                if ( empty( $elements ) ) { // Nothing to walk.
    6571                        return $output;
     72                }
    6673
    6774                $parent_field = $this->db_fields['parent'];
    6875
    6976                // Flat display.
    70                 if ( -1 == $max_depth ) {
     77                if ( -1 === $max_depth ) {
    7178
    7279                        $empty_array = array();
    73                         foreach ( $elements as $e )
     80                        foreach ( $elements as $e ) {
    7481                                $this->display_element( $e, $empty_array, 1, 0, $args, $output );
     82                        }
    7583
    7684                        return $output;
     
    8896                foreach ( $elements as $e ) {
    8997                        // BuddyPress: changed '==' to '==='. This is the only change from version in Walker::walk().
    90                         if ( 0 === $e->$parent_field )
     98                        if ( 0 === $e->$parent_field ) {
    9199                                $top_level_elements[] = $e;
    92                         else
    93                                 $children_elements[$e->$parent_field][] = $e;
     100                        } else {
     101                                $children_elements[ $e->$parent_field ][] = $e;
     102                        }
    94103                }
    95104
     
    106115
    107116                        foreach ( $elements as $e ) {
    108                                 if ( $root->$parent_field == $e->$parent_field )
     117                                if ( $root->$parent_field === $e->$parent_field ) {
    109118                                        $top_level_elements[] = $e;
    110                                 else
    111                                         $children_elements[$e->$parent_field][] = $e;
    112                         }
    113                 }
    114 
    115                 foreach ( $top_level_elements as $e )
     119                                } else {
     120                                        $children_elements[ $e->$parent_field ][] = $e;
     121                                }
     122                        }
     123                }
     124
     125                foreach ( $top_level_elements as $e ) {
    116126                        $this->display_element( $e, $children_elements, $max_depth, 0, $args, $output );
     127                }
    117128
    118129                /*
     
    120131                 * then we got orphans, which should be displayed regardless.
    121132                 */
    122                 if ( ( $max_depth == 0 ) && count( $children_elements ) > 0 ) {
     133                if ( ( 0 === $max_depth ) && count( $children_elements ) > 0 ) {
    123134                        $empty_array = array();
    124135
    125                         foreach ( $children_elements as $orphans )
    126                                 foreach ( $orphans as $op )
     136                        foreach ( $children_elements as $orphans ) {
     137                                foreach ( $orphans as $op ) {
    127138                                        $this->display_element( $op, $empty_array, 1, 0, $args, $output );
    128                  }
    129 
    130                  return $output;
     139                                }
     140                        }
     141                }
     142
     143                return $output;
    131144        }
    132145
     
    152165         * @since 1.7.0
    153166         *
    154          * @param string $output Passed by reference. Used to append
    155          *                       additional content.
    156          * @param object $item   Menu item data object.
    157          * @param int    $depth  Depth of menu item. Used for padding. Optional,
    158          *                       defaults to 0.
    159          * @param array $args   Optional. See {@link Walker::start_el()}.
    160          * @param int    $id     Menu item ID. Optional.
     167         * @param string   $output Passed by reference. Used to append
     168         *                         dditional content.
     169         * @param object   $item   Menu item data object.
     170         * @param int      $depth  Optional. Depth of menu item. Used for padding.
     171         *                         Defaults to 0.
     172         * @param stdClass $args   Optional. See {@link Walker::start_el()}.
     173         * @param int      $id     Menu item ID. Optional.
    161174         */
    162175        public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
     
    169182                 * @since 1.7.0
    170183                 *
    171                  * @param array  $value Array of classes to be added.
    172                  * @param object $item  Menu item data object.
    173                  * @param array  $args  Array of arguments for the item.
     184                 * @param array    $value Array of classes to be added.
     185                 * @param object   $item  Menu item data object.
     186                 * @param stdClass $args  An object of wp_nav_menu() arguments.
    174187                 */
    175188                $class_names = join( ' ', apply_filters( 'bp_nav_menu_css_class', array_filter( $item->class ), $item, $args ) );
    176189                $class_names = ! empty( $class_names ) ? ' class="' . esc_attr( $class_names ) . '"' : '';
    177190
    178                 // Add HTML ID
     191                // Add HTML ID.
    179192                $id = sanitize_html_class( $item->css_id . '-personal-li' );  // Backpat with BP pre-1.7.
    180193
     
    184197                 * @since 1.7.0
    185198                 *
    186                  * @param string $id   ID attribute to be added to the menu item.
    187                  * @param object $item Menu item data object.
    188                  * @param array  $args Array of arguments for the item.
     199                 * @param string   $id   ID attribute to be added to the menu item.
     200                 * @param object   $item Menu item data object.
     201                 * @param stdClass $args An object of wp_nav_menu() arguments.
    189202                 */
    190203                $id = apply_filters( 'bp_nav_menu_item_id', $id, $item, $args );
     
    198211
    199212                // Construct the link.
    200                 $item_output = $args->before;
     213                $item_output  = $args->before;
    201214                $item_output .= '<a' . $attributes . '>';
    202215
     
    206219                 * @since 1.7.0
    207220                 *
    208                  * @param string $name  Item text to be applied.
    209                  * @param int    $value Post ID the title is for.
    210                  */
    211                 $item_output .= $args->link_before . apply_filters( 'the_title', $item->name, 0 ) . $args->link_after;
     221                 * @param string $name    Item text to be applied.
     222                 * @param int    $post_id Post ID the title is for.
     223                 */
     224                $link_text = apply_filters( 'the_title', $item->name, 0 );
     225
     226                $item_output .= $args->link_before . $link_text . $args->link_after;
    212227                $item_output .= '</a>';
    213228                $item_output .= $args->after;
     
    218233                 * @since 1.7.0
    219234                 *
    220                  * @param string $item_output Constructed output for the menu item to append to output.
    221                  * @param object $item        Menu item data object.
    222                  * @param int    $depth       Depth of menu item. Used for padding.
    223                  * @param array  $args        Array of arguments for the item.
     235                 * @param string   $item_output Constructed output for the menu item to append to output.
     236                 * @param object   $item        Menu item data object.
     237                 * @param int      $depth       Depth of menu item. Used for padding.
     238                 * @param stdClass $args        An object of wp_nav_menu() arguments.
    224239                 */
    225240                $output .= apply_filters( 'bp_walker_nav_menu_start_el', $item_output, $item, $depth, $args );
Note: See TracChangeset for help on using the changeset viewer.