Skip to:
Content
Pages
Categories
Search
Top
Bottom

bp_notifications_get_notifications_for_user filter failing


  • phucitol
    Participant

    @phucitol

    I’ve been using bp_notifications_add_notification to add a notification with “component_action”=”activity_liked” for component_name activity. I can see that it is being saved in the database, but when I try to display an entry for it in the notifications view it seems that my callback function never runs. Every example I’ve found online has mirrored my function but it never seems to be called. Do I need to register the component_action or something?

    I’ve looked in the buddypress core files and they all seem to pass 8 parameters instead of 5 during apply_filters_ref_array, which I also tried but still my callback wouldn’t run. I’ve tried it every way with no other plugins but buddypress activated and still it fails.

    I’m truly lost on how to get this working.

    function custom_format_buddypress_notifications( $action, $item_id, $secondary_item_id, $total_items, $format = 'string' ) {
    	// New custom notifications
    	if ( $action == 'activity_liked') {
    
    		$custom_title = 'activity liked';
    		$custom_link  = '/activity/' . $item_id . '/';
    		$custom_text = bp_core_get_user_displayname( $secondary_item_id ) . ' liked your activity';
    
    		// WordPress Toolbar
    		if ( 'string' === $format ) {
    			$return = apply_filters( 'custom_filter', '<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( 'custom_filter', array(
    				'text' => $custom_text,
    				'link' => $custom_link
    			), $custom_link, (int) $total_items, $custom_text, $custom_title );
    		}
    	} else {
    		$return = $action;
    	}
    
    	return $return;
    }
    add_filter( 'bp_notifications_get_notifications_for_user', 'custom_format_buddypress_notifications', 10, 5 );
Viewing 5 replies - 1 through 5 (of 5 total)

  • phucitol
    Participant

    @phucitol

    I should have mentioned

    wordpress 4.9.4
    buddypress 2.9.4


    ethanstein
    Participant

    @ethanstein

    I also had the same issue. It has been working for the past six months but for some reason I’m now getting the error:

    [Thu May 31 03:17:57.637007 2018] [proxy_fcgi:error] [pid 20994:tid 140462744499968] [client 76.95.217.178:52226] AH01071: Got error 'PHP message: PHP Warning: Missing argument 6 for bp_custom_format_buddypress_notifications(), called in /opt/bitnami/apps/wordpress/htdocs/wp-includes/class-wp-hook.php on line 286 and defined in /opt/bitnami/apps/wordpress/htdocs/wp-content/plugins/wbp/lib/party/notifications.php on line 40\nPHP message: PHP Warning: Missing argument 7 for bp_custom_format_buddypress_notifications(), called in /opt/bitnami/apps/wordpress/htdocs/wp-includes/class-wp-hook.php on line 286 and defined in /opt/bitnami/apps/wordpress/htdocs/wp-content/plugins/wbp/lib/party/notifications.php on line 40\nPHP message: PHP Warning: Missing argument 8 for bp_custom_format_buddypress_notifications(), called in /opt/bitnami/apps/wordpress/htdocs/wp-includes/class-wp-hook.php on line 286 and defined in /opt/bitnami/apps/wordpress/htdocs/wp-content/plugins/wbp/lib/party/notifications.php on line 40


    ethanstein
    Participant

    @ethanstein

    It seems like parameters 6-8 are no longer being passed with the new version of buddypress?

    This is my code which has been working:

    function bp_custom_format_buddypress_notifications( $action, $item_id, $secondary_item_id, $total_items, $format = 'string', $component_action, $component_name, $id ) {
    
      if ("wbp_party" === $component_name && is_user_logged_in()) {
    
        ...
    
    if ( 'string' === $format ) {
          $return = apply_filters( 'wbp_notification_filter','<a href="'.$custom_link.'">'.$custom_title.'</a> ', $custom_text, $custom_link );
    
          // Deprecated BuddyBar
        } else {
          $return = apply_filters( 'wbp_notification_filter_array', array(
            'text' => $custom_text,
            'link' => $custom_link
          ), $custom_link, (int) $total_items, $custom_text, $custom_title );
        }
    
        return $return;
      }
    
    }
    add_filter( 'bp_notifications_get_notifications_for_user', 'bp_custom_format_buddypress_notifications', 10, 8 );

    I can’t see any code change in 3.0 that might have affected this. This filter is called in three places, and each place we pass eight parameters.

    If you can debug this, perhaps with wp_debug_backtrace() and find a code execution path, that would be handy.


    ethanstein
    Participant

    @ethanstein

    Okay, I figured out why it failed. I am using my own custom class to create notifications through bp_notifications_add_notification. There was something in my logic that resulted in the additional 3 not coming through. Thanks.

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.
Skip to toolbar