针对buddypress的通知喜欢插件

时间:2013-03-15 21:25:59

标签: wordpress buddypress

我正在使用Buddypress like插件,该功能会将功能添加到状态更新中。现在,当用户喜欢某些内容时,它不会像其他buddypress组件那样发送状态通知。我尝试编辑插件的代码来添加此功能,并将以下代码添加到bp-like.php,但仍然无效:

/******************************************************
/* Notification
 *****************************************************/
function bp_like_setup_globals() {
    global $bp, $current_blog;
    $bp->bp_like->id = 'bp_like_notifier';
    $bp->bp_like->slug = 'BP_LIKE_SLUG';
    $bp->bp_like->notification_callback = 'like_format_notifications';
    $bp->active_components[$bp->bp_like->slug] = $bp->bp_like->id;
    do_action( 'bp_like_setup_globals' );
}
add_action( 'bp_setup_globals', 'bp_like_setup_globals' );

function like_format_notifications( $action, $item_id, $secondary_item_id, $total_items ) {
    global $bp;

    $link=like_notifier_activity_get_permalink( $item_id ); 

    if( 'activity_like' == $action ) {
    if ( (int)$total_items > 1 )
        return apply_filters( 'log_multiple_verifications_notification', '<a href="'. $link .'" title="' . __( 'Likes', 'bp-like' ) . '">' . sprintf( __('You have %d new likes', 'bp-like' ), (int)$total_items ) . '</a>', $total_items );
        else
        return apply_filters( 'log_single_verification_notification', '<a href="'. $link .'" title="' . __( 'likes', 'bp-like' ) . '">' . sprintf( __('You have %d new like', 'bp-like' ), (int)$total_items ) . '</a>', $total_items );
    }

    do_action( 'like_format_notifications', $action, $item_id, $secondary_item_id, $total_items );

    return false;
}
function like_remove_screen_notifications() {
    global $bp;
    if($has_access)//if user can view this activity, remove notification(just a safeguard for hidden activity)
    bp_core_delete_notifications_for_user_by_type( $bp->loggedin_user->id, $bp->bp_like->id, 'new_like' );
}
add_action( 'bp_activity_screen_single_activity_permalink', 'like_remove_screen_notifications' );   

//get the thread permalink for activity
function like_notifier_activity_get_permalink( $item_id, $activity_obj = false ) {
    global $bp;

    if ( !$activity_obj )
        $activity_obj = new BP_Activity_Activity( $item_id );

        if ( 'activity_comment' == $activity_obj->type )
            $link = $bp->root_domain . '/' . BP_ACTIVITY_SLUG . '/p/' . $activity_obj->item_id . '/';
        else
            $link = $bp->root_domain . '/' . BP_ACTIVITY_SLUG . '/p/' . $activity_obj->id . '/';

    return apply_filters( 'like_notifier_activity_get_permalink', $link );
}

并且在bp_like_add_user_like()函数内部我把它放在$ likes_count = count($ users_who_like)之后:

bp_core_add_notification( $item_id, $user_id, $bp->bp_like->id, 'activity_like' );

到目前为止,这不起作用..知道我在这里缺少什么吗?

感谢

0 个答案:

没有答案