Skip to:
Content
Pages
Categories
Search
Top
Bottom

Some questions about creating plugins for BP 1.5


  • grosbouff
    Participant

    @grosbouff

    Hi, I’ve read about the changes for the BP 1.5 plugins.

    I have a WP plugin that I would like to extend for BuddyPress. The only functions I would like for it is add BP notifications for some events.

    1) do we need to extend the BP_Component for every plugin, or just for complex components ?
    I my case, should I do it ?

    2) Guess I’ll have to do it. Then my 2nd question : I did a test and wasn’t able to make it work.
    Seems that the child class do not runs the function “includes”. It work if I run it manually; but then

    3) my plugin’s global “notification_callback” is empty. The function exists. though. Guess this is related with the previous thing. But even if I try
    `
    $bp->query_subscribe = new BP_Query_Subscribe();
    //TO FIX SHOULD RUN AUTOMATICALLY
    $bp->query_subscribe->includes();
    $bp->query_subscribe->bp_query_subscribe_format_notifications=’bp_query_subscribe_format_notifications’;`

    my notifications are not displayed (but they are recorded in the sql tables).

    Could someone give me some advices ? Also, it would be wonderful to update the bp-skeleton-plugin !

    http://pastie.org/2484801

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

  • Boone Gorges
    Keymaster

    @boonebgorges

    1) No, you don’t have to use BP_Component, but if you can, you probably should. It’s so much easier than trying to figure out which hooks to use. If you don’t need a particular method for your plugin (because it doesn’t have any navigation elements, for instance), just don’t include that method.

    2) There seems to be a bug in the way the includes() method works for plugins. For the moment, I recommend that you include your files manually.

    3) You need to call the $bp global before instantiating your class.
    `global $bp;
    $bp->query_subscribe = new BP_Query_Subscribe();`


    grosbouff
    Participant

    @grosbouff

    Like this ?
    Still have a problem for the format notifications function.. Thanks !
    `function bp_query_subscribe_init(){
    global $bp;
    if ( !isset( $bp->query_subscribe ) ){
    $bp->query_subscribe = new BP_Query_Subscribe();
    //TO FIX SHOULD RUN AUTOMATICALLY
    $bp->query_subscribe->includes();

    print_r($bp->query_subscribe);

    }
    }
    bp_query_subscribe_init();
    `


    Boone Gorges
    Keymaster

    @boonebgorges

    The reason why you’re not seeing the callback when you print is because the component class isn’t fully initialized at the time when you’re adding yourself to $bp. Try this:

    `function bp_query_subscribe_init(){
    global $bp;

    if ( !isset( $bp->query_subscribe ) ){
    $bp->query_subscribe = new BP_Query_Subscribe();
    }
    }
    add_action( ‘bp_loaded’, ‘bp_query_subscribe_init’ );

    function bp_query_test() {
    global $bp;
    var_dump( $bp->query_subscribe );
    }
    add_action( ‘bp_init’, ‘bp_query_test’, 999 );`

    As for includes, you will need to do your own manual include() for now. Don’t use BP_Component::includes().


    grosbouff
    Participant

    @grosbouff

    Ok; this DOES print the callback, thanks for the explanation !
    Still; I don’t get my notifications….
    `
    function bp_query_subscribe_format_notifications( $action, $item_id, $secondary_item_id, $total_items, $format = ‘string’ ) {
    die();
    `
    Do not die… :)
    I have notifications in my sql table; and the function IS included :( :( :(


    Boone Gorges
    Keymaster

    @boonebgorges

    Just to be clear, the notification function is a callback – you shouldn’t be calling it directly. Use bp_core_add_notification(). See bp-groups-notifications.php for an example of how it works.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Some questions about creating plugins for BP 1.5’ is closed to new replies.
Skip to toolbar