Ticket #15458: 15458.4.diff
File 15458.4.diff, 25.3 KB (added by , 13 years ago) |
---|
-
wp-includes/user.php
254 254 if ( !empty( $deprecated ) ) 255 255 _deprecated_argument( __FUNCTION__, '3.0' ); 256 256 257 if ( empty( $user) ) {257 if ( empty( $user ) ) 258 258 $user = wp_get_current_user(); 259 $user = $user->ID;260 }259 else 260 $user = new WP_User( $user ); 261 261 262 $user = get_userdata($user); 262 if ( ! isset( $user->ID ) ) 263 return false; 263 264 264 // Keys used as object vars cannot have dashes. 265 $key = str_replace('-', '', $option); 266 267 if ( isset( $user->{$wpdb->prefix . $key} ) ) // Blog specific 268 $result = $user->{$wpdb->prefix . $key}; 269 elseif ( isset( $user->{$key} ) ) // User specific and cross-blog 270 $result = $user->{$key}; 265 if ( $user->exists( $wpdb->prefix . $option ) ) // Blog specific 266 $result = $user->get( $wpdb->prefix . $option ); 267 elseif ( $user->exists( $option ) ) // User specific and cross-blog 268 $result = $user->get( $option ); 271 269 else 272 270 $result = false; 273 271 … … 680 678 } 681 679 682 680 if ( false === $blogs ) { 683 $user = get_userdata( (int) $id);684 if ( !$user)681 $userkeys = array_keys( get_user_meta( (int) $id ) ); 682 if ( empty( $userkeys ) ) 685 683 return false; 686 684 687 685 $blogs = $match = array(); 688 $prefix_length = strlen( $wpdb->base_prefix);689 foreach ( (array) $user as $key => $value) {686 $prefix_length = strlen( $wpdb->base_prefix ); 687 foreach ( $userkeys as $key ) { 690 688 if ( $prefix_length && substr($key, 0, $prefix_length) != $wpdb->base_prefix ) 691 689 continue; 692 690 if ( substr($key, -12, 12) != 'capabilities' ) … … 793 791 * @return mixed Will be an array if $single is false. Will be value of meta data field if $single 794 792 * is true. 795 793 */ 796 function get_user_meta($user_id, $key , $single = false) {794 function get_user_meta($user_id, $key = '', $single = false) { 797 795 return get_metadata('user', $user_id, $key, $single); 798 796 } 799 797 … … 1043 1041 } 1044 1042 1045 1043 /** 1046 * Add user meta data as properties to given user object.1047 *1048 * The finished user data is cached, but the cache is not used to fill in the1049 * user data for the given object. Once the function has been used, the cache1050 * should be used to retrieve user data. The intention is if the current data1051 * had been cached already, there would be no need to call this function.1052 *1053 * @access private1054 * @since 2.5.01055 * @uses $wpdb WordPress database object for queries1056 *1057 * @param object $user The user data object.1058 */1059 function _fill_user( &$user ) {1060 $metavalues = get_user_metavalues(array($user->ID));1061 _fill_single_user($user, $metavalues[$user->ID]);1062 }1063 1064 /**1065 * Perform the query to get the $metavalues array(s) needed by _fill_user and _fill_many_users1066 *1067 * @since 3.0.01068 * @param array $ids User ID numbers list.1069 * @return array of arrays. The array is indexed by user_id, containing $metavalues object arrays.1070 */1071 function get_user_metavalues($ids) {1072 $objects = array();1073 1074 $ids = array_map('intval', $ids);1075 foreach ( $ids as $id )1076 $objects[$id] = array();1077 1078 $metas = update_meta_cache('user', $ids);1079 1080 foreach ( $metas as $id => $meta ) {1081 foreach ( $meta as $key => $metavalues ) {1082 foreach ( $metavalues as $value ) {1083 $objects[$id][] = (object)array( 'user_id' => $id, 'meta_key' => $key, 'meta_value' => $value);1084 }1085 }1086 }1087 1088 return $objects;1089 }1090 1091 /**1092 * Unserialize user metadata, fill $user object, then cache everything.1093 *1094 * @since 3.0.01095 * @param object $user The User object.1096 * @param array $metavalues An array of objects provided by get_user_metavalues()1097 */1098 function _fill_single_user( &$user, &$metavalues ) {1099 global $wpdb;1100 1101 foreach ( $metavalues as $meta ) {1102 $value = maybe_unserialize($meta->meta_value);1103 // Keys used as object vars cannot have dashes.1104 $key = str_replace('-', '', $meta->meta_key);1105 $user->{$key} = $value;1106 }1107 1108 $level = $wpdb->prefix . 'user_level';1109 if ( isset( $user->{$level} ) )1110 $user->user_level = $user->{$level};1111 1112 // For backwards compat.1113 if ( isset($user->first_name) )1114 $user->user_firstname = $user->first_name;1115 if ( isset($user->last_name) )1116 $user->user_lastname = $user->last_name;1117 if ( isset($user->description) )1118 $user->user_description = $user->description;1119 1120 update_user_caches($user);1121 }1122 1123 /**1124 * Take an array of user objects, fill them with metas, and cache them.1125 *1126 * @since 3.0.01127 * @param array $users User objects1128 */1129 function _fill_many_users( &$users ) {1130 $ids = array();1131 foreach( $users as $user_object ) {1132 $ids[] = $user_object->ID;1133 }1134 1135 $metas = get_user_metavalues($ids);1136 1137 foreach ( $users as $user_object ) {1138 if ( isset($metas[$user_object->ID]) ) {1139 _fill_single_user($user_object, $metas[$user_object->ID]);1140 }1141 }1142 }1143 1144 /**1145 * Sanitize every user field.1146 *1147 * If the context is 'raw', then the user object or array will get minimal santization of the int fields.1148 *1149 * @since 2.3.01150 * @uses sanitize_user_field() Used to sanitize the fields.1151 *1152 * @param object|array $user The User Object or Array1153 * @param string $context Optional, default is 'display'. How to sanitize user fields.1154 * @return object|array The now sanitized User Object or Array (will be the same type as $user)1155 */1156 function sanitize_user_object($user, $context = 'display') {1157 if ( is_object($user) ) {1158 if ( !isset($user->ID) )1159 $user->ID = 0;1160 if ( isset($user->data) )1161 $vars = get_object_vars( $user->data );1162 else1163 $vars = get_object_vars($user);1164 foreach ( array_keys($vars) as $field ) {1165 if ( is_string($user->$field) || is_numeric($user->$field) )1166 $user->$field = sanitize_user_field($field, $user->$field, $user->ID, $context);1167 }1168 $user->filter = $context;1169 } else {1170 if ( !isset($user['ID']) )1171 $user['ID'] = 0;1172 foreach ( array_keys($user) as $field )1173 $user[$field] = sanitize_user_field($field, $user[$field], $user['ID'], $context);1174 $user['filter'] = $context;1175 }1176 1177 return $user;1178 }1179 1180 /**1181 1044 * Sanitize user field based on context. 1182 1045 * 1183 1046 * Possible context values are: 'raw', 'edit', 'db', 'display', 'attribute' and 'js'. The … … 1264 1127 * 1265 1128 * @param object $user User object to be cached 1266 1129 */ 1267 function update_user_caches( &$user) {1130 function update_user_caches($user) { 1268 1131 wp_cache_add($user->ID, $user, 'users'); 1269 1132 wp_cache_add($user->user_login, $user->ID, 'userlogins'); 1270 1133 wp_cache_add($user->user_email, $user->ID, 'useremail'); … … 1279 1142 * @param int $id User ID 1280 1143 */ 1281 1144 function clean_user_cache($id) { 1282 $user = new WP_User($id);1145 $user = WP_User::get_data_by( 'id', $id ); 1283 1146 1284 1147 wp_cache_delete($id, 'users'); 1285 1148 wp_cache_delete($user->user_login, 'userlogins'); … … 1390 1253 if ( !empty($ID) ) { 1391 1254 $ID = (int) $ID; 1392 1255 $update = true; 1393 $old_user_data = get_userdata($ID);1256 $old_user_data = WP_User::get_data_by( 'id', $ID ); 1394 1257 } else { 1395 1258 $update = false; 1396 1259 // Hash the password … … 1548 1411 $ID = (int) $userdata['ID']; 1549 1412 1550 1413 // First, get all of the original fields 1551 $user = get_userdata($ID);1414 $user = WP_User::get_data_by('id', $ID); 1552 1415 1553 1416 // Escape data pulled from DB. 1554 1417 $user = add_magic_quotes(get_object_vars($user)); -
wp-includes/capabilities.php
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 } 454 456 455 $this->ID = $this->data->ID; 457 /** 458 * Sets up object properties, including capabilities. 459 * 460 * @param object $data User DB row object 461 * @param int $blog_id Optional. The blog id to initialize for 462 */ 463 function init( $data, $blog_id = '' ) { 464 $this->data = $data; 465 $this->ID = (int) $data->ID; 466 456 467 $this->for_blog( $blog_id ); 457 468 } 458 469 459 470 /** 471 * Return only the main user fields 472 * 473 * @since 3.3.0 474 * 475 * @param string $field The field to query against: 'id', 'slug', 'email' or 'login' 476 * @param string|int $value The field value 477 */ 478 static function get_data_by( $field, $value ) { 479 global $wpdb; 480 481 if ( 'id' == $field ) 482 $value = absint( $value ); 483 else 484 $value = trim( $value ); 485 486 if ( !$value ) 487 return false; 488 489 switch ( $field ) { 490 case 'id': 491 $user_id = $value; 492 $db_field = 'ID'; 493 break; 494 case 'slug': 495 $user_id = wp_cache_get($value, 'userslugs'); 496 $db_field = 'user_nicename'; 497 break; 498 case 'email': 499 $user_id = wp_cache_get($value, 'useremail'); 500 $db_field = 'user_email'; 501 break; 502 case 'login': 503 $value = sanitize_user( $value ); 504 $user_id = wp_cache_get($value, 'userlogins'); 505 $db_field = 'user_login'; 506 break; 507 default: 508 return false; 509 } 510 511 if ( false !== $user_id ) { 512 if ( $user = wp_cache_get( $user_id, 'users' ) ) 513 return $user; 514 } 515 516 if ( !$user = $wpdb->get_row( $wpdb->prepare( 517 "SELECT * FROM $wpdb->users WHERE $db_field = %s", $value 518 ) ) ) 519 return false; 520 521 update_user_caches( $user ); 522 523 return $user; 524 } 525 526 /** 460 527 * Magic method for checking the existance of a certain custom field 461 528 * 462 529 * @since 3.3.0 … … 466 533 _deprecated_argument( 'WP_User->id', '2.1', __( 'Use <code>WP_User->ID</code> instead.' ) ); 467 534 $key = 'ID'; 468 535 } 469 return isset( $this->data->$key ); 536 537 if ( isset( $this->data->$key ) ) 538 return true; 539 540 if ( isset( self::$back_compat_keys[ $key ] ) ) 541 $key = self::$back_compat_keys[ $key ]; 542 543 return metadata_exists( 'user', $this->ID, $key ); 470 544 } 471 545 472 546 /** … … 480 554 return $this->ID; 481 555 } 482 556 483 return $this->data->$key; 557 if ( isset( $this->data->$key ) ) { 558 $value = $this->data->$key; 559 } else { 560 if ( isset( self::$back_compat_keys[ $key ] ) ) 561 $key = self::$back_compat_keys[ $key ]; 562 $value = get_user_meta( $this->ID, $key, true ); 563 } 564 565 if ( $this->filter ) { 566 $value = sanitize_user_field( $key, $value, $this->ID, $this->filter ); 567 } 568 569 return $value; 484 570 } 485 571 486 572 /** … … 499 585 } 500 586 501 587 /** 588 * Retrieve the value of a property or meta key. 589 * 590 * Retrieves from the users and usermeta table. 591 * 592 * @since 3.3.0 593 * 594 * @param string $key Property 595 */ 596 function get( $key ) { 597 return $this->__get( $key ); 598 } 599 600 /** 601 * Determine whether a property of meta key is set 602 * 603 * Consults the users and usermeta tables. 604 * 605 * @since 3.3.0 606 * 607 * @param string $key Property 608 */ 609 function exists( $key ) { 610 return $this->__isset( $key ); 611 } 612 613 /** 502 614 * Set up capability object properties. 503 615 * 504 616 * Will set the value for the 'cap_key' property to current database table … … 519 631 else 520 632 $this->cap_key = $cap_key; 521 633 522 $this->caps = &$this->data->{$this->cap_key}; 634 $this->caps = get_user_meta( $this->ID, $this->cap_key, true ); 635 523 636 if ( ! is_array( $this->caps ) ) 524 637 $this->caps = array(); 525 638 … … 662 775 */ 663 776 function update_user_level_from_caps() { 664 777 global $wpdb; 665 $this->user_level = array_reduce( array_keys( $this->allcaps ), array( &$this, 'level_reduction' ), 0 );778 $this->user_level = array_reduce( array_keys( $this->allcaps ), array( $this, 'level_reduction' ), 0 ); 666 779 update_user_meta( $this->ID, $wpdb->prefix . 'user_level', $this->user_level ); 667 780 } 668 781 … … 1066 1179 $args = array_slice( func_get_args(), 1 ); 1067 1180 $args = array_merge( array( $capability ), $args ); 1068 1181 1069 return call_user_func_array( array( &$current_user, 'has_cap' ), $args );1182 return call_user_func_array( array( $current_user, 'has_cap' ), $args ); 1070 1183 } 1071 1184 1072 1185 /** -
wp-includes/deprecated.php
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 … … 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. … … 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 } -
wp-includes/pluggable.php
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; 104 return get_user_by( 'id', $user_id ); 105 } 106 endif; 105 107 106 if ( ! is_numeric( $user_id ) ) 107 return false; 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 ); 108 120 109 $user_id = absint( $user_id ); 110 if ( ! $user_id ) 121 if ( !$userdata ) 111 122 return false; 112 123 113 $user = wp_cache_get( $user_id, 'users' ); 124 $user = new WP_User; 125 $user->init( $userdata ); 114 126 115 if ( $user )116 return $user;117 118 if ( ! $user = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->users WHERE ID = %d LIMIT 1", $user_id ) ) )119 return false;120 121 _fill_user( $user );122 123 127 return $user; 124 128 } 125 129 endif; … … 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/meta.php
73 73 $mid = (int) $wpdb->insert_id; 74 74 75 75 wp_cache_delete($object_id, $meta_type . '_meta'); 76 // users cache stores usermeta that must be cleared.77 if ( 'user' == $meta_type )78 clean_user_cache($object_id);79 76 80 77 do_action( "added_{$meta_type}_meta", $mid, $object_id, $meta_key, $_meta_value ); 81 78 … … 149 146 } 150 147 151 148 do_action( "update_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value ); 152 149 153 150 if ( 'post' == $meta_type ) 154 do_action( 'update_postmeta', $meta_id, $object_id, $meta_key, $meta_value ); 151 do_action( 'update_postmeta', $meta_id, $object_id, $meta_key, $meta_value ); 155 152 156 153 $wpdb->update( $table, $data, $where ); 157 154 158 155 wp_cache_delete($object_id, $meta_type . '_meta'); 159 // users cache stores usermeta that must be cleared.160 if ( 'user' == $meta_type )161 clean_user_cache($object_id);162 156 163 157 do_action( "updated_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value ); 164 158 165 159 if ( 'post' == $meta_type ) 166 do_action( 'updated_postmeta', $meta_id, $object_id, $meta_key, $meta_value ); 160 do_action( 'updated_postmeta', $meta_id, $object_id, $meta_key, $meta_value ); 167 161 168 162 return true; 169 163 } … … 210 204 211 205 $_meta_value = $meta_value; 212 206 $meta_value = maybe_serialize( $meta_value ); 213 207 214 208 $query = $wpdb->prepare( "SELECT $id_column FROM $table WHERE meta_key = %s", $meta_key ); 215 209 216 210 if ( !$delete_all ) … … 227 221 $object_ids = $wpdb->get_col( $wpdb->prepare( "SELECT $type_column FROM $table WHERE meta_key = %s", $meta_key ) ); 228 222 229 223 do_action( "delete_{$meta_type}_meta", $meta_ids, $object_id, $meta_key, $_meta_value ); 230 224 231 225 if ( 'post' == $meta_type ) 232 226 do_action( 'delete_postmeta', $meta_ids ); 233 227 … … 246 240 wp_cache_delete($object_id, $meta_type . '_meta'); 247 241 } 248 242 249 // users cache stores usermeta that must be cleared. 250 if ( 'user' == $meta_type ) 251 clean_user_cache($object_id); 243 do_action( "deleted_{$meta_type}_meta", $meta_ids, $object_id, $meta_key, $_meta_value ); 252 244 253 do_action( "deleted_{$meta_type}_meta", $meta_ids, $object_id, $meta_key, $_meta_value );254 255 245 if ( 'post' == $meta_type ) 256 246 do_action( 'deleted_postmeta', $meta_ids ); 257 247 … … 310 300 } 311 301 312 302 /** 303 * Determine if a meta key is set for a given object 304 * 305 * @since 3.3.0 306 * 307 * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user) 308 * @param int $object_id ID of the object metadata is for 309 * @param string $meta_key Metadata key. 310 * @return boolean true of the key is set, false if not. 311 */ 312 function metadata_exists( $meta_type, $object_id, $meta_key ) { 313 if ( ! $meta_type ) 314 return false; 315 316 if ( ! $object_id = absint( $object_id ) ) 317 return false; 318 319 $check = apply_filters( "get_{$meta_type}_metadata", null, $object_id, $meta_key, true ); 320 if ( null !== $check ) 321 return true; 322 323 $meta_cache = wp_cache_get( $object_id, $meta_type . '_meta' ); 324 325 if ( !$meta_cache ) { 326 $meta_cache = update_meta_cache( $meta_type, array( $object_id ) ); 327 $meta_cache = $meta_cache[$object_id]; 328 } 329 330 if ( isset( $meta_cache[ $meta_key ] ) ) 331 return true; 332 333 return false; 334 } 335 336 /** 313 337 * Get meta data by meta ID 314 338 * 315 339 * @since 3.3.0 … … 406 430 407 431 if ( 'post' == $meta_type ) 408 432 do_action( 'update_postmeta', $meta_id, $object_id, $meta_key, $meta_value ); 409 433 410 434 // Run the update query, all fields in $data are %s, $where is a %d. 411 435 $result = (bool) $wpdb->update( $table, $data, $where, '%s', '%d' ); 412 436 413 437 // Clear the caches. 414 438 wp_cache_delete($object_id, $meta_type . '_meta'); 415 416 // Users cache stores usermeta that must be cleared.417 if ( 'user' == $meta_type )418 clean_user_cache($object_id);419 439 420 440 do_action( "updated_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value ); 421 441 … … 424 444 425 445 return $result; 426 446 } 427 447 428 448 // And if the meta was not found. 429 449 return false; 430 450 } … … 443 463 */ 444 464 function delete_metadata_by_mid( $meta_type, $meta_id ) { 445 465 global $wpdb; 446 466 447 467 // Make sure everything is valid. 448 468 if ( ! $meta_type ) 449 469 return false; … … 453 473 454 474 if ( ! $table = _get_meta_table( $meta_type ) ) 455 475 return false; 456 476 457 477 // object and id columns 458 478 $column = esc_sql($meta_type . '_id'); 459 479 $id_column = 'user' == $meta_type ? 'umeta_id' : 'meta_id'; … … 473 493 // Clear the caches. 474 494 wp_cache_delete($object_id, $meta_type . '_meta'); 475 495 476 // Users cache stores usermeta that must be cleared.477 if ( 'user' == $meta_type )478 clean_user_cache($object_id);479 480 496 do_action( "deleted_{$meta_type}_meta", (array) $meta_id, $object_id, $meta->meta_key, $meta->meta_value ); 481 497 482 498 if ( 'post' == $meta_type ) … … 485 501 return $result; 486 502 487 503 } 488 504 489 505 // Meta id was not found. 490 506 return false; 491 507 } … … 818 834 819 835 /** 820 836 * Register meta key 821 * 837 * 822 838 * @since 3.3.0 823 839 * 824 840 * @param string $meta_type Type of meta -
wp-admin/includes/class-wp-users-list-table.php
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
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 } 229 $user->filter = 'edit'; 234 230 235 if ( empty($user->description) )236 $user->description = '';237 238 $user = sanitize_user_object($user, 'edit');239 240 231 return $user; 241 232 } 242 233