Skip to content

Instantly share code, notes, and snippets.

@pfactum
Created July 24, 2012 12:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pfactum/3169674 to your computer and use it in GitHub Desktop.
Save pfactum/3169674 to your computer and use it in GitHub Desktop.
WordPress user restrictions
--- user-edit.php~ 2012-07-24 14:23:21.000000000 +0300
+++ user-edit.php 2012-07-24 14:50:01.000000000 +0300
@@ -278,52 +278,74 @@
<tr>
<th><label for="first_name"><?php _e('First Name') ?></label></th>
- <td><input type="text" name="first_name" id="first_name" value="<?php echo esc_attr($profileuser->first_name) ?>" class="regular-text" /></td>
+ <td>
+ <?php
+ if (!current_user_can('change_first_name'))
+ echo esc_attr($profileuser->first_name);
+ else
+ echo '<input type="text" name="first_name" id="first_name" value="'.esc_attr($profileuser->first_name).'" class="regular-text" />';
+ ?>
+ </td>
</tr>
<tr>
<th><label for="last_name"><?php _e('Last Name') ?></label></th>
- <td><input type="text" name="last_name" id="last_name" value="<?php echo esc_attr($profileuser->last_name) ?>" class="regular-text" /></td>
+ <td>
+ <?php
+ if (!current_user_can('change_last_name'))
+ echo esc_attr($profileuser->last_name);
+ else
+ echo '<input type="text" name="last_name" id="last_name" value="'.esc_attr($profileuser->last_name).'" class="regular-text" />';
+ ?>
+ </td>
</tr>
<tr>
<th><label for="nickname"><?php _e('Nickname'); ?> <span class="description"><?php _e('(required)'); ?></span></label></th>
- <td><input type="text" name="nickname" id="nickname" value="<?php echo esc_attr($profileuser->nickname) ?>" class="regular-text" /></td>
+ <td>
+ <?php
+ if (!current_user_can('change_nick_name'))
+ echo esc_attr($profileuser->nickname);
+ else
+ echo '<input type="text" name="nickname" id="nickname" value="'.esc_attr($profileuser->nickname).'" class="regular-text" />';
+ ?>
+ </td>
</tr>
<tr>
<th><label for="display_name"><?php _e('Display name publicly as') ?></label></th>
<td>
- <select name="display_name" id="display_name">
- <?php
- $public_display = array();
- $public_display['display_nickname'] = $profileuser->nickname;
- $public_display['display_username'] = $profileuser->user_login;
-
- if ( !empty($profileuser->first_name) )
- $public_display['display_firstname'] = $profileuser->first_name;
-
- if ( !empty($profileuser->last_name) )
- $public_display['display_lastname'] = $profileuser->last_name;
-
- if ( !empty($profileuser->first_name) && !empty($profileuser->last_name) ) {
- $public_display['display_firstlast'] = $profileuser->first_name . ' ' . $profileuser->last_name;
- $public_display['display_lastfirst'] = $profileuser->last_name . ' ' . $profileuser->first_name;
- }
-
- if ( !in_array( $profileuser->display_name, $public_display ) ) // Only add this if it isn't duplicated elsewhere
- $public_display = array( 'display_displayname' => $profileuser->display_name ) + $public_display;
-
- $public_display = array_map( 'trim', $public_display );
- $public_display = array_unique( $public_display );
-
- foreach ( $public_display as $id => $item ) {
- ?>
- <option <?php selected( $profileuser->display_name, $item ); ?>><?php echo $item; ?></option>
<?php
+ if (!current_user_can('change_display_name'))
+ echo $profileuser->display_name;
+ else {
+ echo '<select name="display_name" id="display_name">';
+ $public_display = array();
+ $public_display['display_nickname'] = $profileuser->nickname;
+ $public_display['display_username'] = $profileuser->user_login;
+
+ if ( !empty($profileuser->first_name) )
+ $public_display['display_firstname'] = $profileuser->first_name;
+
+ if ( !empty($profileuser->last_name) )
+ $public_display['display_lastname'] = $profileuser->last_name;
+
+ if ( !empty($profileuser->first_name) && !empty($profileuser->last_name) ) {
+ $public_display['display_firstlast'] = $profileuser->first_name . ' ' . $profileuser->last_name;
+ $public_display['display_lastfirst'] = $profileuser->last_name . ' ' . $profileuser->first_name;
+ }
+
+ if ( !in_array( $profileuser->display_name, $public_display ) ) // Only add this if it isn't duplicated elsewhere
+ $public_display = array( 'display_displayname' => $profileuser->display_name ) + $public_display;
+
+ $public_display = array_map( 'trim', $public_display );
+ $public_display = array_unique( $public_display );
+
+ foreach ( $public_display as $id => $item )
+ echo '<option '.selected( $profileuser->display_name, $item ).'>'.$item.'</option>';
+ echo '</select>';
}
?>
- </select>
</td>
</tr>
</table>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment