Changeset 13887
- Timestamp:
- 06/01/2024 10:19:51 PM (4 months ago)
- 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 99 99 100 100 $sql_chunks['join'] = array_merge( $sql_chunks['join'], $clause_sql['join'] ); 101 // This is a subquery.101 // This is a subquery. 102 102 } else { 103 103 $clause_sql = $this->get_sql_for_query( $clause, $depth + 1 ); … … 157 157 continue; 158 158 159 // First-order clause.159 // First-order clause. 160 160 } elseif ( $this->is_first_order_clause( $query ) ) { 161 161 if ( isset( $query['value'] ) && array() === $query['value'] ) { … … 165 165 $clean_queries[] = $query; 166 166 167 // Otherwise, it's a nested query, so we recurse.167 // Otherwise, it's a nested query, so we recurse. 168 168 } else { 169 169 $cleaned_query = $this->sanitize_query( $query ); … … 183 183 $clean_queries['relation'] = 'OR'; 184 184 185 /*186 187 188 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 */ 190 190 } elseif ( 1 === count( $clean_queries ) ) { 191 191 $clean_queries['relation'] = 'OR'; 192 192 193 // Default to AND.193 // Default to AND. 194 194 } else { 195 195 $clean_queries['relation'] = 'AND'; -
trunk/src/bp-core/classes/class-bp-theme-compat.php
r13013 r13887 40 40 * 41 41 * @since 1.7.0 42 * 42 43 * @var array 43 44 */ … … 51 52 * @param array $properties Array of properties for BP_Theme_Compat. 52 53 */ 53 public function __construct( Array $properties = array() ) {54 public function __construct( array $properties = array() ) { 54 55 $this->_data = $properties; 55 56 } … … 103 104 */ 104 105 public function __set( $property, $value ) { 105 return $this->_data[ $property] = $value;106 return $this->_data[ $property ] = $value; 106 107 } 107 108 … … 116 117 */ 117 118 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 ] : ''; 119 120 } 120 121 -
trunk/src/bp-core/classes/class-bp-user-query.php
r13395 r13887 18 18 * 19 19 * @since 1.7.0 20 * @since 10.0.0 Added $date_queryparameter.20 * @since 10.0.0 Added `$date_query` parameter. 21 21 * 22 22 * @param array $query { … … 44 44 * @type array|string $member_type__in Array or comma-separated list of member types to limit results to. 45 45 * @type array|string $member_type__not_in Array or comma-separated list of member types that will be 46 * 46 * excluded from results. 47 47 * @type string|bool $meta_key Limit results to users that have usermeta associated with this meta_key. 48 48 * Usually used with $meta_value. Default: false. … … 72 72 * 73 73 * @since 1.8.0 74 * 74 75 * @var array 75 76 */ … … 80 81 * 81 82 * @since 1.7.0 83 * 82 84 * @var array 83 85 */ … … 88 90 * 89 91 * @since 1.7.0 92 * 90 93 * @var array 91 94 */ … … 96 99 * 97 100 * @since 1.7.0 101 * 98 102 * @var int 99 103 */ … … 104 108 * 105 109 * @since 1.7.0 110 * 106 111 * @var array 107 112 */ … … 112 117 * 113 118 * @since 1.7.0 119 * 114 120 * @var array 115 121 */ … … 120 126 * 121 127 * @since 2.2.0 128 * 122 129 * @var string 123 130 */ … … 128 135 * 129 136 * @since 1.7.0 137 * 130 138 * @var string 131 139 */ … … 136 144 * 137 145 * @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 ); 142 153 143 154 /** Methods ***************************************************************/ … … 233 244 * Prepare the query for user_ids. 234 245 * 246 * @global wpdb $wpdb WordPress database object. 247 * 235 248 * @since 1.7.0 236 249 */ … … 256 269 $sql = array( 257 270 'select' => '', 258 'where' => array( '1=1'),271 'where' => array( '1=1' ), 259 272 'orderby' => '', 260 273 'order' => '', 261 'limit' => '' 274 'limit' => '', 262 275 ); 263 276 … … 271 284 // Filter 'bp_user_query_online_interval' to modify the 272 285 // 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'; 275 288 $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 ); 278 291 279 292 /** … … 284 297 * @param int $value Amount of minutes for threshold. Default 15. 285 298 */ 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'; 289 302 290 303 // Date query. … … 298 311 // 'active', 'newest', and 'random' queries 299 312 // 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'; 304 317 $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()'; 313 326 } 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'; 316 329 } 317 330 … … 325 338 326 339 // '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'; 329 342 $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'; 334 347 335 348 break; 336 349 337 350 // 'alphabetical' sorts depend on the xprofile setup. 338 case 'alphabetical' : 339 351 case 'alphabetical': 340 352 // We prefer to do alphabetical sorts against the display_name field 341 353 // of wp_users, because the table is smaller and better indexed. We … … 344 356 // @todo remove need for bp_is_active() check. 345 357 if ( ! bp_disable_profile_sync() || ! bp_is_active( 'xprofile' ) ) { 346 $this->uid_name = 'ID';358 $this->uid_name = 'ID'; 347 359 $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 against353 // 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. 354 366 } else { 355 $this->uid_name = 'user_id';367 $this->uid_name = 'user_id'; 356 368 $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'; 361 373 } 362 374 … … 364 376 // to infer spam/deleted/non-activated users. To ensure that these users 365 377 // 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( '' ) . ' )'; 367 379 368 380 break; 369 381 370 382 // Any other 'type' falls through. 371 default 372 $this->uid_name = 'ID';383 default: 384 $this->uid_name = 'ID'; 373 385 $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"; 375 387 376 388 // In this case, we assume that a plugin is … … 387 399 388 400 // 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 ) ) { 390 402 $sql['where'][] = $this->no_results['where']; 391 403 } elseif ( ! empty( $include_ids ) ) { … … 409 421 $sql['where'][] = "u.{$this->uid_name} IN ({$friend_ids})"; 410 422 411 // If the user has no friends, the query should always412 // return no users.423 // If the user has no friends, the query should always 424 // return no users. 413 425 } else { 414 426 $sql['where'][] = $this->no_results['where']; … … 427 439 $search_terms_space = '%' . $search_terms . ' %'; 428 440 } elseif ( $search_wildcard === 'right' ) { 429 $search_terms_nospace = 441 $search_terms_nospace = $search_terms . '%'; 430 442 $search_terms_space = '% ' . $search_terms . '%'; 431 443 } else { … … 434 446 } 435 447 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 ); 445 459 $sql['where']['search'] = "u.{$this->uid_name} IN ({$match_in_clause})"; 446 460 } … … 455 469 $member_type_clause = $this->get_sql_clause_for_member_types( $member_type__not_in, 'NOT IN' ); 456 470 457 // Member types to include.471 // Member types to include. 458 472 } elseif ( ! empty( $member_type ) ) { 459 473 $member_type_clause = $this->get_sql_clause_for_member_types( $member_type, 'IN' ); … … 470 484 471 485 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 ); 473 487 } 474 488 … … 476 490 477 491 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 ) ) . ')'; 479 493 } else { 480 494 $sql['where'][] = '1 = 0'; … … 483 497 484 498 // '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 ) ); 487 501 } else { 488 502 $sql['limit'] = ''; … … 524 538 * Also used to quickly perform user total counts. 525 539 * 540 * @global wpdb $wpdb WordPress database object. 541 * 526 542 * @since 1.7.0 527 543 */ … … 530 546 531 547 // 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'] ) { 533 549 $this->uid_clauses['select'] = str_replace( 'SELECT', 'SELECT SQL_CALC_FOUND_ROWS', $this->uid_clauses['select'] ); 534 550 } … … 538 554 539 555 // 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'] ) { 541 557 542 558 /** … … 552 568 * @param BP_User_Query $user_query Current BP_User_Query instance. 553 569 */ 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 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'] ); 557 573 558 574 /** This filter is documented in bp-core/classes/class-bp-user-query.php */ … … 582 598 * @param BP_User_Query $user_query Current BP_User_Query instance. 583 599 */ 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 ); 595 615 596 616 /* … … 613 633 foreach ( $this->user_ids as $key => $uid ) { 614 634 if ( isset( $r[ $uid ] ) ) { 615 $r[ $uid ]->ID = (int) $uid;635 $r[ $uid ]->ID = (int) $uid; 616 636 $r[ $uid ]->user_status = (int) $r[ $uid ]->user_status; 617 637 … … 622 642 $this->results[ $uid ]->id = (int) $uid; 623 643 624 // Remove user ID from original user_ids property.644 // Remove user ID from original user_ids property. 625 645 } else { 626 646 unset( $this->user_ids[ $key ] ); … … 641 661 * @since 1.8.0 642 662 * 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. 645 665 * @return array The list of users to which the main query should be 646 666 * limited. 647 667 */ 648 public function get_include_ids( $include = array() ) {649 return $include ;668 public function get_include_ids( $include_ids = array() ) { 669 return $include_ids; 650 670 } 651 671 … … 671 691 // In the case of the 'popular' sort type, we force 672 692 // populate_extras to true, because we need the friend counts. 673 if ( 'popular' == $this->query_vars['type'] ) {693 if ( 'popular' === $this->query_vars['type'] ) { 674 694 $this->query_vars['populate_extras'] = 1; 675 695 } … … 707 727 // Set a last_activity value for each user, even if it's empty. 708 728 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'] : ''; 710 730 $this->results[ $user_id ]->last_activity = $user_last_activity; 711 731 } … … 716 736 // - latest update. 717 737 $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' ); 719 739 720 740 // Total_friend_count must be set for each user, even if its 721 741 // value is 0. 722 742 foreach ( $this->results as $uindex => $user ) { 723 $this->results[ $uindex]->total_friend_count = 0;743 $this->results[ $uindex ]->total_friend_count = 0; 724 744 } 725 745 … … 731 751 foreach ( $user_metas as $user_meta ) { 732 752 switch ( $user_meta->meta_key ) { 733 case $total_friend_count_key 753 case $total_friend_count_key: 734 754 $key = 'total_friend_count'; 735 755 break; 736 756 737 case $bp_latest_update_key 757 case $bp_latest_update_key: 738 758 $key = 'latest_update'; 739 759 break; … … 749 769 if ( ! empty( $this->query_vars['meta_key'] ) ) { 750 770 $meta_sql = array( 751 'select' => "SELECT user_id, meta_key, meta_value",771 'select' => 'SELECT user_id, meta_key, meta_value', 752 772 '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'] ), 754 774 ); 755 775 756 776 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'] ); 758 778 } 759 779 … … 779 799 * @since 2.4.0 780 800 * 801 * @global wpdb $wpdb WordPress database object. 802 * 781 803 * @param string|array $member_types Array or comma-separated list of member types. 782 804 * @param string $operator 'IN' or 'NOT IN'. … … 803 825 } 804 826 805 $tax_query = new WP_Tax_Query( array(827 $tax_query = new WP_Tax_Query( 806 828 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 ); 813 837 814 838 // Switch to the root blog, where member type taxonomies live. … … 828 852 $clause = $this->no_results['where']; 829 853 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'. 831 855 } elseif ( 'NOT IN' === $operator ) { 832 856 $clause = preg_replace( '/^\s*AND\s*/', '', $sql_clauses['where'] ); 833 857 834 // IN clauses must be converted to a subquery.858 // IN clauses must be converted to a subquery. 835 859 } elseif ( preg_match( '/' . $wpdb->term_relationships . '\.term_taxonomy_id IN \([0-9, ]+\)/', $sql_clauses['where'], $matches ) ) { 836 860 $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 1 1 <?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. 11 defined( 'ABSPATH' ) || exit; 12 2 13 /** 3 14 * Walker class to output an unordered list of category checkbox input elements. … … 10 21 */ 11 22 class BP_Walker_Category_Checklist extends Walker { 23 /** 24 * Tree type. 25 * 26 * @since 2.5.0 27 * 28 * @var string 29 */ 12 30 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 ); 14 43 15 44 /** … … 37 66 */ 38 67 public function end_lvl( &$output, $depth = 0, $args = array() ) { 39 $indent = str_repeat( "\t", $depth );68 $indent = str_repeat( "\t", $depth ); 40 69 $output .= "$indent</ul>\n"; 41 70 } … … 57 86 } 58 87 59 if ( $taxonomy == 'category') {88 if ( 'category' === $taxonomy ) { 60 89 $name = 'post_category'; 61 90 } else { … … 64 93 65 94 $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"' : ''; 67 96 68 97 $args['selected_cats'] = empty( $args['selected_cats'] ) ? array() : $args['selected_cats']; … … 70 99 if ( ! empty( $args['list_only'] ) ) { 71 100 $aria_cheched = 'false'; 72 $inner_class = 'category';101 $inner_class = 'category'; 73 102 74 if ( in_array( $category->term_id, $args['selected_cats'] ) ) {103 if ( in_array( $category->term_id, $args['selected_cats'], true ) ) { 75 104 $inner_class .= ' selected'; 76 105 $aria_cheched = 'true'; … … 85 114 /** This filter is documented in wp-includes/category-template.php */ 86 115 $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 ) . 89 118 disabled( empty( $args['disabled'] ), false, false ) . ' /> ' . 90 119 esc_html( apply_filters( 'the_category', $category->description ) ) . '</label>'; … … 102 131 * @param object $category The current term object. 103 132 * @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. 105 134 */ 106 135 public function end_el( &$output, $category, $depth = 0, $args = array() ) { -
trunk/src/bp-core/classes/class-bp-walker-nav-menu.php
r12552 r13887 21 21 * 22 22 * @since 1.7.0 23 * 23 24 * @var array 24 25 */ 25 var $db_fields = array( 'id' => 'css_id', 'parent' => 'parent' ); 26 public $db_fields = array( 27 'id' => 'css_id', 28 'parent' => 'parent', 29 ); 26 30 27 31 /** … … 29 33 * 30 34 * @since 1.7.0 35 * 31 36 * @var string 32 37 */ 33 var$tree_type = array();38 public $tree_type = array(); 34 39 35 40 /** … … 59 64 $output = ''; 60 65 61 if ( $max_depth < -1 ) // Invalid parameter.66 if ( $max_depth < -1 ) { // Invalid parameter. 62 67 return $output; 63 64 if ( empty( $elements ) ) // Nothing to walk. 68 } 69 70 if ( empty( $elements ) ) { // Nothing to walk. 65 71 return $output; 72 } 66 73 67 74 $parent_field = $this->db_fields['parent']; 68 75 69 76 // Flat display. 70 if ( -1 == $max_depth ) {77 if ( -1 === $max_depth ) { 71 78 72 79 $empty_array = array(); 73 foreach ( $elements as $e ) 80 foreach ( $elements as $e ) { 74 81 $this->display_element( $e, $empty_array, 1, 0, $args, $output ); 82 } 75 83 76 84 return $output; … … 88 96 foreach ( $elements as $e ) { 89 97 // 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 ) { 91 99 $top_level_elements[] = $e; 92 else 93 $children_elements[$e->$parent_field][] = $e; 100 } else { 101 $children_elements[ $e->$parent_field ][] = $e; 102 } 94 103 } 95 104 … … 106 115 107 116 foreach ( $elements as $e ) { 108 if ( $root->$parent_field == $e->$parent_field )117 if ( $root->$parent_field === $e->$parent_field ) { 109 118 $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 ) { 116 126 $this->display_element( $e, $children_elements, $max_depth, 0, $args, $output ); 127 } 117 128 118 129 /* … … 120 131 * then we got orphans, which should be displayed regardless. 121 132 */ 122 if ( ( $max_depth == 0) && count( $children_elements ) > 0 ) {133 if ( ( 0 === $max_depth ) && count( $children_elements ) > 0 ) { 123 134 $empty_array = array(); 124 135 125 foreach ( $children_elements as $orphans ) 126 foreach ( $orphans as $op ) 136 foreach ( $children_elements as $orphans ) { 137 foreach ( $orphans as $op ) { 127 138 $this->display_element( $op, $empty_array, 1, 0, $args, $output ); 128 } 129 130 return $output; 139 } 140 } 141 } 142 143 return $output; 131 144 } 132 145 … … 152 165 * @since 1.7.0 153 166 * 154 * @param string $output Passed by reference. Used to append155 * 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. 161 174 */ 162 175 public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) { … … 169 182 * @since 1.7.0 170 183 * 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. 174 187 */ 175 188 $class_names = join( ' ', apply_filters( 'bp_nav_menu_css_class', array_filter( $item->class ), $item, $args ) ); 176 189 $class_names = ! empty( $class_names ) ? ' class="' . esc_attr( $class_names ) . '"' : ''; 177 190 178 // Add HTML ID 191 // Add HTML ID. 179 192 $id = sanitize_html_class( $item->css_id . '-personal-li' ); // Backpat with BP pre-1.7. 180 193 … … 184 197 * @since 1.7.0 185 198 * 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. 189 202 */ 190 203 $id = apply_filters( 'bp_nav_menu_item_id', $id, $item, $args ); … … 198 211 199 212 // Construct the link. 200 $item_output = $args->before;213 $item_output = $args->before; 201 214 $item_output .= '<a' . $attributes . '>'; 202 215 … … 206 219 * @since 1.7.0 207 220 * 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; 212 227 $item_output .= '</a>'; 213 228 $item_output .= $args->after; … … 218 233 * @since 1.7.0 219 234 * 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. 224 239 */ 225 240 $output .= apply_filters( 'bp_walker_nav_menu_start_el', $item_output, $item, $depth, $args );
Note: See TracChangeset
for help on using the changeset viewer.