Ticket #40613: 40613.diff
File 40613.diff, 6.9 KB (added by , 8 years ago) |
---|
-
src/wp-includes/class-wp-user-query.php
233 233 $qv =& $this->query_vars; 234 234 $qv = $this->fill_query_vars( $qv ); 235 235 236 if ( is_array( $qv['fields'] ) ) { 237 $qv['fields'] = array_unique( $qv['fields'] ); 238 239 $this->query_fields = array(); 240 foreach ( $qv['fields'] as $field ) { 241 $field = 'ID' === $field ? 'ID' : sanitize_key( $field ); 242 $this->query_fields[] = "$wpdb->users.$field"; 243 } 244 $this->query_fields = implode( ',', $this->query_fields ); 245 } elseif ( 'all' == $qv['fields'] ) { 246 $this->query_fields = "$wpdb->users.*"; 247 } else { 248 $this->query_fields = "$wpdb->users.ID"; 249 } 236 $this->query_fields = "$wpdb->users.ID"; 250 237 251 238 if ( isset( $qv['count_total'] ) && $qv['count_total'] ) 252 239 $this->query_fields = 'SQL_CALC_FOUND_ROWS ' . $this->query_fields; … … 590 577 591 578 $this->request = "SELECT $this->query_fields $this->query_from $this->query_where $this->query_orderby $this->query_limit"; 592 579 593 if ( is_array( $qv['fields'] ) || 'all' == $qv['fields'] ) { 594 $this->results = $wpdb->get_results( $this->request ); 595 } else { 580 $key = md5( $this->request ); 581 $last_changed = wp_cache_get_last_changed( 'comment' ); 582 583 $cache_key = "get_users:$key:$last_changed"; 584 $cache_value = wp_cache_get( $cache_key, 'comment' ); 585 if ( false !== $cache_value ) { 596 586 $this->results = $wpdb->get_col( $this->request ); 597 }598 587 599 /** 600 * Filters SELECT FOUND_ROWS() query for the current WP_User_Query instance. 601 * 602 * @since 3.2.0 603 * 604 * @global wpdb $wpdb WordPress database abstraction object. 605 * 606 * @param string $sql The SELECT FOUND_ROWS() query for the current WP_User_Query. 607 */ 608 if ( isset( $qv['count_total'] ) && $qv['count_total'] ) 609 $this->total_users = (int) $wpdb->get_var( apply_filters( 'found_users_query', 'SELECT FOUND_ROWS()' ) ); 588 /** 589 * Filters SELECT FOUND_ROWS() query for the current WP_User_Query instance. 590 * 591 * @since 3.2.0 592 * 593 * @global wpdb $wpdb WordPress database abstraction object. 594 * 595 * @param string $sql The SELECT FOUND_ROWS() query for the current WP_User_Query. 596 */ 597 if ( isset( $qv['count_total'] ) && $qv['count_total'] ) { 598 $this->total_users = (int) $wpdb->get_var( apply_filters( 'found_users_query', 'SELECT FOUND_ROWS()' ) ); 599 } 600 $cache_value = array( 601 'user_ids' => $this->results, 602 'total_users' => $this->total_users, 603 ); 604 wp_cache_add( $cache_key, $cache_value, 'users' ); 605 } else { 606 $this->results = $cache_value['user_ids']; 607 $this->total_users = $cache_value['total_users']; 608 } 610 609 611 if ( ! $this->results )610 if ( ! $this->results ) { 612 611 return; 612 } 613 613 614 if ( 'all_with_meta' == $qv['fields'] ) {615 cache_users( $this->results);614 $prime_meta_cache = ( 'all_with_meta' == $qv['fields'] ); 615 cache_users( $this->results, $prime_meta_cache ); 616 616 617 $r = array(); 618 foreach ( $this->results as $userid ) 619 $r[ $userid ] = new WP_User( $userid, '', $qv['blog_id'] ); 620 621 $this->results = $r; 622 } elseif ( 'all' == $qv['fields'] ) { 623 foreach ( $this->results as $key => $user ) { 624 $this->results[ $key ] = new WP_User( $user, '', $qv['blog_id'] ); 617 $r = array(); 618 foreach ( $this->results as $userid ) { 619 $r[] = new WP_User( $userid, '', $qv['blog_id'] ); 620 } 621 if ( is_array( $qv['fields'] ) ) { 622 $nr = array(); 623 foreach ( $r as $user ) { 624 $object = new stdClass; 625 foreach ( $qv['fields'] as $field ) { 626 if ( isset( $user->$field ) ) { 627 $object->$field = $user->$field; 628 } 629 } 630 $nr[] = $object; 625 631 } 632 $r = $nr; 626 633 } 634 $this->results = $r; 635 627 636 } 628 637 629 638 /** -
src/wp-includes/ms-functions.php
206 206 do_action( 'add_user_to_blog', $user_id, $role, $blog_id ); 207 207 wp_cache_delete( $user_id, 'users' ); 208 208 wp_cache_delete( $blog_id . '_user_count', 'blog-details' ); 209 wp_cache_set( 'last_changed', microtime(), 'users' ); 209 210 restore_current_blog(); 210 211 return true; 211 212 } … … 293 294 } 294 295 295 296 restore_current_blog(); 296 297 wp_cache_set( 'last_changed', microtime(), 'users' ); 297 298 return true; 298 299 } 299 300 -
src/wp-includes/user.php
766 766 * @param bool $unique Optional. Whether the same key should not be added. Default false. 767 767 * @return int|false Meta ID on success, false on failure. 768 768 */ 769 function add_user_meta($user_id, $meta_key, $meta_value, $unique = false) { 770 return add_metadata('user', $user_id, $meta_key, $meta_value, $unique); 769 function add_user_meta( $user_id, $meta_key, $meta_value, $unique = false ) { 770 $added = add_metadata( 'user', $user_id, $meta_key, $meta_value, $unique ); 771 772 // Bust user query cache. 773 if ( $added ) { 774 wp_cache_set( 'last_changed', microtime(), 'users' ); 775 } 776 777 return $added; 771 778 } 772 779 773 780 /** … … 785 792 * @param mixed $meta_value Optional. Metadata value. 786 793 * @return bool True on success, false on failure. 787 794 */ 788 function delete_user_meta($user_id, $meta_key, $meta_value = '') { 789 return delete_metadata('user', $user_id, $meta_key, $meta_value); 795 function delete_user_meta( $user_id, $meta_key, $meta_value = '' ) { 796 $deleted = delete_metadata( 'user', $user_id, $meta_key, $meta_value ); 797 798 // Bust user query cache. 799 if ( $deleted ) { 800 wp_cache_set( 'last_changed', microtime(), 'users' ); 801 } 802 803 return $deleted; 790 804 } 791 805 792 806 /** … … 821 835 * @param mixed $prev_value Optional. Previous value to check before removing. 822 836 * @return int|bool Meta ID if the key didn't exist, true on successful update, false on failure. 823 837 */ 824 function update_user_meta($user_id, $meta_key, $meta_value, $prev_value = '') { 825 return update_metadata('user', $user_id, $meta_key, $meta_value, $prev_value); 838 function update_user_meta( $user_id, $meta_key, $meta_value, $prev_value = '' ) { 839 $updated = update_metadata( 'user', $user_id, $meta_key, $meta_value, $prev_value ); 840 841 // Bust user query cache. 842 if ( $updated ) { 843 wp_cache_set( 'last_changed', microtime(), 'users' ); 844 } 845 846 return $updated; 826 847 } 827 848 828 849 /** … … 1296 1317 wp_cache_delete( $user->user_email, 'useremail' ); 1297 1318 wp_cache_delete( $user->user_nicename, 'userslugs' ); 1298 1319 1320 wp_cache_set( 'last_changed', microtime(), 'users' ); 1321 1299 1322 /** 1300 1323 * Fires immediately after the given user's cache is cleaned. 1301 1324 * … … 1739 1762 } 1740 1763 wp_cache_delete( $user_id, 'users' ); 1741 1764 wp_cache_delete( $user_login, 'userlogins' ); 1742 1765 wp_cache_set( 'last_changed', microtime(), 'users' ); 1743 1766 if ( $update ) { 1744 1767 /** 1745 1768 * Fires immediately after an existing user is updated.