Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to display custom made notifications for a plugin?


  • crina27
    Participant

    @crina27

    I created a plugin that allows the members in a group to have a video chat. When the admin starts the chat a notification is send to all the group members.
    The notifications are saved in the database but are not displayed in the notifications page.
    This is the function that sets up the global variables for the plugin:

    function bp_group_videochat_setup_globals() {
    global $bp, $wpdb;

    /* For internal identification */
    $bp->videochat=new BP_Group_videochat();
    $bp->videochat->id = ‘videochat’;

    $bp->videochat->table_name = $wpdb->base_prefix . ‘bp_group_videochat’;
    $bp->videochat->notification_callback=’bp_group_videochat_format_notifications’;
    $bp->videochat->slug = BP_GROUP_videochat_SLUG; //video-chat

    /* Register this in the active components array */
    $bp->active_components[$bp->videochat->slug] =’1′;
    do_action( ‘bp_group_videochat_setup_globals’ );
    }
    add_action( ‘bp_setup_globals’, ‘bp_group_videochat_setup_globals’ );

    And this is the format notifications function:

    function bp_group_videochat_format_notifications( $action, $item_id, $secondary_item_id, $total_items) {
    global $bp;
    switch ( $action ) {
    case ‘new_video_chat’:
    $group_id = $secondary_item_id;

    $group = new BP_Groups_Group( $group_id );
    $group_link = bp_get_group_permalink( $group );

    $groupSlug=groups_get_slug( $secondary_item_id);
    $url=home_url( $bp->groups->slug . ‘/’ .$groupSlug . ‘/group-chat’ );
    return ‘‘ . sprintf( __( ‘%s group broadcast invite!’, ‘video-chat’ ), $groupSlug ) . ‘‘;
    break;
    }
    do_action( ‘bp_group_videochat_format_notifications’);
    return false;

    }

    To create the notifications I use the bp_notifications_add_notification function:

    bp_notifications_add_notification( array(
    ‘user_id’ => $user,
    ‘item_id’ => rand(),
    ‘secondary_item_id’ => $bp->groups->current_group->id,
    ‘component_name’ => ‘video-chat’,
    ‘component_action’ => ‘new_video_chat’,
    ‘date_notified’ => bp_core_current_time(),
    ‘is_new’ => 1,
    ) );

    Is there anyone here that could help me? Should it work in theory?

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to display custom made notifications for a plugin?’ is closed to new replies.
Skip to toolbar