<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[18597] trunk: Introduce metadata_exists(), WP_User::get_data_by(), WP_User::get(), WP_User::has_prop().</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg > ul, #logmsg > ol { margin-left: 0; margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://core.trac.wordpress.org/changeset/18597">18597</a></dd>
<dt>Author</dt> <dd>ryan</dd>
<dt>Date</dt> <dd>2011-08-24 19:32:59 +0000 (Wed, 24 Aug 2011)</dd>
</dl>
<h3>Log Message</h3>
<pre>Introduce metadata_exists(), WP_User::get_data_by(), WP_User::get(), WP_User::has_prop(). Don't fill user objects with meta. Eliminate data duplication in cache and memory. Props scribu. see <a href="http://core.trac.wordpress.org/ticket/15458">#15458</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminincludesclasswpuserslisttablephp">trunk/wp-admin/includes/class-wp-users-list-table.php</a></li>
<li><a href="#trunkwpadminincludesuserphp">trunk/wp-admin/includes/user.php</a></li>
<li><a href="#trunkwpincludescapabilitiesphp">trunk/wp-includes/capabilities.php</a></li>
<li><a href="#trunkwpincludesdeprecatedphp">trunk/wp-includes/deprecated.php</a></li>
<li><a href="#trunkwpincludesmetaphp">trunk/wp-includes/meta.php</a></li>
<li><a href="#trunkwpincludespluggablephp">trunk/wp-includes/pluggable.php</a></li>
<li><a href="#trunkwpincludesuserphp">trunk/wp-includes/user.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminincludesclasswpuserslisttablephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/class-wp-users-list-table.php (18596 => 18597)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/class-wp-users-list-table.php        2011-08-24 11:37:25 UTC (rev 18596)
+++ trunk/wp-admin/includes/class-wp-users-list-table.php        2011-08-24 19:32:59 UTC (rev 18597)
</span><span class="lines">@@ -219,7 +219,7 @@
</span><span class="cx">
</span><span class="cx">                 if ( !( is_object( $user_object ) && is_a( $user_object, 'WP_User' ) ) )
</span><span class="cx">                         $user_object = new WP_User( (int) $user_object );
</span><del>-                $user_object = sanitize_user_object( $user_object, 'display' );
</del><ins>+                $user_object->filter = 'display';
</ins><span class="cx">                 $email = $user_object->user_email;
</span><span class="cx">
</span><span class="cx">                 if ( $this->is_site_users )
</span></span></pre></div>
<a id="trunkwpadminincludesuserphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/user.php (18596 => 18597)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/user.php        2011-08-24 11:37:25 UTC (rev 18596)
+++ trunk/wp-admin/includes/user.php        2011-08-24 19:32:59 UTC (rev 18597)
</span><span class="lines">@@ -226,17 +226,8 @@
</span><span class="cx"> function get_user_to_edit( $user_id ) {
</span><span class="cx">         $user = new WP_User( $user_id );
</span><span class="cx">
</span><del>-        $user_contactmethods = _wp_get_user_contactmethods( $user );
-        foreach ($user_contactmethods as $method => $name) {
-                if ( empty( $user->{$method} ) )
-                        $user->{$method} = '';
-        }
</del><ins>+        $user->filter = 'edit';
</ins><span class="cx">
</span><del>-        if ( empty($user->description) )
-                $user->description = '';
-
-        $user = sanitize_user_object($user, 'edit');
-
</del><span class="cx">         return $user;
</span><span class="cx"> }
</span><span class="cx">
</span></span></pre></div>
<a id="trunkwpincludescapabilitiesphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/capabilities.php (18596 => 18597)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/capabilities.php        2011-08-24 11:37:25 UTC (rev 18596)
+++ trunk/wp-includes/capabilities.php        2011-08-24 19:32:59 UTC (rev 18597)
</span><span class="lines">@@ -420,43 +420,110 @@
</span><span class="cx">          */
</span><span class="cx">         var $filter = null;
</span><span class="cx">
</span><ins>+        private static $back_compat_keys = array(
+                'user_firstname' => 'first_name',
+                'user_lastname' => 'last_name',
+                'user_description' => 'description'
+        );
+
</ins><span class="cx">         /**
</span><del>-         * Constructor - Sets up the object properties.
</del><ins>+         * Constructor
</ins><span class="cx">          *
</span><del>-         * Retrieves the userdata and then assigns all of the data keys to direct
-         * properties of the object. Calls {@link WP_User::_init_caps()} after
-         * setting up the object's user data properties.
</del><ins>+         * Retrieves the userdata and passes it to {@link WP_User::init()}.
</ins><span class="cx">          *
</span><span class="cx">          * @since 2.0.0
</span><span class="cx">          * @access public
</span><span class="cx">          *
</span><del>-         * @param int|string $id User's ID or username
-         * @param int $name Optional. User's username
</del><ins>+         * @param int|string $id User's ID
+         * @param string $name Optional. User's username
</ins><span class="cx">          * @param int $blog_id Optional Blog ID, defaults to current blog.
</span><span class="cx">          * @return WP_User
</span><span class="cx">          */
</span><del>-        function __construct( $id, $name = '', $blog_id = '' ) {
-                if ( empty( $id ) && empty( $name ) )
-                        return;
-
</del><ins>+        function __construct( $id = 0, $name = '', $blog_id = '' ) {
</ins><span class="cx">                 if ( ! is_numeric( $id ) ) {
</span><span class="cx">                         $name = $id;
</span><span class="cx">                         $id = 0;
</span><span class="cx">                 }
</span><span class="cx">
</span><del>-                if ( ! empty( $id ) )
-                        $this->data = get_userdata( $id );
</del><ins>+                if ( $id )
+                        $data = self::get_data_by( 'id', $id );
</ins><span class="cx">                 else
</span><del>-                        $this->data = get_user_by('login', $name );
</del><ins>+                        $data = self::get_data_by( 'login', $name );
</ins><span class="cx">
</span><del>-                if ( empty( $this->data->ID ) )
-                        return;
</del><ins>+                if ( $data )
+                        $this->init( $data, $blog_id );
+        }
</ins><span class="cx">
</span><del>-                $this->ID = $this->data->ID;
</del><ins>+        /**
+         * Sets up object properties, including capabilities.
+         *
+         * @param object $data User DB row object
+         * @param int $blog_id Optional. The blog id to initialize for
+         */
+        function init( $data, $blog_id = '' ) {
+                $this->data = $data;
+                $this->ID = (int) $data->ID;
+
</ins><span class="cx">                 $this->for_blog( $blog_id );
</span><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         /**
</span><ins>+         * Return only the main user fields
+         *
+         * @since 3.3.0
+         *
+         * @param string $field The field to query against: 'id', 'slug', 'email' or 'login'
+         * @param string|int $value The field value
+         */
+        static function get_data_by( $field, $value ) {
+                global $wpdb;
+
+                if ( 'id' == $field )
+                        $value = absint( $value );
+                else
+                        $value = trim( $value );
+
+                if ( !$value )
+                        return false;
+
+                switch ( $field ) {
+                        case 'id':
+                                $user_id = $value;
+                                $db_field = 'ID';
+                                break;
+                        case 'slug':
+                                $user_id = wp_cache_get($value, 'userslugs');
+                                $db_field = 'user_nicename';
+                                break;
+                        case 'email':
+                                $user_id = wp_cache_get($value, 'useremail');
+                                $db_field = 'user_email';
+                                break;
+                        case 'login':
+                                $value = sanitize_user( $value );
+                                $user_id = wp_cache_get($value, 'userlogins');
+                                $db_field = 'user_login';
+                                break;
+                        default:
+                                return false;
+                }
+
+                if ( false !== $user_id ) {
+                        if ( $user = wp_cache_get( $user_id, 'users' ) )
+                                return $user;
+                }
+
+                if ( !$user = $wpdb->get_row( $wpdb->prepare(
+                        "SELECT * FROM $wpdb->users WHERE $db_field = %s", $value
+                ) ) )
+                        return false;
+
+                update_user_caches( $user );
+
+                return $user;
+        }
+
+        /**
</ins><span class="cx">          * Magic method for checking the existance of a certain custom field
</span><span class="cx">          *
</span><span class="cx">          * @since 3.3.0
</span><span class="lines">@@ -466,7 +533,14 @@
</span><span class="cx">                         _deprecated_argument( 'WP_User->id', '2.1', __( 'Use <code>WP_User->ID</code> instead.' ) );
</span><span class="cx">                         $key = 'ID';
</span><span class="cx">                 }
</span><del>-                return isset( $this->data->$key );
</del><ins>+
+                if ( isset( $this->data->$key ) )
+                        return true;
+
+                if ( isset( self::$back_compat_keys[ $key ] ) )
+                        $key = self::$back_compat_keys[ $key ];
+
+                return metadata_exists( 'user', $this->ID, $key );
</ins><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         /**
</span><span class="lines">@@ -480,7 +554,19 @@
</span><span class="cx">                         return $this->ID;
</span><span class="cx">                 }
</span><span class="cx">
</span><del>-                return $this->data->$key;
</del><ins>+                if ( isset( $this->data->$key ) ) {
+                        $value = $this->data->$key;
+                } else {
+                        if ( isset( self::$back_compat_keys[ $key ] ) )
+                                $key = self::$back_compat_keys[ $key ];
+                        $value = get_user_meta( $this->ID, $key, true );
+                }
+
+                if ( $this->filter ) {
+                        $value = sanitize_user_field( $key, $value, $this->ID, $this->filter );
+                }
+
+                return $value;
</ins><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         /**
</span><span class="lines">@@ -499,6 +585,32 @@
</span><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         /**
</span><ins>+         * Retrieve the value of a property or meta key.
+         *
+         * Retrieves from the users and usermeta table.
+         *
+         * @since 3.3.0
+         *
+         * @param string $key Property
+         */
+        function get( $key ) {
+                return $this->__get( $key );
+        }
+
+        /**
+         * Determine whether a property or meta key is set
+         *
+         * Consults the users and usermeta tables.
+         *
+         * @since 3.3.0
+         *
+         * @param string $key Property
+         */
+        function has_prop( $key ) {
+                return $this->__isset( $key );
+        }
+
+        /**
</ins><span class="cx">          * Set up capability object properties.
</span><span class="cx">          *
</span><span class="cx">          * Will set the value for the 'cap_key' property to current database table
</span><span class="lines">@@ -519,7 +631,8 @@
</span><span class="cx">                 else
</span><span class="cx">                         $this->cap_key = $cap_key;
</span><span class="cx">
</span><del>-                $this->caps = &$this->data->{$this->cap_key};
</del><ins>+                $this->caps = get_user_meta( $this->ID, $this->cap_key, true );
+
</ins><span class="cx">                 if ( ! is_array( $this->caps ) )
</span><span class="cx">                         $this->caps = array();
</span><span class="cx">
</span><span class="lines">@@ -662,7 +775,7 @@
</span><span class="cx">          */
</span><span class="cx">         function update_user_level_from_caps() {
</span><span class="cx">                 global $wpdb;
</span><del>-                $this->user_level = array_reduce( array_keys( $this->allcaps ), array( &$this, 'level_reduction' ), 0 );
</del><ins>+                $this->user_level = array_reduce( array_keys( $this->allcaps ), array( $this, 'level_reduction' ), 0 );
</ins><span class="cx">                 update_user_meta( $this->ID, $wpdb->prefix . 'user_level', $this->user_level );
</span><span class="cx">         }
</span><span class="cx">
</span><span class="lines">@@ -1066,7 +1179,7 @@
</span><span class="cx">         $args = array_slice( func_get_args(), 1 );
</span><span class="cx">         $args = array_merge( array( $capability ), $args );
</span><span class="cx">
</span><del>-        return call_user_func_array( array( &$current_user, 'has_cap' ), $args );
</del><ins>+        return call_user_func_array( array( $current_user, 'has_cap' ), $args );
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span></span></pre></div>
<a id="trunkwpincludesdeprecatedphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/deprecated.php (18596 => 18597)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/deprecated.php        2011-08-24 11:37:25 UTC (rev 18596)
+++ trunk/wp-includes/deprecated.php        2011-08-24 19:32:59 UTC (rev 18597)
</span><span class="lines">@@ -2627,13 +2627,13 @@
</span><span class="cx"> */
</span><span class="cx"> function wp_default_editor() {
</span><span class="cx">         _deprecated_function( __FUNCTION__, '3.3' );
</span><del>-        
</del><ins>+
</ins><span class="cx">         global $wp_editor;
</span><span class="cx">         if ( !is_a($wp_editor, 'WP_Editor') ) {
</span><span class="cx">                 require_once( ABSPATH . WPINC . '/class-wp-editor.php' );
</span><span class="cx">                 $wp_editor = new WP_Editor;
</span><span class="cx">         }
</span><del>-        
</del><ins>+
</ins><span class="cx">         return $wp_editor->wp_default_editor();
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -2641,7 +2641,7 @@
</span><span class="cx"> * Display editor: TinyMCE, HTML, or both.
</span><span class="cx"> *
</span><span class="cx"> * @since 2.1.0
</span><del>- * @deprecated 3.3
</del><ins>+ * @deprecated 3.3
</ins><span class="cx"> *
</span><span class="cx"> * @param string $content Textarea content.
</span><span class="cx"> * @param string $id Optional, default is 'content'. HTML ID attribute value.
</span><span class="lines">@@ -2650,8 +2650,74 @@
</span><span class="cx"> * @param int $tab_index Optional, not used
</span><span class="cx"> */
</span><span class="cx"> function the_editor($content, $id = 'content', $prev_id = 'title', $media_buttons = true, $tab_index = 2, $extended = true) {
</span><del>-        
</del><ins>+
</ins><span class="cx">         wp_editor( $content, $id, array( 'media_buttons' => $media_buttons ) );
</span><span class="cx">         return;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+/**
+ * Perform the query to get the $metavalues array(s) needed by _fill_user and _fill_many_users
+ *
+ * @since 3.0.0
+ * @param array $ids User ID numbers list.
+ * @return array of arrays. The array is indexed by user_id, containing $metavalues object arrays.
+ */
+function get_user_metavalues($ids) {
+        _deprecated_function( __FUNCTION__, '3.3' );
+
+        $objects = array();
+
+        $ids = array_map('intval', $ids);
+        foreach ( $ids as $id )
+                $objects[$id] = array();
+
+        $metas = update_meta_cache('user', $ids);
+
+        foreach ( $metas as $id => $meta ) {
+                foreach ( $meta as $key => $metavalues ) {
+                        foreach ( $metavalues as $value ) {
+                                $objects[$id][] = (object)array( 'user_id' => $id, 'meta_key' => $key, 'meta_value' => $value);
+                        }
+                }
+        }
+
+        return $objects;
+}
+
+/**
+ * Sanitize every user field.
+ *
+ * If the context is 'raw', then the user object or array will get minimal santization of the int fields.
+ *
+ * @since 2.3.0
+ * @deprecated 3.3.0
+ * @uses sanitize_user_field() Used to sanitize the fields.
+ *
+ * @param object|array $user The User Object or Array
+ * @param string $context Optional, default is 'display'. How to sanitize user fields.
+ * @return object|array The now sanitized User Object or Array (will be the same type as $user)
+ */
+function sanitize_user_object($user, $context = 'display') {
+        _deprecated_function( __FUNCTION__, '3.3' );
+
+        if ( is_object($user) ) {
+                if ( !isset($user->ID) )
+                        $user->ID = 0;
+                if ( !is_a( $user, 'WP_User' ) ) {
+                        $vars = get_object_vars($user);
+                        foreach ( array_keys($vars) as $field ) {
+                                if ( is_string($user->$field) || is_numeric($user->$field) )
+                                        $user->$field = sanitize_user_field($field, $user->$field, $user->ID, $context);
+                        }
+                }
+                $user->filter = $context;
+        } else {
+                if ( !isset($user['ID']) )
+                        $user['ID'] = 0;
+                foreach ( array_keys($user) as $field )
+                        $user[$field] = sanitize_user_field($field, $user[$field], $user['ID'], $context);
+                $user['filter'] = $context;
+        }
+
+        return $user;
+}
</ins></span></pre></div>
<a id="trunkwpincludesmetaphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/meta.php (18596 => 18597)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/meta.php        2011-08-24 11:37:25 UTC (rev 18596)
+++ trunk/wp-includes/meta.php        2011-08-24 19:32:59 UTC (rev 18597)
</span><span class="lines">@@ -73,9 +73,6 @@
</span><span class="cx">         $mid = (int) $wpdb->insert_id;
</span><span class="cx">
</span><span class="cx">         wp_cache_delete($object_id, $meta_type . '_meta');
</span><del>-        // users cache stores usermeta that must be cleared.
-        if ( 'user' == $meta_type )
-                clean_user_cache($object_id);
</del><span class="cx">
</span><span class="cx">         do_action( "added_{$meta_type}_meta", $mid, $object_id, $meta_key, $_meta_value );
</span><span class="cx">
</span><span class="lines">@@ -149,21 +146,18 @@
</span><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         do_action( "update_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value );
</span><del>-        
</del><ins>+
</ins><span class="cx">         if ( 'post' == $meta_type )
</span><del>-                do_action( 'update_postmeta', $meta_id, $object_id, $meta_key, $meta_value );        
</del><ins>+                do_action( 'update_postmeta', $meta_id, $object_id, $meta_key, $meta_value );
</ins><span class="cx">
</span><span class="cx">         $wpdb->update( $table, $data, $where );
</span><span class="cx">
</span><span class="cx">         wp_cache_delete($object_id, $meta_type . '_meta');
</span><del>-        // users cache stores usermeta that must be cleared.
-        if ( 'user' == $meta_type )
-                clean_user_cache($object_id);
</del><span class="cx">
</span><span class="cx">         do_action( "updated_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value );
</span><del>-        
</del><ins>+
</ins><span class="cx">         if ( 'post' == $meta_type )
</span><del>-                do_action( 'updated_postmeta', $meta_id, $object_id, $meta_key, $meta_value );                
</del><ins>+                do_action( 'updated_postmeta', $meta_id, $object_id, $meta_key, $meta_value );
</ins><span class="cx">
</span><span class="cx">         return true;
</span><span class="cx"> }
</span><span class="lines">@@ -210,7 +204,7 @@
</span><span class="cx">
</span><span class="cx">         $_meta_value = $meta_value;
</span><span class="cx">         $meta_value = maybe_serialize( $meta_value );
</span><del>-                
</del><ins>+
</ins><span class="cx">         $query = $wpdb->prepare( "SELECT $id_column FROM $table WHERE meta_key = %s", $meta_key );
</span><span class="cx">
</span><span class="cx">         if ( !$delete_all )
</span><span class="lines">@@ -227,7 +221,7 @@
</span><span class="cx">                 $object_ids = $wpdb->get_col( $wpdb->prepare( "SELECT $type_column FROM $table WHERE meta_key = %s", $meta_key ) );
</span><span class="cx">
</span><span class="cx">         do_action( "delete_{$meta_type}_meta", $meta_ids, $object_id, $meta_key, $_meta_value );
</span><del>-        
</del><ins>+
</ins><span class="cx">         if ( 'post' == $meta_type )
</span><span class="cx">                 do_action( 'delete_postmeta', $meta_ids );
</span><span class="cx">
</span><span class="lines">@@ -246,12 +240,8 @@
</span><span class="cx">                 wp_cache_delete($object_id, $meta_type . '_meta');
</span><span class="cx">         }
</span><span class="cx">
</span><del>-        // users cache stores usermeta that must be cleared.
-        if ( 'user' == $meta_type )
-                clean_user_cache($object_id);
</del><ins>+        do_action( "deleted_{$meta_type}_meta", $meta_ids, $object_id, $meta_key, $_meta_value );
</ins><span class="cx">
</span><del>-        do_action( "deleted_{$meta_type}_meta", $meta_ids, $object_id, $meta_key, $_meta_value );
-        
</del><span class="cx">         if ( 'post' == $meta_type )
</span><span class="cx">                 do_action( 'deleted_postmeta', $meta_ids );
</span><span class="cx">
</span><span class="lines">@@ -310,6 +300,40 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><ins>+ * Determine if a meta key is set for a given object
+ *
+ * @since 3.3.0
+ *
+ * @param string $meta_type Type of object metadata is for (e.g., comment, post, or user)
+ * @param int $object_id ID of the object metadata is for
+ * @param string $meta_key Metadata key.
+ * @return boolean true of the key is set, false if not.
+ */
+function metadata_exists( $meta_type, $object_id, $meta_key ) {
+        if ( ! $meta_type )
+                return false;
+
+        if ( ! $object_id = absint( $object_id ) )
+                return false;
+
+        $check = apply_filters( "get_{$meta_type}_metadata", null, $object_id, $meta_key, true );
+        if ( null !== $check )
+                return true;
+
+        $meta_cache = wp_cache_get( $object_id, $meta_type . '_meta' );
+
+        if ( !$meta_cache ) {
+                $meta_cache = update_meta_cache( $meta_type, array( $object_id ) );
+                $meta_cache = $meta_cache[$object_id];
+        }
+
+        if ( isset( $meta_cache[ $meta_key ] ) )
+                return true;
+
+        return false;
+}
+
+/**
</ins><span class="cx"> * Get meta data by meta ID
</span><span class="cx"> *
</span><span class="cx"> * @since 3.3.0
</span><span class="lines">@@ -406,16 +430,12 @@
</span><span class="cx">
</span><span class="cx">                 if ( 'post' == $meta_type )
</span><span class="cx">                         do_action( 'update_postmeta', $meta_id, $object_id, $meta_key, $meta_value );
</span><del>-                
</del><ins>+
</ins><span class="cx">                 // Run the update query, all fields in $data are %s, $where is a %d.
</span><span class="cx">                 $result = (bool) $wpdb->update( $table, $data, $where, '%s', '%d' );
</span><span class="cx">
</span><span class="cx">                 // Clear the caches.
</span><span class="cx">                 wp_cache_delete($object_id, $meta_type . '_meta');
</span><del>-                
-                // Users cache stores usermeta that must be cleared.
-                if ( 'user' == $meta_type )
-                        clean_user_cache($object_id);
</del><span class="cx">
</span><span class="cx">                 do_action( "updated_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $_meta_value );
</span><span class="cx">
</span><span class="lines">@@ -424,7 +444,7 @@
</span><span class="cx">
</span><span class="cx">                 return $result;
</span><span class="cx">         }
</span><del>-        
</del><ins>+
</ins><span class="cx">         // And if the meta was not found.
</span><span class="cx">         return false;
</span><span class="cx"> }
</span><span class="lines">@@ -443,7 +463,7 @@
</span><span class="cx"> */
</span><span class="cx"> function delete_metadata_by_mid( $meta_type, $meta_id ) {
</span><span class="cx">         global $wpdb;
</span><del>-        
</del><ins>+
</ins><span class="cx">         // Make sure everything is valid.
</span><span class="cx">         if ( ! $meta_type )
</span><span class="cx">                 return false;
</span><span class="lines">@@ -453,7 +473,7 @@
</span><span class="cx">
</span><span class="cx">         if ( ! $table = _get_meta_table( $meta_type ) )
</span><span class="cx">                 return false;
</span><del>-        
</del><ins>+
</ins><span class="cx">         // object and id columns
</span><span class="cx">         $column = esc_sql($meta_type . '_id');
</span><span class="cx">         $id_column = 'user' == $meta_type ? 'umeta_id' : 'meta_id';
</span><span class="lines">@@ -473,10 +493,6 @@
</span><span class="cx">                 // Clear the caches.
</span><span class="cx">                 wp_cache_delete($object_id, $meta_type . '_meta');
</span><span class="cx">
</span><del>-                // Users cache stores usermeta that must be cleared.
-                if ( 'user' == $meta_type )
-                        clean_user_cache($object_id);
-
</del><span class="cx">                 do_action( "deleted_{$meta_type}_meta", (array) $meta_id, $object_id, $meta->meta_key, $meta->meta_value );
</span><span class="cx">
</span><span class="cx">                 if ( 'post' == $meta_type )
</span><span class="lines">@@ -485,7 +501,7 @@
</span><span class="cx">                 return $result;
</span><span class="cx">
</span><span class="cx">         }
</span><del>-        
</del><ins>+
</ins><span class="cx">         // Meta id was not found.
</span><span class="cx">         return false;
</span><span class="cx"> }
</span><span class="lines">@@ -818,7 +834,7 @@
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="cx"> * Register meta key
</span><del>- *
</del><ins>+ *
</ins><span class="cx"> * @since 3.3.0
</span><span class="cx"> *
</span><span class="cx"> * @param string $meta_type Type of meta
</span></span></pre></div>
<a id="trunkwpincludespluggablephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/pluggable.php (18596 => 18597)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/pluggable.php        2011-08-24 11:37:25 UTC (rev 18596)
+++ trunk/wp-includes/pluggable.php        2011-08-24 19:32:59 UTC (rev 18597)
</span><span class="lines">@@ -98,28 +98,32 @@
</span><span class="cx"> * @since 0.71
</span><span class="cx"> *
</span><span class="cx"> * @param int $user_id User ID
</span><del>- * @return bool|object False on failure, User DB row object
</del><ins>+ * @return bool|object False on failure, WP_User object on success
</ins><span class="cx"> */
</span><span class="cx"> function get_userdata( $user_id ) {
</span><del>-        global $wpdb;
</del><ins>+        return get_user_by( 'id', $user_id );
+}
+endif;
</ins><span class="cx">
</span><del>-        if ( ! is_numeric( $user_id ) )
-                return false;
</del><ins>+if ( !function_exists('get_user_by') ) :
+/**
+ * Retrieve user info by a given field
+ *
+ * @since 2.8.0
+ *
+ * @param string $field The field to retrieve the user with. id | slug | email | login
+ * @param int|string $value A value for $field. A user ID, slug, email address, or login name.
+ * @return bool|object False on failure, WP_User object on success
+ */
+function get_user_by( $field, $value ) {
+        $userdata = WP_User::get_data_by( $field, $value );
</ins><span class="cx">
</span><del>-        $user_id = absint( $user_id );
-        if ( ! $user_id )
</del><ins>+        if ( !$userdata )
</ins><span class="cx">                 return false;
</span><span class="cx">
</span><del>-        $user = wp_cache_get( $user_id, 'users' );
</del><ins>+        $user = new WP_User;
+        $user->init( $userdata );
</ins><span class="cx">
</span><del>-        if ( $user )
-                return $user;
-
-        if ( ! $user = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->users WHERE ID = %d LIMIT 1", $user_id ) ) )
-                return false;
-
-        _fill_user( $user );
-
</del><span class="cx">         return $user;
</span><span class="cx"> }
</span><span class="cx"> endif;
</span><span class="lines">@@ -130,75 +134,32 @@
</span><span class="cx"> *
</span><span class="cx"> * @since 3.0.0
</span><span class="cx"> *
</span><del>- * @param array $users User ID numbers list
</del><ins>+ * @param array $user_ids User ID numbers list
</ins><span class="cx"> */
</span><del>-function cache_users( $users ) {
</del><ins>+function cache_users( $user_ids ) {
</ins><span class="cx">         global $wpdb;
</span><span class="cx">
</span><span class="cx">         $clean = array();
</span><del>-        foreach($users as $id) {
</del><ins>+        foreach ( $user_ids as $id ) {
</ins><span class="cx">                 $id = (int) $id;
</span><del>-                if (wp_cache_get($id, 'users')) {
-                        // seems to be cached already
-                } else {
</del><ins>+                if ( !wp_cache_get( $id, 'users' ) ) {
</ins><span class="cx">                         $clean[] = $id;
</span><span class="cx">                 }
</span><span class="cx">         }
</span><span class="cx">
</span><del>-        if ( 0 == count($clean) )
</del><ins>+        if ( empty( $clean ) )
</ins><span class="cx">                 return;
</span><span class="cx">
</span><del>-        $list = implode(',', $clean);
</del><ins>+        $list = implode( ',', $clean );
</ins><span class="cx">
</span><del>-        $results = $wpdb->get_results("SELECT * FROM $wpdb->users WHERE ID IN ($list)");
</del><ins>+        $users = $wpdb->get_results( "SELECT * FROM $wpdb->users WHERE ID IN ($list)" );
</ins><span class="cx">
</span><del>-        _fill_many_users($results);
-}
-endif;
-
-if ( !function_exists('get_user_by') ) :
-/**
- * Retrieve user info by a given field
- *
- * @since 2.8.0
- *
- * @param string $field The field to retrieve the user with. id | slug | email | login
- * @param int|string $value A value for $field. A user ID, slug, email address, or login name.
- * @return bool|object False on failure, User DB row object
- */
-function get_user_by($field, $value) {
-        global $wpdb;
-
-        switch ($field) {
-                case 'id':
-                        return get_userdata($value);
-                        break;
-                case 'slug':
-                        $user_id = wp_cache_get($value, 'userslugs');
-                        $field = 'user_nicename';
-                        break;
-                case 'email':
-                        $user_id = wp_cache_get($value, 'useremail');
-                        $field = 'user_email';
-                        break;
-                case 'login':
-                        $value = sanitize_user( $value );
-                        $user_id = wp_cache_get($value, 'userlogins');
-                        $field = 'user_login';
-                        break;
-                default:
-                        return false;
</del><ins>+        $ids = array();
+        foreach ( $users as $user ) {
+                update_user_caches( $user );
+                $ids[] = $user->ID;
</ins><span class="cx">         }
</span><del>-
-         if ( false !== $user_id )
-                return get_userdata($user_id);
-
-        if ( !$user = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->users WHERE $field = %s", $value) ) )
-                return false;
-
-        _fill_user($user);
-
-        return $user;
</del><ins>+        update_meta_cache( 'user', $ids );
</ins><span class="cx"> }
</span><span class="cx"> endif;
</span><span class="cx">
</span></span></pre></div>
<a id="trunkwpincludesuserphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/user.php (18596 => 18597)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/user.php        2011-08-24 11:37:25 UTC (rev 18596)
+++ trunk/wp-includes/user.php        2011-08-24 19:32:59 UTC (rev 18597)
</span><span class="lines">@@ -254,20 +254,18 @@
</span><span class="cx">         if ( !empty( $deprecated ) )
</span><span class="cx">                 _deprecated_argument( __FUNCTION__, '3.0' );
</span><span class="cx">
</span><del>-        if ( empty($user) ) {
</del><ins>+        if ( empty( $user ) )
</ins><span class="cx">                 $user = wp_get_current_user();
</span><del>-                $user = $user->ID;
-        }
</del><ins>+        else
+                $user = new WP_User( $user );
</ins><span class="cx">
</span><del>-        $user = get_userdata($user);
</del><ins>+        if ( ! isset( $user->ID ) )
+                return false;
</ins><span class="cx">
</span><del>-        // Keys used as object vars cannot have dashes.
-        $key = str_replace('-', '', $option);
-
-        if ( isset( $user->{$wpdb->prefix . $key} ) ) // Blog specific
-                $result = $user->{$wpdb->prefix . $key};
-        elseif ( isset( $user->{$key} ) ) // User specific and cross-blog
-                $result = $user->{$key};
</del><ins>+        if ( $user->has_prop( $wpdb->prefix . $option ) ) // Blog specific
+                $result = $user->get( $wpdb->prefix . $option );
+        elseif ( $user->has_prop( $option ) ) // User specific and cross-blog
+                $result = $user->get( $option );
</ins><span class="cx">         else
</span><span class="cx">                 $result = false;
</span><span class="cx">
</span><span class="lines">@@ -680,13 +678,13 @@
</span><span class="cx">         }
</span><span class="cx">
</span><span class="cx">         if ( false === $blogs ) {
</span><del>-                $user = get_userdata( (int) $id );
-                if ( !$user )
</del><ins>+                $userkeys = array_keys( get_user_meta( (int) $id ) );
+                if ( empty( $userkeys ) )
</ins><span class="cx">                         return false;
</span><span class="cx">
</span><span class="cx">                 $blogs = $match = array();
</span><del>-                $prefix_length = strlen($wpdb->base_prefix);
-                foreach ( (array) $user as $key => $value ) {
</del><ins>+                $prefix_length = strlen( $wpdb->base_prefix );
+                foreach ( $userkeys as $key ) {
</ins><span class="cx">                         if ( $prefix_length && substr($key, 0, $prefix_length) != $wpdb->base_prefix )
</span><span class="cx">                                 continue;
</span><span class="cx">                         if ( substr($key, -12, 12) != 'capabilities' )
</span><span class="lines">@@ -793,7 +791,7 @@
</span><span class="cx"> * @return mixed Will be an array if $single is false. Will be value of meta data field if $single
</span><span class="cx"> * is true.
</span><span class="cx"> */
</span><del>-function get_user_meta($user_id, $key, $single = false) {
</del><ins>+function get_user_meta($user_id, $key = '', $single = false) {
</ins><span class="cx">         return get_metadata('user', $user_id, $key, $single);
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -1043,141 +1041,6 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><del>- * Add user meta data as properties to given user object.
- *
- * The finished user data is cached, but the cache is not used to fill in the
- * user data for the given object. Once the function has been used, the cache
- * should be used to retrieve user data. The intention is if the current data
- * had been cached already, there would be no need to call this function.
- *
- * @access private
- * @since 2.5.0
- * @uses $wpdb WordPress database object for queries
- *
- * @param object $user The user data object.
- */
-function _fill_user( &$user ) {
-        $metavalues = get_user_metavalues(array($user->ID));
-        _fill_single_user($user, $metavalues[$user->ID]);
-}
-
-/**
- * Perform the query to get the $metavalues array(s) needed by _fill_user and _fill_many_users
- *
- * @since 3.0.0
- * @param array $ids User ID numbers list.
- * @return array of arrays. The array is indexed by user_id, containing $metavalues object arrays.
- */
-function get_user_metavalues($ids) {
-        $objects = array();
-
-        $ids = array_map('intval', $ids);
-        foreach ( $ids as $id )
-                $objects[$id] = array();
-
-        $metas = update_meta_cache('user', $ids);
-
-        foreach ( $metas as $id => $meta ) {
-                foreach ( $meta as $key => $metavalues ) {
-                        foreach ( $metavalues as $value ) {
-                                $objects[$id][] = (object)array( 'user_id' => $id, 'meta_key' => $key, 'meta_value' => $value);
-                        }
-                }
-        }
-
-        return $objects;
-}
-
-/**
- * Unserialize user metadata, fill $user object, then cache everything.
- *
- * @since 3.0.0
- * @param object $user The User object.
- * @param array $metavalues An array of objects provided by get_user_metavalues()
- */
-function _fill_single_user( &$user, &$metavalues ) {
-        global $wpdb;
-
-        foreach ( $metavalues as $meta ) {
-                $value = maybe_unserialize($meta->meta_value);
-                // Keys used as object vars cannot have dashes.
-                $key = str_replace('-', '', $meta->meta_key);
-                $user->{$key} = $value;
-        }
-
-        $level = $wpdb->prefix . 'user_level';
-        if ( isset( $user->{$level} ) )
-                $user->user_level = $user->{$level};
-
-        // For backwards compat.
-        if ( isset($user->first_name) )
-                $user->user_firstname = $user->first_name;
-        if ( isset($user->last_name) )
-                $user->user_lastname = $user->last_name;
-        if ( isset($user->description) )
-                $user->user_description = $user->description;
-
-        update_user_caches($user);
-}
-
-/**
- * Take an array of user objects, fill them with metas, and cache them.
- *
- * @since 3.0.0
- * @param array $users User objects
- */
-function _fill_many_users( &$users ) {
-        $ids = array();
-        foreach( $users as $user_object ) {
-                $ids[] = $user_object->ID;
-        }
-
-        $metas = get_user_metavalues($ids);
-
-        foreach ( $users as $user_object ) {
-                if ( isset($metas[$user_object->ID]) ) {
-                        _fill_single_user($user_object, $metas[$user_object->ID]);
-                }
-        }
-}
-
-/**
- * Sanitize every user field.
- *
- * If the context is 'raw', then the user object or array will get minimal santization of the int fields.
- *
- * @since 2.3.0
- * @uses sanitize_user_field() Used to sanitize the fields.
- *
- * @param object|array $user The User Object or Array
- * @param string $context Optional, default is 'display'. How to sanitize user fields.
- * @return object|array The now sanitized User Object or Array (will be the same type as $user)
- */
-function sanitize_user_object($user, $context = 'display') {
-        if ( is_object($user) ) {
-                if ( !isset($user->ID) )
-                        $user->ID = 0;
-                if ( isset($user->data) )
-                        $vars = get_object_vars( $user->data );
-                else
-                        $vars = get_object_vars($user);
-                foreach ( array_keys($vars) as $field ) {
-                        if ( is_string($user->$field) || is_numeric($user->$field) )
-                                $user->$field = sanitize_user_field($field, $user->$field, $user->ID, $context);
-                }
-                $user->filter = $context;
-        } else {
-                if ( !isset($user['ID']) )
-                        $user['ID'] = 0;
-                foreach ( array_keys($user) as $field )
-                        $user[$field] = sanitize_user_field($field, $user[$field], $user['ID'], $context);
-                $user['filter'] = $context;
-        }
-
-        return $user;
-}
-
-/**
</del><span class="cx"> * Sanitize user field based on context.
</span><span class="cx"> *
</span><span class="cx"> * Possible context values are: 'raw', 'edit', 'db', 'display', 'attribute' and 'js'. The
</span><span class="lines">@@ -1264,7 +1127,7 @@
</span><span class="cx"> *
</span><span class="cx"> * @param object $user User object to be cached
</span><span class="cx"> */
</span><del>-function update_user_caches(&$user) {
</del><ins>+function update_user_caches($user) {
</ins><span class="cx">         wp_cache_add($user->ID, $user, 'users');
</span><span class="cx">         wp_cache_add($user->user_login, $user->ID, 'userlogins');
</span><span class="cx">         wp_cache_add($user->user_email, $user->ID, 'useremail');
</span><span class="lines">@@ -1279,7 +1142,7 @@
</span><span class="cx"> * @param int $id User ID
</span><span class="cx"> */
</span><span class="cx"> function clean_user_cache($id) {
</span><del>-        $user = new WP_User($id);
</del><ins>+        $user = WP_User::get_data_by( 'id', $id );
</ins><span class="cx">
</span><span class="cx">         wp_cache_delete($id, 'users');
</span><span class="cx">         wp_cache_delete($user->user_login, 'userlogins');
</span><span class="lines">@@ -1390,7 +1253,7 @@
</span><span class="cx">         if ( !empty($ID) ) {
</span><span class="cx">                 $ID = (int) $ID;
</span><span class="cx">                 $update = true;
</span><del>-                $old_user_data = get_userdata($ID);
</del><ins>+                $old_user_data = WP_User::get_data_by( 'id', $ID );
</ins><span class="cx">         } else {
</span><span class="cx">                 $update = false;
</span><span class="cx">                 // Hash the password
</span><span class="lines">@@ -1548,7 +1411,7 @@
</span><span class="cx">         $ID = (int) $userdata['ID'];
</span><span class="cx">
</span><span class="cx">         // First, get all of the original fields
</span><del>-        $user = get_userdata($ID);
</del><ins>+        $user = WP_User::get_data_by('id', $ID);
</ins><span class="cx">
</span><span class="cx">         // Escape data pulled from DB.
</span><span class="cx">         $user = add_magic_quotes(get_object_vars($user));
</span></span></pre>
</div>
</div>
</body>
</html>