WordPress.org

Ready to get started?Download WordPress

Forums

Jetpack by WordPress.com
[resolved] Jetpack dashboard menu capability hook (7 posts)

  1. wWave
    Member
    Posted 1 year ago #

    On Jetpack 2.0, the capability attribute for 'add_menu_page' is set to 'read', making it visible to even 'subscriber' users, this was set to 'manage_options' before the 2.0 update.

    At the moment I've changed
    $hook = add_menu_page( 'Jetpack', $title, 'read', 'jetpack', array( $this, 'admin_page' ), 'div' );

    to:

    $hook = add_menu_page( 'Jetpack', $title, 'manage_options', 'jetpack', array( $this, 'admin_page' ), 'div' );

    On the jetpack.php file.
    Does anyone can come up with way to hook a filter and change this without hacking the plugin files (as my 'solution' get over written when a new update is installed)

    Thanks!!

    http://wordpress.org/extend/plugins/jetpack/

  2. Adam Capriola
    Member
    Posted 1 year ago #

    I noticed this too. I'm trying to figure out a way to unset it from the menu, but I can't figure out the key. Trying to do something like this:

    /**
     * Hide menu items
     *
     */
    add_action( 'admin_menu', 'ac_hide_menu_items' );
    
    function ac_hide_menu_items() {
    
    	global $menu;
    
    	if ( !current_user_can( 'administrator' ) ) {
    
    		unset($menu[3]); // Jetpack
    
    	}
    
    }

    3 isn't the right key. Neither is 4. I'm kind of stumped.

    EDIT: For now, you can hide it with CSS. It's obviously not a great solution, but better than nothing:

    /**
     * Hide Jetpack menu item from non-administrators
     *
     */
    add_action( 'admin_head', 'ac_hide_jetpack_menu' );
    
    function ac_hide_jetpack_menu() {
    
    	if ( !current_user_can( 'administrator' ) ) { ?>
    
    		<style type="text/css">
    		#toplevel_page_jetpack { display: none; }
    		</style>
    
    	<?php }
    
    }
  3. wWave
    Member
    Posted 1 year ago #

    It's a good alternative Adam, in addition I'm adding a redirection to the profile page, only if by any chance the user ends up in the jetpack page (or tries to go to it).

    function wave_hide_jetpack_menu() {
    	if ( !current_user_can( 'administrator' ) ) { ?>
    		<style type="text/css">
    		#toplevel_page_jetpack { display: none; }
    		</style>
    	<?php
    		if($_GET['page']=='jetpack')
    		{
    			if (headers_sent()) {
    				echo '<meta http-equiv="refresh" content="0;url='.admin_url('profile.php').'">';
    				echo '<script type="text/javascript">document.location.href="'.admin_url('profile.php').'"</script>';
    			} else {
    				wp_redirect(admin_url('profile.php'));
    				exit();
    			}
    		}
    
    	}
    }
  4. Charl Pretorius
    Member
    Posted 1 year ago #

    You should be able to use the following :

    add_action('admin_init', 'remove_menus');
    function remove_menus(){
    	if(!current_user_can('add_users')){
    		remove_menu_page('jetpack');
    	}
    }
  5. wWave
    Member
    Posted 1 year ago #

    Thanks charl@kri8it.com!! I tried something similar but I had it hooked to the wrong action!

  6. rustyellis
    Member
    Posted 1 year ago #

    Thanks Adam, I appreciate the code. Last thing I want to do is confuse those signing up and give them more things to tinker with. The CSS hide worked great.

  7. zanzaboonda
    Member
    Posted 1 year ago #

    That worked perfectly. Thanks so much!! :D

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic