• Resolved petet_uk

    (@petet_uk)


    Hi all,

    I’ve created a new Sub nav item for the Events Manager, but I have had to hardcode the events slug and parent link because the $bp object doesn’t seem to have the events object in when I run the code.

    I would much rather be creating the events slug by below line of code, but $bp->events doesn’t exist at the point of running the action.

    $events_slug = $bp->events->slug

    Could anyone tell me what action I should be tying the sub menu creation in to.

    See below for my current version.

    [Code moderated as per the Forum Rules. Please use the pastebin]

    Thanks in advance

Viewing 8 replies - 1 through 8 (of 8 total)
  • did try putting it into global?

    global $bp;

    Thread Starter petet_uk

    (@petet_uk)

    Update from the moderation, code can be found at https://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? https://www.ads-software.com/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 https://pastebin.com/BM8adpdH or the do_action( 'my_invites_setup_nav' ); is inside the function?

    Thread Starter petet_uk

    (@petet_uk)

    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

    Thread Starter petet_uk

    (@petet_uk)

    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

    Thread Starter petet_uk

    (@petet_uk)

    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.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘[Plugin: Events Manager] Sub nav creation on Events navigation (Buddypress)’ is closed to new replies.