My notification test would get blank / empty
-
I am going to create a new custom notification for a user that if someone mention the user in any review with @, the related user will get a email and a new notification has been generated, this notification I created dynamically, but I get empty message showing on user profile notification area, I checked the db_table for notification as well it has proper entries as well,
$description = apply_filters_ref_array( 'bp_notifications_get_notifications_for_user', array( $notification->component_action, $notification->item_id, $notification->secondary_item_id, 1, 'string', $notification->component_action, $notification->component_name, $notification->id ) );
In the above line I found that ‘bp_notifications_get_notifications_for_user’ filter return me the empty description of my notification from line no 523 in function “bp_get_the_notification_description” of file buddypress/bp-notifications/bp-notifications-template.php
Below is my custom code for generate notification:
//add new notification mention_in_comment function mention_in_comment_filter_notifications_publish_post_get_registered_components( $component_names = array() ) { // Force $component_names to be an array if ( ! is_array( $component_names ) ) { $component_names = array(); } // Add 'custom' component to registered components array array_push( $component_names, 'mention_in_comment' ); // Return component's with 'custom' appended return $component_names; } add_filter( 'bp_notifications_get_registered_components', 'mention_in_comment_filter_notifications_publish_post_get_registered_components' ); //show new notification text function bp_mention_in_comment_format_buddypress_notifications( $action, $item_id, $secondary_item_id, $total_items, $format = 'string' ) { // New custom notifications if ( 'mention_in_comment_action' === $action ) { $comment_info = get_comment( $item_id ); $author_name = ($comment_info->user_id) ? get_the_author_meta( 'display_name', $comment_info->user_id ) : $comment_info->comment_author; $custom_title = $author_name. ' mentioned you in a new comment on '.get_the_title($comment_info->comment_post_ID); $custom_link = get_comment_link( $comment_info->comment_ID ); $custom_text = $author_name. ' mentioned you in a new comment: <br/>' . $comment_info->comment_content; // WordPress Toolbar if ( 'string' === $format ) { $return = apply_filters( 'mention_in_comment_filter', '' . esc_html( $custom_text ) . '', $custom_text, $custom_link ); // Deprecated BuddyBar } else { $return = apply_filters( 'mention_in_comment_filter', array( 'text' => $custom_text, 'link' => $custom_link ), $custom_link, (int) $total_items, $custom_text, $custom_title ); } //var_dump($return); return "Just say hello."; } } add_filter( 'bp_notifications_get_notifications_for_user', 'bp_mention_in_comment_format_buddypress_notifications', 1, 5 ); //add notification to the mentioned user $notification = bp_notifications_add_notification( array( 'user_id' => $user_id, 'item_id' => $comment->comment_ID, 'secondary_item_id' => $user_id, 'component_name' => 'mention_in_comment', 'component_action' => 'mention_in_comment_action', 'date_notified' => bp_core_current_time(), 'is_new' => 1) );
Could you please let me knwo what is wrong with my code or something else, how can more debug and solve this.
- You must be logged in to reply to this topic.