Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to use bp_init and bp_setup_globals at the same time ?

  • Profile photo of calvin_42
    calvin_42
    Participant

    @calvin_42

    Hi there.

    I have a small issue : I am using different action hooks like [strong]bp_setup_globals[/strong] or [strong]groups_setup_globals[/strong] in a file my-plugin-bp-functions.php and it works perfectly

    add_action( 'bp_setup_globals', 'my_function' );

    But I want to make my plugin aware of BuddyPress using the recommended code :

    /* Only load the BuddyPress plugin functions if BuddyPress is loaded and initialized. */
    function my_plugin_init() {
    require( dirname( __FILE__ ) . '/my-plugin-bp-functions.php' );
    }
    add_action( 'bp_init', 'my_plugin_init' );

    Problem : my_function isn’t called anymore and it’s pretty logic : bp_init is called after bp_setup_globals has been called.

    So how to use bp_init to load my plugin and still using my hook functions ?

    Thanks!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Profile photo of Paul Gibbs
    Paul Gibbs
    Keymaster

    @djpaul

    In the current versions, the actions are called with the wrong priorities in the BP code resulting in this sort of problem. For now, rather than hooking into bp_setup_globals, hook into ‘wp’ and/or ‘admin_menu’

    Profile photo of calvin_42
    calvin_42
    Participant

    @calvin_42

    Thanks for your answer DJPaul.

    So does it really mean (using buddypress aware recommended code) that we cannot hook all the filters and the functions which are called before bp_init() ? For example “groups_setup_globals” used to add a step during creation groups ?

    Profile photo of Paul Gibbs
    Paul Gibbs
    Keymaster

    @djpaul

    It just means that the BP code was changed since that documentation was written.

    Profile photo of calvin_42
    calvin_42
    Participant

    @calvin_42

    So how to do it then ?

    Profile photo of Grosbouff
    grosbouff
    Participant

    @grosbouff

    @Paul :
    not working either with

    //TO FIX
    //https://buddypress.org/community/groups/creating-extending/forum/topic/how-to-use-bp_init-and-bp_setup_globals-at-the-same-time/
    //add_action( 'bp_setup_globals', 'bp_yclads_setup_globals' );
    add_action( 'wp', 'bp_yclads_setup_globals' );
    add_action( 'admin_menu', 'bp_yclads_setup_globals' );

    For the same problem (https://buddypress.org/community/groups/creating-extending/forum/topic/custom-plugin-hook-bp_setup_globals-is-not-fired/)

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to use bp_init and bp_setup_globals at the same time ?’ is closed to new replies.