Skip to:
Content
Pages
Categories
Search
Top
Bottom

custom plugin : hook bp_setup_globals is not fired


  • grosbouff
    Participant

    @grosbouff

    Hi; I’m making a new plugin. I have WP 3 & BP 1.2.4.1
    I have a file loader.php with

    function yclads_bp_init() {
    require_once( YCLADS_BP_PLUGIN_PATH . 'includes/yclads-bp-core.php' );
    }
    add_action( 'bp_init', 'yclads_bp_init');

    inside yclads-bp-core.php;

    function bp_yclads_setup_globals() {
    global $bp;

    // For internal identification
    $bp->yclads->id = 'yclads';

    $bp->yclads->format_notification_function = 'bp_yclads_format_notifications';
    $bp->yclads->slug = YCLADS_SLUG;

    // Register this in the active components array
    $bp->active_components[$bp->yclads->slug] = $bp->yclads->id;

    do_action( 'bp_yclads_setup_globals' );

    }
    add_action( 'bp_setup_globals', 'bp_yclads_setup_globals' );

    The function is not fired.
    if I use

    function bp_yclads_setup_globals() {
    exit;
    }

    it does not exit.
    Any idea ?
    Thanks.

Viewing 8 replies - 1 through 8 (of 8 total)

  • r-a-y
    Keymaster

    @r-a-y


    grosbouff
    Participant

    @grosbouff

    Ok. Here my code now :

    loader.php
    function yclads_bp_init() {
    require_once( YCLADS_BP_PLUGIN_PATH . 'includes/yclads-bp-core.php' );
    }
    add_action( 'bp_init', 'yclads_bp_init');

    yclads-bp-core.php

    function bp_yclads_setup_globals() {
    global $bp;

    // For internal identification
    $bp->yclads->id = 'yclads';

    $bp->yclads->format_notification_function = 'bp_yclads_format_notifications';
    $bp->yclads->slug = YCLADS_SLUG;

    // Register this in the active components array
    $bp->active_components[$bp->yclads->slug] = $bp->yclads->id;

    do_action( 'bp_yclads_setup_globals' );

    }
    //TO FIX
    //add_action( 'bp_setup_globals', 'bp_yclads_setup_globals' );
    add_action( 'wp', 'bp_yclads_setup_globals');
    add_action( 'admin_menu', 'bp_yclads_setup_globals');

    function bp_yclads_setup_root_component() {
    /* Register 'yclads' as a root component */
    bp_core_add_root_component( YCLADS_SLUG );

    }
    //TO FIX
    //add_action( 'bp_setup_root_components', 'bp_yclads_setup_root_component' );
    add_action( 'wp', 'bp_yclads_setup_root_component');
    add_action( 'admin_menu', 'bp_yclads_setup_root_component');

    function bp_yclads_setup_nav() {
    global $bp;
    global $post;

    if ((is_single()) && ($post->post_type=='yclad')) {

    // This is a single ad.
    $bp->is_single_item = true;
    $bp->yclads->current_ad = $post;

    [...]

    }

    [...]

    print_r($bp->current_component);
    exit;

    do_action( 'yclads_setup_nav', $bp->yclads->current_ads->user_has_access );

    }
    //TO FIX
    //add_action( 'bp_setup_nav', 'bp_yclads_setup_nav' );
    add_action( 'wp', 'bp_yclads_setup_nav' );
    add_action( 'admin_menu', 'bp_yclads_setup_nav' );

    If I access /wordpress/classified-ads/i-give-kitties/ (single-ad)


    print_r($bp->current_component);
    exit;

    outputs “i-give-kitties” while it should output “classified-ads”. So something is wrong with all this.
    Any idea ?


    Boone Gorges
    Keymaster

    @boonebgorges

    Have you tried @jeffsayre‘s Hook Sniffer to see if your hooks aren’t being recognized in the right order? Last time I had a problem like this, Hook Sniffer solved it in five minutes. https://wordpress.org/extend/plugins/wordpress-hook-sniffer/


    John James Jacoby
    Keymaster

    @johnjamesjacoby

    On top of everyone’s ideas, be sure to check out how to correctly attach your plugin to bp_init:
    https://codex.buddypress.org/how-to-guides/make-your-plugin-buddypress-aware-v1-2/

    Because of the way that WordPress loads plugins, its possible that bp_init is firing before your plugin has added the hook. If that’s the case, your function is safe to run and needs to be called directly as a fall-back.


    grosbouff
    Participant

    @grosbouff

    @johnjamesjacoby : it fixed it !
    thanks A LOT.


    John James Jacoby
    Keymaster

    @johnjamesjacoby

    :D


    grosbouff
    Participant

    @grosbouff

    Ok; it’s broken again with 1.2.5…
    I did read your post about new hooks for plugins for 1.2.5; but I don’t understand how to adapt this.
    So :
    my loader file : http://pastie.org/1023309
    A part of my core file : http://pastie.org/1023315

    Could you have a look at this ?

    Thanks !


    Dwenaus
    Participant

    @dwenaus

    this handy code, https://codex.buddypress.org/how-to-guides/make-your-plugin-buddypress-aware-v1-2/, should probably be added to the skeleton component. Because I believe the problem still persists with the skeleton component in that bp_setup_globals never gets called in time. ugh. but not sure if even that fixes this perplexing issue. bp_globals_doesn’t seem to fire still.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘custom plugin : hook bp_setup_globals is not fired’ is closed to new replies.
Skip to toolbar