Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter bobemil

    (@bobemil)

    I tried to setup the notifications by myself but it’s not working (blank page). I used these code snippets in the bp-like.php file inside the plugin folder (adopted from Buddypress Followers plugin) . If you want to help me and understand how to set it up, I will pay 20$ through PayPal.

    function bp_like_setup_globals() {
    	global $bp, $wpdb;
    
    	// For internal identification
    	$bp->like->id              = 'like';
    
    	/* Register this in the active components array */
    	$bp->active_components[$bp->like->id] = $bp->like->id;
    
    	// BP 1.2.x only
    	if ( version_compare( BP_VERSION, '1.3' ) < 0 ) {
    		$bp->like->format_notification_function = 'bp_like_format_notifications';
    	}
    	// BP 1.5-specific
    	else {
    		$bp->like->notification_callback        = 'bp_like_format_notifications';
    	}
    }
    add_action( 'bp_setup_globals', 'bp_likesetup_globals' );
    /**
     * bp_like_process_ajax()
     *
     * Runs the relevant function depending on what Ajax call has been made.
     *
     */
    function bp_like_process_ajax() {
    	global $bp;
    
    	$id = preg_replace( "/\D/", "", $_POST['id'] ); 
    
    	if ( $_POST['type'] == 'like' )
    		bp_like_add_user_like( $id, 'activity' );
    
    	if ( $_POST['type'] == 'unlike' )
    		bp_like_remove_user_like( $id, 'activity' );
    
    	if ( $_POST['type'] == 'view-likes' )
    		bp_like_get_likes( $id, 'blogpost' );
    
    	if ( $_POST['type'] == 'like_blogpost' )
    		bp_like_add_user_like( $id, 'blogpost' );
    		bp_core_add_notification( $bp->like->id, 'new_like' );
    
    	if ( $_POST['type'] == 'unlike_blogpost' )
    		bp_like_remove_user_like( $id, 'blogpost' );
    
    	die();
    }
    add_action( 'wp_ajax_activity_like', 'bp_like_process_ajax' );
    /**
     * Format on screen notifications into something readable by users.
     *
     * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
     */
    function bp_like_format_notifications( $action, $item_id, $secondary_item_id, $total_items, $format ) {
    	global $bp;
    
    	do_action( 'bp_like_format_notifications', $action, $item_id, $secondary_item_id, $total_items, $format );
    
    	switch ( $action ) {
    		case 'new_like':
    			$link = bp_loggedin_user_domain();
    
    			if ( 1 == $total_items ) {
    				$text = __( '1 user likes your shot', 'bp-like' );
    			}
    			else {
    				$text = sprintf( __( '%d users likes your shot', 'bp-like' ), $total_items );
    			}
    		break;
    
    		default :
    			$link = apply_filters( 'bp_like_extend_notification_link', false, $action, $item_id, $secondary_item_id, $total_items );
    			$text = apply_filters( 'bp_like_extend_notification_text', false, $action, $item_id, $secondary_item_id, $total_items );
    		break;
    	}
    
    	if ( !$link || !$text )
    		return false;
    
    	if ( 'string' == $format ) {
    		return apply_filters( 'bp_like_new_followers_notification', '<a href="' . $link . '" title="' . __( 'Your shot', 'bp-follow' ) . '">' . $text . '</a>', $total_items, $link, $text, $item_id, $secondary_item_id );
    	}
    	else {
    		$array = array(
    			'text' => $text,
    			'link' => $link
    		);
    
    		return apply_filters( 'bp_like_new_like_return_notification', $array, $item_id, $secondary_item_id, $total_items );
    	}
    }

    Hi.. did you ever get this figured out?

    If anybody figured it out, it would be great to share the solution.
    Thanks

    I tried this code, but still didn’t work:

    /******************************************************
    /* 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 );
    }

    and inside bp_like_add_user_like() function I put this after $liked_count = count( $users_who_like ):
    bp_core_add_notification( $item_id, $user_id, $bp->bp_like->id, 'activity_like' );

    any help?

    [email protected]

    (@rakshithvbharanigmailcom)

    This feature is the most wanted feature…..request you to add this ….

    I would love to see this feature too. This would really be great.

    Indeed! Would be awesome!
    ??

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘[Plugin: BuddyPress Like] Notifications?’ is closed to new replies.