I have a feature on my BuddyPress groups when I send out custom notifications to all members when a group activity is posted as an announcement. There is a possibility that something could go wrong of course and so I want to be able to add an error message to the activity if the notification fails to send.

Since my notification is hooked to the bp_activity_after_save action the update will already be posted so I still want the post to appear on the activity feed but just make the user aware that the notifications were not sent for a given reason.

add_action( 'bp_activity_after_save', array( $this, 'send_team_notification'), 10, 1 );

I've tried to look for a filter or something I could use to modify the content of the activity before it was posted but unfortunately I couldn't find anything of use so far.


With enough digging I figured it out. First off you must save your error message to as activity meta data like so:

public function send_team_notification($activity) {
    $message = $this->send_custom_notification($activity->content);
        bp_activity_update_meta( $activity->id, 'custom_error', $message );

This will appear in the database under the wp_bp_activity_meta table like so:

enter image description here

From there you can either manually update your theme template file, buddypress\activity\entry.php otherwise I chose to hook into the bp_activity_entry_meta action like so:

add_action('bp_activity_entry_meta', array( $this, 'add_activity_error') );
function add_activity_error(){
    $error = bp_activity_get_meta(bp_get_activity_id(), 'custom_error');
    _e('<div><p class="error">'.$error->get_error_message('error-code').'</p></div>');

Hope that helps!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.