<!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>[13539] trunk/wp-admin: Dynamically remove duplicates from the '
display name' profile.php option.</title>
</head>
<body>
<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/13539">13539</a></dd>
<dt>Author</dt> <dd>nacin</dd>
<dt>Date</dt> <dd>2010-03-01 22:34:43 +0000 (Mon, 01 Mar 2010)</dd>
</dl>
<h3>Log Message</h3>
<pre>Dynamically remove duplicates from the 'display name' profile.php option. fixes <a href="http://trac.wordpress.org/ticket/10030">#10030</a></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminjsuserprofiledevjs">trunk/wp-admin/js/user-profile.dev.js</a></li>
<li><a href="#trunkwpadminjsuserprofilejs">trunk/wp-admin/js/user-profile.js</a></li>
<li><a href="#trunkwpadminusereditphp">trunk/wp-admin/user-edit.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminjsuserprofiledevjs"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/js/user-profile.dev.js (13538 => 13539)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/js/user-profile.dev.js        2010-03-01 21:04:37 UTC (rev 13538)
+++ trunk/wp-admin/js/user-profile.dev.js        2010-03-01 22:34:43 UTC (rev 13539)
</span><span class="lines">@@ -31,21 +31,29 @@
</span><span class="cx">                 $('.color-palette').click(function(){$(this).siblings('input[name=admin_color]').attr('checked', 'checked')});
</span><span class="cx">                 $('#nickname').blur(function(){
</span><span class="cx">                         var str = $(this).val() || $('#user_login').val();
</span><del>-                        $('#display_name #display_nickname').val(str).html(str);
</del><ins>+                        var select = $('#display_name');
+                        var sel = select.children('option:selected').attr('id');
+                        select.children('#display_nickname').remove();
+                        if ( ! select.children('option[value=' + str + ']').length )
+                                select.append('<option id="display_nickname" value="' + str + '">' + str + '</option>');
+                        $('#'+sel).attr('selected', 'selected');
</ins><span class="cx">                 });
</span><span class="cx">                 $('#first_name, #last_name').blur(function(){
</span><ins>+                        var select = $('#display_name');
</ins><span class="cx">                         var first = $('#first_name').val(), last = $('#last_name').val();
</span><ins>+                        var sel = select.children('option:selected').attr('id');
</ins><span class="cx">                         $('#display_firstname, #display_lastname, #display_firstlast, #display_lastfirst').remove();
</span><ins>+                        if ( first && ! select.children('option[value=' + first + ']').length )
+                                select.append('<option id="display_firstname" value="' + first + '">' + first + '</option>');
+                        if ( last && ! select.children('option[value=' + last + ']').length )
+                                select.append('<option id="display_lastname" value="' + last + '">' + last + '</option>');
</ins><span class="cx">                         if ( first && last ) {
</span><del>-                                $('#display_name').append('<option id="display_firstname" value="' + first + '">' + first + '</option>' +
-                                        '<option id="display_lastname" value="' + last + '">' + last + '</option>' +
-                                        '<option id="display_firstlast" value="' + first + ' ' + last + '">' + first + ' ' + last + '</option>' +
-                                        '<option id="display_lastfirst" value="' + last + ' ' + first + '">' + last + ' ' + first + '</option>');
-                        } else if ( first && !last ) {
-                                $('#display_name').append('<option id="display_firstname" value="' + first + '">' + first + '</option>');
-                        } else if ( !first && last ) {
-                                $('#display_name').append('<option id="display_lastname" value="' + last + '">' + last + '</option>');
</del><ins>+                                if ( ! select.children('option[value=' + first + ' ' + last + ']').length )
+                                        select.append('<option id="display_firstlast" value="' + first + ' ' + last + '">' + first + ' ' + last + '</option>');
+                                if ( ! select.children('option[value=' + last + ' ' + first + ']').length )
+                                        select.append('<option id="display_lastfirst" value="' + last + ' ' + first + '">' + last + ' ' + first + '</option>');
</ins><span class="cx">                         }
</span><ins>+                        $('#'+sel).attr('selected', 'selected');
</ins><span class="cx">                 });
</span><span class="cx"> });
</span><span class="cx">
</span></span></pre></div>
<a id="trunkwpadminjsuserprofilejs"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/js/user-profile.js (13538 => 13539)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/js/user-profile.js        2010-03-01 21:04:37 UTC (rev 13538)
+++ trunk/wp-admin/js/user-profile.js        2010-03-01 22:34:43 UTC (rev 13539)
</span><span class="lines">@@ -1 +1 @@
</span><del>-(function(a){function b(){var d=a("#pass1").val(),c=a("#user_login").val(),e;a("#pass-strength-result").removeClass("short bad good strong");if(!d){a("#pass-strength-result").html(pwsL10n.empty);return}e=passwordStrength(d,c);switch(e){case 2:a("#pass-strength-result").addClass("bad").html(pwsL10n.bad);break;case 3:a("#pass-strength-result").addClass("good").html(pwsL10n.good);break;case 4:a("#pass-strength-result").addClass("strong").html(pwsL10n.strong);break;default:a("#pass-strength-result").addClass("short").html(pwsL10n["short"])}}a(document).ready(function(){a("#pass1").val("").keyup(b);a(".color-palette").click(function(){a(this).siblings("input[name=admin_color]").attr("checked","checked")});a("#nickname").blur(function(){var c=a(this).val()||a("#user_login").val();a("#display_name #display_nickname").val(c).html(c)});a("#first_name, #last_name").blur(function(){var d=a("#first_name").val(),c=a("#last_name").val();a("#display_firstname, #display_lastname, #display_firstlast, #display_lastfirst").remove();if(d&&c){a("#display_name").append('<option id="display_firstname" value="'+d+'">'+d+'</option><option id="display_lastname" value="'+c+'">'+c+'</option><option id="display_firstlast" value="'+d+" "+c+'">'+d+" "+c+'</option><option id="display_lastfirst" value="'+c+" "+d+'">'+c+" "+d+"</option>")}else{if(d&&!c){a("#display_name").append('<option id="display_firstname" value="'+d+'">'+d+"</option>")}else{if(!d&&c){a("#display_name").append('<option id="display_lastname" value="'+c+'">'+c+"</option>")}}}})})})(jQuery);
</del><span class="cx">\ No newline at end of file
</span><ins>+(function(a){function b(){var d=a("#pass1").val(),c=a("#user_login").val(),e;a("#pass-strength-result").removeClass("short bad good strong");if(!d){a("#pass-strength-result").html(pwsL10n.empty);return}e=passwordStrength(d,c);switch(e){case 2:a("#pass-strength-result").addClass("bad").html(pwsL10n.bad);break;case 3:a("#pass-strength-result").addClass("good").html(pwsL10n.good);break;case 4:a("#pass-strength-result").addClass("strong").html(pwsL10n.strong);break;default:a("#pass-strength-result").addClass("short").html(pwsL10n["short"])}}a(document).ready(function(){a("#pass1").val("").keyup(b);a(".color-palette").click(function(){a(this).siblings("input[name=admin_color]").attr("checked","checked")});a("#nickname").blur(function(){var e=a(this).val()||a("#user_login").val();var c=a("#display_name");var d=c.children("option:selected").attr("id");c.children("#display_nickname").remove();if(!c.children("option[value="+e+"]").length){c.append('<option id="display_nickname" value="'+e+'">'+e+"</option>")}a("#"+d).attr("selected","selected")});a("#first_name, #last_name").blur(function(){var c=a("#display_name");var f=a("#first_name").val(),d=a("#last_name").val();var e=c.children("option:selected").attr("id");a("#display_firstname, #display_lastname, #display_firstlast, #display_lastfirst").remove();if(f&&!c.children("option[value="+f+"]").length){c.append('<option id="display_firstname" value="'+f+'">'+f+"</option>")}if(d&&!c.children("option[value="+d+"]").length){c.append('<option id="display_lastname" value="'+d+'">'+d+"</option>")}if(f&&d){if(!c.children("option[value="+f+" "+d+"]").length){c.append('<option id="display_firstlast" value="'+f+" "+d+'">'+f+" "+d+"</option>")}if(!c.children("option[value="+d+" "+f+"]").length){c.append('<option id="display_lastfirst" value="'+d+" "+f+'">'+d+" "+f+"</option>")}}a("#"+e).attr("selected","selected")})})})(jQuery);
</ins><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkwpadminusereditphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/user-edit.php (13538 => 13539)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/user-edit.php        2010-03-01 21:04:37 UTC (rev 13538)
+++ trunk/wp-admin/user-edit.php        2010-03-01 22:34:43 UTC (rev 13539)
</span><span class="lines">@@ -256,8 +256,8 @@
</span><span class="cx">                 <select name="display_name" id="display_name">
</span><span class="cx">                 <?php
</span><span class="cx">                         $public_display = array();
</span><ins>+                        $public_display['display_username'] = $profileuser->user_login;
</ins><span class="cx">                         $public_display['display_nickname'] = $profileuser->nickname;
</span><del>-                        $public_display['display_username'] = $profileuser->user_login;
</del><span class="cx">                         if ( !empty($profileuser->first_name) )
</span><span class="cx">                                 $public_display['display_firstname'] = $profileuser->first_name;
</span><span class="cx">                         if ( !empty($profileuser->last_name) )
</span><span class="lines">@@ -266,9 +266,10 @@
</span><span class="cx">                                 $public_display['display_firstlast'] = $profileuser->first_name . ' ' . $profileuser->last_name;
</span><span class="cx">                                 $public_display['display_lastfirst'] = $profileuser->last_name . ' ' . $profileuser->first_name;
</span><span class="cx">                         }
</span><del>-                        if ( !in_array( $profileuser->display_name, $public_display ) )// Only add this if it isn't duplicated elsewhere
</del><ins>+                        if ( !in_array( $profileuser->display_name, $public_display ) ) // Only add this if it isn't duplicated elsewhere
</ins><span class="cx">                                 $public_display = array( 'display_displayname' => $profileuser->display_name ) + $public_display;
</span><span class="cx">                         $public_display = array_map( 'trim', $public_display );
</span><ins>+                        $public_display = array_unique( $public_display );
</ins><span class="cx">                         foreach ( $public_display as $id => $item ) {
</span><span class="cx">                 ?>
</span><span class="cx">                         <option id="<?php echo $id; ?>" value="<?php echo esc_attr($item); ?>"<?php selected( $profileuser->display_name, $item ); ?>><?php echo $item; ?></option>
</span></span></pre>
</div>
</div>
</body>
</html>