Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author useStrict

    (@usestrict)

    It’s not on Github, but feel free to paste your diff here and I’ll integrate them into the plugin.

    Thanks for contributing!

    Thread Starter chaoix

    (@chaoix)

    Here are my updated functions:

    function notify_new_topic($topic_id = 0, $forum_id = 0)
    	{
    		global $wpdb;
    
    		$status = get_post_status($topic_id); 
    
    		if ( 'spam' === $status || 'publish' !== $status )
    			return -1;
    
    		if (0 === $forum_id)
    			$forum_id = bbp_get_topic_forum_id($topic_id);
    
    		if (true === apply_filters('bbpnns_skip_topic_notification', false, $forum_id, $topic_id))
    			return -3;
    
    		$opt_recipients = apply_filters('bbpress_notify_recipients_hidden_forum', get_option('bbpress_notify_newtopic_recipients'), $forum_id);
    
    		$recipients = array();
    		foreach ((array)$opt_recipients as $opt_recipient)
    		{
    			if (! $opt_recipient) continue;
    
    			$users = get_users(array('role' => $opt_recipient));
    			foreach ((array)$users as $user)
    			{
    				$user = get_object_vars($user);
    				$recipients[$user['ID']] = $user['ID']; // make sure unique recepients
    			}
    		}
    
    		$recipients = apply_filters('bbpress_topic_notify_recipients', $recipients, $topic_id, $forum_id);
    
    		if ( empty($recipients) )
    			return -2;
    
    		list($email_subject, $email_body) = $this->_build_email('topic', $topic_id);
    
    		return $this->send_notification($recipients, $email_subject, $email_body);
    	}
    function notify_new_reply($reply_id = 0, $topic_id = 0, $forum_id = 0)
    	{
    		global $wpdb;
    
    		$status = get_post_status($reply_id); 
    
    		if ( 'spam' === $status || 'publish' !== $status )
    			return -1;
    
    		if (true === apply_filters('bbpnns_skip_reply_notification', false, $forum_id, $topic_id, $reply_id))
    			return -3;
    
    		$opt_recipients = apply_filters('bbpress_notify_recipients_hidden_forum', get_option('bbpress_notify_newreply_recipients'), $forum_id);
    
    		$recipients = array();
    		foreach ((array)$opt_recipients as $opt_recipient)
    		{
    			if (! $opt_recipient) continue;
    
    			$users = get_users(array('role' => $opt_recipient));
    			foreach ((array)$users as $user)
    			{
    				$user = get_object_vars($user);
    				$recipients[$user['ID']] = $user['ID']; // make sure unique recepients
    			}
    		}
    
    		$recipients = apply_filters('bbpress_reply_notify_recipients', $recipients, $reply_id, $topic_id, $forum_id);
    
    		if ( empty($recipients) )
    			return -2;
    
    		list($email_subject, $email_body) = $this->_build_email('reply', $reply_id);
    
    		return $this->send_notification($recipients, $email_subject, $email_body);
    	}

    I added the ‘bbpress_topic_notify_recipients’ and the ‘bbpress_reply_notify_recipients’ filters as a way to manually add user ids to notify based on custom criteria.

    Thread Starter chaoix

    (@chaoix)

    Another change to the plugin to add basic HTML formatting to the email notifications:

    private function _build_email($type, $post_id)
    	{
    		$email_subject = get_option("bbpress_notify_new{$type}_email_subject");
    		$email_body    = get_option("bbpress_notify_new{$type}_email_body");
    
    		$blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
    		$excerpt_size = apply_filters('bpnns_excerpt_size', 100);
    
    		// Replace shortcodes
    		if ('topic' === $type)
    		{
    			$content = bbp_get_topic_content($post_id);
    			$title   = html_entity_decode(strip_tags(bbp_get_topic_title($post_id)), ENT_NOQUOTES, 'UTF-8');
    			$excerpt = html_entity_decode(strip_tags(bbp_get_topic_excerpt($post_id, $excerpt_size)), ENT_NOQUOTES, 'UTF-8');
    			$author  = bbp_get_topic_author($post_id);
    			$url     = apply_filters( 'bbpnns_topic_url', bbp_get_topic_permalink($post_id), $post_id, $title );
    		}
    		elseif ('reply' === $type)
    		{
    			$content = bbp_get_reply_content($post_id);
    			$title   = html_entity_decode(strip_tags(bbp_get_reply_title($post_id)), ENT_NOQUOTES, 'UTF-8');
    			$excerpt = html_entity_decode(strip_tags(bbp_get_reply_excerpt($post_id, $excerpt_size)), ENT_NOQUOTES, 'UTF-8');
    			$author  = bbp_get_reply_author($post_id);
    			$url     = apply_filters( 'bbpnns_reply_url', bbp_get_reply_permalink($post_id), $post_id, $title );
    		}
    		else
    		{
    			wp_die('Invalid type!');
    		}
    
    		$content = preg_replace('/<br\s*\/?>/is', "\n", $content);
    		$content = preg_replace('/(?:<\/p>\s*<p>)/ism', "\n\n", $content);
    		$content = html_entity_decode(strip_tags($content), ENT_NOQUOTES, 'UTF-8');
    
    		$topic_reply = apply_filters( 'bbpnns_topic_reply', bbp_get_reply_url($post_id), $post_id, $title );
    
    		$email_subject = str_replace('[blogname]', $blogname, $email_subject);
    		$email_subject = str_replace("[$type-title]", $title, $email_subject);
    		$email_subject = str_replace("[$type-content]", $content, $email_subject);
    		$email_subject = str_replace("[$type-excerpt]", $excerpt, $email_subject);
    		$email_subject = str_replace("[$type-author]", $author, $email_subject);
    		$email_subject = str_replace("[$type-url]", $url, $email_subject);
    		$email_subject = str_replace("[$type-replyurl]", $topic_reply, $email_subject);
    
    		$email_body = str_replace('[blogname]', $blogname, $email_body);
    		$email_body = str_replace("[$type-title]", $title, $email_body);
    		$email_body = str_replace("[$type-content]", $content, $email_body);
    		$email_body = str_replace("[$type-excerpt]", $excerpt, $email_body);
    		$email_body = str_replace("[$type-author]", $author, $email_body);
    		$email_body = str_replace("[$type-url]", $url, $email_body);
    		$email_body = str_replace("[$type-replyurl]", $topic_reply, $email_body);
    
    		// Sanitize line endings
    		$email_body = str_replace(array("\r\n", "\r"), "\n", $email_body);
    		//Add basic HTML formatting
    		$email_body = nl2br($email_body);
    
    		return array($email_subject, $email_body);
    	}

    Plugin Author useStrict

    (@usestrict)

    Hi chaoix,

    I’ve added your filters to 1.6.5 (just released). Have a look also at the filters added in 1.6.4.

    Regarding your HTML changes, I’ll add a general filter to the email subject and body lines (aside from the ones I added in 1.6.4) so you can massage the message however you prefer. In the future I’ll work on adding multitype messages with MIME as many people don’t want to receive HTML messages.

    Plugin Author useStrict

    (@usestrict)

    In version 1.6.6, added filters to the subject and body inside _build_email().

    Cheers,
    Vinny

    Thread Starter chaoix

    (@chaoix)

    Awesome, Vinny. Thanks for accepting my contributions.

    Love the plugin btw. It is working great.

    Would you be open to starting a Github or Bitbucket repo for future contributions? I would love to add a couple other things like Mandrill or Railgun support. I don’t mind copy/pasting code diffs for you on the forums, but we could probably get contributions from other developers in the future if we maintained a repo.

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

The topic ‘Plugin on Github?’ is closed to new replies.