[wp-trac] [WordPress Trac] #18749: Remove "the hackiest hack that ever did hack" from add_user()

WordPress Trac wp-trac at lists.automattic.com
Thu Sep 22 16:44:32 UTC 2011


#18749: Remove "the hackiest hack that ever did hack" from add_user()
-------------------------+-----------------------------------
 Reporter:  duck_        |      Owner:
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  Users        |    Version:
 Severity:  normal       |   Keywords:  has-patch 2nd-opinion
-------------------------+-----------------------------------
 "The hackiest hack that ever did hack" was introduced in [3677] as part of
 #2624 to "[allow] adding new users of any defined role straight from
 users.php (i.e. without having to create a user of the default role and
 the promoting to the desired level)".

 This seems unnecessary now as wp_insert_user() does this anyway:

 {{{
 if ( isset($role) )
     $user->set_role($role);
 elseif ( !$update )
     $user->set_role(get_option('default_role'));
 }}}

 `$role` being set in `edit_user()` from `$_POST['role']`.

 Back at [http://core.trac.wordpress.org/browser/trunk/wp-includes
 /registration-functions.php?rev=3677#L82 revision 3677] this was a
 different story:

 {{{
 if ($update && !empty($role)) {
     $user = new WP_User($user_id);
     $user->set_role($role);
 }

 if ( !$update ) {
     $user = new WP_User($user_id);
     $user->set_role(get_settings('default_role'));
 }
 }}}

 New users would always have the default role set on insert.

 The add-user ajax action isn't actually used any more, but I tested the
 hack removal by using Chromium's JavaScript console to send AJAX requests.

 At the very least the documentation should be updated to reflect the
 actual reasoning for the code rather than just "seems that [it] is for
 backwards compatibility".

 ''Issue found during testing''

 The add-user admin-ajax case doesn't set the current screen so several
 notices are thrown by the list table code:

 {{{
 Notice: Trying to get property of non-object in wp-admin/includes/class-
 wp-users-list-table.php on line 17
 Notice: Trying to get property of non-object in wp-admin/includes/class-
 wp-list-table.php on line 89
 Notice: Trying to get property of non-object in wp-
 admin/includes/template.php on line 238
 Notice: Trying to get property of non-object in wp-
 admin/includes/template.php on line 239
 Notice: Trying to get property of non-object in wp-
 admin/includes/template.php on line 239
 Notice: Trying to get property of non-object in wp-
 admin/includes/template.php on line 242
 Notice: Trying to get property of non-object in wp-
 admin/includes/template.php on line 257
 Notice: Trying to get property of non-object in wp-admin/includes/class-
 wp-list-table.php on line 602
 }}}

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/18749>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list