<!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, #msg p { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul { 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>[11784] trunk:
Make it much easier to filter contact methods from user profiles adding and removing at will
.</title>
</head>
<body>
<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/11784">11784</a></dd>
<dt>Author</dt> <dd>westi</dd>
<dt>Date</dt> <dd>2009-08-06 21:59:52 +0000 (Thu, 06 Aug 2009)</dd>
</dl>
<h3>Log Message</h3>
<pre>Make it much easier to filter contact methods from user profiles adding and removing at will. Fixes <a href="http://trac.wordpress.org/ticket/10240">#10240</a> props joostdevalk.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminincludesuserphp">trunk/wp-admin/includes/user.php</a></li>
<li><a href="#trunkwpadminusereditphp">trunk/wp-admin/user-edit.php</a></li>
<li><a href="#trunkwpincludesregistrationphp">trunk/wp-includes/registration.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminincludesuserphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/user.php (11783 => 11784)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/user.php        2009-08-06 20:48:59 UTC (rev 11783)
+++ trunk/wp-admin/includes/user.php        2009-08-06 21:59:52 UTC (rev 11784)
</span><span class="lines">@@ -105,12 +105,11 @@
</span><span class="cx">                 $user->display_name = esc_html( trim( $_POST['display_name'] ));
</span><span class="cx">         if ( isset( $_POST['description'] ))
</span><span class="cx">                 $user->description = trim( $_POST['description'] );
</span><del>-        if ( isset( $_POST['jabber'] ))
-                $user->jabber = esc_html( trim( $_POST['jabber'] ));
-        if ( isset( $_POST['aim'] ))
-                $user->aim = esc_html( trim( $_POST['aim'] ));
-        if ( isset( $_POST['yim'] ))
-                $user->yim = esc_html( trim( $_POST['yim'] ));
</del><ins>+        $user_contactmethods = _wp_get_user_contactmethods();
+        foreach ($user_contactmethods as $method => $name) {
+                if ( isset( $_POST[$method] ))
+                        $user->$method = esc_html( trim( $_POST[$method] ) );
+        }
</ins><span class="cx">         if ( !$update )
</span><span class="cx">                 $user->rich_editing = 'true'; // Default to true for new users.
</span><span class="cx">         else if ( isset( $_POST['rich_editing'] ) )
</span><span class="lines">@@ -378,9 +377,12 @@
</span><span class="cx">         $user->last_name = esc_attr($user->last_name);
</span><span class="cx">         $user->display_name = esc_attr($user->display_name);
</span><span class="cx">         $user->nickname = esc_attr($user->nickname);
</span><del>-        $user->aim = isset( $user->aim ) && !empty( $user->aim ) ? esc_attr($user->aim) : '';
-        $user->yim = isset( $user->yim ) && !empty( $user->yim ) ? esc_attr($user->yim) : '';
-        $user->jabber = isset( $user->jabber ) && !empty( $user->jabber ) ? esc_attr($user->jabber) : '';
</del><ins>+
+        $user_contactmethods = _wp_get_user_contactmethods();
+        foreach ($user_contactmethods as $method => $name) {
+                $user->{$method} = isset( $user->{$method} ) && !empty( $user->{$method} ) ? esc_attr($user->{$method}) : '';
+        }
+        
</ins><span class="cx">         $user->description = isset( $user->description ) && !empty( $user->description ) ? esc_html($user->description) : '';
</span><span class="cx">
</span><span class="cx">         return $user;
</span><span class="lines">@@ -835,4 +837,21 @@
</span><span class="cx">         echo '</p></div>';
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+/**
+ * Setup the default contact methods
+ *
+ * @access private
+ * @since
+ *
+ * @return array $user_contactmethods Array of contact methods and their labels.
+ */
+function _wp_get_user_contactmethods() {
+        $user_contactmethods = array(
+                'aim' => __('AIM'),
+                'yim' => __('Yahoo IM'),
+                'jabber' => __('Jabber / Google Talk')
+        );
+        return apply_filters('user_contactmethods',$user_contactmethods);
+}
+
</ins><span class="cx"> ?>
</span></span></pre></div>
<a id="trunkwpadminusereditphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/user-edit.php (11783 => 11784)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/user-edit.php        2009-08-06 20:48:59 UTC (rev 11783)
+++ trunk/wp-admin/user-edit.php        2009-08-06 21:59:52 UTC (rev 11784)
</span><span class="lines">@@ -267,20 +267,16 @@
</span><span class="cx">         <td><input type="text" name="url" id="url" value="<?php echo esc_attr($profileuser->user_url) ?>" class="regular-text code" /></td>
</span><span class="cx"> </tr>
</span><span class="cx">
</span><ins>+<?php
+        foreach (_wp_get_user_contactmethods() as $name => $desc) {
+?>
</ins><span class="cx"> <tr>
</span><del>-        <th><label for="aim"><?php echo apply_filters('user_aim_label', __('AIM')); ?></label></th>
-        <td><input type="text" name="aim" id="aim" value="<?php echo esc_attr($profileuser->aim) ?>" class="regular-text" /></td>
-</tr>
-
-<tr>
-        <th><label for="yim"><?php echo apply_filters('user_yim_label', __('Yahoo IM')); ?></label></th>
-        <td><input type="text" name="yim" id="yim" value="<?php echo esc_attr($profileuser->yim) ?>" class="regular-text" /></td>
-</tr>
-
-<tr>
-        <th><label for="jabber"><?php echo apply_filters('user_jabber_label', __('Jabber / Google Talk')); ?></label></th>
-        <td><input type="text" name="jabber" id="jabber" value="<?php echo esc_attr($profileuser->jabber) ?>" class="regular-text" /></td>
-</tr>
</del><ins>+        <th><label for="<?php echo $name; ?>"><?php echo apply_filters('user_'.$name.'_label', $desc); ?></label></th>
+        <td><input type="text" name="<?php echo $name; ?>" id="<?php echo $name; ?>" value="<?php echo esc_attr($profileuser->$name) ?>" class="regular-text" /></td>
+</tr>        
+<?php
+        }
+?>
</ins><span class="cx"> </table>
</span><span class="cx">
</span><span class="cx"> <h3><?php IS_PROFILE_PAGE ? _e('About Yourself') : _e('About the user'); ?></h3>
</span></span></pre></div>
<a id="trunkwpincludesregistrationphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/registration.php (11783 => 11784)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/registration.php        2009-08-06 20:48:59 UTC (rev 11783)
+++ trunk/wp-includes/registration.php        2009-08-06 21:59:52 UTC (rev 11784)
</span><span class="lines">@@ -164,15 +164,6 @@
</span><span class="cx">         if ( empty($use_ssl) )
</span><span class="cx">                 $use_ssl = 0;
</span><span class="cx">
</span><del>-        if ( empty($jabber) )
-                $jabber = '';
-
-        if ( empty($aim) )
-                $aim = '';
-
-        if ( empty($yim) )
-                $yim = '';
-
</del><span class="cx">         if ( empty($user_registered) )
</span><span class="cx">                 $user_registered = gmdate('Y-m-d H:i:s');
</span><span class="cx">
</span><span class="lines">@@ -203,13 +194,16 @@
</span><span class="cx">         update_usermeta( $user_id, 'last_name', $last_name);
</span><span class="cx">         update_usermeta( $user_id, 'nickname', $nickname );
</span><span class="cx">         update_usermeta( $user_id, 'description', $description );
</span><del>-        update_usermeta( $user_id, 'jabber', $jabber );
-        update_usermeta( $user_id, 'aim', $aim );
-        update_usermeta( $user_id, 'yim', $yim );
</del><span class="cx">         update_usermeta( $user_id, 'rich_editing', $rich_editing);
</span><span class="cx">         update_usermeta( $user_id, 'comment_shortcuts', $comment_shortcuts);
</span><span class="cx">         update_usermeta( $user_id, 'admin_color', $admin_color);
</span><span class="cx">         update_usermeta( $user_id, 'use_ssl', $use_ssl);
</span><ins>+        foreach (_wp_get_user_contactmethods() as $method => $name) {
+                if ( empty($$method) )
+                        $$method = '';
+                
+                update_usermeta( $user_id, $method, $$method );
+        }
</ins><span class="cx">
</span><span class="cx">         if ( isset($role) ) {
</span><span class="cx">                 $user = new WP_User($user_id);
</span></span></pre>
</div>
</div>
</body>
</html>