<!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" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { 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 #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#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>
<title>[12983] trunk: Switch to *_user_option()
  for default password nag to avoid extra DB queries.</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/12983">12983</a></dd>
<dt>Author</dt> <dd>dd32</dd>
<dt>Date</dt> <dd>2010-02-06 06:20:38 +0000 (Sat, 06 Feb 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>Switch to *_user_option() for default password nag to avoid extra DB queries. Fixes <a href="http://trac.wordpress.org/ticket/11380">#11380</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminincludesupgradephp">trunk/wp-admin/includes/upgrade.php</a></li>
<li><a href="#trunkwpadminincludesuserphp">trunk/wp-admin/includes/user.php</a></li>
<li><a href="#trunkwploginphp">trunk/wp-login.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminincludesupgradephp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/upgrade.php (12982 => 12983)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/upgrade.php        2010-02-06 05:15:26 UTC (rev 12982)
+++ trunk/wp-admin/includes/upgrade.php        2010-02-06 06:20:38 UTC (rev 12983)
</span><span class="lines">@@ -64,7 +64,7 @@
</span><span class="cx">                 $random_password = wp_generate_password();
</span><span class="cx">                 $message = __('&lt;strong&gt;&lt;em&gt;Note that password&lt;/em&gt;&lt;/strong&gt; carefully! It is a &lt;em&gt;random&lt;/em&gt; password that was generated just for you.');
</span><span class="cx">                 $user_id = wp_create_user($user_name, $random_password, $user_email);
</span><del>-                update_usermeta($user_id, 'default_password_nag', true);
</del><ins>+                update_user_option($user_id, 'default_password_nag', true, true);
</ins><span class="cx">         } else {
</span><span class="cx">                 $random_password = '';
</span><span class="cx">                 $message =  __('User already exists.  Password inherited.');
</span></span></pre></div>
<a id="trunkwpadminincludesuserphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/user.php (12982 => 12983)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/user.php        2010-02-06 05:15:26 UTC (rev 12982)
+++ trunk/wp-admin/includes/user.php        2010-02-06 06:20:38 UTC (rev 12983)
</span><span class="lines">@@ -807,34 +807,33 @@
</span><span class="cx"> add_action('admin_init', 'default_password_nag_handler');
</span><span class="cx"> function default_password_nag_handler($errors = false) {
</span><span class="cx">         global $user_ID;
</span><del>-        if ( ! get_usermeta($user_ID, 'default_password_nag') ) //Short circuit it.
</del><ins>+        if ( ! get_user_option('default_password_nag') ) //Short circuit it.
</ins><span class="cx">                 return;
</span><span class="cx"> 
</span><span class="cx">         //get_user_setting = JS saved UI setting. else no-js-falback code.
</span><span class="cx">         if ( 'hide' == get_user_setting('default_password_nag') || isset($_GET['default_password_nag']) &amp;&amp; '0' == $_GET['default_password_nag'] ) {
</span><span class="cx">                 delete_user_setting('default_password_nag');
</span><del>-                update_usermeta($user_ID, 'default_password_nag', false);
</del><ins>+                update_user_option($user_ID, 'default_password_nag', false, true);
</ins><span class="cx">         }
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> add_action('profile_update', 'default_password_nag_edit_user', 10, 2);
</span><span class="cx"> function default_password_nag_edit_user($user_ID, $old_data) {
</span><span class="cx">         global $user_ID;
</span><del>-        if ( ! get_usermeta($user_ID, 'default_password_nag') ) //Short circuit it.
</del><ins>+        if ( ! get_user_option('default_password_nag') ) //Short circuit it.
</ins><span class="cx">                 return;
</span><span class="cx"> 
</span><span class="cx">         $new_data = get_userdata($user_ID);
</span><span class="cx"> 
</span><span class="cx">         if ( $new_data-&gt;user_pass != $old_data-&gt;user_pass ) { //Remove the nag if the password has been changed.
</span><span class="cx">                 delete_user_setting('default_password_nag');
</span><del>-                update_usermeta($user_ID, 'default_password_nag', false);
</del><ins>+                update_user_option($user_ID, 'default_password_nag', false, true);
</ins><span class="cx">         }
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> add_action('admin_notices', 'default_password_nag');
</span><span class="cx"> function default_password_nag() {
</span><del>-        global $user_ID;
-        if ( ! get_usermeta($user_ID, 'default_password_nag') )
</del><ins>+        if ( ! get_user_option('default_password_nag') ) //Short circuit it.
</ins><span class="cx">                 return;
</span><span class="cx"> 
</span><span class="cx">         echo '&lt;div class=&quot;error default-password-nag&quot;&gt;&lt;p&gt;';
</span></span></pre></div>
<a id="trunkwploginphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-login.php (12982 => 12983)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-login.php        2010-02-06 05:15:26 UTC (rev 12982)
+++ trunk/wp-login.php        2010-02-06 06:20:38 UTC (rev 12983)
</span><span class="lines">@@ -242,7 +242,7 @@
</span><span class="cx">         do_action('password_reset', $user, $new_pass);
</span><span class="cx"> 
</span><span class="cx">         wp_set_password($new_pass, $user-&gt;ID);
</span><del>-        update_usermeta($user-&gt;ID, 'default_password_nag', true); //Set up the Password change nag.
</del><ins>+        update_user_option($user_ID, 'default_password_nag', true, true); //Set up the Password change nag.
</ins><span class="cx">         $message  = sprintf(__('Username: %s'), $user-&gt;user_login) . &quot;\r\n&quot;;
</span><span class="cx">         $message .= sprintf(__('Password: %s'), $new_pass) . &quot;\r\n&quot;;
</span><span class="cx">         $message .= site_url('wp-login.php', 'login') . &quot;\r\n&quot;;
</span></span></pre>
</div>
</div>

</body>
</html>