bbpress_topic_post_type = bbp_get_topic_post_type(); $this->bbpress_reply_post_type = bbp_get_reply_post_type(); } function bg_notify_new_reply($topic_id = 0, $forum_id = 0, $anonymous_data = false, $topic_author = 0) { wp_schedule_single_event(time() + 10, 'bbpress_notify_bg_reply', array($topic_id, $forum_id, $anonymous_data, $topic_author)); } function bg_notify_new_topic($topic_id = 0, $forum_id = 0, $anonymous_data = false, $topic_author = 0) { wp_schedule_single_event(time() + 10, 'bbpress_notify_bg_topic', array($topic_id, $forum_id, $anonymous_data, $topic_author)); } function deactivate_old() { $old_plugin = 'bbpress-notify/bbpress-notify.php'; if (is_plugin_active($old_plugin)) { deactivate_plugins($old_plugin); } } /** * Deprecated, the project did not get backing. */ function maybe_show_pro_message() { if ( isset($_GET['dismiss-bbpnp']) ) { update_option('bbpress-notify-pro-dismissed', true); } elseif ( ! get_option('bbpress-notify-pro-dismissed') ) { $url = add_query_arg( array( 'dismiss-bbpnp' => 1), $_SERVER['REQUEST_URI'] ); ?>
bbPress Notify Pro project at Kickstarter? ' . 'Help us reach the goal and get a nifty reward =] ! | Dismiss.',$url), $this->domain ); ?>
)/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_subject = str_replace("[$type-forum]", $forum, $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);
$email_body = str_replace("[$type-forum]", $forum, $email_body);
/**
* Allow subject and body modifications
* @since 1.6.6
*/
$email_subject = apply_filters('bbpnns_filter_email_subject_in_build', $email_subject);
$email_body = apply_filters('bbpnns_filter_email_body_in_build', $email_body);
return array($email_subject, $email_body);
}
/**
* @since 1.0
*/
function send_notification($recipients, $subject, $body)
{
$headers = sprintf("From: %s <%s>\r\n", get_option('blogname'), get_bloginfo('admin_email'));
$headers = apply_filters('bbpnns_extra_headers', $headers, $recipients, $subject, $body);
// Allow Management of recipients list
$recipients = apply_filters('bbpnns_filter_recipients_before_send', $recipients);
foreach ( (array) $recipients as $recipient_id)
{
$user_info = get_userdata($recipient_id);
/**
* Allow per user subject and body modifications
* @since 1.6.4
*/
$filtered_subject = apply_filters('bbpnns_filter_email_subject_for_user', $subject, $user_info);
$filtered_body = apply_filters('bbpnns_filter_email_body_for_user', $body, $user_info);
$email = ($recipient_id == -1) ? get_bloginfo('admin_email') : (string) $user_info->user_email ;
if (false === apply_filters('bbpnns_dry_run', false))
{
if ( ! wp_mail($email, $filtered_subject, $filtered_body, $headers) )
{
error_log('[bbPress Notify No Spam] wp_mail failed: ' . print_r(error_get_last(),1));
return false;
}
}
}
if (true === apply_filters('bbpnns_dry_run', false))
return array($recipients, $body);
return true;
}
/**
* @since 1.0
*/
/* Add the settings to the bbPress page in the Dashboard */
function admin_settings() {
// Add section to bbPress options
add_settings_section($this->settings_section, __('E-mail Notifications', 'bbpress_notify'), array(&$this,'_settings_intro_text'), 'bbpress');
// Add background option
add_settings_field('bbpress_notify_newtopic_background', __('Background Topic Notifications', 'bbpress_notify'), array(&$this,'_topic_background_inputfield'), 'bbpress', 'bbpress_notify_options');
// Add default notification option
add_settings_field("bbpress_notify_default_{$this->bbpress_topic_post_type}_notification", __('Admin UI Topic Notifications', 'bbpress_notify'), array(&$this,'_admin_ui_topic_inputfield'), 'bbpress', 'bbpress_notify_options');
// Add form fields for all settings
add_settings_field('bbpress_notify_newtopic_recipients', __('Notifications about new topics are sent to', 'bbpress_notify'), array(&$this,'_topic_recipients_inputfield'), 'bbpress', 'bbpress_notify_options');
add_settings_field('bbpress_notify_hidden_forum_topic_override', __('Force Admin-only emails if Forum is hidden (topics)', 'bbpress_notify'), array(&$this,'_hidden_forum_topic_override'), 'bbpress', 'bbpress_notify_options');
add_settings_field('bbpress_notify_newtopic_email_subject', __('E-mail subject', 'bbpress_notify'), array(&$this,'_email_newtopic_subject_inputfield'), 'bbpress', 'bbpress_notify_options');
add_settings_field('bbpress_notify_newtopic_email_body', __('E-mail body (template tags: [blogname], [topic-title], [topic-content], [topic-excerpt], [topic-author], [topic-url], [topic-forum], [topic-replyurl])', 'bbpress_notify'), array(&$this,'_email_newtopic_body_inputfield'), 'bbpress', 'bbpress_notify_options');
add_settings_field('bbpress_notify_newreply_background', __('Background Reply Notifications', 'bbpress_notify'), array(&$this,'_reply_background_inputfield'), 'bbpress', 'bbpress_notify_options');
// Add default notification option
add_settings_field("bbpress_notify_default_{$this->bbpress_reply_post_type}_notification", __('Admin UI Reply Notifications', 'bbpress_notify'), array(&$this,'_admin_ui_reply_inputfield'), 'bbpress', 'bbpress_notify_options');
add_settings_field('bbpress_notify_newreply_recipients', __('Notifications about replies are sent to', 'bbpress_notify'), array(&$this,'_reply_recipients_inputfield'), 'bbpress', 'bbpress_notify_options');
add_settings_field('bbpress_notify_hidden_forum_reply_override', __('Force Admin-only emails if Forum is hidden (replies)', 'bbpress_notify'), array(&$this,'_hidden_forum_reply_override'), 'bbpress', 'bbpress_notify_options');
add_settings_field('bbpress_notify_newreply_email_subject', __('E-mail subject', 'bbpress_notify'), array(&$this,'_email_newreply_subject_inputfield'), 'bbpress', 'bbpress_notify_options');
add_settings_field('bbpress_notify_newreply_email_body', __('E-mail body (template tags: [blogname], [reply-title], [reply-content], [reply-excerpt], [reply-author], [reply-url], [reply-forum], [reply-replyurl])', 'bbpress_notify'), array(&$this,'_email_newreply_body_inputfield'), 'bbpress', 'bbpress_notify_options');
// Register the settings as part of the bbPress settings
register_setting('bbpress', 'bbpress_notify_newtopic_recipients');
register_setting('bbpress', 'bbpress_notify_hidden_forum_topic_override');
register_setting('bbpress', 'bbpress_notify_hidden_forum_reply_override');
register_setting('bbpress', 'bbpress_notify_newtopic_email_subject');
register_setting('bbpress', 'bbpress_notify_newtopic_email_body');
register_setting('bbpress', 'bbpress_notify_newtopic_background');
register_setting('bbpress', 'bbpress_notify_newreply_recipients');
register_setting('bbpress', 'bbpress_notify_newreply_email_subject');
register_setting('bbpress', 'bbpress_notify_newreply_email_body');
register_setting('bbpress', 'bbpress_notify_newreply_background');
register_setting('bbpress', "bbpress_notify_default_{$this->bbpress_topic_post_type}_notification");
register_setting('bbpress', "bbpress_notify_default_{$this->bbpress_reply_post_type}_notification");
}
/**
* @since 1.0
*/
function _settings_intro_text($args)
{
printf('%s', $args['id'], __('Configure e-mail notifications when new topics and/or replies are posted.', 'bbpress_notify'));
}
/**
* @since 1.3
*/
function _topic_background_inputfield()
{
$saved_option = get_option('bbpress_notify_newtopic_background');
$html_checked = ( $saved_option ) ? 'checked="checked"' : '';
$description = __('Send emails in the background the next time the site is visited', 'bbpress_notify');
printf(' %s
', $html_checked, $description);
}
/**
* @since 1.3
*/
function _reply_background_inputfield()
{
$saved_option = get_option('bbpress_notify_newreply_background');
$html_checked = ( $saved_option ) ? 'checked="checked"' : '';
$description = __('Send emails in the background the next time the site is visited', 'bbpress_notify');
printf(' %s
', $html_checked, $description);
}
/**
* @since 1.0
*/
/* Show a