did try putting it into global?
global $bp;
Update from the moderation, code can be found at http://pastebin.com/BM8adpdH
The events object is created as a child of the global $bp, but I think somehow my code above is being run before the the events object is created. Therefore, I don’t think I’m tying it to the right action.
can you try this forum? http://wordpress.org/support/topic/determine-if-single-or-list-event-in-template?replies=3
so that you check first if the event object is loaded before you execute your code AND also why does at line 12 of http://pastebin.com/BM8adpdH or the do_action( 'my_invites_setup_nav' ); is inside the function?
Thanks for that. It’s hitting the final else clause, which confirms that the events object hasn’t yet been created.
do_action on line 12 has been removed, but it was an idle line anyway.
The code is being run before the events plugin is initialised, and therefore I need to somehow run it after.
make sure your code is run after the action that sets up the navigation menus. probably just requires adding a priority number to add_action
Hi Marcus,
Thanks, I’ve tried that by adding a priority of 12 and it didn’t have any effect. Also tried it with priority 100 with no difference.
I’m using var_dump($bp->events); to see the contents of the object, just to prove it exists, but nothing is outputted because it still hasn’t created the events object, even with a priority of 100 on the bp_setup_nav action.
add_action( 'bp_setup_nav', 'my_invites_setup_nav', 100 );
If you’ve got any other suggestions, I would really appreciate them because I’m at a bit of a loss as to why it’s being run before the $bp->events object is created.
if your plugin is adding stuff that EM overwrites, the solution is to make sure you’re loading this after EM has done it’s stuff.
bp stuff is added to EM after plugins_loaded so that BP is definitely there, make sure whatever you’re running is after that too (as well as after our function to set up the navs).
you could also try modifying the do_action filter to output actions as it goes to see what’s going wrong on your code
I eventually fixed this by hooking my function into the wp_loaded action.
My first problem was that I had my code running from mu-plugins, which runs before events manager and therefore it couldn’t find it.
I move the code into functions.php and then added it to the wp_loaded action.
Thanks for your help Marcus.