<?php
add_action ("init", "s2_fix_user_names");
function s2_fix_user_names ()
{
if (!empty ($_GET[__FUNCTION__]))
{
foreach (get_users () as $user)
{
if (($user = new WP_User ($user->ID)))
{
if (!$user->first_name && !$user->last_name && $user->display_name)
{
list ($first_name, $last_name) = preg_split ("/ +/", $user->display_name, 2);
wp_update_user(array ("ID" => $user->ID, "first_name" => $first_name, "last_name" => $last_name));
echo 'Updated User ID: ' . $user->ID . ' First Name: ' . $first_name . ', Last Name: ' . (($last_name) ? $last_name : '[empty]') . '<br />';
}
else if ($user->first_name || $user->last_name)
echo 'Skipping User ID: ' . $user->ID . '. User already has a First and/or Last name recorded.<br />';
/**/
else if (!$user->display_name)
echo 'Skipping User ID: ' . $user->ID . '. User has no Display name on record, unable to parse.<br />';
}
}
exit("All fixed!");
}
}
?>
Statistics: Posted by Jason Caldwell — September 27th, 2011, 9:09 pm
Statistics: Posted by skipshean — September 27th, 2011, 8:35 pm
Statistics: Posted by Jason Caldwell — September 27th, 2011, 6:39 pm
Statistics: Posted by Cristián Lávaque — September 24th, 2011, 11:48 pm
Statistics: Posted by skipshean — September 21st, 2011, 10:19 pm
Statistics: Posted by skipshean — September 21st, 2011, 9:58 pm
Statistics: Posted by skipshean — September 21st, 2011, 7:22 am
Statistics: Posted by skipshean — September 20th, 2011, 8:20 pm
<?php
add_action ("init", "s2_fix_user_names");
function s2_fix_user_names ()
{
if (!empty ($_GET[__FUNCTION__]))
{
foreach (get_users () as $user)
{
if (($user = new WP_User ($user->ID)) && !$user->first_name && !$user->last_name && $user->display_name)
{
list ($first_name, $last_name) = preg_split ("/ +/", $user->display_name, 2);
wp_update_user (array ("ID" => $user->ID, "first_name" => $first_name, "last_name" => $last_name));
}
}
exit ("All fixed!");
}
}
?>
http://yoursite.com/?s2_fix_user_names=yes
Statistics: Posted by Jason Caldwell — September 20th, 2011, 7:59 pm
Statistics: Posted by skipshean — September 20th, 2011, 7:41 pm
Statistics: Posted by Jason Caldwell — September 20th, 2011, 7:05 pm
Statistics: Posted by skipshean — September 20th, 2011, 5:48 pm
Statistics: Posted by Jason Caldwell — September 20th, 2011, 5:41 pm
Statistics: Posted by skipshean — September 20th, 2011, 4:07 pm