Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Same question more money WordPress

  • REFUNDED

Buddypress sends a notification when a user gets a new message on their wall. Clicking that notification takes the user to the activity.

Buddypress also sends a notification when a user leaves a comment/reply on the original wall message. Clicking that notification links to a page that can't be found.

I need to change the notification so that if the user is being notified of a reply on a wall post, it links to the parent wall post instead of directly to the activity ID.

Notifications are provided by the bp-wall plugin (https://wordpress.org/plugins/buddypress-wall/)

This is the notification code:

[[LINK href="null"]]<blockquote></blockquote>[[/LINK]]

if ( bp_is_active( 'notifications' ) ) {

bp_notifications_add_notification( array(

'user_id' => $displayed_user->id,

'item_id' => $activity->id,

'secondary_item_id' => $loggedin_user->id,

'component_name' => $bp->activity->id,

'component_action' => 'new_at_wall',

'date_notified' => bp_core_current_time(),

'is_new' => 1,

) );

}

Answers (5)

2015-03-10

Kyle answers:

Some stuff that would help is the HTML from the email so we can see what variable is used for the link. Also if you dump the activity variable we could see that.

My initial thought is this:

if ( bp_is_active( 'notifications' ) ) {

$child = get_post( $activity->id );

bp_notifications_add_notification( array(

'user_id' => $displayed_user->id,

'item_id' => $child->post_parent,

'secondary_item_id' => $loggedin_user->id,

'component_name' => $bp->activity->id,

'component_action' => 'new_at_wall',

'date_notified' => bp_core_current_time(),

'is_new' => 1,

) );

}


Kyle comments:

Additionally, it looks like you could actually apply a filter directly to the message itself and make it say whatever you want, rather than just playing with what is sent to it.

The filter is bp_activity_at_message_notification_message which has a parameter called $message_link which contains the permalink to the activity. So you could use that permalink with something like url_to_postid(); to filter the link.

Something like:

add_filter('bp_activity_at_message_notification_message','',10,5);
function change_the_link($message, $poster_name, $content, $message_link, $settings_link){

$postid = url_to_postid( $message_link );
$post = get_post( $postid );
$new_message_link = get_permalink( $post->post_parent );

$new_message = 'You have been mentioned in a post '.$poster_name.', you can view it here: '. $new_message_link;

return $new_message;


}

2015-03-10

Ian Lincicome answers:

If no one else comes through for you with a quick answer, you can hire me to do it for the question amount, but I would require access to the site. I don't want to attempt to troubleshoot back and forth for an issue that can be fixed easy enough if I were to have FTP access. ...or Skype me at ianlin11 if you want to work it out asap. I am a plugin and theme developer, so this rather simple modification won't be difficult once provided with the proper access. The code you provided is only a piece of a larger puzzle.

2015-03-10

Romel Apuya answers:

Hi Please try this

if ( bp_is_active( 'notifications' ) ) {

$act_item = bp_activity_get_specific( array(
'display_comments' => true,
'activity_ids' => $activity->id
) );

bp_notifications_add_notification( array(
'user_id' => $displayed_user->id,
'item_id' => $act_item,
'secondary_item_id' => $loggedin_user->id,
'component_name' => $bp->activity->id,
'component_action' => 'new_at_wall',
'date_notified' => bp_core_current_time(),
'is_new' => 1,
) );
}

2015-03-10

Arnav Joy answers:

Hi ,
can you show me your site ?

2015-03-10

Andrea P answers:

I think Romel answer could be nearly correct.

but the output of bp_get_activity_specific is an array of objects, so needs to be singled


f ( bp_is_active( 'notifications' ) ) {

$act_item_arr = bp_activity_get_specific( array(

'display_comments' => true,

'activity_ids' => $activity->id

) );

$act_item = $act_item_arr [0];


bp_notifications_add_notification( array(

'user_id' => $displayed_user->id,

'item_id' => $act_item->id,

'secondary_item_id' => $loggedin_user->id,

'component_name' => $bp->activity->id,

'component_action' => 'new_at_wall',

'date_notified' => bp_core_current_time(),

'is_new' => 1,

) );

}