Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to Stop Admin subscription emails…


  • manheim
    Participant

    @jasonmanheim

    We’re getting an email to noreply@ourwebsite.com every single time someone posts a reply. Looking into bbpress/includes/common/function.php starting on line 1023 it looks like this is the intended behavior. It sends an email to:

    $do_not_reply = '<noreply@' . ltrim( get_home_url(), '^(http|https)://' ) . '>';

    …and it BCC’s any users who are subscribed:
    wp_mail( $do_not_reply, $subject, $message, $headers );

    This seems silly. Am I really reading this right? Why can we not disable emails coming to noreply@ ? Big forums will get hundreds of emails a day….

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

  • tharsheblows
    Participant

    @tharsheblows

    The reason for this is that sending out subscription emails one by one was appreciably slowing down some large sites, so in the last update they switched to bcc’ing in subscribers.

    It’s fairly straightforward to change how the subscription emails are handled once you know how. If you unhook ‘bbp_notify_topic_subscribers’ you can then hook in your own subscription function.

    Below is similar to what I did – I have it in a plugin but you could put it in your bbpress-functions.php file too, I think – this should be in a child theme. If you do this, please test it first as this is simply an example and not necessarily working code. I’ve gone ahead and simply pasted in the function that was used in the previous version of bbPress so you don’t have to find it.

    //custom topic subscription emails, unhook old function, hook in new one
    remove_action( 'bbp_new_reply',    'bbp_notify_topic_subscribers', 11, 5 );
    add_action( 'bbp_new_reply',    'mjj_bbp_notify_topic_subscribers', 11, 5 );
    
    /** 
    * from bbpress / includes / common / functions.php
    * this is taken from 2.5.3 - I've left in all comments to make it easier to understand
    **/
    
    /** Subscriptions *************************************************************/
    
    /**
     * Sends notification emails for new replies to subscribed topics
     *
     * Gets new post's ID and check if there are subscribed users to that topic, and
     * if there are, send notifications
     *
     * @since bbPress (r2668)
     *
     * @param int $reply_id ID of the newly made reply
     * @uses bbp_is_subscriptions_active() To check if the subscriptions are active
     * @uses bbp_get_reply_id() To validate the reply ID
     * @uses bbp_get_topic_id() To validate the topic ID
     * @uses bbp_get_forum_id() To validate the forum ID
     * @uses bbp_get_reply() To get the reply
     * @uses bbp_is_reply_published() To make sure the reply is published
     * @uses bbp_get_topic_id() To validate the topic ID
     * @uses bbp_get_topic() To get the reply's topic
     * @uses bbp_is_topic_published() To make sure the topic is published
     * @uses bbp_get_reply_author_display_name() To get the reply author's display name
     * @uses do_action() Calls 'bbp_pre_notify_subscribers' with the reply id,
     *                    topic id and user id
     * @uses bbp_get_topic_subscribers() To get the topic subscribers
     * @uses apply_filters() Calls 'bbp_subscription_mail_message' with the
     *                    message, reply id, topic id and user id
     * @uses apply_filters() Calls 'bbp_subscription_mail_title' with the
     *                    topic title, reply id, topic id and user id
     * @uses apply_filters() Calls 'bbp_subscription_mail_headers'
     * @uses get_userdata() To get the user data
     * @uses wp_mail() To send the mail
     * @uses do_action() Calls 'bbp_post_notify_subscribers' with the reply id,
     *                    topic id and user id
     * @return bool True on success, false on failure
     */
    function mjj_bbp_notify_subscribers( $reply_id = 0, $topic_id = 0, $forum_id = 0, $anonymous_data = false, $reply_author = 0 ) {
    
    	// Bail if subscriptions are turned off
    	if ( !bbp_is_subscriptions_active() )
    		return false;
    
    	/** Validation ************************************************************/
    
    	$reply_id = bbp_get_reply_id( $reply_id );
    	$topic_id = bbp_get_topic_id( $topic_id );
    	$forum_id = bbp_get_forum_id( $forum_id );
    
    	/** Reply *****************************************************************/
    
    	// Bail if reply is not published
    	if ( !bbp_is_reply_published( $reply_id ) )
    		return false;
    
    	/** Topic *****************************************************************/
    
    	// Bail if topic is not published
    	if ( !bbp_is_topic_published( $topic_id ) )
    		return false;
    
    	/** User ******************************************************************/
    
    	// Get topic subscribers and bail if empty
    	$user_ids = bbp_get_topic_subscribers( $topic_id, true );
    	if ( empty( $user_ids ) )
    		return false;
    
    	// Poster name
    	$reply_author_name = bbp_get_reply_author_display_name( $reply_id );
    
    	/** Mail ******************************************************************/
    
    	do_action( 'bbp_pre_notify_subscribers', $reply_id, $topic_id, $user_ids );
    
    	// Remove filters from reply content and topic title to prevent content
    	// from being encoded with HTML entities, wrapped in paragraph tags, etc...
    	remove_all_filters( 'bbp_get_reply_content' );
    	remove_all_filters( 'bbp_get_topic_title'   );
    
    	// Strip tags from text
    	$topic_title   = strip_tags( bbp_get_topic_title( $topic_id ) );
    	$reply_content = strip_tags( bbp_get_reply_content( $reply_id ) );
    	$reply_url     = bbp_get_reply_url( $reply_id );
    	$blog_name     = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
    
    	// Loop through users
    	foreach ( (array) $user_ids as $user_id ) {
    
    		// Don't send notifications to the person who made the post
    		if ( !empty( $reply_author ) && (int) $user_id === (int) $reply_author )
    			continue;
    
    		// For plugins to filter messages per reply/topic/user
    		$message = sprintf( __( '%1$s wrote:
    
    %2$s
    
    Post Link: %3$s
    
    -----------
    
    You are receiving this email because you subscribed to a forum topic.
    
    Login and visit the topic to unsubscribe from these emails.', 'bbpress' ),
    
    			$reply_author_name,
    			$reply_content,
    			$reply_url
    		);
    
    		$message = apply_filters( 'bbp_subscription_mail_message', $message, $reply_id, $topic_id, $user_id );
    		if ( empty( $message ) )
    			continue;
    
    		// For plugins to filter titles per reply/topic/user
    		$subject = apply_filters( 'bbp_subscription_mail_title', '[' . $blog_name . '] ' . $topic_title, $reply_id, $topic_id, $user_id );
    		if ( empty( $subject ) )
    			continue;
    
    		// Custom headers
    		$headers = apply_filters( 'bbp_subscription_mail_headers', array() );
    
    		// Get user data of this user
    		$user = get_userdata( $user_id );
    
    		// Send notification email
    		wp_mail( $user->user_email, $subject, $message, $headers );
    	}
    
    	do_action( 'bbp_post_notify_subscribers', $reply_id, $topic_id, $user_ids );
    
    	return true;
    }

    manheim
    Participant

    @jasonmanheim

    Fantastic. Thanks.

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