Skip to:
Content
Pages
Categories
Search
Top
Bottom

Custom notification is NOT displayed twice


  • Antonio
    Participant

    @anth0ny167

    Hi guys, I created a custom notification that is added when an user receive a like on a custom post type.

    All good unitl now, but I noticed that if the post receive 2 likes, from 2 different users, the user receive only the first notification and not the second one.

    Any help would be really appreciated.

    
    //Component declaration
    if(!function_exists('my_custom_register_wiki_notification')) {
    	function my_custom_register_wiki_notification() {
    		// Register component manually into buddypress() singleton
    		buddypress()->my_custom_wiki = new stdClass;
    		// Add notification callback function
    		buddypress()->my_custom_wiki->notification_callback = 'my_custom_wiki_like_format_notifications';
    
    		// Now register components into active components array
    		buddypress()->active_components['my_custom_wiki'] = 1;
    	}
    };
    
    //Notification format declaration
    if(!function_exists('my_custom_wiki_like_format_notifications')) {
    	function my_custom_wiki_like_format_notifications( $action, $item_id, $secondary_item_id, $total_items, $format = 'string' ) {
    
    		// New custom notifications
    		if ( 'my_custom_wiki_like' === $action ) {
    
    			$wiki_post = get_post( $item_id );
    			$post_title = get_the_title( $item_id );
    
    			$custom_title = sprintf( esc_html__( 'Your post "%1$s" received a like', 'my_custom' ), $post_title );
    			$custom_text  = sprintf( esc_html__( 'Your post "%1$s" received a like', 'my_custom' ), $post_title );
    			$custom_link  = get_permalink( $item_id );
    
    			// WordPress Toolbar
    			if ( 'string' === $format ) {
    				$return = apply_filters( 'my_custom_wiki_like_format', '<a href="' . esc_url( $custom_link ) . '" title="' . esc_attr( $custom_title ) . '">' . esc_html( $custom_text ) . '</a>', $custom_text, $custom_link );
    
    				// Deprecated BuddyBar
    			} else {
    				$return = apply_filters( 'my_custom_wiki_like_format', array(
    					'text' => $custom_text,
    					'link' => $custom_link
    				), $custom_link, (int) $total_items, $custom_text, $custom_title );
    			}
    
    			return $return;
    
    		}
    
    		return $action;
    
    	}
    }
    
    //Function that add the notification when like is triggered
    function my_custom_add_like() {
      //...
      //...
    
      if(my_custom_is_wiki_like_notification_enabled()) {
    		        bp_notifications_add_notification( array(
    			        'user_id'           => $post_object->post_author,
    			        'item_id'           => $post_id,
    			        'secondary_item_id' => get_current_user_id(),
    			        'component_name'    => 'my_custom_wiki',
    			        'component_action'  => 'my_custom_wiki_like',
    			        'date_notified'     => bp_core_current_time(),
    			        'is_new'            => 1,
    		        ) );
    	        }
      
    }
    
  • You must be logged in to reply to this topic.
Skip to toolbar