bbPress: Email the Admin About New Topics
Sends the site admin (or a moderator address) an email with the title, author and link whenever a new forum topic is posted.
Opens WPIDE on
Code
if ( ! function_exists( 'bbp_get_topic_permalink' ) ) {
return;
}
$wpide_bbp_notify_to = get_option( 'admin_email' );
$wpide_bbp_notify_forums = array();
add_action( 'bbp_new_topic', function ( $topic_id, $forum_id ) use ( $wpide_bbp_notify_to, $wpide_bbp_notify_forums ) {
if ( $wpide_bbp_notify_forums && ! in_array( (int) $forum_id, $wpide_bbp_notify_forums, true ) ) {
return;
}
wp_mail(
$wpide_bbp_notify_to,
sprintf( 'New topic in %s: %s', bbp_get_forum_title( $forum_id ), bbp_get_topic_title( $topic_id ) ),
sprintf(
"%s started a new topic.\n\n%s\n\n%s",
bbp_get_topic_author_display_name( $topic_id ),
wp_trim_words( wp_strip_all_tags( bbp_get_topic_content( $topic_id ) ), 60 ),
bbp_get_topic_permalink( $topic_id )
)
);
}, 10, 2 );
Notes
Limit it to some forums with $wpide_bbp_notify_forums; leave empty for all forums.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.