Ticket #15458: lazy-load.2.diff
File lazy-load.2.diff, 18.4 KB (added by , 13 years ago) |
---|
-
wp-admin/includes/class-wp-users-list-table.php
diff --git a/wp-admin/includes/class-wp-users-list-table.php b/wp-admin/includes/class-wp-users-list-table.php index de22748..13bdeb4 100644
a b class WP_Users_List_Table extends WP_List_Table { 219 219 220 220 if ( !( is_object( $user_object ) && is_a( $user_object, 'WP_User' ) ) ) 221 221 $user_object = new WP_User( (int) $user_object ); 222 $user_object = sanitize_user_object( $user_object, 'display' );222 $user_object->filter = 'display'; 223 223 $email = $user_object->user_email; 224 224 225 225 if ( $this->is_site_users ) -
wp-admin/includes/user.php
diff --git a/wp-admin/includes/user.php b/wp-admin/includes/user.php index 758c065..5d513b9 100644
a b function get_editable_roles() { 226 226 function get_user_to_edit( $user_id ) { 227 227 $user = new WP_User( $user_id ); 228 228 229 $user_contactmethods = _wp_get_user_contactmethods( $user ); 230 foreach ($user_contactmethods as $method => $name) { 231 if ( empty( $user->{$method} ) ) 232 $user->{$method} = ''; 233 } 234 235 if ( empty($user->description) ) 236 $user->description = ''; 237 238 $user = sanitize_user_object($user, 'edit'); 229 $user->filter = 'edit'; 239 230 240 231 return $user; 241 232 } -
wp-includes/capabilities.php
diff --git a/wp-includes/capabilities.php b/wp-includes/capabilities.php index ae2dc2a..cdc3fd3 100644
a b class WP_User { 420 420 */ 421 421 var $filter = null; 422 422 423 private static $back_compat_keys = array( 424 'user_firstname' => 'first_name', 425 'user_lastname' => 'last_name', 426 'user_description' => 'description' 427 ); 428 423 429 /** 424 * Constructor - Sets up the object properties.430 * Constructor 425 431 * 426 * Retrieves the userdata and then assigns all of the data keys to direct 427 * properties of the object. Calls {@link WP_User::_init_caps()} after 428 * setting up the object's user data properties. 432 * Retrieves the userdata and passes it to {@link WP_User::init()}. 429 433 * 430 434 * @since 2.0.0 431 435 * @access public 432 436 * 433 * @param int|string $id User's ID or username434 * @param int$name Optional. User's username437 * @param int|string $id User's ID 438 * @param string $name Optional. User's username 435 439 * @param int $blog_id Optional Blog ID, defaults to current blog. 436 440 * @return WP_User 437 441 */ 438 function __construct( $id, $name = '', $blog_id = '' ) { 439 if ( empty( $id ) && empty( $name ) ) 440 return; 441 442 function __construct( $id = 0, $name = '', $blog_id = '' ) { 442 443 if ( ! is_numeric( $id ) ) { 443 444 $name = $id; 444 445 $id = 0; 445 446 } 446 447 447 if ( ! empty( $id ))448 $ this->data = get_userdata($id );448 if ( $id ) 449 $data = self::get_data_by( 'id', $id ); 449 450 else 450 $ this->data = get_user_by('login', $name );451 $data = self::get_data_by( 'login', $name ); 451 452 452 if ( empty( $this->data->ID ) ) 453 return; 453 if ( $data ) 454 $this->init( $data, $blog_id ); 455 } 456 457 /** 458 * Sets up object properties, including capabilities. 459 * 460 * @param object User DB row object 461 */ 462 function init( $data, $blog_id = '' ) { 463 $this->data = $data; 464 $this->ID = (int) $data->ID; 454 465 455 $this->ID = $this->data->ID;456 466 $this->for_blog( $blog_id ); 457 467 } 458 468 459 469 /** 470 * Return only the main user fields 471 */ 472 static function get_data_by( $field, $value ) { 473 global $wpdb; 474 475 switch ( $field ) { 476 case 'id': 477 $user_id = $value = absint($value); 478 $field = 'ID'; 479 break; 480 case 'slug': 481 $user_id = wp_cache_get($value, 'userslugs'); 482 $field = 'user_nicename'; 483 break; 484 case 'email': 485 $user_id = wp_cache_get($value, 'useremail'); 486 $field = 'user_email'; 487 break; 488 case 'login': 489 $value = sanitize_user( $value ); 490 $user_id = wp_cache_get($value, 'userlogins'); 491 $field = 'user_login'; 492 break; 493 default: 494 return false; 495 } 496 497 if ( false !== $user_id ) { 498 if ( $user = wp_cache_get( $user_id, 'users' ) ) 499 return $user; 500 } 501 502 if ( !$user = $wpdb->get_row( $wpdb->prepare( 503 "SELECT * FROM $wpdb->users WHERE $field = %s", $value 504 ) ) ) 505 return false; 506 507 update_user_caches( $user ); 508 509 return $user; 510 } 511 512 /** 460 513 * Magic method for checking the existance of a certain custom field 461 514 * 462 515 * @since 3.3.0 … … class WP_User { 480 533 return $this->ID; 481 534 } 482 535 483 return $this->data->$key; 536 if ( isset( $this->data->$key ) ) { 537 $value = $this->data->$key; 538 } else { 539 if ( isset( self::$back_compat_keys[ $key ] ) ) 540 $key = self::$back_compat_keys[ $key ]; 541 $value = get_user_meta( $this->ID, $key, true ); 542 } 543 544 if ( $this->filter ) { 545 $value = sanitize_user_field( $key, $value, $this->ID, $this->filter ); 546 } 547 548 return $value; 484 549 } 485 550 486 551 /** … … class WP_User { 519 584 else 520 585 $this->cap_key = $cap_key; 521 586 522 $this->caps = &$this->data->{$this->cap_key}; 587 $this->caps = get_user_meta( $this->ID, $this->cap_key, true ); 588 523 589 if ( ! is_array( $this->caps ) ) 524 590 $this->caps = array(); 525 591 … … class WP_User { 662 728 */ 663 729 function update_user_level_from_caps() { 664 730 global $wpdb; 665 $this->user_level = array_reduce( array_keys( $this->allcaps ), array( &$this, 'level_reduction' ), 0 );731 $this->user_level = array_reduce( array_keys( $this->allcaps ), array( $this, 'level_reduction' ), 0 ); 666 732 update_user_meta( $this->ID, $wpdb->prefix . 'user_level', $this->user_level ); 667 733 } 668 734 … … function current_user_can( $capability ) { 1066 1132 $args = array_slice( func_get_args(), 1 ); 1067 1133 $args = array_merge( array( $capability ), $args ); 1068 1134 1069 return call_user_func_array( array( &$current_user, 'has_cap' ), $args );1135 return call_user_func_array( array( $current_user, 'has_cap' ), $args ); 1070 1136 } 1071 1137 1072 1138 /** -
wp-includes/deprecated.php
diff --git a/wp-includes/deprecated.php b/wp-includes/deprecated.php index 8313a3f..b135361 100644
a b function wp_timezone_supported() { 2627 2627 */ 2628 2628 function wp_default_editor() { 2629 2629 _deprecated_function( __FUNCTION__, '3.3' ); 2630 2630 2631 2631 global $wp_editor; 2632 2632 if ( !is_a($wp_editor, 'WP_Editor') ) { 2633 2633 require_once( ABSPATH . WPINC . '/class-wp-editor.php' ); 2634 2634 $wp_editor = new WP_Editor; 2635 2635 } 2636 2636 2637 2637 return $wp_editor->wp_default_editor(); 2638 2638 } 2639 2639 … … function wp_default_editor() { 2641 2641 * Display editor: TinyMCE, HTML, or both. 2642 2642 * 2643 2643 * @since 2.1.0 2644 * @deprecated 3.3 2644 * @deprecated 3.3 2645 2645 * 2646 2646 * @param string $content Textarea content. 2647 2647 * @param string $id Optional, default is 'content'. HTML ID attribute value. … … function wp_default_editor() { 2650 2650 * @param int $tab_index Optional, not used 2651 2651 */ 2652 2652 function the_editor($content, $id = 'content', $prev_id = 'title', $media_buttons = true, $tab_index = 2, $extended = true) { 2653 2653 2654 2654 wp_editor( $content, $id, array( 'media_buttons' => $media_buttons ) ); 2655 2655 return; 2656 2656 } 2657 2657 2658 /** 2659 * Perform the query to get the $metavalues array(s) needed by _fill_user and _fill_many_users 2660 * 2661 * @since 3.0.0 2662 * @param array $ids User ID numbers list. 2663 * @return array of arrays. The array is indexed by user_id, containing $metavalues object arrays. 2664 */ 2665 function get_user_metavalues($ids) { 2666 _deprecated_function( __FUNCTION__, '3.3' ); 2667 2668 $objects = array(); 2669 2670 $ids = array_map('intval', $ids); 2671 foreach ( $ids as $id ) 2672 $objects[$id] = array(); 2673 2674 $metas = update_meta_cache('user', $ids); 2675 2676 foreach ( $metas as $id => $meta ) { 2677 foreach ( $meta as $key => $metavalues ) { 2678 foreach ( $metavalues as $value ) { 2679 $objects[$id][] = (object)array( 'user_id' => $id, 'meta_key' => $key, 'meta_value' => $value); 2680 } 2681 } 2682 } 2683 2684 return $objects; 2685 } 2686 2687 /** 2688 * Sanitize every user field. 2689 * 2690 * If the context is 'raw', then the user object or array will get minimal santization of the int fields. 2691 * 2692 * @since 2.3.0 2693 * @deprecated 3.3.0 2694 * @uses sanitize_user_field() Used to sanitize the fields. 2695 * 2696 * @param object|array $user The User Object or Array 2697 * @param string $context Optional, default is 'display'. How to sanitize user fields. 2698 * @return object|array The now sanitized User Object or Array (will be the same type as $user) 2699 */ 2700 function sanitize_user_object($user, $context = 'display') { 2701 _deprecated_function( __FUNCTION__, '3.3' ); 2702 2703 if ( is_object($user) ) { 2704 if ( !isset($user->ID) ) 2705 $user->ID = 0; 2706 if ( !is_a( $user, 'WP_User' ) ) { 2707 $vars = get_object_vars($user); 2708 foreach ( array_keys($vars) as $field ) { 2709 if ( is_string($user->$field) || is_numeric($user->$field) ) 2710 $user->$field = sanitize_user_field($field, $user->$field, $user->ID, $context); 2711 } 2712 } 2713 $user->filter = $context; 2714 } else { 2715 if ( !isset($user['ID']) ) 2716 $user['ID'] = 0; 2717 foreach ( array_keys($user) as $field ) 2718 $user[$field] = sanitize_user_field($field, $user[$field], $user['ID'], $context); 2719 $user['filter'] = $context; 2720 } 2721 2722 return $user; 2723 } 2724 -
wp-includes/pluggable.php
diff --git a/wp-includes/pluggable.php b/wp-includes/pluggable.php index fab5d41..9c5ad1d 100644
a b if ( !function_exists('get_userdata') ) : 98 98 * @since 0.71 99 99 * 100 100 * @param int $user_id User ID 101 * @return bool|object False on failure, User DB row object101 * @return bool|object False on failure, WP_User object on success 102 102 */ 103 103 function get_userdata( $user_id ) { 104 global $wpdb; 105 106 if ( ! is_numeric( $user_id ) ) 107 return false; 108 109 $user_id = absint( $user_id ); 110 if ( ! $user_id ) 111 return false; 112 113 $user = wp_cache_get( $user_id, 'users' ); 104 return get_user_by( 'id', $user_id ); 105 } 106 endif; 114 107 115 if ( $user ) 116 return $user; 108 if ( !function_exists('get_user_by') ) : 109 /** 110 * Retrieve user info by a given field 111 * 112 * @since 2.8.0 113 * 114 * @param string $field The field to retrieve the user with. id | slug | email | login 115 * @param int|string $value A value for $field. A user ID, slug, email address, or login name. 116 * @return bool|object False on failure, WP_User object on success 117 */ 118 function get_user_by( $field, $value ) { 119 $userdata = WP_User::get_data_by( $field, $value ); 117 120 118 if ( ! $user = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->users WHERE ID = %d LIMIT 1", $user_id ) ))121 if ( !$userdata ) 119 122 return false; 120 123 121 _fill_user( $user ); 124 $user = new WP_User; 125 $user->init( $userdata ); 122 126 123 127 return $user; 124 128 } … … if ( !function_exists('cache_users') ) : 130 134 * 131 135 * @since 3.0.0 132 136 * 133 * @param array $user s User ID numbers list137 * @param array $user_ids User ID numbers list 134 138 */ 135 function cache_users( $user s ) {139 function cache_users( $user_ids ) { 136 140 global $wpdb; 137 141 138 142 $clean = array(); 139 foreach ($users as $id) {143 foreach ( $user_ids as $id ) { 140 144 $id = (int) $id; 141 if (wp_cache_get($id, 'users')) { 142 // seems to be cached already 143 } else { 145 if ( !wp_cache_get( $id, 'users' ) ) { 144 146 $clean[] = $id; 145 147 } 146 148 } 147 149 148 if ( 0 == count($clean) )150 if ( empty( $clean ) ) 149 151 return; 150 152 151 $list = implode( ',', $clean);153 $list = implode( ',', $clean ); 152 154 153 $ results = $wpdb->get_results("SELECT * FROM $wpdb->users WHERE ID IN ($list)");155 $users = $wpdb->get_results( "SELECT * FROM $wpdb->users WHERE ID IN ($list)" ); 154 156 155 _fill_many_users($results); 156 } 157 endif; 158 159 if ( !function_exists('get_user_by') ) : 160 /** 161 * Retrieve user info by a given field 162 * 163 * @since 2.8.0 164 * 165 * @param string $field The field to retrieve the user with. id | slug | email | login 166 * @param int|string $value A value for $field. A user ID, slug, email address, or login name. 167 * @return bool|object False on failure, User DB row object 168 */ 169 function get_user_by($field, $value) { 170 global $wpdb; 171 172 switch ($field) { 173 case 'id': 174 return get_userdata($value); 175 break; 176 case 'slug': 177 $user_id = wp_cache_get($value, 'userslugs'); 178 $field = 'user_nicename'; 179 break; 180 case 'email': 181 $user_id = wp_cache_get($value, 'useremail'); 182 $field = 'user_email'; 183 break; 184 case 'login': 185 $value = sanitize_user( $value ); 186 $user_id = wp_cache_get($value, 'userlogins'); 187 $field = 'user_login'; 188 break; 189 default: 190 return false; 157 $ids = array(); 158 foreach ( $users as $user ) { 159 update_user_caches( $user ); 160 $ids[] = $user->ID; 191 161 } 192 193 if ( false !== $user_id ) 194 return get_userdata($user_id); 195 196 if ( !$user = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->users WHERE $field = %s", $value) ) ) 197 return false; 198 199 _fill_user($user); 200 201 return $user; 162 update_meta_cache( 'user', $ids ); 202 163 } 203 164 endif; 204 165 -
wp-includes/user.php
diff --git a/wp-includes/user.php b/wp-includes/user.php index 68b2704..42b9207 100644
a b function get_blogs_of_user( $id, $all = false ) { 680 680 } 681 681 682 682 if ( false === $blogs ) { 683 $user = get_userdata( (int) $id);684 if ( !$user)683 $userkeys = array_keys( get_user_meta( (int) $id ) ); 684 if ( empty( $userkeys ) ) 685 685 return false; 686 686 687 687 $blogs = $match = array(); 688 $prefix_length = strlen( $wpdb->base_prefix);689 foreach ( (array) $user as $key => $value) {688 $prefix_length = strlen( $wpdb->base_prefix ); 689 foreach ( $userkeys as $key ) { 690 690 if ( $prefix_length && substr($key, 0, $prefix_length) != $wpdb->base_prefix ) 691 691 continue; 692 692 if ( substr($key, -12, 12) != 'capabilities' ) … … function delete_user_meta($user_id, $meta_key, $meta_value = '') { 792 792 * @return mixed Will be an array if $single is false. Will be value of meta data field if $single 793 793 * is true. 794 794 */ 795 function get_user_meta($user_id, $key , $single = false) {795 function get_user_meta($user_id, $key = '', $single = false) { 796 796 return get_metadata('user', $user_id, $key, $single); 797 797 } 798 798 … … function wp_dropdown_users( $args = '' ) { 1042 1042 } 1043 1043 1044 1044 /** 1045 * Add user meta data as properties to given user object.1046 *1047 * The finished user data is cached, but the cache is not used to fill in the1048 * user data for the given object. Once the function has been used, the cache1049 * should be used to retrieve user data. The intention is if the current data1050 * had been cached already, there would be no need to call this function.1051 *1052 * @access private1053 * @since 2.5.01054 * @uses $wpdb WordPress database object for queries1055 *1056 * @param object $user The user data object.1057 */1058 function _fill_user( &$user ) {1059 $metavalues = get_user_metavalues(array($user->ID));1060 _fill_single_user($user, $metavalues[$user->ID]);1061 }1062 1063 /**1064 * Perform the query to get the $metavalues array(s) needed by _fill_user and _fill_many_users1065 *1066 * @since 3.0.01067 * @param array $ids User ID numbers list.1068 * @return array of arrays. The array is indexed by user_id, containing $metavalues object arrays.1069 */1070 function get_user_metavalues($ids) {1071 $objects = array();1072 1073 $ids = array_map('intval', $ids);1074 foreach ( $ids as $id )1075 $objects[$id] = array();1076 1077 $metas = update_meta_cache('user', $ids);1078 1079 foreach ( $metas as $id => $meta ) {1080 foreach ( $meta as $key => $metavalues ) {1081 foreach ( $metavalues as $value ) {1082 $objects[$id][] = (object)array( 'user_id' => $id, 'meta_key' => $key, 'meta_value' => $value);1083 }1084 }1085 }1086 1087 return $objects;1088 }1089 1090 /**1091 * Unserialize user metadata, fill $user object, then cache everything.1092 *1093 * @since 3.0.01094 * @param object $user The User object.1095 * @param array $metavalues An array of objects provided by get_user_metavalues()1096 */1097 function _fill_single_user( &$user, &$metavalues ) {1098 global $wpdb;1099 1100 foreach ( $metavalues as $meta ) {1101 $value = maybe_unserialize($meta->meta_value);1102 // Keys used as object vars cannot have dashes.1103 $key = str_replace('-', '', $meta->meta_key);1104 $user->{$key} = $value;1105 }1106 1107 $level = $wpdb->prefix . 'user_level';1108 if ( isset( $user->{$level} ) )1109 $user->user_level = $user->{$level};1110 1111 // For backwards compat.1112 if ( isset($user->first_name) )1113 $user->user_firstname = $user->first_name;1114 if ( isset($user->last_name) )1115 $user->user_lastname = $user->last_name;1116 if ( isset($user->description) )1117 $user->user_description = $user->description;1118 1119 update_user_caches($user);1120 }1121 1122 /**1123 * Take an array of user objects, fill them with metas, and cache them.1124 *1125 * @since 3.0.01126 * @param array $users User objects1127 */1128 function _fill_many_users( &$users ) {1129 $ids = array();1130 foreach( $users as $user_object ) {1131 $ids[] = $user_object->ID;1132 }1133 1134 $metas = get_user_metavalues($ids);1135 1136 foreach ( $users as $user_object ) {1137 if ( isset($metas[$user_object->ID]) ) {1138 _fill_single_user($user_object, $metas[$user_object->ID]);1139 }1140 }1141 }1142 1143 /**1144 * Sanitize every user field.1145 *1146 * If the context is 'raw', then the user object or array will get minimal santization of the int fields.1147 *1148 * @since 2.3.01149 * @uses sanitize_user_field() Used to sanitize the fields.1150 *1151 * @param object|array $user The User Object or Array1152 * @param string $context Optional, default is 'display'. How to sanitize user fields.1153 * @return object|array The now sanitized User Object or Array (will be the same type as $user)1154 */1155 function sanitize_user_object($user, $context = 'display') {1156 if ( is_object($user) ) {1157 if ( !isset($user->ID) )1158 $user->ID = 0;1159 if ( isset($user->data) )1160 $vars = get_object_vars( $user->data );1161 else1162 $vars = get_object_vars($user);1163 foreach ( array_keys($vars) as $field ) {1164 if ( is_string($user->$field) || is_numeric($user->$field) )1165 $user->$field = sanitize_user_field($field, $user->$field, $user->ID, $context);1166 }1167 $user->filter = $context;1168 } else {1169 if ( !isset($user['ID']) )1170 $user['ID'] = 0;1171 foreach ( array_keys($user) as $field )1172 $user[$field] = sanitize_user_field($field, $user[$field], $user['ID'], $context);1173 $user['filter'] = $context;1174 }1175 1176 return $user;1177 }1178 1179 /**1180 1045 * Sanitize user field based on context. 1181 1046 * 1182 1047 * Possible context values are: 'raw', 'edit', 'db', 'display', 'attribute' and 'js'. The … … function sanitize_user_field($field, $value, $user_id, $context) { 1263 1128 * 1264 1129 * @param object $user User object to be cached 1265 1130 */ 1266 function update_user_caches( &$user) {1131 function update_user_caches($user) { 1267 1132 wp_cache_add($user->ID, $user, 'users'); 1268 1133 wp_cache_add($user->user_login, $user->ID, 'userlogins'); 1269 1134 wp_cache_add($user->user_email, $user->ID, 'useremail'); … … function wp_insert_user($userdata) { 1389 1254 if ( !empty($ID) ) { 1390 1255 $ID = (int) $ID; 1391 1256 $update = true; 1392 $old_user_data = get_userdata($ID);1257 $old_user_data = WP_User::get_data_by( 'id', $ID ); 1393 1258 } else { 1394 1259 $update = false; 1395 1260 // Hash the password … … function wp_update_user($userdata) { 1547 1412 $ID = (int) $userdata['ID']; 1548 1413 1549 1414 // First, get all of the original fields 1550 $user = get_userdata($ID);1415 $user = WP_User::get_data_by('id', $ID); 1551 1416 1552 1417 // Escape data pulled from DB. 1553 1418 $user = add_magic_quotes(get_object_vars($user));