Forum Replies Created
-
AuthorPosts
-
Vladimir
KeymasterThanks for the information. It’s a strange effect. Roles editing core was not changed. So I can not repeat and explain it.
Vladimir
KeymasterTry this variant:
add_filter('woocommerce_disable_admin_bar', '_wc_disable_admin_bar', 10, 1); function _wc_disable_admin_bar($prevent_admin_access) { if ( !( current_user_can('data_entry') || current_user_can('operator') || current_user_can('manager') ) ) { return $prevent_admin_access; } return false; } add_filter('woocommerce_prevent_admin_access', '_wc_prevent_admin_access', 10, 1); function _wc_prevent_admin_access($prevent_admin_access) { if ( !( current_user_can('data_entry') || current_user_can('operator') || current_user_can('manager') ) ) { return $prevent_admin_access; } return false; }
Vladimir
KeymasterGood. Thanks for the information.
You may use one complex expression for all roles, like this one:
if (!(current_user_can('role1') || current_user_can('role2'))) { return .... }
Vladimir
KeymasterIt seems I found a problem with code. Replace ‘no’ to ‘false’. It should help.
add_filter('woocommerce_disable_admin_bar', '_wc_disable_admin_bar', 10, 1); function _wc_disable_admin_bar($prevent_admin_access) { return false; }
Vladimir
KeymasterOk. I will re-test this code myself.
Vladimir
KeymasterWhile it worked for me as it is, try to add filter with lower priority value – 9 instead of 10.
Vladimir
KeymasterDeactivate all plugins except WooCommerce and try. If that will help activate plugins back one by one. May be something else takes an effect.
Vladimir
KeymasterThe logic is correct. If it’s exactly the code you paste – it uses wrong quotes, it should use simple single quote character
'
for all string constants.Vladimir
KeymasterTry to start from more simple code. Comment role checking. May be something wrong is there. Let’s it work for all users for begin.
Vladimir
KeymasterCreate ‘mu-plugins’ folder. File name does not matter. WordPress executes any .php file it find in this folder.
https://codex.wordpress.org/Must_Use_PluginsVladimir
KeymasterTry another variant. Create .php file, open it in editor, start from <?php tag and insert there a code above, save it. Then put that file to the ‘wp-content/mu-plugins/’ folder (“must use” plugins). Will it help?
Vladimir
KeymasterThis post will help:
https://www.role-editor.com/woocommerce-admin-bar-access/Vladimir
KeymasterThanks. It seems to be correct.
Please check, if your child theme is really active.
Do you use WooCommerce plugin?Vladimir
KeymasterShow the code after modification.
Vladimir
KeymasterHi,
This code shows admin top menu bar for the role:
add_action('wp_head', 'show_top_admin_menu_bar', 100); function show_top_admin_menu_bar() { if (current_user_can('some_role')) { show_admin_bar(true); } }
Pay attention for the 100 value of a priority parameter. With this value code should be executed after that other plugin did its work.
You may add it to the functions.php file of your active theme.
-
AuthorPosts