Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Using a WordPress multisite network with Buddypress. In order to modify the top nav bar, I've written a function to replace part of the menu. Calling it thus:

add_action('bp_adminbar_menus', 'new_adminbar_blogs_menu', 6);

remove_action('bp_adminbar_menus', 'bp_adminbar_blogs_menu', 6);

Works perfectly in my functions.php, but when I try to move the above code to the plugin file, the remove_action fails to fire, but the add_action works as expected.

As a temporary solution, renaming the function folder to something appearing after Buddypress alphabetically solved the issue.

share|improve this question
add comment

4 Answers

up vote 1 down vote accepted

I am not sure about BuddyPress specifics.

In general case remove doesn't work when it is firing before function is actually added to the hook. Between core, plugins, parent and child themes there are a lot of relative combinations of add/remove possible.

In such case to make remove fire properly you need to wrap it into function and hook that wrapper function to some point later, after add.

share|improve this answer
add comment

Hi @Chris Cox:

I'm not sure, but I have a guess. Are those two lines of code just listed off by themselves in your theme's functions.php file, or are they wrapped in an 'init' hook? If not, or you don't know what I'm talking about then here's the code I think you need to include in your plugin:

add_action('init','yourplugin_init');
function yourplugin_init() {
  add_action('bp_adminbar_menus', 'new_adminbar_blogs_menu', 6);
  remove_action('bp_adminbar_menus', 'bp_adminbar_blogs_menu', 6);
}
share|improve this answer
add comment

You must check, how was fired this inside BP; maybe the hook plugins_loaded cam later as the functions.php of the Theme, she is very fast and before plugins. You can set a new priotity wuth the value. Add your plugin via init-hook and after this include your remove_action.

share|improve this answer
add comment

BuddyPress has its own 'init' function, check the docs for that. As Mike said your BuddyPress is loaded before your functions.php.

http://codex.buddypress.org/plugin-development/checking-buddypress-is-active/

This will help you.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.