Ticket #6014: diff-mar22.txt

File diff-mar22.txt, 4.8 kB (added by jeremyclarke, 8 months ago)

the patch to core (with comments)

Line 
1 Index: wp-admin/includes/template.php
2 ===================================================================
3 --- wp-admin/includes/template.php      (revision 7276)
4 +++ wp-admin/includes/template.php      (working copy)
5 @@ -535,12 +535,15 @@
6         if ( current_user_can( 'edit_user', $user_object->ID ) ) {
7                 $edit = clean_url( add_query_arg( 'wp_http_referer', urlencode( clean_url( stripslashes( $_SERVER['REQUEST_URI'] ) ) ), "user-edit.php?user_id=$user_object->ID" ) );
8                 $edit = "<a href=\"$edit\">$user_object->user_login</a>";
9 +               //define the checkbox_disabled as empty only if the user is editable
10 +               $checkbox_disabled = "";
11         } else {
12                 $edit = $user_object->user_login;
13 +               // otherwise the checkbox is disabled.
14 +               $checkbox_disabled = "disabled='true'";
15         }
16         $role_name = translate_with_context($wp_roles->role_names[$role]);
17 -       $r = "<tr id='user-$user_object->ID'$style>
18 -               <th scope='row' class='check-column'><input type='checkbox' name='users[]' id='user_{$user_object->ID}' class='$role' value='{$user_object->ID}' /></th>
19 +       $r = "<tr id='user-$user_object->ID'$style><th scope='row' class='check-column'><input type='checkbox' name='users[]' id='user_{$user_object->ID}' class='$role' value='{$user_object->ID}' $checkbox_disabled /></th>         
20                 <td><strong>$edit</strong></td>
21                 <td>$user_object->first_name $user_object->last_name</td>
22                 <td><a href='mailto:$email' title='" . sprintf( __('e-mail: %s' ), $email ) . "'>$email</a></td>
23 @@ -926,12 +929,26 @@
24  <?php
25  }
26  
27 -function wp_dropdown_roles( $default = false ) {
28 +function wp_dropdown_roles( $selected = false ) {
29         global $wp_roles;
30 +       
31 +       // ORIGINALLY: only arg is $default.
32 +       //         if $default is given then when we get to it, it is set as selected.
33 +       // NOW: arg name is changed to $selected
34 +       //     exact same effect, but now it makes sense for the user_edit.php version as well
35 +       //     where the highest role of the user can be passed in and used instead of
36 +       //     "default" which was what we wanted selected on the user listing page.
37 +       // filter the roles to remove ones the logged-in user shouldn't
38 +       // be able to apply to others, or whatever other filters people
39 +       // might want. 
40 +       
41 +       $role_names = $wp_roles->role_names;
42 +       $role_names = apply_filters('role_names_listing', $role_names);
43 +       
44         $r = '';
45 -       foreach( $wp_roles->role_names as $role => $name ) {
46 +       foreach( $role_names as $role => $name ) {
47                 $name = translate_with_context($name);
48 -               if ( $default == $role ) // Make default first in list
49 +               if ( $selected == $role ) // Make $selected first in list
50                         $p = "\n\t<option selected='selected' value='$role'>$name</option>";
51                 else
52                         $r .= "\n\t<option value='$role'>$name</option>";
53 Index: wp-admin/user-edit.php
54 ===================================================================
55 --- wp-admin/user-edit.php      (revision 7276)
56 +++ wp-admin/user-edit.php      (working copy)
57 @@ -197,9 +197,23 @@
58  <?php
59  // print_r($profileuser);
60  echo '<td><select name="role" id="role">';
61 -$role_list = '';
62 -$user_has_role = false;
63 -foreach($wp_roles->role_names as $role => $name) {
64 +
65 +// These are replaced by a direct check to the user object below
66 +//$role_list = '';
67 +//$user_has_role = false;
68 +       
69 +// ORIGINALLY : if the user has a cap, it is set as selected.
70 +// NOW : we use the argument in wp_dropdown_roles to define what is selected.
71 +//       we will just use their primary role, defined in the same way as for
72 +//       the role label on the user listing page.
73 +
74 +$user_roles = $profileuser->roles;
75 +$user_role = array_shift($user_roles);
76 +
77 +// old: go through roles, if one matches set selected and user_has_role
78 +//      if it doesnt' match add empty one (--No Role for this Blog--).\
79 +
80 +/* foreach($wp_roles->role_names as $role => $name) {
81         $name = translate_with_context($name);
82         if ( $profileuser->has_cap($role) ) {
83                 $selected = ' selected="selected"';
84 @@ -209,11 +223,27 @@
85         }
86         $role_list .= "<option value=\"{$role}\"{$selected}>{$name}</option>";
87  }
88 -if ( $user_has_role )
89 -       $role_list .= '<option value="">' . __('&mdash; No role for this blog &mdash;') . '</option>';
90 +*/
91 +
92 +// at the end, if there was a role selected add the roleless state
93 +
94 +// new: use wp_dropdown_roles(), this way the role list can be filtered.
95 +
96 +wp_dropdown_roles($user_role);
97 +
98 +// old: check if we found a matching role to determine whether stateless role
99 +//      is selected
100 +
101 +//if ( $user_has_role )
102 +
103 +// new: use our direct check value.
104 +if ( $user_role )
105 +       echo "\n\t".'<option value="">' . __('&mdash; No role for this blog &mdash;') . '</option>';
106  else
107 -       $role_list .= '<option value="" selected="selected">' . __('&mdash; No role for this blog &mdash;') . '</option>';
108 -echo $role_list . '</select></td></tr>';
109 +// if there was no role, make the roleless state selected.
110 +       echo "\n\t".'<option value="" selected="selected">' . __('&mdash; No role for this blog &mdash;') . '</option>';
111 +       
112 +echo "\n</select>\n</td>\n</tr>";
113  ?>
114  <?php endif; ?>
115