/** * Update counts after a reply is inserted via `bbp_insert_reply`. * * @since 2.6.0 bbPress (r6036) * * @param int $reply_id The reply id. * @param int $topic_id The topic id. * @param int $forum_id The forum id. * * @uses bbp_get_reply_status() To get the reply status * @uses bbp_get_public_status_id() To get the public status id * @uses bbp_increase_topic_reply_count() To bump the topics reply count by 1 * @uses bbp_increase_forum_reply_count() To bump the forums reply count by 1 * @uses bbp_increase_topic_reply_count_hidden() To bump the topics hidden reply * count by 1 * * @return void */ function bbp_insert_reply_update_counts($reply_id = 0, $topic_id = 0, $forum_id = 0) { // If the reply is public, update the forum/topic reply counts. if (bbp_get_reply_status($reply_id) === bbp_get_public_status_id()) { bbp_increase_topic_reply_count($topic_id); bbp_increase_forum_reply_count($forum_id); // If the reply isn't public only update the topic reply hidden count. } else { bbp_increase_topic_reply_count_hidden($topic_id); } }
/** * @group canonical * @covers ::bbp_insert_reply */ public function test_bbp_insert_reply() { $f = $this->factory->forum->create(); $t = $this->factory->topic->create(array('post_parent' => $f, 'topic_meta' => array('forum_id' => $f))); $r = $this->factory->reply->create(array('post_title' => 'Reply To: Topic 1', 'post_content' => 'Content of reply to Topic 1', 'post_parent' => $t, 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t))); // Get the reply. $reply = bbp_get_reply($r); remove_all_filters('bbp_get_reply_content'); // Reply post. $this->assertSame('Reply To: Topic 1', bbp_get_reply_title($r)); $this->assertSame('Content of reply to Topic 1', bbp_get_reply_content($r)); $this->assertSame('publish', bbp_get_reply_status($r)); $this->assertSame($t, wp_get_post_parent_id($r)); $this->assertEquals('http://' . WP_TESTS_DOMAIN . '/?reply=' . $reply->post_name, $reply->guid); // Reply meta. $this->assertSame($f, bbp_get_reply_forum_id($r)); $this->assertSame($t, bbp_get_reply_topic_id($r)); }
/** * Return admin links for reply * * @since bbPress (r2667) * * @param array $args This function supports these arguments: * - id: Optional. Reply id * - before: HTML before the links. Defaults to * '<span class="bbp-admin-links">' * - after: HTML after the links. Defaults to '</span>' * - sep: Separator. Defaults to ' | ' * - links: Array of the links to display. By default, edit, trash, * spam, reply move, and topic split links are displayed * @uses bbp_is_topic() To check if it's the topic page * @uses bbp_is_reply() To check if it's the reply page * @uses bbp_get_reply_id() To get the reply id * @uses bbp_get_reply_edit_link() To get the reply edit link * @uses bbp_get_reply_trash_link() To get the reply trash link * @uses bbp_get_reply_spam_link() To get the reply spam link * @uses bbp_get_reply_move_link() To get the reply move link * @uses bbp_get_topic_split_link() To get the topic split link * @uses current_user_can() To check if the current user can edit or * delete the reply * @uses apply_filters() Calls 'bbp_get_reply_admin_links' with the * reply admin links and args * @return string Reply admin links */ function bbp_get_reply_admin_links($args = array()) { // Parse arguments against default values $r = bbp_parse_args($args, array('id' => 0, 'before' => '<span class="bbp-admin-links">', 'after' => '</span>', 'sep' => ' | ', 'links' => array()), 'get_reply_admin_links'); $r['id'] = bbp_get_reply_id((int) $r['id']); // If post is a topic, return the topic admin links instead if (bbp_is_topic($r['id'])) { return bbp_get_topic_admin_links($args); } // If post is not a reply, return if (!bbp_is_reply($r['id'])) { return; } // If topic is trashed, do not show admin links if (bbp_is_topic_trash(bbp_get_reply_topic_id($r['id']))) { return; } // If no links were passed, default to the standard if (empty($r['links'])) { $r['links'] = apply_filters('bbp_reply_admin_links', array('edit' => bbp_get_reply_edit_link($r), 'move' => bbp_get_reply_move_link($r), 'split' => bbp_get_topic_split_link($r), 'trash' => bbp_get_reply_trash_link($r), 'spam' => bbp_get_reply_spam_link($r), 'reply' => bbp_get_reply_to_link($r)), $r['id']); } // See if links need to be unset $reply_status = bbp_get_reply_status($r['id']); if (in_array($reply_status, array(bbp_get_spam_status_id(), bbp_get_trash_status_id()))) { // Spam link shouldn't be visible on trashed topics if (bbp_get_trash_status_id() === $reply_status) { unset($r['links']['spam']); // Trash link shouldn't be visible on spam topics } elseif (bbp_get_spam_status_id() === $reply_status) { unset($r['links']['trash']); } } // Process the admin links $links = implode($r['sep'], array_filter($r['links'])); $retval = $r['before'] . $links . $r['after']; return apply_filters('bbp_get_reply_admin_links', $retval, $r, $args); }
/** * Reset main query vars and filter 'the_content' to output a bbPress * template part as needed. * * @since bbPress (r3032) * @param string $template * @uses bbp_is_single_user() To check if page is single user * @uses bbp_get_single_user_template() To get user template * @uses bbp_is_single_user_edit() To check if page is single user edit * @uses bbp_get_single_user_edit_template() To get user edit template * @uses bbp_is_single_view() To check if page is single view * @uses bbp_get_single_view_template() To get view template * @uses bbp_is_forum_edit() To check if page is forum edit * @uses bbp_get_forum_edit_template() To get forum edit template * @uses bbp_is_topic_merge() To check if page is topic merge * @uses bbp_get_topic_merge_template() To get topic merge template * @uses bbp_is_topic_split() To check if page is topic split * @uses bbp_get_topic_split_template() To get topic split template * @uses bbp_is_topic_edit() To check if page is topic edit * @uses bbp_get_topic_edit_template() To get topic edit template * @uses bbp_is_reply_edit() To check if page is reply edit * @uses bbp_get_reply_edit_template() To get reply edit template * @uses bbp_set_theme_compat_template() To set the global theme compat template */ function bbp_template_include_theme_compat($template = '') { // Bail if the template already matches a bbPress template. This includes // archive-* and single-* WordPress post_type matches (allowing // themes to use the expected format) as well as all bbPress-specific // template files for users, topics, forums, etc... if (!empty(bbpress()->theme_compat->bbpress_template)) { return $template; } /** Users *************************************************************/ if (bbp_is_single_user_edit() || bbp_is_single_user()) { // Reset post bbp_theme_compat_reset_post(array('ID' => 0, 'post_author' => 0, 'post_date' => 0, 'post_content' => '', 'post_type' => '', 'post_title' => esc_attr(bbp_get_displayed_user_field('display_name')), 'post_status' => bbp_get_public_status_id(), 'is_archive' => false, 'comment_status' => 'closed')); /** Forums ************************************************************/ // Forum archive } elseif (bbp_is_forum_archive()) { // Reset post bbp_theme_compat_reset_post(array('ID' => 0, 'post_title' => bbp_get_forum_archive_title(), 'post_author' => 0, 'post_date' => 0, 'post_content' => '', 'post_type' => bbp_get_forum_post_type(), 'post_status' => bbp_get_public_status_id(), 'is_archive' => true, 'comment_status' => 'closed')); // Single Forum } elseif (bbp_is_forum_edit() || bbp_is_single_forum()) { // Reset post bbp_theme_compat_reset_post(array('ID' => bbp_get_forum_id(), 'post_title' => bbp_get_forum_title(), 'post_author' => bbp_get_forum_author_id(), 'post_date' => 0, 'post_content' => get_post_field('post_content', bbp_get_forum_id()), 'post_type' => bbp_get_forum_post_type(), 'post_status' => bbp_get_forum_visibility(), 'is_single' => true, 'comment_status' => 'closed')); /** Topics ************************************************************/ // Topic archive } elseif (bbp_is_topic_archive()) { // Reset post bbp_theme_compat_reset_post(array('ID' => 0, 'post_title' => bbp_get_topic_archive_title(), 'post_author' => 0, 'post_date' => 0, 'post_content' => '', 'post_type' => bbp_get_topic_post_type(), 'post_status' => bbp_get_public_status_id(), 'is_archive' => true, 'comment_status' => 'closed')); // Single Topic } elseif (bbp_is_topic_edit() || bbp_is_single_topic()) { // Reset post bbp_theme_compat_reset_post(array('ID' => bbp_get_topic_id(), 'post_title' => bbp_get_topic_title(), 'post_author' => bbp_get_topic_author_id(), 'post_date' => 0, 'post_content' => get_post_field('post_content', bbp_get_topic_id()), 'post_type' => bbp_get_topic_post_type(), 'post_status' => bbp_get_topic_status(), 'is_single' => true, 'comment_status' => 'closed')); /** Replies ***********************************************************/ // Reply archive } elseif (is_post_type_archive(bbp_get_reply_post_type())) { // Reset post bbp_theme_compat_reset_post(array('ID' => 0, 'post_title' => __('Replies', 'bbpress'), 'post_author' => 0, 'post_date' => 0, 'post_content' => '', 'post_type' => bbp_get_reply_post_type(), 'post_status' => bbp_get_public_status_id(), 'comment_status' => 'closed')); // Single Reply } elseif (bbp_is_reply_edit() || bbp_is_single_reply()) { // Reset post bbp_theme_compat_reset_post(array('ID' => bbp_get_reply_id(), 'post_title' => bbp_get_reply_title(), 'post_author' => bbp_get_reply_author_id(), 'post_date' => 0, 'post_content' => get_post_field('post_content', bbp_get_reply_id()), 'post_type' => bbp_get_reply_post_type(), 'post_status' => bbp_get_reply_status(), 'comment_status' => 'closed')); /** Views *************************************************************/ } elseif (bbp_is_single_view()) { // Reset post bbp_theme_compat_reset_post(array('ID' => 0, 'post_title' => bbp_get_view_title(), 'post_author' => 0, 'post_date' => 0, 'post_content' => '', 'post_type' => '', 'post_status' => bbp_get_public_status_id(), 'comment_status' => 'closed')); /** Topic Tags ********************************************************/ // Topic Tag Edit } elseif (bbp_is_topic_tag_edit() || bbp_is_topic_tag()) { // Stash the current term in a new var set_query_var('bbp_topic_tag', get_query_var('term')); // Reset the post with our new title bbp_theme_compat_reset_post(array('ID' => 0, 'post_author' => 0, 'post_date' => 0, 'post_content' => '', 'post_type' => '', 'post_title' => sprintf(__('Topic Tag: %s', 'bbpress'), '<span>' . bbp_get_topic_tag_name() . '</span>'), 'post_status' => bbp_get_public_status_id(), 'comment_status' => 'closed')); } /** * If we are relying on bbPress's built in theme compatibility to load * the proper content, we need to intercept the_content, replace the * output, and display ours instead. * * To do this, we first remove all filters from 'the_content' and hook * our own function into it, which runs a series of checks to determine * the context, and then uses the built in shortcodes to output the * correct results from inside an output buffer. * * Uses bbp_get_theme_compat_templates() to provide fall-backs that * should be coded without superfluous mark-up and logic (prev/next * navigation, comments, date/time, etc...) * * Hook into the 'bbp_get_bbpress_template' to override the array of * possible templates, or 'bbp_bbpress_template' to override the result. */ if (bbp_is_theme_compat_active()) { // Remove all filters from the_content bbp_remove_all_filters('the_content'); // Add a filter on the_content late, which we will later remove add_filter('the_content', 'bbp_replace_the_content'); // Find the appropriate template file $template = bbp_get_theme_compat_templates(); } return apply_filters('bbp_template_include_theme_compat', $template); }
/** * Returns reply status downdown * * This dropdown is only intended to be seen by users with the 'moderate' * capability. Because of this, no additional capablitiy checks are performed * within this function to check available reply statuses. * * @since 2.6.0 bbPress (r5399) * * @param $args This function supports these arguments: * - select_id: Select id. Defaults to bbp_reply_status * - tab: Deprecated. Tabindex * - reply_id: Reply id * - selected: Override the selected option */ function bbp_get_form_reply_status_dropdown($args = array()) { // Parse arguments against default values $r = bbp_parse_args($args, array('select_id' => 'bbp_reply_status', 'select_class' => 'bbp_dropdown', 'tab' => false, 'reply_id' => 0, 'selected' => false), 'reply_status_dropdown'); // No specific selected value passed if (empty($r['selected'])) { // Post value is passed if (bbp_is_reply_form_post_request() && isset($_POST[$r['select_id']])) { $r['selected'] = sanitize_key($_POST[$r['select_id']]); // No Post value was passed } else { // Edit reply if (bbp_is_reply_edit()) { $r['reply_id'] = bbp_get_reply_id($r['reply_id']); $r['selected'] = bbp_get_reply_status($r['reply_id']); // New reply } else { $r['selected'] = bbp_get_public_status_id(); } } } // Used variables $tab = !empty($r['tab']) ? ' tabindex="' . (int) $r['tab'] . '"' : ''; // Start an output buffer, we'll finish it after the select loop ob_start(); ?> <select name="<?php echo esc_attr($r['select_id']); ?> " id="<?php echo esc_attr($r['select_id']); ?> _select" class="<?php echo esc_attr($r['select_class']); ?> "<?php echo $tab; ?> > <?php foreach (bbp_get_reply_statuses($r['reply_id']) as $key => $label) { ?> <option value="<?php echo esc_attr($key); ?> "<?php selected($key, $r['selected']); ?> ><?php echo esc_html($label); ?> </option> <?php } ?> </select> <?php // Return the results return apply_filters('bbp_get_form_reply_status_dropdown', ob_get_clean(), $r); }
/** * Is the reply marked as reported? * * @since 1.0.0 * * @param int $reply_id Optional. Reply id * @uses bbp_get_reply_id() To get the reply id * @uses bbp_get_reply_status() To get the reply status * @return bool True if report, false if not. */ public function is_reply_reported($reply_id = 0) { $reply_status = bbp_get_reply_status(bbp_get_reply_id($reply_id)) === $this->get_reported_status_id(); return (bool) apply_filters('bbp_rc_is_reply_reported', (bool) $reply_status, $reply_id); }
/** * @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)); }
/** * @covers ::bbp_unapprove_reply */ public function test_bbp_unapprove_reply() { // Create a forum. $f = $this->factory->forum->create(); // Create a topic. $t = $this->factory->topic->create(array('post_parent' => $f, 'topic_meta' => array('forum_id' => $f))); // Create some replies. $r1 = $this->factory->reply->create(array('post_parent' => $t, 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t))); $reply_post_status = bbp_get_reply_status($r1); $this->assertSame('publish', $reply_post_status); $topic_reply_count = bbp_get_topic_reply_count($t); $this->assertSame('1', $topic_reply_count); $r2 = $this->factory->reply->create(array('post_parent' => $t, 'reply_meta' => array('forum_id' => $f, 'topic_id' => $t))); $reply_post_status = bbp_get_reply_status($r2); $this->assertSame('publish', $reply_post_status); $topic_reply_count = bbp_get_topic_reply_count($t); $this->assertSame('2', $topic_reply_count); bbp_unapprove_reply($r2); $reply_post_status = bbp_get_reply_status($r2); $this->assertSame('pending', $reply_post_status); $topic_reply_count = bbp_get_topic_reply_count($t); $this->assertSame('1', $topic_reply_count); }
/** * Reset main query vars and filter 'the_content' to output a bbPress * template part as needed. * * @since 2.0.0 bbPress (r3032) * * @param string $template * @uses bbp_is_single_user() To check if page is single user * @uses bbp_get_single_user_template() To get user template * @uses bbp_is_single_user_edit() To check if page is single user edit * @uses bbp_get_single_user_edit_template() To get user edit template * @uses bbp_is_single_view() To check if page is single view * @uses bbp_get_single_view_template() To get view template * @uses bbp_is_search() To check if page is search * @uses bbp_get_search_template() To get search template * @uses bbp_is_forum_edit() To check if page is forum edit * @uses bbp_get_forum_edit_template() To get forum edit template * @uses bbp_is_topic_merge() To check if page is topic merge * @uses bbp_get_topic_merge_template() To get topic merge template * @uses bbp_is_topic_split() To check if page is topic split * @uses bbp_get_topic_split_template() To get topic split template * @uses bbp_is_topic_edit() To check if page is topic edit * @uses bbp_get_topic_edit_template() To get topic edit template * @uses bbp_is_reply_move() To check if page is reply move * @uses bbp_get_reply_move_template() To get reply move template * @uses bbp_is_reply_edit() To check if page is reply edit * @uses bbp_get_reply_edit_template() To get reply edit template * @uses bbp_set_theme_compat_template() To set the global theme compat template */ function bbp_template_include_theme_compat($template = '') { /** * Bail if a root template was already found. This prevents unintended * recursive filtering of 'the_content'. * * @link https://bbpress.trac.wordpress.org/ticket/2429 */ if (bbp_is_template_included()) { return $template; } /** * If BuddyPress is activated at a network level, the action order is * reversed, which causes the template integration to fail. If we're looking * at a BuddyPress page here, bail to prevent the extra processing. * * This is a bit more brute-force than is probably necessary, but gets the * job done while we work towards something more elegant. */ if (function_exists('is_buddypress') && is_buddypress()) { return $template; } // Define local variable(s) $bbp_shortcodes = bbpress()->shortcodes; // Bail if shortcodes are unset somehow if (!is_a($bbp_shortcodes, 'BBP_Shortcodes')) { return $template; } /** Users *************************************************************/ if (bbp_is_single_user_edit() || bbp_is_single_user()) { // Reset post bbp_theme_compat_reset_post(array('ID' => 0, 'post_author' => 0, 'post_date' => 0, 'post_content' => bbp_buffer_template_part('content', 'single-user', false), 'post_type' => '', 'post_title' => bbp_get_displayed_user_field('display_name'), 'post_status' => bbp_get_public_status_id(), 'is_single' => true, 'is_archive' => false, 'comment_status' => 'closed')); /** Forums ************************************************************/ // Forum archive } elseif (bbp_is_forum_archive()) { // Page exists where this archive should be $page = bbp_get_page_by_path(bbp_get_root_slug()); // Should we replace the content... if (empty($page->post_content)) { // Use the topics archive if ('topics' === bbp_show_on_root()) { $new_content = $bbp_shortcodes->display_topic_index(); // No page so show the archive } else { $new_content = $bbp_shortcodes->display_forum_index(); } // ...or use the existing page content? } else { $new_content = apply_filters('the_content', $page->post_content); } // Should we replace the title... if (empty($page->post_title)) { // Use the topics archive if ('topics' === bbp_show_on_root()) { $new_title = bbp_get_topic_archive_title(); // No page so show the archive } else { $new_title = bbp_get_forum_archive_title(); } // ...or use the existing page title? } else { $new_title = apply_filters('the_title', $page->post_title); } // Reset post bbp_theme_compat_reset_post(array('ID' => !empty($page->ID) ? $page->ID : 0, 'post_title' => $new_title, 'post_author' => 0, 'post_date' => 0, 'post_content' => $new_content, 'post_type' => bbp_get_forum_post_type(), 'post_status' => bbp_get_public_status_id(), 'is_archive' => true, 'comment_status' => 'closed')); // Single Forum } elseif (bbp_is_forum_edit()) { // Reset post bbp_theme_compat_reset_post(array('ID' => bbp_get_forum_id(), 'post_title' => bbp_get_forum_title(), 'post_author' => bbp_get_forum_author_id(), 'post_date' => 0, 'post_content' => $bbp_shortcodes->display_forum_form(), 'post_type' => bbp_get_forum_post_type(), 'post_status' => bbp_get_forum_visibility(), 'is_single' => true, 'comment_status' => 'closed')); } elseif (bbp_is_single_forum()) { // Reset post bbp_theme_compat_reset_post(array('ID' => bbp_get_forum_id(), 'post_title' => bbp_get_forum_title(), 'post_author' => bbp_get_forum_author_id(), 'post_date' => 0, 'post_content' => $bbp_shortcodes->display_forum(array('id' => bbp_get_forum_id())), 'post_type' => bbp_get_forum_post_type(), 'post_status' => bbp_get_forum_visibility(), 'is_single' => true, 'comment_status' => 'closed')); /** Topics ************************************************************/ // Topic archive } elseif (bbp_is_topic_archive()) { // Page exists where this archive should be $page = bbp_get_page_by_path(bbp_get_topic_archive_slug()); // Should we replace the content... if (empty($page->post_content)) { $new_content = $bbp_shortcodes->display_topic_index(); // ...or use the existing page content? } else { $new_content = apply_filters('the_content', $page->post_content); } // Should we replace the title... if (empty($page->post_title)) { $new_title = bbp_get_topic_archive_title(); // ...or use the existing page title? } else { $new_title = apply_filters('the_title', $page->post_title); } // Reset post bbp_theme_compat_reset_post(array('ID' => !empty($page->ID) ? $page->ID : 0, 'post_title' => bbp_get_topic_archive_title(), 'post_author' => 0, 'post_date' => 0, 'post_content' => $new_content, 'post_type' => bbp_get_topic_post_type(), 'post_status' => bbp_get_public_status_id(), 'is_archive' => true, 'comment_status' => 'closed')); // Single Topic } elseif (bbp_is_topic_edit() || bbp_is_single_topic()) { // Split if (bbp_is_topic_split()) { $new_content = bbp_buffer_template_part('form', 'topic-split', false); // Merge } elseif (bbp_is_topic_merge()) { $new_content = bbp_buffer_template_part('form', 'topic-merge', false); // Edit } elseif (bbp_is_topic_edit()) { $new_content = $bbp_shortcodes->display_topic_form(); // Single } else { $new_content = $bbp_shortcodes->display_topic(array('id' => bbp_get_topic_id())); } // Reset post bbp_theme_compat_reset_post(array('ID' => bbp_get_topic_id(), 'post_title' => bbp_get_topic_title(), 'post_author' => bbp_get_topic_author_id(), 'post_date' => 0, 'post_content' => $new_content, 'post_type' => bbp_get_topic_post_type(), 'post_status' => bbp_get_topic_status(), 'is_single' => true, 'comment_status' => 'closed')); /** Replies ***********************************************************/ // Reply archive } elseif (is_post_type_archive(bbp_get_reply_post_type())) { // Reset post bbp_theme_compat_reset_post(array('ID' => 0, 'post_title' => __('Replies', 'bbpress'), 'post_author' => 0, 'post_date' => 0, 'post_content' => $bbp_shortcodes->display_reply_index(), 'post_type' => bbp_get_reply_post_type(), 'post_status' => bbp_get_public_status_id(), 'comment_status' => 'closed')); // Single Reply } elseif (bbp_is_reply_edit() || bbp_is_single_reply()) { // Move if (bbp_is_reply_move()) { $new_content = bbp_buffer_template_part('form', 'reply-move', false); // Edit } elseif (bbp_is_reply_edit()) { $new_content = $bbp_shortcodes->display_reply_form(); // Single } else { $new_content = $bbp_shortcodes->display_reply(array('id' => get_the_ID())); } // Reset post bbp_theme_compat_reset_post(array('ID' => bbp_get_reply_id(), 'post_title' => bbp_get_reply_title(), 'post_author' => bbp_get_reply_author_id(), 'post_date' => 0, 'post_content' => $new_content, 'post_type' => bbp_get_reply_post_type(), 'post_status' => bbp_get_reply_status(), 'comment_status' => 'closed')); /** Views *************************************************************/ } elseif (bbp_is_single_view()) { // Reset post bbp_theme_compat_reset_post(array('ID' => 0, 'post_title' => bbp_get_view_title(), 'post_author' => 0, 'post_date' => 0, 'post_content' => $bbp_shortcodes->display_view(array('id' => get_query_var(bbp_get_view_rewrite_id()))), 'post_type' => '', 'post_status' => bbp_get_public_status_id(), 'comment_status' => 'closed')); /** Search ************************************************************/ } elseif (bbp_is_search()) { // Reset post bbp_theme_compat_reset_post(array('ID' => 0, 'post_title' => bbp_get_search_title(), 'post_author' => 0, 'post_date' => 0, 'post_content' => $bbp_shortcodes->display_search(array('search' => get_query_var(bbp_get_search_rewrite_id()))), 'post_type' => '', 'post_status' => bbp_get_public_status_id(), 'comment_status' => 'closed')); /** Topic Tags ********************************************************/ // Topic Tag Edit } elseif (bbp_is_topic_tag_edit() || bbp_is_topic_tag()) { // Stash the current term in a new var set_query_var('bbp_topic_tag', get_query_var('term')); // Show topics of tag if (bbp_is_topic_tag()) { $new_content = $bbp_shortcodes->display_topics_of_tag(array('id' => bbp_get_topic_tag_id())); // Edit topic tag } elseif (bbp_is_topic_tag_edit()) { $new_content = $bbp_shortcodes->display_topic_tag_form(); } // Reset the post with our new title bbp_theme_compat_reset_post(array('ID' => 0, 'post_author' => 0, 'post_date' => 0, 'post_content' => $new_content, 'post_type' => '', 'post_title' => sprintf(__('Topic Tag: %s', 'bbpress'), '<span>' . bbp_get_topic_tag_name() . '</span>'), 'post_status' => bbp_get_public_status_id(), 'comment_status' => 'closed', 'is_tax' => true)); } /** * Bail if the template already matches a bbPress template. This includes * archive-* and single-* WordPress post_type matches (allowing * themes to use the expected format) as well as all bbPress-specific * template files for users, topics, forums, etc... * * We do this after the above checks to prevent incorrect 404 body classes * and header statuses, as well as to set the post global as needed. * * @see https://bbpress.trac.wordpress.org/ticket/1478/ */ if (bbp_is_template_included()) { return $template; /** * If we are relying on bbPress's built in theme compatibility to load * the proper content, we need to intercept the_content, replace the * output, and display ours instead. * * To do this, we first remove all filters from 'the_content' and hook * our own function into it, which runs a series of checks to determine * the context, and then uses the built in shortcodes to output the * correct results from inside an output buffer. * * Uses bbp_get_theme_compat_templates() to provide fall-backs that * should be coded without superfluous mark-up and logic (prev/next * navigation, comments, date/time, etc...) * * Hook into the 'bbp_get_bbpress_template' to override the array of * possible templates, or 'bbp_bbpress_template' to override the result. */ } elseif (bbp_is_theme_compat_active()) { bbp_remove_all_filters('the_content'); $template = bbp_get_theme_compat_templates(); } return apply_filters('bbp_template_include_theme_compat', $template); }
/** * Return admin links for reply * * @since bbPress (r2667) * * @param mixed $args This function supports these arguments: * - id: Optional. Reply id * - before: HTML before the links. Defaults to * '<span class="bbp-admin-links">' * - after: HTML after the links. Defaults to '</span>' * - sep: Separator. Defaults to ' | ' * - links: Array of the links to display. By default, edit, trash, * spam and topic split links are displayed * @uses bbp_is_topic() To check if it's the topic page * @uses bbp_is_reply() To check if it's the reply page * @uses bbp_get_reply_id() To get the reply id * @uses bbp_get_reply_edit_link() To get the reply edit link * @uses bbp_get_reply_trash_link() To get the reply trash link * @uses bbp_get_reply_spam_link() To get the reply spam link * @uses bbp_get_topic_split_link() To get the topic split link * @uses current_user_can() To check if the current user can edit or * delete the reply * @uses apply_filters() Calls 'bbp_get_reply_admin_links' with the * reply admin links and args * @return string Reply admin links */ function bbp_get_reply_admin_links($args = '') { $defaults = array('id' => 0, 'before' => '<span class="bbp-admin-links">', 'after' => '</span>', 'sep' => ' | ', 'links' => array()); $r = bbp_parse_args($args, $defaults, 'get_reply_admin_links'); $r['id'] = bbp_get_reply_id((int) $r['id']); // If post is a topic, return the topic admin links instead if (bbp_is_topic($r['id'])) { return bbp_get_topic_admin_links($args); } // If post is not a reply, return if (!bbp_is_reply($r['id'])) { return; } // Make sure user can edit this reply if (!current_user_can('edit_reply', $r['id'])) { return; } // If topic is trashed, do not show admin links if (bbp_is_topic_trash(bbp_get_reply_topic_id($r['id']))) { return; } // If no links were passed, default to the standard if (empty($r['links'])) { $r['links'] = array('edit' => bbp_get_reply_edit_link($r), 'split' => bbp_get_topic_split_link($r), 'trash' => bbp_get_reply_trash_link($r), 'spam' => bbp_get_reply_spam_link($r)); } // Check caps for trashing the topic if (!current_user_can('delete_reply', $r['id']) && !empty($r['links']['trash'])) { unset($r['links']['trash']); } // See if links need to be unset $reply_status = bbp_get_reply_status($r['id']); if (in_array($reply_status, array(bbp_get_spam_status_id(), bbp_get_trash_status_id()))) { // Spam link shouldn't be visible on trashed topics if ($reply_status == bbp_get_trash_status_id()) { unset($r['links']['spam']); // Trash link shouldn't be visible on spam topics } elseif (isset($r['links']['trash']) && bbp_get_spam_status_id() == $reply_status) { unset($r['links']['trash']); } } // Process the admin links $links = implode($r['sep'], array_filter($r['links'])); $retval = $r['before'] . $links . $r['after']; return apply_filters('bbp_get_reply_admin_links', $retval, $args); }
/** * Notify admin of new reply with pending status * * @param int $reply_id * @param int $topic_id * @param int $forum_id * @param boolean $anonymous_data * @param int $reply_author */ function new_reply($reply_id = 0, $topic_id = 0, $forum_id = 0, $anonymous_data = false, $reply_author = 0) { $reply_id = bbp_get_reply_id($reply_id); $status = bbp_get_reply_status($reply_id); if ($status == 'pending') { $this->notify_admin($reply_id); } }