Skip to content

Instantly share code, notes, and snippets.

@edheltzel
Last active February 15, 2023 18:47
Show Gist options
  • Save edheltzel/6417906 to your computer and use it in GitHub Desktop.
Save edheltzel/6417906 to your computer and use it in GitHub Desktop.
Remove personal options from profile page in wordpress
/** REMOVE PERSONAL OPTIONS FROM PROFILE PAGE **/
<?
// removes the `profile.php` admin color scheme options
remove_action( 'admin_color_scheme_picker', 'admin_color_scheme_picker' );
if ( ! function_exists( 'rdm_remove_personal_options' ) ) {
// removes the leftover 'Visual Editor', 'Keyboard Shortcuts' and 'Toolbar' options.
function rdm_remove_personal_options( $subject ) {
$subject = preg_replace( '#<h2>Personal Options</h2>.+?/table>#s', '', $subject, 1 );
return $subject;
}
function rdm_profile_subject_start() {
ob_start( 'rdm_remove_personal_options' );
}
function rdm_profile_subject_end() {
ob_end_flush();
}
}
add_action( 'admin_head-profile.php', 'rdm_profile_subject_start' );
add_action( 'admin_footer-profile.php', 'rdm_profile_subject_end' );
class RDM_User_Caps {
// add some filters
function RDM_User_Caps(){
add_filter( 'editable_roles', array(&$this, 'editable_roles'));
add_filter( 'map_meta_cap', array(&$this, 'map_meta_cap'),10,4);
}
// remove 'Administrator' from the list of roles if the current user is not an admin
function editable_roles( $roles ){
if( isset( $roles['administrator'] ) && !current_user_can('administrator') ){
unset( $roles['administrator']);
}
return $roles;
}
// don't allow users to edit or delete unless they are an admin
function map_meta_cap( $caps, $cap, $user_id, $args ){
switch( $cap ){
case 'edit_user':
case 'remove_user':
case 'promote_user':
if( isset($args[0]) && $args[0] == $user_id )
break;
elseif( !isset($args[0]) )
$caps[] = 'do_not_allow';
$other = new WP_User( absint($args[0]) );
if( $other->has_cap( 'administrator' ) ){
if(!current_user_can('administrator')){
$caps[] = 'do_not_allow';
}
}
break;
case 'delete_user':
case 'delete_users':
if( !isset($args[0]) )
break;
$other = new WP_User( absint($args[0]) );
if( $other->has_cap( 'administrator' ) ){
if(!current_user_can('administrator')){
$caps[] = 'do_not_allow';
}
}
break;
default:
break;
}
return $caps;
}
}
$rdm_user_caps = new RDM_User_Caps();
@oakwoodgates
Copy link

edit line 10
$subject = preg_replace( '#<h2>Personal Options</h2>.+?/table>#s', '', $subject, 1 );

@morsalin1342
Copy link

Very Very Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment