Skip to:
Content
Pages
Categories
Search
Top
Bottom

Admin notification for all activity


  • chrismalone617
    Participant

    @chrismalone617

    We are starting a new community and want our Admins to receive email notification for all activity on the site. We won’t do that forever but want to at the beginning. How could I achieve that?

Viewing 4 replies - 1 through 4 (of 4 total)

  • Venutius
    Moderator

    @venutius

    Hi there, yes this is possible. You would need to hook on the filter bp_activity_add and use that to send an email to the site admin. You could add this to your child thees functions.php:

    add_filter( 'bp_activity_add', 'venutius_activity_admin_notify', 10, 2 );
    
    function venutius_activity_admin_notify( $activity_array, $activity_id ) {
    	$site_admin_email = get_option( 'admin_email' );
    	$username = bp_core_get_username( $activity_array['user_id']);
    	$view_link = bp_get_root_domain() . '/' . bp_get_activity_root_slug() . '/p/' . $activity_id;
    	$subject                  = 'New Activity Posted ';
    	$message                  = 'A new activity has been published.';
    	$message                 .= "\r\n\r\n";
    	$message                 .= 'Author' . ': ' . $username . "\r\n";
    	$message                 .= 'View the activity' . ': ' . $view_link;
    	$result                   = wp_mail( $site_admin_email, $subject, $message );
    }

    chrismalone617
    Participant

    @chrismalone617

    Thank you SO much! It works perfectly. Hopefully, it won’t be long til we have enough members on the community that it will be overwhelming to get notifications of all activity.


    rezocom
    Participant

    @rezocom

    Hello,
    Thanks for this one…
    Is it possible to directly receive the “message” of the content of the activity ? instead of only link… 🙂

    The content of the activity item would be $activity_array['content']. You can see the action that Venutius was using here: https://buddypress.trac.wordpress.org/browser/tags/5.0.0/src/bp-activity/bp-activity-functions.php#L1931

    So you’d just add something like
    $message .= "$activity_array['content']";
    to the code posted above.

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