<!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>[18504] trunk: Add magic get/set/isset methods to WP_User to avoid data duplication.</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/18504">18504</a></dd>
<dt>Author</dt> <dd>ryan</dd>
<dt>Date</dt> <dd>2011-08-04 03:09:27 +0000 (Thu, 04 Aug 2011)</dd>
</dl>

<h3>Log Message</h3>
<pre>Add magic get/set/isset methods to WP_User to avoid data duplication. Standardize on WP_User::ID. Props scribu. see <a href="http://core.trac.wordpress.org/ticket/15458">#15458</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminincludesdeprecatedphp">trunk/wp-admin/includes/deprecated.php</a></li>
<li><a href="#trunkwpadminincludesmsphp">trunk/wp-admin/includes/ms.php</a></li>
<li><a href="#trunkwpadminmysitesphp">trunk/wp-admin/my-sites.php</a></li>
<li><a href="#trunkwpadminusersphp">trunk/wp-admin/users.php</a></li>
<li><a href="#trunkwpincludescapabilitiesphp">trunk/wp-includes/capabilities.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>
<li><a href="#trunkwploginphp">trunk/wp-login.php</a></li>
<li><a href="#trunkwpsignupphp">trunk/wp-signup.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminincludesdeprecatedphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/deprecated.php (18503 => 18504)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/deprecated.php        2011-08-03 23:56:21 UTC (rev 18503)
+++ trunk/wp-admin/includes/deprecated.php        2011-08-04 03:09:27 UTC (rev 18504)
</span><span class="lines">@@ -255,7 +255,7 @@
</span><span class="cx"> 
</span><span class="cx">         if ( ! $user-&gt;has_cap($post_type_obj-&gt;cap-&gt;edit_others_posts) ) {
</span><span class="cx">                 if ( $user-&gt;has_cap($post_type_obj-&gt;cap-&gt;edit_posts) || ! $exclude_zeros )
</span><del>-                        return array($user-&gt;id);
</del><ins>+                        return array($user-&gt;ID);
</ins><span class="cx">                 else
</span><span class="cx">                         return array();
</span><span class="cx">         }
</span></span></pre></div>
<a id="trunkwpadminincludesmsphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/ms.php (18503 => 18504)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/ms.php        2011-08-03 23:56:21 UTC (rev 18503)
+++ trunk/wp-admin/includes/ms.php        2011-08-04 03:09:27 UTC (rev 18504)
</span><span class="lines">@@ -250,7 +250,7 @@
</span><span class="cx">         if ( ! is_object($errors) )
</span><span class="cx">                 $errors = new WP_Error();
</span><span class="cx"> 
</span><del>-        if ( $current_user-&gt;id != $_POST['user_id'] )
</del><ins>+        if ( $current_user-&gt;ID != $_POST['user_id'] )
</ins><span class="cx">                 return false;
</span><span class="cx"> 
</span><span class="cx">         if ( $current_user-&gt;user_email != $_POST['email'] ) {
</span></span></pre></div>
<a id="trunkwpadminmysitesphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/my-sites.php (18503 => 18504)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/my-sites.php        2011-08-03 23:56:21 UTC (rev 18503)
+++ trunk/wp-admin/my-sites.php        2011-08-04 03:09:27 UTC (rev 18504)
</span><span class="lines">@@ -17,7 +17,7 @@
</span><span class="cx"> 
</span><span class="cx"> $action = isset( $_POST['action'] ) ? $_POST['action'] : 'splash';
</span><span class="cx"> 
</span><del>-$blogs = get_blogs_of_user( $current_user-&gt;id );
</del><ins>+$blogs = get_blogs_of_user( $current_user-&gt;ID );
</ins><span class="cx"> 
</span><span class="cx"> if ( empty( $blogs ) )
</span><span class="cx">         wp_die( __( 'You must be a member of at least one site to use this page.' ) );
</span><span class="lines">@@ -28,7 +28,7 @@
</span><span class="cx"> 
</span><span class="cx">         $blog = get_blog_details( (int) $_POST['primary_blog'] );
</span><span class="cx">         if ( $blog &amp;&amp; isset( $blog-&gt;domain ) ) {
</span><del>-                update_user_option( $current_user-&gt;id, 'primary_blog', (int) $_POST['primary_blog'], true );
</del><ins>+                update_user_option( $current_user-&gt;ID, 'primary_blog', (int) $_POST['primary_blog'], true );
</ins><span class="cx">                 $updated = true;
</span><span class="cx">         } else {
</span><span class="cx">                 wp_die( __( 'The primary site you chose does not exist.' ) );
</span></span></pre></div>
<a id="trunkwpadminusersphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/users.php (18503 => 18504)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/users.php        2011-08-03 23:56:21 UTC (rev 18503)
+++ trunk/wp-admin/users.php        2011-08-04 03:09:27 UTC (rev 18504)
</span><span class="lines">@@ -216,7 +216,7 @@
</span><span class="cx">         $update = 'remove';
</span><span class="cx">          foreach ( $userids as $id ) {
</span><span class="cx">                 $id = (int) $id;
</span><del>-                if ( $id == $current_user-&gt;id &amp;&amp; !is_super_admin() ) {
</del><ins>+                if ( $id == $current_user-&gt;ID &amp;&amp; !is_super_admin() ) {
</ins><span class="cx">                         $update = 'err_admin_remove';
</span><span class="cx">                         continue;
</span><span class="cx">                 }
</span><span class="lines">@@ -269,7 +269,7 @@
</span><span class="cx">          foreach ( $userids as $id ) {
</span><span class="cx">                 $id = (int) $id;
</span><span class="cx">                  $user = new WP_User($id);
</span><del>-                if ( $id == $current_user-&gt;id &amp;&amp; !is_super_admin() ) {
</del><ins>+                if ( $id == $current_user-&gt;ID &amp;&amp; !is_super_admin() ) {
</ins><span class="cx">                         echo &quot;&lt;li&gt;&quot; . sprintf(__('ID #%1s: %2s &lt;strong&gt;The current user will not be removed.&lt;/strong&gt;'), $id, $user-&gt;user_login) . &quot;&lt;/li&gt;\n&quot;;
</span><span class="cx">                 } elseif ( !current_user_can('remove_user', $id) ) {
</span><span class="cx">                         echo &quot;&lt;li&gt;&quot; . sprintf(__('ID #%1s: %2s &lt;strong&gt;You don\'t have permission to remove this user.&lt;/strong&gt;'), $id, $user-&gt;user_login) . &quot;&lt;/li&gt;\n&quot;;
</span></span></pre></div>
<a id="trunkwpincludescapabilitiesphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/capabilities.php (18503 => 18504)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/capabilities.php        2011-08-03 23:56:21 UTC (rev 18503)
+++ trunk/wp-includes/capabilities.php        2011-08-04 03:09:27 UTC (rev 18504)
</span><span class="lines">@@ -360,8 +360,6 @@
</span><span class="cx">         /**
</span><span class="cx">          * User data container.
</span><span class="cx">          *
</span><del>-         * This will be set as properties of the object.
-         *
</del><span class="cx">          * @since 2.0.0
</span><span class="cx">          * @access private
</span><span class="cx">          * @var array
</span><span class="lines">@@ -378,17 +376,6 @@
</span><span class="cx">         var $ID = 0;
</span><span class="cx"> 
</span><span class="cx">         /**
</span><del>-         * The deprecated user's ID.
-         *
-         * @since 2.0.0
-         * @access public
-         * @deprecated Use WP_User::$ID
-         * @see WP_User::$ID
-         * @var int
-         */
-        var $id = 0;
-
-        /**
</del><span class="cx">          * The individual capabilities the user has been given.
</span><span class="cx">          *
</span><span class="cx">          * @since 2.0.0
</span><span class="lines">@@ -471,7 +458,6 @@
</span><span class="cx">          * @return WP_User
</span><span class="cx">          */
</span><span class="cx">         function __construct( $id, $name = '', $blog_id = '' ) {
</span><del>-
</del><span class="cx">                 if ( empty( $id ) &amp;&amp; empty( $name ) )
</span><span class="cx">                         return;
</span><span class="cx"> 
</span><span class="lines">@@ -488,15 +474,43 @@
</span><span class="cx">                 if ( empty( $this-&gt;data-&gt;ID ) )
</span><span class="cx">                         return;
</span><span class="cx"> 
</span><del>-                foreach ( get_object_vars( $this-&gt;data ) as $key =&gt; $value ) {
-                        $this-&gt;{$key} = $value;
</del><ins>+                $this-&gt;ID = $this-&gt;data-&gt;ID;
+                $this-&gt;for_blog( $blog_id );
+        }
+
+        /**
+         * Magic method for checking the existance of a certain custom field
+         *
+         * @since 3.3.0
+         */
+        function __isset( $key ) {
+                return isset( $this-&gt;data-&gt;$key );
+        }
+
+        /**
+         * Magic method for accessing custom fields
+         *
+         * @since 3.3.0
+         */
+        function __get( $key ) {
+                if ( 'id' == $key ) {
+                        _deprecated_argument( 'WP_User-&gt;id', '2.1', __( 'Use &lt;code&gt;WP_User-&gt;ID&lt;/code&gt; instead.' ) );
+                        return $this-&gt;ID;
</ins><span class="cx">                 }
</span><span class="cx"> 
</span><del>-                $this-&gt;id = $this-&gt;ID;
-                $this-&gt;for_blog( $blog_id );
</del><ins>+                return $this-&gt;data-&gt;$key;
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         /**
</span><ins>+         * Magic method for setting custom fields
+         *
+         * @since 3.3.0
+         */
+        function __set( $key, $value ) {
+                $this-&gt;data-&gt;$key = $value;
+        }
+
+        /**
</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">@@ -511,13 +525,16 @@
</span><span class="cx">          */
</span><span class="cx">         function _init_caps( $cap_key = '' ) {
</span><span class="cx">                 global $wpdb;
</span><ins>+
</ins><span class="cx">                 if ( empty($cap_key) )
</span><span class="cx">                         $this-&gt;cap_key = $wpdb-&gt;prefix . 'capabilities';
</span><span class="cx">                 else
</span><span class="cx">                         $this-&gt;cap_key = $cap_key;
</span><del>-                $this-&gt;caps = &amp;$this-&gt;{$this-&gt;cap_key};
</del><ins>+
+                $this-&gt;caps = &amp;$this-&gt;data-&gt;{$this-&gt;cap_key};
</ins><span class="cx">                 if ( ! is_array( $this-&gt;caps ) )
</span><span class="cx">                         $this-&gt;caps = array();
</span><ins>+
</ins><span class="cx">                 $this-&gt;get_role_caps();
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="lines">@@ -956,10 +973,10 @@
</span><span class="cx">         case 'add_post_meta':
</span><span class="cx">                 $post = get_post( $args[0] );
</span><span class="cx">                 $post_type_object = get_post_type_object( $post-&gt;post_type );
</span><del>-                $caps = map_meta_cap( $post_type_object-&gt;cap-&gt;edit_post, $user_id, $post-&gt;ID );        
</del><ins>+                $caps = map_meta_cap( $post_type_object-&gt;cap-&gt;edit_post, $user_id, $post-&gt;ID );
</ins><span class="cx"> 
</span><del>-                $meta_key = isset( $args[ 1 ] ) ? $args[ 1 ] : false; 
-                        
</del><ins>+                $meta_key = isset( $args[ 1 ] ) ? $args[ 1 ] : false;
+
</ins><span class="cx">                 if ( $meta_key &amp;&amp; has_filter( &quot;auth_post_meta_{$meta_key}&quot; ) ) {
</span><span class="cx">                         $allowed = apply_filters( &quot;auth_post_meta_{$meta_key}&quot;, false, $meta_key, $post-&gt;ID, $user_id, $cap, $caps );
</span><span class="cx">                         if ( ! $allowed )
</span><span class="lines">@@ -1080,7 +1097,7 @@
</span><span class="cx">                 return false;
</span><span class="cx"> 
</span><span class="cx">         // Create new object to avoid stomping the global current_user.
</span><del>-        $user = new WP_User( $current_user-&gt;id) ;
</del><ins>+        $user = new WP_User( $current_user-&gt;ID) ;
</ins><span class="cx"> 
</span><span class="cx">         // Set the blog id.  @todo add blog id arg to WP_User constructor?
</span><span class="cx">         $user-&gt;for_blog( $blog_id );
</span><span class="lines">@@ -1225,7 +1242,7 @@
</span><span class="cx">         else
</span><span class="cx">                 $user = wp_get_current_user();
</span><span class="cx"> 
</span><del>-        if ( empty( $user-&gt;id ) )
</del><ins>+        if ( empty( $user-&gt;ID ) )
</ins><span class="cx">                 return false;
</span><span class="cx"> 
</span><span class="cx">         if ( is_multisite() ) {
</span></span></pre></div>
<a id="trunkwpincludespluggablephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/pluggable.php (18503 => 18504)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/pluggable.php        2011-08-03 23:56:21 UTC (rev 18503)
+++ trunk/wp-includes/pluggable.php        2011-08-04 03:09:27 UTC (rev 18504)
</span><span class="lines">@@ -783,7 +783,7 @@
</span><span class="cx"> function is_user_logged_in() {
</span><span class="cx">         $user = wp_get_current_user();
</span><span class="cx"> 
</span><del>-        if ( $user-&gt;id == 0 )
</del><ins>+        if ( $user-&gt;ID == 0 )
</ins><span class="cx">                 return false;
</span><span class="cx"> 
</span><span class="cx">         return true;
</span><span class="lines">@@ -1308,7 +1308,7 @@
</span><span class="cx">  */
</span><span class="cx"> function wp_verify_nonce($nonce, $action = -1) {
</span><span class="cx">         $user = wp_get_current_user();
</span><del>-        $uid = (int) $user-&gt;id;
</del><ins>+        $uid = (int) $user-&gt;ID;
</ins><span class="cx"> 
</span><span class="cx">         $i = wp_nonce_tick();
</span><span class="cx"> 
</span><span class="lines">@@ -1334,7 +1334,7 @@
</span><span class="cx">  */
</span><span class="cx"> function wp_create_nonce($action = -1) {
</span><span class="cx">         $user = wp_get_current_user();
</span><del>-        $uid = (int) $user-&gt;id;
</del><ins>+        $uid = (int) $user-&gt;ID;
</ins><span class="cx"> 
</span><span class="cx">         $i = wp_nonce_tick();
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkwpincludesuserphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/user.php (18503 => 18504)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/user.php        2011-08-03 23:56:21 UTC (rev 18503)
+++ trunk/wp-includes/user.php        2011-08-04 03:09:27 UTC (rev 18504)
</span><span class="lines">@@ -1566,7 +1566,7 @@
</span><span class="cx"> 
</span><span class="cx">         // Update the cookies if the password changed.
</span><span class="cx">         $current_user = wp_get_current_user();
</span><del>-        if ( $current_user-&gt;id == $ID ) {
</del><ins>+        if ( $current_user-&gt;ID == $ID ) {
</ins><span class="cx">                 if ( isset($plaintext_pass) ) {
</span><span class="cx">                         wp_clear_auth_cookie();
</span><span class="cx">                         wp_set_auth_cookie($ID);
</span></span></pre></div>
<a id="trunkwploginphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-login.php (18503 => 18504)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-login.php        2011-08-03 23:56:21 UTC (rev 18503)
+++ trunk/wp-login.php        2011-08-04 03:09:27 UTC (rev 18504)
</span><span class="lines">@@ -586,10 +586,10 @@
</span><span class="cx"> 
</span><span class="cx">                 if ( ( empty( $redirect_to ) || $redirect_to == 'wp-admin/' || $redirect_to == admin_url() ) ) {
</span><span class="cx">                         // If the user doesn't belong to a blog, send them to user admin. If the user can't edit posts, send them to their profile.
</span><del>-                        if ( is_multisite() &amp;&amp; !get_active_blog_for_user($user-&gt;id) &amp;&amp; !is_super_admin( $user-&gt;id ) )
</del><ins>+                        if ( is_multisite() &amp;&amp; !get_active_blog_for_user($user-&gt;ID) &amp;&amp; !is_super_admin( $user-&gt;ID ) )
</ins><span class="cx">                                 $redirect_to = user_admin_url();
</span><span class="cx">                         elseif ( is_multisite() &amp;&amp; !$user-&gt;has_cap('read') )
</span><del>-                                $redirect_to = get_dashboard_url( $user-&gt;id );
</del><ins>+                                $redirect_to = get_dashboard_url( $user-&gt;ID );
</ins><span class="cx">                         elseif ( !$user-&gt;has_cap('edit_posts') )
</span><span class="cx">                                 $redirect_to = admin_url('profile.php');
</span><span class="cx">                 }
</span></span></pre></div>
<a id="trunkwpsignupphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-signup.php (18503 => 18504)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-signup.php        2011-08-03 23:56:21 UTC (rev 18503)
+++ trunk/wp-signup.php        2011-08-04 03:09:27 UTC (rev 18504)
</span><span class="lines">@@ -213,7 +213,7 @@
</span><span class="cx">         $meta = apply_filters( 'signup_create_blog_meta', array( 'lang_id' =&gt; 1, 'public' =&gt; $public ) ); // deprecated
</span><span class="cx">         $meta = apply_filters( 'add_signup_meta', $meta );
</span><span class="cx"> 
</span><del>-        wpmu_create_blog( $domain, $path, $blog_title, $current_user-&gt;id, $meta, $wpdb-&gt;siteid );
</del><ins>+        wpmu_create_blog( $domain, $path, $blog_title, $current_user-&gt;ID, $meta, $wpdb-&gt;siteid );
</ins><span class="cx">         confirm_another_blog_signup($domain, $path, $blog_title, $current_user-&gt;user_login, $current_user-&gt;user_email, $meta);
</span><span class="cx">         return true;
</span><span class="cx"> }
</span></span></pre>
</div>
</div>

</body>
</html>