/** * Send a notification to subscribers * * @wp-filter bbp_new_reply 1 */ public function notify_on_reply($reply_id = 0, $topic_id = 0, $forum_id = 0, $anonymous_data = false, $reply_author = 0) { if ($this->handler === null) { return false; } global $wpdb; if (!bbp_is_subscriptions_active()) { return false; } $reply_id = bbp_get_reply_id($reply_id); $topic_id = bbp_get_topic_id($topic_id); $forum_id = bbp_get_forum_id($forum_id); if (!bbp_is_reply_published($reply_id)) { return false; } if (!bbp_is_topic_published($topic_id)) { return false; } $user_ids = bbp_get_topic_subscribers($topic_id, true); if (empty($user_ids)) { return false; } // Poster name $reply_author_name = apply_filters('bbsub_reply_author_name', bbp_get_reply_author_display_name($reply_id)); do_action('bbp_pre_notify_subscribers', $reply_id, $topic_id, $user_ids); // Don't send notifications to the person who made the post $send_to_author = Falcon::get_option('bbsub_send_to_author', false); if (!$send_to_author && !empty($reply_author)) { $user_ids = array_filter($user_ids, function ($id) use($reply_author) { return (int) $id !== (int) $reply_author; }); } // Get userdata for all users $user_ids = array_map(function ($id) { return get_userdata($id); }, $user_ids); // Sanitize the HTML into text $content = apply_filters('bbsub_html_to_text', bbp_get_reply_content($reply_id)); // Build email $text = "%1\$s\n\n"; $text .= "---\nReply to this email directly or view it online:\n%2\$s\n\n"; $text .= "You are receiving this email because you subscribed to it. Login and visit the topic to unsubscribe from these emails."; $text = sprintf($text, $content, bbp_get_reply_url($reply_id)); $text = apply_filters('bbsub_email_message', $text, $reply_id, $topic_id, $content); $subject = apply_filters('bbsub_email_subject', 'Re: [' . get_option('blogname') . '] ' . bbp_get_topic_title($topic_id), $reply_id, $topic_id); $options = array('id' => $topic_id, 'author' => $reply_author_name); $this->handler->send_mail($user_ids, $subject, $text, $options); do_action('bbp_post_notify_subscribers', $reply_id, $topic_id, $user_ids); return true; }
/** * Update the forum last topic id * * @since bbPress (r2625) * * @param int $forum_id Optional. Forum id * @param int $topic_id Optional. Topic id * @uses bbp_get_forum_id() To get the forum id * @uses bbp_forum_query_subforum_ids() To get the subforum ids * @uses bbp_update_forum_last_topic_id() To update the last topic id of child * forums * @uses get_posts() To get the most recent topic in the forum * @uses update_post_meta() To update the forum's last active id meta * @uses apply_filters() Calls 'bbp_update_forum_last_topic_id' with the last * reply id and forum id * @return bool True on success, false on failure */ function bbp_update_forum_last_topic_id($forum_id = 0, $topic_id = 0) { $forum_id = bbp_get_forum_id($forum_id); // Define local variable(s) $children_last_topic = 0; // Do some calculation if not manually set if (empty($topic_id)) { // Loop through children and add together forum reply counts $children = bbp_forum_query_subforum_ids($forum_id); if (!empty($children)) { foreach ((array) $children as $child) { $children_last_topic = bbp_update_forum_last_topic_id($child); // Recursive } } // Setup recent topic query vars $post_vars = array('post_parent' => $forum_id, 'post_type' => bbp_get_topic_post_type(), 'meta_key' => '_bbp_last_active_time', 'orderby' => 'meta_value', 'numberposts' => 1); // Get the most recent topic in this forum_id $recent_topic = get_posts($post_vars); if (!empty($recent_topic)) { $topic_id = $recent_topic[0]->ID; } } // Cast as integer in case of empty or string $topic_id = (int) $topic_id; $children_last_topic = (int) $children_last_topic; // If child forums have higher id, use that instead if (!empty($children) && $children_last_topic > $topic_id) { $topic_id = $children_last_topic; } // Update the last public topic ID if (bbp_is_topic_published($topic_id)) { update_post_meta($forum_id, '_bbp_last_topic_id', $topic_id); } return (int) apply_filters('bbp_update_forum_last_topic_id', $topic_id, $forum_id); }
/** * Record an activity stream entry when a topic is created or updated * * @since bbPress (r3395) * @param int $topic_id * @param int $forum_id * @param array $anonymous_data * @param int $topic_author_id * @uses bbp_get_topic_id() * @uses bbp_get_forum_id() * @uses bbp_get_user_profile_link() * @uses bbp_get_topic_permalink() * @uses bbp_get_topic_title() * @uses bbp_get_topic_content() * @uses bbp_get_forum_permalink() * @uses bbp_get_forum_title() * @uses bp_create_excerpt() * @uses apply_filters() * @return Bail early if topic is by anonymous user */ public function topic_create($topic_id, $forum_id, $anonymous_data, $topic_author_id) { // Bail early if topic is by anonymous user if (!empty($anonymous_data)) { return; } // Bail if site is private if (!bbp_is_site_public()) { return; } // Validate activity data $user_id = $topic_author_id; $topic_id = bbp_get_topic_id($topic_id); $forum_id = bbp_get_forum_id($forum_id); // Bail if user is not active if (bbp_is_user_inactive($user_id)) { return; } // Bail if topic is not published if (!bbp_is_topic_published($topic_id)) { return; } // User link for topic author $user_link = bbp_get_user_profile_link($user_id); // Topic $topic_permalink = bbp_get_topic_permalink($topic_id); $topic_title = get_post_field('post_title', $topic_id, 'raw'); $topic_content = get_post_field('post_content', $topic_id, 'raw'); $topic_link = '<a href="' . $topic_permalink . '" title="' . $topic_title . '">' . $topic_title . '</a>'; // Forum $forum_permalink = bbp_get_forum_permalink($forum_id); $forum_title = get_post_field('post_title', $forum_id, 'raw'); $forum_link = '<a href="' . $forum_permalink . '" title="' . $forum_title . '">' . $forum_title . '</a>'; // Activity action & text $activity_text = sprintf(__('%1$s started the topic %2$s in the forum %3$s', 'bbpress'), $user_link, $topic_link, $forum_link); $activity_action = apply_filters('bbp_activity_topic_create', $activity_text, $user_id, $topic_id, $forum_id); $activity_content = apply_filters('bbp_activity_topic_create_excerpt', bp_create_excerpt($topic_content), $topic_content); // Compile the activity stream results $activity = array('id' => $this->get_activity_id($topic_id), 'user_id' => $user_id, 'action' => $activity_action, 'content' => $activity_content, 'primary_link' => $topic_permalink, 'type' => $this->topic_create, 'item_id' => $topic_id, 'secondary_item_id' => $forum_id, 'recorded_time' => get_post_time('Y-m-d H:i:s', true, $topic_id), 'hide_sitewide' => !bbp_is_forum_public($forum_id, false)); // Record the activity $activity_id = $this->record_activity($activity); // Add the activity entry ID as a meta value to the topic if (!empty($activity_id)) { update_post_meta($topic_id, '_bbp_activity_id', $activity_id); } }
/** * Send priority messages to Hall * * @since 1.0.0 * @param int $topic_id The ID of this topic * @param int $forum_id The ID of the forum this topic belongs to * @param bool $anonymous_data * @param int $topic_author The author of this topic * @return void */ function edd_bbp_send_priority_to_hall($topic_id = 0, $forum_id = 0, $anonymous_data = false, $topic_author = 0) { // Bail if topic is not published if (!bbp_is_topic_published($topic_id)) { return; } if ($forum_id != 499) { return; } $json = json_encode(array('title' => 'A new priority ticket has been posted', 'message' => esc_html(get_the_title($topic_id)) . ' - ' . esc_url(get_permalink($topic_id)))); $args = array('headers' => array('content-type' => 'application/json'), 'body' => $json, 'timeout' => 15, 'sslverify' => false); wp_remote_post('https://hall.com/api/1/services/generic/7a4672fbb62a48920058d7cc0c1da6c8', $args); }
/** * Sends notification emails for new topics to subscribed forums * * Gets new post's ID and check if there are subscribed users to that forum, and * if there are, send notifications * * Note: in bbPress 2.6, we've moved away from 1 email per subscriber to 1 email * with everyone BCC'd. This may have negative repercussions for email services * that limit the number of addresses in a BCC field (often to around 500.) In * those cases, we recommend unhooking this function and creating your own * custom emailer script. * * @since 2.5.0 bbPress (r5156) * * @param int $topic_id ID of the newly made reply * @param int $forum_id ID of the forum for the topic * @param mixed $anonymous_data Array of anonymous user data * @param int $topic_author ID of the topic author ID * * @uses bbp_is_subscriptions_active() To check if the subscriptions are active * @uses bbp_get_topic_id() To validate the topic ID * @uses bbp_get_forum_id() To validate the forum ID * @uses bbp_is_topic_published() To make sure the topic is published * @uses bbp_get_forum_subscribers() To get the forum subscribers * @uses bbp_get_topic_author_display_name() To get the topic author's display name * @uses do_action() Calls 'bbp_pre_notify_forum_subscribers' with the topic id, * forum id and user id * @uses apply_filters() Calls 'bbp_forum_subscription_mail_message' with the * message, topic id, forum id and user id * @uses apply_filters() Calls 'bbp_forum_subscription_mail_title' with the * topic title, topic id, forum id and user id * @uses apply_filters() Calls 'bbp_forum_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_forum_subscribers' with the topic, * id, forum id and user id * @return bool True on success, false on failure */ function bbp_notify_forum_subscribers($topic_id = 0, $forum_id = 0, $anonymous_data = false, $topic_author = 0) { // Bail if subscriptions are turned off if (!bbp_is_subscriptions_active()) { return false; } /** Validation ************************************************************/ $topic_id = bbp_get_topic_id($topic_id); $forum_id = bbp_get_forum_id($forum_id); /** * Necessary for backwards compatibility * * @see https://bbpress.trac.wordpress.org/ticket/2620 */ $user_id = 0; /** Topic *****************************************************************/ // Bail if topic is not published if (!bbp_is_topic_published($topic_id)) { return false; } // Poster name $topic_author_name = bbp_get_topic_author_display_name($topic_id); /** Mail ******************************************************************/ // 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_topic_content'); remove_all_filters('bbp_get_topic_title'); // Strip tags from text and setup mail data $topic_title = strip_tags(bbp_get_topic_title($topic_id)); $topic_content = strip_tags(bbp_get_topic_content($topic_id)); $topic_url = get_permalink($topic_id); $blog_name = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); // For plugins to filter messages per reply/topic/user $message = sprintf(__('%1$s wrote: %2$s Topic Link: %3$s ----------- You are receiving this email because you subscribed to a forum. Login and visit the topic to unsubscribe from these emails.', 'bbpress'), $topic_author_name, $topic_content, $topic_url); $message = apply_filters('bbp_forum_subscription_mail_message', $message, $topic_id, $forum_id, $user_id); if (empty($message)) { return; } // For plugins to filter titles per reply/topic/user $subject = apply_filters('bbp_forum_subscription_mail_title', '[' . $blog_name . '] ' . $topic_title, $topic_id, $forum_id, $user_id); if (empty($subject)) { return; } /** User ******************************************************************/ // Get the noreply@ address $no_reply = bbp_get_do_not_reply_address(); // Setup "From" email address $from_email = apply_filters('bbp_subscription_from_email', $no_reply); // Setup the From header $headers = array('From: ' . get_bloginfo('name') . ' <' . $from_email . '>'); // Get topic subscribers and bail if empty $user_ids = bbp_get_forum_subscribers($forum_id, true); // Dedicated filter to manipulate user ID's to send emails to $user_ids = apply_filters('bbp_forum_subscription_user_ids', $user_ids); if (empty($user_ids)) { return false; } // Loop through users foreach ((array) $user_ids as $user_id) { // Don't send notifications to the person who made the post if (!empty($topic_author) && (int) $user_id === (int) $topic_author) { continue; } // Get email address of subscribed user $headers[] = 'Bcc: ' . get_userdata($user_id)->user_email; } /** Send it ***************************************************************/ // Custom headers $headers = apply_filters('bbp_subscription_mail_headers', $headers); $to_email = apply_filters('bbp_subscription_to_email', $no_reply); do_action('bbp_pre_notify_forum_subscribers', $topic_id, $forum_id, $user_ids); // Send notification email wp_mail($to_email, $subject, $message, $headers); do_action('bbp_post_notify_forum_subscribers', $topic_id, $forum_id, $user_ids); return true; }
/** * Topic Row actions * * Remove the quick-edit action link under the topic title and add the * content and close/stick/spam links * * @since 2.0.0 bbPress (r2485) * * @param array $actions Actions * @param array $topic Topic object * @uses bbp_get_topic_post_type() To get the topic post type * @uses bbp_topic_content() To output topic content * @uses bbp_get_topic_permalink() To get the topic link * @uses bbp_get_topic_title() To get the topic title * @uses current_user_can() To check if the current user can edit or * delete the topic * @uses bbp_is_topic_open() To check if the topic is open * @uses bbp_is_topic_spam() To check if the topic is marked as spam * @uses bbp_is_topic_sticky() To check if the topic is a sticky or a * super sticky * @uses get_post_type_object() To get the topic post type object * @uses add_query_arg() To add custom args to the url * @uses remove_query_arg() To remove custom args from the url * @uses wp_nonce_url() To nonce the url * @uses get_delete_post_link() To get the delete post link of the topic * @return array $actions Actions */ public function row_actions($actions, $topic) { if ($this->bail()) { return $actions; } unset($actions['inline hide-if-no-js']); // Show view link if it's not set, the topic is trashed and the user can view trashed topics if (empty($actions['view']) && bbp_get_trash_status_id() === $topic->post_status && current_user_can('view_trash')) { $actions['view'] = '<a href="' . esc_url(bbp_get_topic_permalink($topic->ID)) . '" title="' . esc_attr(sprintf(__('View “%s”', 'bbpress'), bbp_get_topic_title($topic->ID))) . '" rel="permalink">' . esc_html__('View', 'bbpress') . '</a>'; } // Only show the actions if the user is capable of viewing them :) if (current_user_can('moderate', $topic->ID)) { // Pending // Show the 'approve' and 'view' link on pending posts only and 'unapprove' on published posts only $approve_uri = wp_nonce_url(add_query_arg(array('topic_id' => $topic->ID, 'action' => 'bbp_toggle_topic_approve'), remove_query_arg(array('bbp_topic_toggle_notice', 'topic_id', 'failed', 'super'))), 'approve-topic_' . $topic->ID); if (bbp_is_topic_published($topic->ID)) { $actions['unapproved'] = '<a href="' . esc_url($approve_uri) . '" title="' . esc_attr__('Unapprove this topic', 'bbpress') . '">' . _x('Unapprove', 'Unapprove Topic', 'bbpress') . '</a>'; } elseif (!bbp_is_topic_private($topic->ID)) { $actions['approved'] = '<a href="' . esc_url($approve_uri) . '" title="' . esc_attr__('Approve this topic', 'bbpress') . '">' . _x('Approve', 'Approve Topic', 'bbpress') . '</a>'; $actions['view'] = '<a href="' . esc_url(bbp_get_topic_permalink($topic->ID)) . '" title="' . esc_attr(sprintf(__('View “%s”', 'bbpress'), bbp_get_topic_title($topic->ID))) . '" rel="permalink">' . esc_html__('View', 'bbpress') . '</a>'; } // Close // Show the 'close' and 'open' link on published and closed posts only if (in_array($topic->post_status, array(bbp_get_public_status_id(), bbp_get_closed_status_id()))) { $close_uri = wp_nonce_url(add_query_arg(array('topic_id' => $topic->ID, 'action' => 'bbp_toggle_topic_close'), remove_query_arg(array('bbp_topic_toggle_notice', 'topic_id', 'failed', 'super'))), 'close-topic_' . $topic->ID); if (bbp_is_topic_open($topic->ID)) { $actions['closed'] = '<a href="' . esc_url($close_uri) . '" title="' . esc_attr__('Close this topic', 'bbpress') . '">' . _x('Close', 'Close a Topic', 'bbpress') . '</a>'; } else { $actions['closed'] = '<a href="' . esc_url($close_uri) . '" title="' . esc_attr__('Open this topic', 'bbpress') . '">' . _x('Open', 'Open a Topic', 'bbpress') . '</a>'; } } // Sticky // Dont show sticky if topic links is spam, trash or pending if (!bbp_is_topic_spam($topic->ID) && !bbp_is_topic_trash($topic->ID) && !bbp_is_topic_pending($topic->ID)) { $stick_uri = wp_nonce_url(add_query_arg(array('topic_id' => $topic->ID, 'action' => 'bbp_toggle_topic_stick'), remove_query_arg(array('bbp_topic_toggle_notice', 'topic_id', 'failed', 'super'))), 'stick-topic_' . $topic->ID); if (bbp_is_topic_sticky($topic->ID)) { $actions['stick'] = '<a href="' . esc_url($stick_uri) . '" title="' . esc_attr__('Unstick this topic', 'bbpress') . '">' . esc_html__('Unstick', 'bbpress') . '</a>'; } else { $super_uri = wp_nonce_url(add_query_arg(array('topic_id' => $topic->ID, 'action' => 'bbp_toggle_topic_stick', 'super' => '1'), remove_query_arg(array('bbp_topic_toggle_notice', 'topic_id', 'failed', 'super'))), 'stick-topic_' . $topic->ID); $actions['stick'] = '<a href="' . esc_url($stick_uri) . '" title="' . esc_attr__('Stick this topic to its forum', 'bbpress') . '">' . esc_html__('Stick', 'bbpress') . '</a> <a href="' . esc_url($super_uri) . '" title="' . esc_attr__('Stick this topic to front', 'bbpress') . '">' . esc_html__('(to front)', 'bbpress') . '</a>'; } } // Spam $spam_uri = wp_nonce_url(add_query_arg(array('topic_id' => $topic->ID, 'action' => 'bbp_toggle_topic_spam'), remove_query_arg(array('bbp_topic_toggle_notice', 'topic_id', 'failed', 'super'))), 'spam-topic_' . $topic->ID); if (bbp_is_topic_spam($topic->ID)) { $actions['spam'] = '<a href="' . esc_url($spam_uri) . '" title="' . esc_attr__('Mark the topic as not spam', 'bbpress') . '">' . esc_html__('Not spam', 'bbpress') . '</a>'; } else { $actions['spam'] = '<a href="' . esc_url($spam_uri) . '" title="' . esc_attr__('Mark this topic as spam', 'bbpress') . '">' . esc_html__('Spam', 'bbpress') . '</a>'; } } // Do not show trash links for spam topics, or spam links for trashed topics if (current_user_can('delete_topic', $topic->ID)) { if (bbp_get_trash_status_id() === $topic->post_status) { $post_type_object = get_post_type_object(bbp_get_topic_post_type()); $actions['untrash'] = "<a title='" . esc_attr__('Restore this item from the Trash', 'bbpress') . "' href='" . wp_nonce_url(add_query_arg(array('_wp_http_referer' => add_query_arg(array('post_type' => bbp_get_topic_post_type()), admin_url('edit.php'))), admin_url(sprintf($post_type_object->_edit_link . '&action=untrash', $topic->ID))), 'untrash-' . $topic->post_type . '_' . $topic->ID) . "'>" . esc_html__('Restore', 'bbpress') . "</a>"; } elseif (EMPTY_TRASH_DAYS) { $actions['trash'] = "<a class='submitdelete' title='" . esc_attr__('Move this item to the Trash', 'bbpress') . "' href='" . esc_url(add_query_arg(array('_wp_http_referer' => add_query_arg(array('post_type' => bbp_get_topic_post_type()), admin_url('edit.php'))), get_delete_post_link($topic->ID))) . "'>" . esc_html__('Trash', 'bbpress') . "</a>"; } if (bbp_get_trash_status_id() === $topic->post_status || !EMPTY_TRASH_DAYS) { $actions['delete'] = "<a class='submitdelete' title='" . esc_attr__('Delete this item permanently', 'bbpress') . "' href='" . esc_url(add_query_arg(array('_wp_http_referer' => add_query_arg(array('post_type' => bbp_get_topic_post_type()), admin_url('edit.php'))), get_delete_post_link($topic->ID, '', true))) . "'>" . esc_html__('Delete Permanently', 'bbpress') . "</a>"; } elseif (bbp_get_spam_status_id() === $topic->post_status) { unset($actions['trash']); } } return $actions; }
/** * @group canonical * @covers ::bbp_create_initial_content */ public function test_bbp_create_initial_content() { $category_id = $this->factory->forum->create(array('forum_meta' => array('_bbp_forum_type' => 'category', '_bbp_status' => 'open'))); bbp_create_initial_content(array('forum_parent' => $category_id)); $forum_id = bbp_forum_query_subforum_ids($category_id); $forum_id = (int) $forum_id[0]; $topic_id = bbp_get_forum_last_topic_id($forum_id); $reply_id = bbp_get_forum_last_reply_id($forum_id); // Forum post $this->assertSame('General', bbp_get_forum_title($forum_id)); $this->assertSame('General chit-chat', bbp_get_forum_content($forum_id)); $this->assertSame('open', bbp_get_forum_status($forum_id)); $this->assertTrue(bbp_is_forum_public($forum_id)); $this->assertSame($category_id, bbp_get_forum_parent_id($forum_id)); // Topic post $this->assertSame($forum_id, bbp_get_topic_forum_id($topic_id)); $this->assertSame('Hello World!', bbp_get_topic_title($topic_id)); remove_all_filters('bbp_get_topic_content'); $topic_content = "I am the first topic in your new forums."; $this->assertSame($topic_content, bbp_get_topic_content($topic_id)); $this->assertSame('publish', bbp_get_topic_status($topic_id)); $this->assertTrue(bbp_is_topic_published($topic_id)); // Reply post $this->assertSame($forum_id, bbp_get_reply_forum_id($reply_id)); $this->assertSame('Reply To: Hello World!', bbp_get_reply_title($reply_id)); $this->assertSame($reply_id, bbp_get_reply_title_fallback($reply_id)); remove_all_filters('bbp_get_reply_content'); $reply_content = "Oh, and this is what a reply looks like."; $this->assertSame($reply_content, bbp_get_reply_content($reply_id)); $this->assertSame('publish', bbp_get_reply_status($reply_id)); $this->assertTrue(bbp_is_reply_published($reply_id)); // Category meta $this->assertSame(1, bbp_get_forum_subforum_count($category_id, true)); $this->assertSame(0, bbp_get_forum_topic_count($category_id, false, true)); $this->assertSame(0, bbp_get_forum_topic_count_hidden($category_id, true)); $this->assertSame(0, bbp_get_forum_reply_count($category_id, false, true)); $this->assertSame(1, bbp_get_forum_topic_count($category_id, true, true)); $this->assertSame(1, bbp_get_forum_reply_count($category_id, true, true)); $this->assertSame(0, bbp_get_forum_post_count($category_id, false, true)); $this->assertSame(2, bbp_get_forum_post_count($category_id, true, true)); $this->assertSame($topic_id, bbp_get_forum_last_topic_id($category_id)); $this->assertSame('Hello World!', bbp_get_forum_last_topic_title($category_id)); $this->assertSame($reply_id, bbp_get_forum_last_reply_id($category_id)); $this->assertSame('Reply To: Hello World!', bbp_get_forum_last_reply_title($category_id)); $this->assertSame($reply_id, bbp_get_forum_last_active_id($category_id)); $this->assertSame('1 day, 16 hours ago', bbp_get_forum_last_active_time($category_id)); // Forum meta $this->assertSame(0, bbp_get_forum_subforum_count($forum_id, true)); $this->assertSame(1, bbp_get_forum_topic_count($forum_id, false, true)); $this->assertSame(0, bbp_get_forum_topic_count_hidden($forum_id, true)); $this->assertSame(1, bbp_get_forum_reply_count($forum_id, false, true)); $this->assertSame(1, bbp_get_forum_topic_count($forum_id, true, true)); $this->assertSame(1, bbp_get_forum_reply_count($forum_id, true, true)); $this->assertSame(2, bbp_get_forum_post_count($forum_id, false, true)); $this->assertSame(2, bbp_get_forum_post_count($forum_id, true, true)); $this->assertSame($topic_id, bbp_get_forum_last_topic_id($forum_id)); $this->assertSame('Hello World!', bbp_get_forum_last_topic_title($forum_id)); $this->assertSame($reply_id, bbp_get_forum_last_reply_id($forum_id)); $this->assertSame('Reply To: Hello World!', bbp_get_forum_last_reply_title($forum_id)); $this->assertSame($reply_id, bbp_get_forum_last_active_id($forum_id)); $this->assertSame('1 day, 16 hours ago', bbp_get_forum_last_active_time($forum_id)); // Topic meta $this->assertSame('127.0.0.1', bbp_current_author_ip($topic_id)); $this->assertSame($forum_id, bbp_get_topic_forum_id($topic_id)); $this->assertSame(1, bbp_get_topic_voice_count($topic_id, true)); $this->assertSame(1, bbp_get_topic_reply_count($topic_id, true)); $this->assertSame(0, bbp_get_topic_reply_count_hidden($topic_id, true)); $this->assertSame($reply_id, bbp_get_topic_last_reply_id($topic_id)); $this->assertSame($reply_id, bbp_get_topic_last_active_id($topic_id)); $this->assertSame('1 day, 16 hours ago', bbp_get_topic_last_active_time($topic_id)); // Reply Meta $this->assertSame('127.0.0.1', bbp_current_author_ip($reply_id)); $this->assertSame($forum_id, bbp_get_reply_forum_id($reply_id)); $this->assertSame($topic_id, bbp_get_reply_topic_id($reply_id)); }
/** * Sends notification emails for new topics to subscribed forums * * Gets new post's ID and check if there are subscribed users to that topic, and * if there are, send notifications * * @since bbPress (r5156) * * @param int $topic_id ID of the newly made reply * @uses bbp_is_subscriptions_active() To check if the subscriptions are active * @uses bbp_get_topic_id() To validate the topic ID * @uses bbp_get_forum_id() To validate the forum ID * @uses bbp_is_topic_published() To make sure the topic is published * @uses bbp_get_forum_subscribers() To get the forum subscribers * @uses bbp_get_topic_author_display_name() To get the topic author's display name * @uses do_action() Calls 'bbp_pre_notify_forum_subscribers' with the topic id, * forum id and user id * @uses apply_filters() Calls 'bbp_forum_subscription_mail_message' with the * message, topic id, forum id and user id * @uses apply_filters() Calls 'bbp_forum_subscription_mail_title' with the * topic title, topic id, forum id and user id * @uses apply_filters() Calls 'bbp_forum_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_forum_subscribers' with the topic, * id, forum id and user id * @return bool True on success, false on failure */ function bbp_notify_forum_subscribers($topic_id = 0, $forum_id = 0, $anonymous_data = false, $topic_author = 0) { // Bail if subscriptions are turned off if (!bbp_is_subscriptions_active()) { return false; } /** Validation ************************************************************/ $topic_id = bbp_get_topic_id($topic_id); $forum_id = bbp_get_forum_id($forum_id); /** Topic *****************************************************************/ // Bail if topic is not published if (!bbp_is_topic_published($topic_id)) { return false; } /** User ******************************************************************/ // Get forum subscribers and bail if empty $user_ids = bbp_get_forum_subscribers($forum_id, true); if (empty($user_ids)) { return false; } // Poster name $topic_author_name = bbp_get_topic_author_display_name($topic_id); /** Mail ******************************************************************/ do_action('bbp_pre_notify_forum_subscribers', $topic_id, $forum_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_topic_content'); remove_all_filters('bbp_get_topic_title'); // Strip tags from text $topic_title = strip_tags(bbp_get_topic_title($topic_id)); $topic_content = strip_tags(bbp_get_topic_content($topic_id)); $topic_url = get_permalink($topic_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($topic_author) && (int) $user_id === (int) $topic_author) { continue; } // For plugins to filter messages per reply/topic/user $message = sprintf(__('%1$s wrote: %2$s Topic Link: %3$s ----------- You are receiving this email because you subscribed to a forum. Login and visit the topic to unsubscribe from these emails.', 'bbpress'), $topic_author_name, $topic_content, $topic_url); $message = apply_filters('bbp_forum_subscription_mail_message', $message, $topic_id, $forum_id, $user_id); if (empty($message)) { continue; } // For plugins to filter titles per reply/topic/user $subject = apply_filters('bbp_forum_subscription_mail_title', '[' . $blog_name . '] ' . $topic_title, $topic_id, $forum_id, $user_id); if (empty($subject)) { continue; } // Custom headers $headers = apply_filters('bbp_forum_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_forum_subscribers', $topic_id, $forum_id, $user_ids); return true; }
public static function roost_bbp_notify_subscribers( $reply_id, $topic_id, $forum_id, $anonymous_data, $reply_author = 0 ) { $topic_id = bbp_get_topic_id( $topic_id ); $forum_id = bbp_get_forum_id( $forum_id ); if ( ! bbp_is_topic_published( $topic_id ) ) { return false; } $topic_title = bbp_get_topic_title( $topic_id ); $topic_url = get_permalink( $topic_id ); if ( isset( $_POST['bbp_reply_to'] ) ) { $reply_to_id = $_POST['bbp_reply_to']; } $roost_settings = ROOST::roost_settings(); $app_key = $roost_settings['appKey']; $app_secret = $roost_settings['appSecret']; $message = 'New Post in ' . $topic_title; if ( ! empty( $reply_to_id ) ) { $reply_subscriptions = get_post_meta( $reply_to_id, '_roost_bbp_subscription', true ); } $topic_subscriptions = get_post_meta( $topic_id, '_roost_bbp_subscription', true ); $forum_subscriptions = get_post_meta( $forum_id, '_roost_bbp_subscription', true ); if ( ! empty( $reply_subscriptions ) ) { $device_tokens = array(); foreach( $reply_subscriptions as $token => $active ) { $device_tokens[] = $token; } } if ( ! empty( $topic_subscriptions ) ) { if ( empty( $device_tokens ) ) { $device_tokens = array(); } foreach( $topic_subscriptions as $token => $active ) { $device_tokens[] = $token; } } if ( ! empty( $forum_subscriptions ) ) { if ( empty( $device_tokens ) ) { $device_tokens = array(); } foreach( $forum_subscriptions as $token => $active ) { $device_tokens[] = $token; } } if ( empty( $device_tokens) ) { return; } Roost_API::send_notification( $message, $topic_url, null, $app_key, $app_secret, $device_tokens, null ); }
/** * Send priority messages to Slack * * @since 1.0.0 * * @TODO : Slack integration * * @param int $topic_id The ID of this topic * @param int $forum_id The ID of the forum this topic belongs to * @param bool $anonymous_data * @param int $topic_author The author of this topic * * @return void */ function wi_bbp_send_priority_to_slack($topic_id = 0, $forum_id = 0, $anonymous_data = false, $topic_author = 0) { // Bail if topic is not published if (!bbp_is_topic_published($topic_id)) { return; } if ($forum_id != 499) { return; } $json = json_encode(array('username' => 'give-bot', 'icon_emoji' => ':happy:', 'text' => 'A new priority ticket has been posted - ' . esc_html(get_the_title($topic_id)) . ' - <' . esc_url(get_permalink($topic_id)) . '|View Ticket>')); $args = array('headers' => array('content-type' => 'application/json'), 'body' => $json, 'timeout' => 15, 'sslverify' => false); wp_remote_post('https://hooks.slack.com/services/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', $args); }