Changeset 13994
- Timestamp:
- 08/07/2024 01:46:38 AM (3 months ago)
- Location:
- trunk/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-core/classes/class-bp-user-query.php
r13896 r13994 677 677 * 678 678 * @since 1.7.0 679 * 680 * @global wpdb $wpdb WordPress database object. 679 * @since 15.0.0 Some properties were moved into action hooks. 681 680 */ 682 681 public function populate_extras() { 683 global $wpdb;684 682 685 683 // Bail if no users. … … 708 706 * avoid running multiple queries per user in the loop. 709 707 * 710 * T woBuddyPress components currently do this:708 * Three BuddyPress components currently do this: 711 709 * - XProfile: To override display names. 712 * - Friends: To set whether or not a user is the current users friend. 710 * - Friends: To set whether a user is the current users friend. 711 * - Members: To set last activity, total friend count, last update, 712 * and meta_key/meta_value if passed to the query. 713 713 * 714 714 * @see bp_xprofile_filter_user_query_populate_extras() 715 715 * @see bp_friends_filter_user_query_populate_extras() 716 * @see bp_members_filter_user_query_populate_extras_last_activity() 717 * @see bp_members_filter_user_query_populate_extras_friend_count_latest_update() 718 * @see bp_members_filter_user_query_populate_extras_meta() 716 719 * 717 720 * @since 1.7.0 … … 721 724 */ 722 725 do_action_ref_array( 'bp_user_query_populate_extras', array( $this, $user_ids_sql ) ); 723 724 // Fetch last_active data from the activity table.725 $last_activities = BP_Core_User::get_last_activity( $this->user_ids );726 727 // Set a last_activity value for each user, even if it's empty.728 foreach ( $this->results as $user_id => $user ) {729 $user_last_activity = isset( $last_activities[ $user_id ]['date_recorded'] ) ? $last_activities[ $user_id ]['date_recorded'] : '';730 $this->results[ $user_id ]->last_activity = $user_last_activity;731 }732 733 // Fetch usermeta data734 // We want the three following pieces of info from usermeta:735 // - friend count736 // - latest update.737 $total_friend_count_key = bp_get_user_meta_key( 'total_friend_count' );738 $bp_latest_update_key = bp_get_user_meta_key( 'bp_latest_update' );739 740 // Total_friend_count must be set for each user, even if its741 // value is 0.742 foreach ( $this->results as $uindex => $user ) {743 $this->results[ $uindex ]->total_friend_count = 0;744 }745 746 // Create, prepare, and run the separate usermeta query.747 $user_metas = $wpdb->get_results( $wpdb->prepare( "SELECT user_id, meta_key, meta_value FROM {$wpdb->usermeta} WHERE meta_key IN (%s,%s) AND user_id IN ({$user_ids_sql})", $total_friend_count_key, $bp_latest_update_key ) );748 749 // The $members_template global expects the index key to be different750 // from the meta_key in some cases, so we rejig things here.751 foreach ( $user_metas as $user_meta ) {752 switch ( $user_meta->meta_key ) {753 case $total_friend_count_key:754 $key = 'total_friend_count';755 break;756 757 case $bp_latest_update_key:758 $key = 'latest_update';759 break;760 }761 762 if ( isset( $this->results[ $user_meta->user_id ] ) ) {763 $this->results[ $user_meta->user_id ]->{$key} = $user_meta->meta_value;764 }765 }766 767 // When meta_key or meta_value have been passed to the query,768 // fetch the resulting values for use in the template functions.769 if ( ! empty( $this->query_vars['meta_key'] ) ) {770 $meta_sql = array(771 'select' => 'SELECT user_id, meta_key, meta_value',772 'from' => "FROM $wpdb->usermeta",773 'where' => $wpdb->prepare( 'WHERE meta_key = %s', $this->query_vars['meta_key'] ),774 );775 776 if ( false !== $this->query_vars['meta_value'] ) {777 $meta_sql['where'] .= $wpdb->prepare( ' AND meta_value = %s', $this->query_vars['meta_value'] );778 }779 780 $metas = $wpdb->get_results( "{$meta_sql['select']} {$meta_sql['from']} {$meta_sql['where']}" );781 782 if ( ! empty( $metas ) ) {783 foreach ( $metas as $meta ) {784 if ( isset( $this->results[ $meta->user_id ] ) ) {785 $this->results[ $meta->user_id ]->meta_key = $meta->meta_key;786 787 if ( ! empty( $meta->meta_value ) ) {788 $this->results[ $meta->user_id ]->meta_value = $meta->meta_value;789 }790 }791 }792 }793 }794 726 } 795 727 -
trunk/src/bp-friends/bp-friends-filters.php
r13092 r13994 48 48 } 49 49 } 50 add_ filter( 'bp_user_query_populate_extras', 'bp_friends_filter_user_query_populate_extras', 4, 2 );50 add_action( 'bp_user_query_populate_extras', 'bp_friends_filter_user_query_populate_extras', 4, 2 ); 51 51 52 52 /** -
trunk/src/bp-members/bp-members-filters.php
r13878 r13994 35 35 36 36 // Filters on sign-up fields. 37 $fields = array 37 $fields = array( 38 38 'bp_get_signup_username_value', 39 39 'bp_get_signup_email_value', … … 47 47 // Add the filters to each field. 48 48 foreach ( $fields as $filter ) { 49 add_filter( $filter, 'esc_html', 49 add_filter( $filter, 'esc_html', 1 ); 50 50 add_filter( $filter, 'wp_filter_kses', 2 ); 51 add_filter( $filter, 'stripslashes', 51 add_filter( $filter, 'stripslashes', 3 ); 52 52 } 53 53 … … 76 76 77 77 if ( is_network_admin() && isset( $_POST['blog'] ) ) { 78 $blog = $_POST['blog'];78 $blog = $_POST['blog']; 79 79 $domain = ''; 80 80 … … 86 86 $illegal_names[] = $domain; 87 87 } 88 89 88 } else { 90 89 $illegal_names[] = buddypress()->signup->username; … … 131 130 } 132 131 add_filter( 'edit_profile_url', 'bp_members_edit_profile_url', 10, 3 ); 132 133 /** 134 * Filter BP_User_Query::populate_extras to add last activity. 135 * 136 * @since 15.0.0 137 * 138 * @param BP_User_Query $user_query The BP_User_Query object. 139 */ 140 function bp_members_filter_user_query_populate_extras_last_activity( $user_query ) { 141 $last_activities = BP_Core_User::get_last_activity( $user_query->user_ids ); 142 143 // Set a last_activity value for each user, even if it's empty. 144 foreach ( $user_query->results as $user_id => $user ) { 145 $user_last_activity = isset( $last_activities[ $user_id ]['date_recorded'] ) 146 ? $last_activities[ $user_id ]['date_recorded'] 147 : ''; 148 149 $user_query->results[ $user_id ]->last_activity = $user_last_activity; 150 } 151 } 152 add_action( 'bp_user_query_populate_extras', 'bp_members_filter_user_query_populate_extras_last_activity' ); 153 154 /** 155 * Filter BP_User_Query::populate_extras to add friend count & latest update. 156 * 157 * @since 15.0.0 158 * 159 * @global wpdb $wpdb WordPress database object. 160 * 161 * @param BP_User_Query $user_query The BP_User_Query object. 162 * @param string $user_ids_sql Comma-separated list of user IDs to fetch extra 163 * data for, as determined by BP_User_Query. 164 */ 165 function bp_members_filter_user_query_populate_extras_friend_count_latest_update( $user_query, $user_ids_sql ) { 166 global $wpdb; 167 168 $total_friend_count_key = bp_get_user_meta_key( 'total_friend_count' ); 169 $bp_latest_update_key = bp_get_user_meta_key( 'bp_latest_update' ); 170 171 // Total_friend_count must be set for each user, even if its 172 // value is 0. 173 foreach ( $user_query->results as $uindex => $user ) { 174 $user_query->results[ $uindex ]->total_friend_count = 0; 175 } 176 177 // Create, prepare, and run the separate usermeta query. 178 $user_metas = $wpdb->get_results( 179 $wpdb->prepare( 180 "SELECT user_id, meta_key, meta_value FROM {$wpdb->usermeta} WHERE meta_key IN (%s,%s) AND user_id IN ({$user_ids_sql})", 181 $total_friend_count_key, 182 $bp_latest_update_key 183 ) 184 ); 185 186 // The $members_template global expects the index key to be different 187 // from the meta_key in some cases, so we rejig things here. 188 foreach ( $user_metas as $user_meta ) { 189 switch ( $user_meta->meta_key ) { 190 case $total_friend_count_key: 191 $key = 'total_friend_count'; 192 break; 193 194 case $bp_latest_update_key: 195 $key = 'latest_update'; 196 break; 197 } 198 199 if ( isset( $user_query->results[ $user_meta->user_id ] ) ) { 200 $user_query->results[ $user_meta->user_id ]->{$key} = $user_meta->meta_value; 201 } 202 } 203 } 204 add_action( 'bp_user_query_populate_extras', 'bp_members_filter_user_query_populate_extras_friend_count_latest_update', 10, 2 ); 205 206 /** 207 * Filter BP_User_Query::populate_extras to add meta key / value. 208 * 209 * Only added if 'meta_key' or 'meta_value' is passed to the user query. 210 * 211 * @since 15.0.0 212 * 213 * @global wpdb $wpdb WordPress database object. 214 * 215 * @param BP_User_Query $user_query The BP_User_Query object. 216 */ 217 function bp_members_filter_user_query_populate_extras_meta( $user_query ) { 218 global $wpdb; 219 220 if ( empty( $user_query->query_vars['meta_key'] ) ) { 221 return; 222 } 223 224 $meta_sql = array( 225 'select' => 'SELECT user_id, meta_key, meta_value', 226 'from' => "FROM $wpdb->usermeta", 227 'where' => $wpdb->prepare( 'WHERE meta_key = %s', $user_query->query_vars['meta_key'] ), 228 ); 229 230 if ( false !== $user_query->query_vars['meta_value'] ) { 231 $meta_sql['where'] .= $wpdb->prepare( ' AND meta_value = %s', $user_query->query_vars['meta_value'] ); 232 } 233 234 $metas = $wpdb->get_results( "{$meta_sql['select']} {$meta_sql['from']} {$meta_sql['where']}" ); 235 236 if ( empty( $metas ) || ! is_array( $metas ) ) { 237 return; 238 } 239 240 foreach ( $metas as $meta ) { 241 if ( isset( $user_query->results[ $meta->user_id ] ) ) { 242 $user_query->results[ $meta->user_id ]->meta_key = $meta->meta_key; 243 244 if ( ! empty( $meta->meta_value ) ) { 245 $user_query->results[ $meta->user_id ]->meta_value = $meta->meta_value; 246 } 247 } 248 } 249 } 250 add_action( 'bp_user_query_populate_extras', 'bp_members_filter_user_query_populate_extras_meta' ); 133 251 134 252 /** … … 241 359 ); 242 360 243 // This user can register!361 // This user can register! 244 362 } else { 245 363 … … 302 420 303 421 $message = implode( ' ', $message_parts ); 304 } else 422 } elseif ( 'nouveau' === bp_get_theme_package_id() ) { 305 423 $message = sprintf( 306 424 /* translators: 1: The log in link `<a href="login_url">log in</a>`. 2: The lost password link `<a href="lost_password_url">log in</a>` */ -
trunk/src/bp-xprofile/bp-xprofile-filters.php
r13878 r13994 13 13 defined( 'ABSPATH' ) || exit; 14 14 15 add_filter( 'bp_get_the_profile_group_name', 15 add_filter( 'bp_get_the_profile_group_name', 'wp_filter_kses', 1 ); 16 16 add_filter( 'bp_get_the_profile_group_description', 'wp_filter_kses', 1 ); 17 add_filter( 'bp_get_the_profile_field_name', 18 add_filter( 'bp_get_the_profile_field_edit_value', 17 add_filter( 'bp_get_the_profile_field_name', 'wp_filter_kses', 1 ); 18 add_filter( 'bp_get_the_profile_field_edit_value', 'xprofile_sanitize_data_value_before_display', 1, 3 ); 19 19 add_filter( 'bp_get_the_profile_field_description', 'wp_filter_kses', 1 ); 20 add_filter( 'bp_get_the_profile_field_value', 21 22 add_filter( 'bp_get_the_profile_field_value', 'wptexturize');23 add_filter( 'bp_get_the_profile_field_value', 'convert_chars');24 add_filter( 'bp_get_the_profile_field_value', 'wpautop');25 add_filter( 'bp_get_the_profile_field_value', 26 add_filter( 'bp_get_the_profile_field_value', 'make_clickable');27 add_filter( 'bp_get_the_profile_field_value', 28 add_filter( 'bp_get_the_profile_field_value', 29 add_filter( 'bp_get_the_profile_field_value', 'xprofile_filter_format_field_value',1, 2 );30 add_filter( 'bp_get_the_profile_field_value', 31 add_filter( 'bp_get_the_profile_field_value', 'xprofile_filter_link_profile_data',9, 3 );32 33 add_filter( 'bp_get_the_profile_field_edit_value', 34 add_filter( 'bp_get_the_profile_field_edit_value', 35 36 add_filter( 'bp_get_the_profile_group_name', 37 add_filter( 'bp_get_the_profile_group_description', 38 add_filter( 'bp_get_the_profile_field_value', 39 add_filter( 'bp_get_the_profile_field_edit_value', 40 add_filter( 'bp_get_the_profile_field_name', 41 add_filter( 'bp_get_the_profile_field_description', 42 43 add_filter( 'xprofile_get_field_data', 44 add_filter( 'xprofile_field_name_before_save', 45 add_filter( 'xprofile_field_description_before_save', 46 47 add_filter( 'xprofile_get_field_data', 48 add_filter( 'xprofile_field_name_before_save', 49 add_filter( 'xprofile_field_description_before_save', 50 51 add_filter( 'xprofile_get_field_data', 52 add_filter( 'xprofile_get_field_data', 53 54 add_filter( 'bp_xprofile_set_field_data_pre_validate', 55 add_filter( 'xprofile_data_value_before_save', 20 add_filter( 'bp_get_the_profile_field_value', 'xprofile_sanitize_data_value_before_display', 1, 3 ); 21 22 add_filter( 'bp_get_the_profile_field_value', 'wptexturize' ); 23 add_filter( 'bp_get_the_profile_field_value', 'convert_chars' ); 24 add_filter( 'bp_get_the_profile_field_value', 'wpautop' ); 25 add_filter( 'bp_get_the_profile_field_value', 'force_balance_tags' ); 26 add_filter( 'bp_get_the_profile_field_value', 'make_clickable' ); 27 add_filter( 'bp_get_the_profile_field_value', 'bp_xprofile_escape_field_data', 8, 3 ); 28 add_filter( 'bp_get_the_profile_field_value', 'convert_smilies', 9 ); 29 add_filter( 'bp_get_the_profile_field_value', 'xprofile_filter_format_field_value', 1, 2 ); 30 add_filter( 'bp_get_the_profile_field_value', 'xprofile_filter_format_field_value_by_type', 8, 3 ); 31 add_filter( 'bp_get_the_profile_field_value', 'xprofile_filter_link_profile_data', 9, 3 ); 32 33 add_filter( 'bp_get_the_profile_field_edit_value', 'force_balance_tags' ); 34 add_filter( 'bp_get_the_profile_field_edit_value', 'bp_xprofile_escape_field_data', 10, 3 ); 35 36 add_filter( 'bp_get_the_profile_group_name', 'stripslashes' ); 37 add_filter( 'bp_get_the_profile_group_description', 'stripslashes' ); 38 add_filter( 'bp_get_the_profile_field_value', 'stripslashes' ); 39 add_filter( 'bp_get_the_profile_field_edit_value', 'stripslashes' ); 40 add_filter( 'bp_get_the_profile_field_name', 'stripslashes' ); 41 add_filter( 'bp_get_the_profile_field_description', 'stripslashes' ); 42 43 add_filter( 'xprofile_get_field_data', 'xprofile_sanitize_data_value_before_display_from_get_field_data', 1, 2 ); 44 add_filter( 'xprofile_field_name_before_save', 'wp_filter_kses', 1 ); 45 add_filter( 'xprofile_field_description_before_save', 'wp_filter_kses', 1 ); 46 47 add_filter( 'xprofile_get_field_data', 'force_balance_tags' ); 48 add_filter( 'xprofile_field_name_before_save', 'force_balance_tags' ); 49 add_filter( 'xprofile_field_description_before_save', 'force_balance_tags' ); 50 51 add_filter( 'xprofile_get_field_data', 'stripslashes' ); 52 add_filter( 'xprofile_get_field_data', 'xprofile_filter_format_field_value_by_field_id', 5, 2 ); 53 54 add_filter( 'bp_xprofile_set_field_data_pre_validate', 'xprofile_filter_pre_validate_value_by_field_type', 10, 3 ); 55 add_filter( 'xprofile_data_value_before_save', 'xprofile_sanitize_data_value_before_save', 1, 4 ); 56 56 add_filter( 'xprofile_filtered_data_value_before_save', 'trim', 2 ); 57 57 58 58 // Save field groups. 59 add_filter( 'xprofile_group_name_before_save', 59 add_filter( 'xprofile_group_name_before_save', 'wp_filter_kses' ); 60 60 add_filter( 'xprofile_group_description_before_save', 'wp_filter_kses' ); 61 61 62 add_filter( 'xprofile_group_name_before_save', 63 add_filter( 'xprofile_group_description_before_save', 62 add_filter( 'xprofile_group_name_before_save', 'stripslashes' ); 63 add_filter( 'xprofile_group_description_before_save', 'stripslashes' ); 64 64 65 65 // Save fields. 66 add_filter( 'xprofile_field_name_before_save', 67 add_filter( 'xprofile_field_type_before_save', 68 add_filter( 'xprofile_field_description_before_save', 69 add_filter( 'xprofile_field_order_by_before_save', 70 71 add_filter( 'xprofile_field_is_required_before_save', 72 add_filter( 'xprofile_field_field_order_before_save', 66 add_filter( 'xprofile_field_name_before_save', 'wp_filter_kses' ); 67 add_filter( 'xprofile_field_type_before_save', 'wp_filter_kses' ); 68 add_filter( 'xprofile_field_description_before_save', 'wp_filter_kses' ); 69 add_filter( 'xprofile_field_order_by_before_save', 'wp_filter_kses' ); 70 71 add_filter( 'xprofile_field_is_required_before_save', 'absint' ); 72 add_filter( 'xprofile_field_field_order_before_save', 'absint' ); 73 73 add_filter( 'xprofile_field_option_order_before_save', 'absint' ); 74 add_filter( 'xprofile_field_can_delete_before_save', 74 add_filter( 'xprofile_field_can_delete_before_save', 'absint' ); 75 75 76 76 // Save field options. … … 138 138 if ( $field_id && bp_xprofile_is_richtext_enabled_for_field( $field_id ) ) { 139 139 $richtext_tags = array( 140 'img' => array( 'src' => 1, 'alt' => 1, 'width' => 1, 'height' => 1 ), 140 'img' => array( 141 'src' => 1, 142 'alt' => 1, 143 'width' => 1, 144 'height' => 1, 145 ), 141 146 'ul' => array(), 142 147 'ol' => array(), … … 237 242 $filtered_field_value = apply_filters( 'xprofile_filtered_data_value_before_save', $filtered_field_value, $field_value, $data_obj ); 238 243 239 // Sanitize multiple individual option values.244 // Sanitize multiple individual option values. 240 245 } else { 241 246 $filtered_values = array(); … … 426 431 $values = explode( ';', $field_value ); 427 432 428 array_walk( $values, function ( &$value, $key ) use ( $field_type, $field ) { 429 $value = bp_xprofile_escape_field_data( $value, $field_type, $field->id ); 430 } ); 433 array_walk( 434 $values, 435 function ( &$value, $key ) use ( $field_type, $field ) { 436 $value = bp_xprofile_escape_field_data( $value, $field_type, $field->id ); 437 } 438 ); 431 439 } 432 440 … … 439 447 $new_values[] = make_clickable( $value ); 440 448 441 // Is not clickable.449 // Is not clickable. 442 450 } else { 443 451 … … 446 454 $new_values[] = $value; 447 455 448 // Less than 5 spaces.456 // Less than 5 spaces. 449 457 } else { 450 458 $query_arg = bp_core_get_component_search_query_arg( 'members' ); … … 516 524 * @since 1.7.0 517 525 * 518 * @param BP_User_Query $user_query User query to filter. 519 * @param string $user_ids_sql SQL statement to use. 520 */ 521 function bp_xprofile_filter_user_query_populate_extras( BP_User_Query $user_query, $user_ids_sql = '' ) { 526 * @param BP_User_Query $user_query The BP_User_Query object. 527 */ 528 function bp_xprofile_filter_user_query_populate_extras( $user_query ) { 522 529 523 530 if ( ! bp_is_active( 'xprofile' ) ) { … … 534 541 } 535 542 } 536 add_ filter( 'bp_user_query_populate_extras', 'bp_xprofile_filter_user_query_populate_extras', 2, 2 );543 add_action( 'bp_user_query_populate_extras', 'bp_xprofile_filter_user_query_populate_extras', 2 ); 537 544 538 545 /** … … 541 548 * @since 2.2.0 542 549 * 543 * @param BP_User_Query $q User query object.544 */ 545 function bp_xprofile_add_xprofile_query_to_user_query( BP_User_Query$q ) {550 * @param BP_User_Query $q The BP_User_Query object. 551 */ 552 function bp_xprofile_add_xprofile_query_to_user_query( $q ) { 546 553 547 554 // Bail if no `xprofile_query` clause. … … 555 562 if ( ! empty( $sql['join'] ) ) { 556 563 $q->uid_clauses['select'] .= $sql['join']; 557 $q->uid_clauses['where'] .= $sql['where'];564 $q->uid_clauses['where'] .= $sql['where']; 558 565 } 559 566 } … … 609 616 * - append the 'object type' WHERE clause 610 617 */ 611 case 'SELECT' 618 case 'SELECT': 612 619 $q = str_replace( 613 620 array( … … 630 637 * - append the 'object type' WHERE clause 631 638 */ 632 case 'UPDATE' 633 case 'DELETE' 639 case 'UPDATE': 640 case 'DELETE': 634 641 $q = str_replace( 635 642 array( … … 650 657 * - ensure that the object_type field gets filled in 651 658 */ 652 case 'INSERT' 659 case 'INSERT': 653 660 $q = str_replace( 654 661 array( … … 658 665 array( 659 666 '`object_type`,`object_id`', 660 $wpdb->prepare( "VALUES (%s,", $matches[1] ),667 $wpdb->prepare( 'VALUES (%s,', $matches[1] ), 661 668 ), 662 669 $q … … 669 676 for ( $i = 0; $i < count( $quoted_matches[0] ); $i++ ) { 670 677 $quote_pos = strpos( $q, '__QUOTE__' ); 671 $q = substr_replace( $q, $quoted_matches[0][ $i ], $quote_pos, 9 );678 $q = substr_replace( $q, $quoted_matches[0][ $i ], $quote_pos, 9 ); 672 679 } 673 680 }
Note: See TracChangeset
for help on using the changeset viewer.