How I can hide WordPress admin panel options for all except one user. I want to hide some setting options and theme options for all users except me (username: jacob).
This code will hide admin bar for all users:
show_admin_bar( false );
And this one will prevent admin bar from being hidden:
show_admin_bar( false );
So you need to use code for the condition if the username is jacob then show the admin bar and hide it for all the others. So here is the complete code.
global $current_user;
get_currentuserinfo();
if ( is_user_logged_in() ) {
if($current_user->user_login == 'jacob') {
show_admin_bar( true );
} else {
show_admin_bar( false );
} } else {
show_admin_bar( false );
}
You can use this code inside your theme's functions.php or you can also create separate plugin for this.
Admin Bar Disabler plug-in can hide admin panel for users with roles. I expect you are administrator and rest of users are not (since they shouldn't see the panel), so you can let show Wordpress panel for admin role only. ;)
https://wordpress.org/plugins/admin-bar-disabler/
If you have users that are logging in, you can re-direct around the Admin - check perms..
Better yet, send them around it!!
Have a look here - https://wordpress.org/plugins/peters-login-redirect/
I use this on our church website and works great!
Thanks!
Add below code into your theme functions.php
global $current_user; get_currentuserinfo(); if ( is_user_logged_in() ) {
if($current_user->user_login == 'jacob') {
show_admin_bar( true );
} else {
show_admin_bar( false );
} } else { }
Hope this will help you
Related
in wordpress, how to create a new user role that can only access the 'donation' sidebar function as the image below? Please help...View Image
Yes yes it is possible to do this.
You need to select the user role "Give Accountant" for the concerned user in the WordPress backoffice "Accounts" -> "All Accounts" -> Select the user and change his status.
Then you have to add these PHP instructions in your child theme
add_action( 'current_screen', 'restrict_screen' );
function restrict_screen() {
if (current_user_can('give_accountant')) {
if( preg_match('/\bindex\.php\b|\bprofile\.php\b|\bwp-admin.?$/', $_SERVER['REQUEST_URI'])) {
$current_admin = get_admin_url() .'edit.php?post_type=give_forms';
header('Location: ' . $current_admin . '', true, 301);
}
}
}
add_action('admin_init', 'disable_dashboard');
function disable_dashboard() {
if (!is_user_logged_in()) {
return null;
}
if (current_user_can('give_accountant')) {
remove_menu_page( 'index.php' );
remove_menu_page( 'profile.php' );
}
}
For user role capabilities you can also use the plugin.
Here I have shared the plugin which I like.
https://wordpress.org/plugins/user-role-editor/
I know it is a little bit longer but it is a very good plugin if in the future any changes in the requirement then the plugin will very helpful.
Here you can set the settings according to your requirement.
Is there a way to remove the WordPress admin bar but just on a specific page?
I know that I can remove it or hide it completely by adding an action:
add_action('after_setup_theme', 'remove_admin_bar');
function remove_admin_bar() {
if (!current_user_can('administrator') && !is_admin()) {
show_admin_bar(false);
}
}
I've done that but on my site I have one page that is displayed in an iframe (using colorbox) and I don't ever want the admin bar to show up in that iframe.
Is there a way to hide the admin bar but just for a specific page?
Thanks,
Ben
Your function is a bit complicated, there's a filter for that. Just check for the Page ID and filter it out using the show_admin_bar filter.
function riga_hide_admin_bar(){
if( $post->ID == YOUR_POST_ID ){
return false;
}
}
add_filter( 'show_admin_bar' , 'riga_hide_admin_bar' );
Remove WordPress admin bar on a single page
Yes, you can remove admin bar from a specific page as you wish.
Use add_filter( 'show_admin_bar', '__return_false' ); to hide admin bar from a specific page.
function my_function_admin_bar(){
return false;
}
add_filter( 'show_admin_bar' , 'my_function_admin_bar');
For more details please see below link:
https://codex.wordpress.org/Plugin_API/Filter_Reference/show_admin_bar
Get ID of specific page and add your filter in condition which meet the page ID
`If(get_the_ID()==#736637){
add_action('after_setup_theme', 'remove_admin_bar');
function remove_admin_bar() {
if (!current_user_can('administrator') && !is_admin()) {
show_admin_bar(false);
}
}
}`
For me the easiest way is to add the code in the template of the page I don't want to show. At the top of the template file I just add:
<?php
show_admin_bar(false);
I'm trying to disable admin bar for registered users, whiche are not administrators. I found many solutions like adding
if ( ! current_user_can( 'add_users' ) ) {
show_admin_bar( false ); }
to functions.php, but it totally doesn't work. As I understand it is problem of "the best" version 3.9. I also tried many plugins - there are no working ones... Does any solution exist today?
Have you tried using the filter? Add this to your functions.php replacing your existing code:
function wpse_hide_admin_bar() {
if ( current_user_can( 'manage_settings' ) ) {
return true; // Show for admins
} else {
return false; // Hide for other users
}
}
add_filter( 'show_admin_bar', 'wpse_hide_admin_bar' );
including this line of code in functions.php will disable it altogether,
add_filter( 'show_admin_bar', '__return_false');
Edit: The accepted answer is better than my answer, because that method doesn't disable the admin bar altogether, but it disables it based on the user permissions.
Go to Users > Admin Profile > Toolbar > Deselect "Show Toolbar when viewing site"
I have a WordPress site. There are many users. I want when an author logs in, the author who currently is currently logged on couldn't access the "edit page" menu in the admin bar.
Is there any plugin to disable that?
You can use this plugin :
http://wordpress.org/extend/plugins/admin-bar-disabler/
OR Alternative and manual way is under if condition place this
show_admin_bar(false);
E.g.
if(!is_admin())
{
show_admin_bar(false);
}
place this code in functions.php so that it will disable the admin bar for all the other users.
In your functions.php file, you can add one of the following code snippets to get the indicated results:
// Only display to administrators
add_action('after_setup_theme', 'remove_admin_bar');
function remove_admin_bar() {
if (!current_user_can('administrator') && !is_admin()) {
show_admin_bar(false);
}
}
// Disable for specific role (in this case, 'subscriber')
function remove_admin_bar() {
$user = wp_get_current_user();
if (in_array(‘subscriber’, $user->roles)) {
show_admin_bar(false);
}
}
I am using my functions.php to add a custom meta box on my posts page in the WordPress Admin Area. However, I need to make it so its only visible to admins, and not editors, contributors, etc.
What would I do to make it visible to admins only?
function your_function() {
global $current_user;
if($current_user->roles[0] == 'administrator') {
add_meta_box(your parameters);
// fill in your parameters
}
}
add_action('admin_init','your_function');
if ( is_user_logged_in() ) {
get_currentuserinfo();
# check if current user is admin
if ( $current_user->wp_user_level >= 10 ) {
# put your admin-only function here
}
}
This snippet works for custom taxonomies. It removes / hides a custom taxonomy meta box for all non-admins, assuming no other role has the update_core capability. Similar, but opposite of the answer by #johannes-pille
function remove_tax_metaboxes() {
if (!current_user_can('update_core')) {
remove_meta_box( 'taxdiv', 'post', 'side' );
}
}
add_action( 'do_meta_boxes', 'remove_tax_metaboxes' );
Note that the third argument of remove_meta_box may differ, see https://codex.wordpress.org/Function_Reference/remove_meta_box