admin管理员组文章数量:1313347
I need to remove the link to the Jetpack settings, but not the links to Omnisearch and Site Stats from the admin menu for everyone not having an administrator role:
For this, I came up with this code:
function remove_posts_menu() {
if (!current_user_can('administrator')) {
remove_submenu_page('admin.php?page=jetpack', 'admin.php?page=jetpack');
}
}
add_action('admin_init', 'remove_posts_menu');
(Reference for the remove_submenu_page()
function)
However, this doesn't work. I did check that the function is called and so by adding remove_submenu_page('tools.php', 'tools.php');
- when this is added to the function, just after the removal of the Jetpack settings link, the Tools link is removed, but the Broken Link Checker link (of a plugin I installed) is still visible.
What's the correct way to remove the Jetpack link?
I need to remove the link to the Jetpack settings, but not the links to Omnisearch and Site Stats from the admin menu for everyone not having an administrator role:
For this, I came up with this code:
function remove_posts_menu() {
if (!current_user_can('administrator')) {
remove_submenu_page('admin.php?page=jetpack', 'admin.php?page=jetpack');
}
}
add_action('admin_init', 'remove_posts_menu');
(Reference for the remove_submenu_page()
function)
However, this doesn't work. I did check that the function is called and so by adding remove_submenu_page('tools.php', 'tools.php');
- when this is added to the function, just after the removal of the Jetpack settings link, the Tools link is removed, but the Broken Link Checker link (of a plugin I installed) is still visible.
What's the correct way to remove the Jetpack link?
Share Improve this question asked Jun 23, 2013 at 7:53 user26607user266074 Answers
Reset to default 0Try this instead:
function remove_posts_menu() {
if ( ! current_user_can( 'manage_options' ) )
remove_submenu_page( 'jetpack', 'jetpack' );
}
add_action( 'admin_init', 'remove_posts_menu' );
where the menu slug and submenu slug are jetpack
.
Jetpack's menu is added quite late, so you'll need to change the default priority to remove it a bit later (priority 999), like so:
function jetpackme_remove_jetpack_menu() {
if ( ! current_user_can( 'manage_options' ) ) {
remove_submenu_page( 'jetpack', 'jetpack' );
}
}
add_action ( 'admin_menu', 'jetpackme_remove_jetpack_menu', 999 );
function wpdocs_remove_menus(){
remove_menu_page( 'jetpack' );
}
add_action( 'admin_init', 'wpdocs_remove_menus' );
//paste in functions.php removes menu item for admin users
For the people that never want to see jetpack again. The code above unsets the admin menu item from administrators in wp-admin. "admin_init" is a way of calling the action before any other hook is triggered in wp-admin (call back only). Jetpack triggers super late which is why setting a priority of 1 or 11 or 99999 won't clear it.
*If you're like me, you're only using it for free woo commerce tax calculation and you never want to see jetpack again as well as your annoyed about how much resources it takes from your ultra light wordpress..
someone asked if this removes jetpack from taking up resources, no.
If you need further help nuking the resource hog (jetpack) I suggest disabling all the modules in jetpack. youtube video disabling jetpack modules
tony if your like me, and all you use is the zip code tax calculation and hate ads and ... jetpack paste this in your functions.php
/* Disable Ajax Call from WooCommerce on front page and posts // wc-ajax=get_refreshed_fragments fix*/
add_action( 'wp_enqueue_scripts', 'dequeue_woocommerce_cart_fragments', 11);
function dequeue_woocommerce_cart_fragments() {
if (is_front_page() || is_single() ) wp_dequeue_script('wc-cart-fragments');
}
// remove heart beat api widgets
add_action( 'init', 'stop_heartbeat', 1 );
function stop_heartbeat() {
wp_deregister_script('heartbeat');
}
// Analytics, if you need it, then view it the right way. Anywhere but wp dashboard.
function jetpackcom_no_woo_analytics( $tools ) {
$index = array_search( 'woocommerce-analytics/wp-woocommerce-analytics.php', $tools );
if ( false !== $index ) {
unset( $tools[ $index ] );
}
return $tools;
}
add_filter( 'jetpack_tools_to_include', 'jetpackcom_no_woo_analytics' );
// kill devicepx-jetpack.js good bye ads
function tj_dequeue_devicepx() {
wp_dequeue_script( 'devicepx' );
}
add_action( 'wp_enqueue_scripts', 'tj_dequeue_devicepx' );
function remove_menus(){
if ( ! current_user_can( 'administrator' ) ) {
remove_menu_page( 'jetpack' );
}
}
add_action( 'admin_menu', 'remove_menus', 999 );
This seemed to work for me and allowed me to only give access to administrators. You can adapt it to hide any page from the Wordpress list here.
本文标签: functionsRemoving the main link to Jetpack from the menu
版权声明:本文标题:functions - Removing the main link to Jetpack from the menu 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741928443a2405433.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论