Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Unhook admin pages in BackupBuddy WordPress

  • SOLVED

I need to remove the admin settings pages for non Super admin users of the <a href="http://pluginbuddy.com/purchase/backupbuddy/">BackupBuddy plugin</a>.

This is a paid plugin, so out of respect for the developers of the plugin I won't post a full download link to it here, but the following seems to be the code I need to unhook:
add_action('admin_menu', array(&$this, 'admin_menu')); // Add menu in admin.

Please provide the code necessary to unhook the admin pages.

I thought the following would work, but it did not :(
remove_action( 'admin_menu', array(&$this, 'view_gettingstarted') );

Answers (5)

2011-02-09

Utkarsh Kukreti answers:

Not sure if this is the best way, but it works fine for me.

global $wp_filter;

if( isset( $wp_filter['admin_menu'] ) && isset( $wp_filter['admin_menu'][10] ) ) {
foreach( $wp_filter['admin_menu'][10] as $key => $val ) {
if( isset( $val['function']) && is_array( $val['function'] ) && is_object( $val['function'][0] ) && is_a( $val['function'][0], 'iThemesBackupBuddy' ) ) {
unset( $wp_filter['admin_menu'][10][$key] );
}
}
}

2011-02-08

Nilesh shiragave answers:

try this


remove_action('admin_menu', array(&$this, 'admin_menu')); // Add menu in admin.


Ryan Hellyer comments:

Nope. That doesn't work unfortunately.


Nilesh shiragave comments:

hi

check the admin_menu() function in that backupbuddy.php file

function admin_menu() {
// Add main menu (default when clicking top of menu)
add_menu_page('Getting Started', $this->_name, 'administrator', $this->_var, array(&$this, 'view_gettingstarted'), $this->_pluginURL.'/images/pluginbuddy.png');
// Add sub-menu items (first should match default page above)
add_submenu_page($this->_var, 'Getting Started with '.$this->_name, 'Getting Started', 'administrator', $this->_var, array(&$this, 'view_gettingstarted'));
add_submenu_page($this->_var, $this->_name.' Backups', 'Backups', 'administrator', $this->_var.'-backup', array(&$this, 'view_backup'));
//add_submenu_page($this->_var, $this->_name.' Importing', 'Importing', 'administrator', $this->_var.'-importing', array(&$this, 'view_importing'));
add_submenu_page($this->_var, $this->_name.' Scheduling', 'Scheduling', 'administrator', $this->_var.'-scheduling', array(&$this, 'view_scheduling'));
add_submenu_page($this->_var, $this->_name.' Settings', 'Settings', 'administrator', $this->_var.'-settings', array(&$this, 'view_settings'));
}


in that replace "administrator" with "Administrator"

so final function will be


function admin_menu() {
// Add main menu (default when clicking top of menu)
add_menu_page('Getting Started', $this->_name, 'Administrator', $this->_var, array(&$this, 'view_gettingstarted'), $this->_pluginURL.'/images/pluginbuddy.png');
// Add sub-menu items (first should match default page above)
add_submenu_page($this->_var, 'Getting Started with '.$this->_name, 'Getting Started', 'Administrator', $this->_var, array(&$this, 'view_gettingstarted'));
add_submenu_page($this->_var, $this->_name.' Backups', 'Backups', 'Administrator', $this->_var.'-backup', array(&$this, 'view_backup'));
//add_submenu_page($this->_var, $this->_name.' Importing', 'Importing', 'administrator', $this->_var.'-importing', array(&$this, 'view_importing'));
add_submenu_page($this->_var, $this->_name.' Scheduling', 'Scheduling', 'Administrator', $this->_var.'-scheduling', array(&$this, 'view_scheduling'));
add_submenu_page($this->_var, $this->_name.' Settings', 'Settings', 'Administrator', $this->_var.'-settings', array(&$this, 'view_settings'));
}


Nilesh shiragave comments:

or try this code


function admin_menu() {
// Add main menu (default when clicking top of menu)
add_menu_page('Getting Started', $this->_name, 'update_core', $this->_var, array(&$this, 'view_gettingstarted'), $this->_pluginURL.'/images/pluginbuddy.png');
// Add sub-menu items (first should match default page above)
add_submenu_page($this->_var, 'Getting Started with '.$this->_name, 'Getting Started', 'update_core', $this->_var, array(&$this, 'view_gettingstarted'));
add_submenu_page($this->_var, $this->_name.' Backups', 'Backups', 'update_core', $this->_var.'-backup', array(&$this, 'view_backup'));
//add_submenu_page($this->_var, $this->_name.' Importing', 'Importing', 'update_core', $this->_var.'-importing', array(&$this, 'view_importing'));
add_submenu_page($this->_var, $this->_name.' Scheduling', 'Scheduling', 'update_core', $this->_var.'-scheduling', array(&$this, 'view_scheduling'));
add_submenu_page($this->_var, $this->_name.' Settings', 'Settings', 'update_core', $this->_var.'-settings', array(&$this, 'view_settings'));
}


Ryan Hellyer comments:

I want to be able to keep updating the BackupBuddy plugin and also release a plugin which extends it's functionality for use on WordPress multi-site setups. So I need to unhook the existing code, not modify the core code of the plugin unfortunately.

2011-02-09

Denzel Chia answers:

Hi,

<blockquote>I need to remove the admin settings pages for non Super admin users</blockquote>

Since you did not post full code of plugin, I can only guess the answer.
You can use wordpress capabilities to limit the admin page to only hook if user is super admin.
use if current user can to check capability of manage_network, which is the capability only available to super admins.


if(current_user_can('manage_network')){
add_action('admin_menu', array(&$this, 'admin_menu')); // Add menu in admin.
}


Thanks.


Denzel Chia comments:

And if you want to unhook it in your new plugin, instead of changing the backup buddy plugin.

Try this in your new plugin,


function remove_backupbuddy_menu(){
remove_action( 'admin_menu', 'view_gettingstarted', 2 );
}
add_action('admin_init','remove_backupbuddy_menu');


Try changing the number 2 to other numbers if this does not work.
Number 2 if the priority of remove action. We need to let backupbuddy hook in first before remove action, so we need to figure out the priority, it should be after backup buddy menu hook.

Hope it helps!

Thanks.


Denzel Chia comments:

Hi,

try priority 11 as default is priority 10.


function remove_backupbuddy_menu(){
remove_action( 'admin_menu', 'view_gettingstarted', 11 );
}
add_action('admin_init','remove_backupbuddy_menu');


Thanks.


Ryan Hellyer comments:

is_super_admin() is the conditional to use for checking super admin user permissions rather than current_user_can(). That's not what I'm stuck on though.

I tried your code snippets to remove the menus but they didn't work unfortunately :(

I've sent you a link to the plugin in case that helps you figure it out.


Denzel Chia comments:

Hi,

Use the following as a plugin.
Save it in something like remove.php in your wp-content/plugins/ folder and activate it.


<?php
/*
Plugin Name: Remove Backup Buddy Menu
Author: Denzel Chia
Version: 1.0
Author URI: http://denzeldesigns.com/
*/

function dd_remove_menus () {
global $menu;
while ($menu_name = current($menu)) {
if ($menu_name[0] == 'BackupBuddy') {
$killer = key($menu);
}
next($menu);
}
unset($menu[$killer]);
}
add_action('admin_menu', 'dd_remove_menus');
?>


The above codes are tested and working.
Thanks.


Ryan Hellyer comments:

Unfortunately that only removes the admin menu.

My question relates to unhooking the entire page so that the administrators can't access it.

2011-02-09

John Cotton answers:

The &$this is the original add_action suggests that the call is made inside a class.

Since your code isn't in that class you have to call it differently.

Have you tried:

remove_action('admin_menu', array('CLASS_NAME', 'admin_menu'));

Also, you need to call the remove after the add so you need to look which hook the add is itself called with and use that one or a slightly later one.

JC


Ryan Hellyer comments:

I've been messing around with that, but can't nut it out how to get to make it work :(

I've sent you a copy of the plugin to look at it in case that helps with figuring it out.


John Cotton comments:


function remove_backupbuddy_admin_menu(){

remove_action( 'admin_menu', array('iThemesBackupBuddy', 'admin_menu') );

}

add_action('admin_init','remove_backupbuddy_admin_menu');


Ryan Hellyer comments:

I've tried using that approach before, but it didn't work. I copy and pasted your code and didn't work this time either :(

Did you test that by any chance? It's certainly not working for me.

2011-02-09

Semih Aksu answers:

try this plugin: http://wordpress.org/extend/plugins/hide-admin-panels/
you can hide menus easily.


Ryan Hellyer comments:

I'm not trying to hide a menu. I'm trying to unhook admin pages.