Remove Option Tree menu in admin page - wordpress

I integrated option tree in my template.
I want to hide OptionTree menu item from users. How to remove Option Tree menu item in admin page?

Add this code to your theme's functions.php:
// Remove Option Tree Settings Menu
add_filter( 'ot_show_pages', '__return_false' );
That will remove the Option Tree admin menu.

Here is another solution.
function remove_ot_menu () {
remove_menu_page( "ot-settings" ); } add_action( 'admin_menu', 'remove_ot_menu' );

I know i'm late to the party but since i got to find
a solution (for an old website i restructering) i tought
i might share "a softer" solution.
2 steps
1. We ad the current user id to the admin body class
2. We add a css to hide the menu except for the intended user.
User id in the body class
/*********************************************
** CUSTOM BODY CLASS
*********************************************/
add_filter('admin_body_class', 'custom_admin_body_class');
function custom_admin_body_class($classes){
$cuserid = get_current_user_id();
return $classes. 'user-'.$cuserid;
}
Add the desired css to anytype of css loaded to wp-admin
** replace user-[number] with yours*
.wp-admin:not(.user-1) #toplevel_page_ot-settings {display: none;}
If your not loading any css to wp-admin you can use this
add_action('admin_head', 'my_custom_fonts');
function my_custom_fonts() {
echo '<style>.wp-admin:not(.user-1) #toplevel_page_ot-settings {display: none;}</style>';
}

Related

How to remove menu item from WordPress admin bar menu?

i want to remove an menu item from admin bar , tried the following code
add_action( 'admin_menu', 'remove_admin_menu_items', 999 );
function remove_admin_menu_items() {
remove_menu_page('admin.php?page=litespeed&LSCWP_CTRL=purge&LSCWP_NONCE=ccd23d492e&litespeed_type=purge_all_lscache' );
}
unfortunately it doesn't work ! I have attached a screenshot of menu I want to remove
I like to hide the menu using the child theme function.php code.
Plugin author posts the following:
The best way to hide our menu is by CSS. For top icon in adminbar, use
.litespeed-top-toolbar {display:none}. It can be done by using 3rd party plugin like https://wordpress.org/plugins/add-admin-css/ or
add_action('admin_head', 'hide_litespeed_icon');
function hide_litespeed_icon() {
echo '<style>.litespeed-top-toolbar {display:none}</style>';
}
into your theme’s functions.php
Alternatively, try adding the following code to functions.php:
function remove_lscwp_admin_menu($wp_admin_bar) {
$wp_admin_bar->remove_node('litespeed-menu');
}
add_action('admin_bar_menu', 'remove_lscwp_admin_menu', 999);

WordPress admin menu: custom logout link shows as submenu item instead of menu item

I added a custom logout link to my WP admin menu, but instead of appearing as a top-level menu item, it is displayed as a submenu item (smaller font size, left padding). The link itself works perfectly though. Any ideas how the code can be changed? Thanks!
current admin menu
The code I use is from this thread.
add_action('admin_init', 'text_domain_logout_link');
function text_domain_logout_link() {
global $menu;
$menu[9999] = array(__('Logout'), 'manage_options', wp_logout_url());
}
Can you try this?:
add_action('admin_menu', 'text_domain_logout_link');
function text_domain_logout_link() {
global $menu;
$menu[9999] = array(__('Logout'), 'manage_options', wp_logout_url());
}
Tested and works on my wordpress
Updated:
If you want to show it to top-level then use this code:
add_action('admin_menu', 'text_domain_logout_link');
function text_domain_logout_link() {
global $menu;
$menu[9999] = array(__('Logout'), 'manage_options', wp_logout_url());
// add class
$menu[9999][4] = "menu-top toplevel_page_menu";
// Add Icon
$menu[9999][6] = "dashicons-update";
}
So it will look like this:

WordPress add Login/Logout to menu editor

Ok, so I found this code, which I modified to suit my needs. Btw, I'm using WooCommerce, which explains the "wc" in some of the function calls:
//Add login/logout link to primary menu
add_filter( 'wp_nav_menu_items', 'add_loginout_link', 10, 2 );
function add_loginout_link( $items, $args ) {
if (is_user_logged_in() && $args->theme_location == 'primary') {
$items .= '<li>Log Out</li>';
}
elseif (!is_user_logged_in() && $args->theme_location == 'primary') {
$items .= '<li>Log In</li>';
}
return $items;
This adds the login/logout menu items, and they work fine. However, they're stuck at the end of the menu, at the moment. I'd like to be able to edit the position using the editor in wp-admin. The solution I thought of was to maybe just create login and logout pages, and use header location redirects with those lines of code in them to get to the proper URLs, but the issue I see with that is that there will always be a login item and logout, no matter what status the user is currently in. Would there maybe be a way to dynamically add a site-wide CSS rule to hide the opposite menu item, based on the log in status?
Or is there an easier way?
Not the best idea but you can try.
Create in wp-admin menu section new menu item like "Custom Link"
Log Out
http://www.example.com/account/customer-logout/
Log In
http://www.example.com/account/
And add a custom class to a WordPress menu item to manage visibility
For example, you will see "logged-in" class on the body of the page and hide "Log In" link or change it to "Account" with the same link.

how to remove delete option when mouse hover on all users in wordpress?

I am working on a project in wordpress.
In user options, when I select all users it shows a list of all users with edit / delete option. In my project, I want to remove delete option.
What do I need to do for this
Here is a snippet that hides the delete option from user with specific role (administrator in this case)
$role = get_role( 'administrator' ); // This is the user role
$role->remove_cap( 'delete_users' ); // This is the capability you remove
Refer to the codex for more info. Here are the two functions you need to use:
remove_cap()
get_role()
roles and capabilities - https://codex.wordpress.org/Roles_and_Capabilities#delete_users
You could use CSS to hide the delete option from appearing on hover. The following code adds custom styles the Admin area.
add_action('admin_head', 'hide_user_delete_option');
function hide_user_delete_option() {
echo '<style>
.users-php tr:hover .row-actions .delete{
visibility: hidden;
}
</style>';
}

Wordpress remove menu items from wp-admin

I want that in wp-admin will be only Posts, Pages and Settings, it's possible to remove al remaining Media, Plugins, Users, Tools etc.
This function remove only from dashboard remove_menu_page( 'upload.php' );
Remove that menus from $restricted, that you want to prevent.
function remove_menus () {
global $menu;
$restricted = array(__('Dashboard'), __('Posts'), __('Media'), __('Links'), __('Pages'), __('Appearance'), __('Tools'), __('Users'), __('Settings'), __('Comments'), __('Plugins'));
end ($menu);
while (prev($menu)){
$value = explode(' ',$menu[key($menu)][0]);
if(in_array($value[0] != NULL?$value[0]:"" , $restricted)){unset($menu[key($menu)]);}
}
}
Credit goes to hungred via wprecipes
Since WordPress 3.1 you can better use remove_menu_page()
add_action( 'admin_menu', 'prefix_remove_menu_pages' );
function prefix_remove_menu_pages() {
remove_menu_page('edit-comments.php');
remove_menu_page('upload.php');
remove_menu_page('tools.php');
// Remove any item you want
}
}
from the docs:
Please be aware that remove_menu_pages would not prevent a user from accessing
these screens directly. Removing a menu does not replace the need to
filter a user's permissions as appropriate.
And for submenu items:
To remove submenu items in the admin, use remove_submenu_page. Using
remove_menu_page() will not work for submenu items.

Resources