<!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>[17198] trunk: Introduce include_selected arg for wp_dropdown_users().</title>
</head>
<body>
<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/17198">17198</a></dd>
<dt>Author</dt> <dd>ryan</dd>
<dt>Date</dt> <dd>2011-01-01 01:52:03 +0000 (Sat, 01 Jan 2011)</dd>
</dl>
<h3>Log Message</h3>
<pre>Introduce include_selected arg for wp_dropdown_users(). Add current author to dropdown in post_author_meta_box(). fixes <a href="http://trac.wordpress.org/ticket/16045">#16045</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminincludesmetaboxesphp">trunk/wp-admin/includes/meta-boxes.php</a></li>
<li><a href="#trunkwpincludesuserphp">trunk/wp-includes/user.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminincludesmetaboxesphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/meta-boxes.php (17197 => 17198)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/meta-boxes.php        2011-01-01 00:21:18 UTC (rev 17197)
+++ trunk/wp-admin/includes/meta-boxes.php        2011-01-01 01:52:03 UTC (rev 17198)
</span><span class="lines">@@ -530,7 +530,8 @@
</span><span class="cx">         wp_dropdown_users( array(
</span><span class="cx">                 'who' => 'authors',
</span><span class="cx">                 'name' => 'post_author_override',
</span><del>-                'selected' => empty($post->ID) ? $user_ID : $post->post_author
</del><ins>+                'selected' => empty($post->ID) ? $user_ID : $post->post_author,
+                'include_selected' => true
</ins><span class="cx">         ) );
</span><span class="cx"> }
</span><span class="cx">
</span></span></pre></div>
<a id="trunkwpincludesuserphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/user.php (17197 => 17198)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/user.php        2011-01-01 00:21:18 UTC (rev 17197)
+++ trunk/wp-includes/user.php        2011-01-01 01:52:03 UTC (rev 17198)
</span><span class="lines">@@ -957,6 +957,7 @@
</span><span class="cx"> * <li>show - Default is 'display_name'. User table column to display. If the selected item is empty then the user_login will be displayed in parentheses</li>
</span><span class="cx"> * <li>echo - Default is '1'. Whether to display or retrieve content.</li>
</span><span class="cx"> * <li>selected - Which User ID is selected.</li>
</span><ins>+ * <li>include_selected - Always include the selected user ID in the dropdown. Default is false.</li>
</ins><span class="cx"> * <li>name - Default is 'user'. Name attribute of select element.</li>
</span><span class="cx"> * <li>id - Default is the value of the 'name' parameter. ID attribute of select element.</li>
</span><span class="cx"> * <li>class - Class attribute of select element.</li>
</span><span class="lines">@@ -977,7 +978,7 @@
</span><span class="cx">                 'include' => '', 'exclude' => '', 'multi' => 0,
</span><span class="cx">                 'show' => 'display_name', 'echo' => 1,
</span><span class="cx">                 'selected' => 0, 'name' => 'user', 'class' => '', 'id' => '',
</span><del>-                'blog_id' => $GLOBALS['blog_id'], 'who' => ''
</del><ins>+                'blog_id' => $GLOBALS['blog_id'], 'who' => '', 'include_selected' => false
</ins><span class="cx">         );
</span><span class="cx">
</span><span class="cx">         $defaults['selected'] = is_author() ? get_query_var( 'author' ) : 0;
</span><span class="lines">@@ -1007,13 +1008,23 @@
</span><span class="cx">                         $output .= "\t<option value='-1'$_selected>$show_option_none</option>\n";
</span><span class="cx">                 }
</span><span class="cx">
</span><ins>+                $found_selected = false;
</ins><span class="cx">                 foreach ( (array) $users as $user ) {
</span><span class="cx">                         $user->ID = (int) $user->ID;
</span><span class="cx">                         $_selected = selected( $user->ID, $selected, false );
</span><ins>+                        if ( $_selected )
+                                $found_selected = true;
</ins><span class="cx">                         $display = !empty($user->$show) ? $user->$show : '('. $user->user_login . ')';
</span><span class="cx">                         $output .= "\t<option value='$user->ID'$_selected>" . esc_html($display) . "</option>\n";
</span><span class="cx">                 }
</span><span class="cx">
</span><ins>+                if ( $include_selected && ! $found_selected && ( $selected > 0 ) ) {
+                        $user = get_userdata( $selected );
+                        $_selected = selected( $user->ID, $selected, false );
+                        $display = !empty($user->$show) ? $user->$show : '('. $user->user_login . ')';
+                        $output .= "\t<option value='$user->ID'$_selected>" . esc_html($display) . "</option>\n";
+                }
+
</ins><span class="cx">                 $output .= "</select>";
</span><span class="cx">         }
</span><span class="cx">
</span></span></pre>
</div>
</div>
</body>
</html>