Tuesday, March 6, 2018

Remove dashboard bar to a profile from WordPress site


METHOD #1 - Plugin

Suppose that you have a site that you desire to supress the dashboard bar and admin bar to the users except the administrators.

Use "Editor Menu And Widget Access" plugin and just set the configuration like this:




-----------------------------------------------------------------------------------------------------------
METHOD #2 - Coding

@DEPRECATED:
In recent versions using others themes, the solution was not effective anymore, requiring more code digging. A better alternative solution was adopted above.


Suppose that you have a site that you desire to supress the dashboard bar and admin bar to the "subscriber" profile.
Follow the example.

1. Go to the themes' function.php file.
For instance, if the active theme is named "vale", edit:
$SITE_DIR/public_html/wp-content/themes/vale/function.php

2. Add the following

// This file is not called from WordPress. We don't like that.
! defined( 'ABSPATH' ) and exit;

add_action( 'init', 'fb_remove_admin_bar', 0 );
function fb_remove_admin_bar() {
if ( current_user_can('subscriber') || current_user_can('assinante') ) {
wp_deregister_script( 'admin-bar' );
wp_deregister_style( 'admin-bar' );
remove_action( 'init', '_wp_admin_bar_init' );
remove_action( 'wp_footer', 'wp_admin_bar_render', 1000 );
remove_action( 'admin_footer', 'wp_admin_bar_render', 1000 );
// maybe also: 'wp_head'
foreach ( array( 'admin_head' ) as $hook ) {
add_action(
$hook,
create_function(
'',
"echo '';"
)
);
}
}
}


Adapted from:
https://wordpress.stackexchange.com/questions/77639/disable-the-admin-bar/77648#77648

No comments:

Post a Comment

eclipse: java: SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder" or Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder

  >PROBLEM Using Eclipse, you try to run a simple logging test using "org.slf4j.Logger" like the sample below: package Test; im...