function mycred_exclude_post_type_bbPress($excludes) { $excludes[] = bbp_get_forum_post_type(); $excludes[] = bbp_get_topic_post_type(); $excludes[] = bbp_get_reply_post_type(); return $excludes; }
/** * Move our custom separator above our custom post types * * @since bbPress (r2957) * * @param array $menu_order Menu Order * @uses bbp_get_forum_post_type() To get the forum post type * @return array Modified menu order */ function bbp_admin_menu_order($menu_order) { // Bail if user cannot see any top level bbPress menus if (empty($menu_order) || false === bbpress()->admin->show_separator) { return $menu_order; } // Initialize our custom order array $bbp_menu_order = array(); // Menu values $second_sep = 'separator2'; $custom_menus = array('separator-bbpress', 'edit.php?post_type=' . bbp_get_forum_post_type(), 'edit.php?post_type=' . bbp_get_topic_post_type(), 'edit.php?post_type=' . bbp_get_reply_post_type()); // Loop through menu order and do some rearranging foreach ($menu_order as $item) { // Position bbPress menus above appearance if ($second_sep == $item) { // Add our custom menus foreach ($custom_menus as $custom_menu) { if (array_search($custom_menu, $menu_order)) { $bbp_menu_order[] = $custom_menu; } } // Add the appearance separator $bbp_menu_order[] = $second_sep; // Skip our menu items } elseif (!in_array($item, $custom_menus)) { $bbp_menu_order[] = $item; } } // Return our custom order return $bbp_menu_order; }
/** * Remove the meta box from some post types. * * @since 1.3.0 * @param string $post_type The post type of the current post being edited. * @param object $post The current post being edited. * @return void */ function hybrid_meta_box_post_remove_seo($post_type, $post) { /* Removes post stylesheets support of the bbPress 'topic' post type. */ if (function_exists('bbp_get_topic_post_type') && bbp_get_topic_post_type() == $post_type) { remove_meta_box('hybrid-core-post-seo', bbp_get_topic_post_type(), 'normal'); } elseif (function_exists('bbp_get_reply_post_type') && bbp_get_reply_post_type() == $post_type) { remove_meta_box('hybrid-core-post-seo', bbp_get_reply_post_type(), 'normal'); } }
/** * Remove the meta box from some post types. * * @since 1.3.0 * @access public * @param string $post_type The post type of the current post being edited. * @param object $post The current post being edited. * @return void */ function hybrid_meta_box_post_remove_template($post_type, $post) { /* Removes meta box from pages since this is a built-in WordPress feature. */ if ('page' == $post_type) { remove_meta_box('hybrid-core-post-template', 'page', 'side'); } elseif (function_exists('bbp_get_topic_post_type') && bbp_get_topic_post_type() == $post_type) { remove_meta_box('hybrid-core-post-template', bbp_get_topic_post_type(), 'side'); } elseif (function_exists('bbp_get_reply_post_type') && bbp_get_reply_post_type() == $post_type) { remove_meta_box('hybrid-core-post-template', bbp_get_reply_post_type(), 'side'); } }
function register_bb_custom_sidebar_mb() { if (!function_exists('bbp_get_topic_post_type') || !function_exists('bbp_get_forum_post_type') || !function_exists('bbp_get_reply_post_type')) { return; } $options = array('id' => 'circleflip-custom-sidebar-page', 'title' => 'Custom Sidebar', 'callback' => 'render_page_custom_sidebar_mb', 'context' => 'normal', 'priority' => 'high', 'callback_args' => NULL); extract($options); add_meta_box($id, $title, $callback, bbp_get_topic_post_type(), $context, $priority, $callback_args); add_meta_box($id, $title, $callback, bbp_get_forum_post_type(), $context, $priority, $callback_args); add_meta_box($id, $title, $callback, bbp_get_reply_post_type(), $context, $priority, $callback_args); }
function bbpvotes_buddypress_voted_activity($post_id, $user_id, $vote) { //check vote value if (is_bool($vote) === false) { return new WP_Error('vote_is_not_bool', __('Vote is not a boolean', 'bbpvotes')); } $voteplus = $vote === true; $voteminus = $vote === false; $post = get_post($post_id); $user_link = bbp_get_user_profile_link($user_id); //build item link if ($post->post_type == bbp_get_topic_post_type()) { $topic_id = $post->ID; $post_permalink = get_permalink($post->ID); } elseif ($post->post_type == bbp_get_reply_post_type()) { $topic_id = bbp_get_reply_topic_id($post->ID); $post_permalink = bbp_get_reply_url($post->ID); } //topic infos $topic = get_post($topic_id); $topic_author_link = bbp_get_user_profile_link($topic->post_author); $topic_title = $topic->post_title; $post_link = '<a href="' . $post_permalink . '">' . $topic_title . '</a>'; if ($voteplus) { $type = 'bbpvotes_voted_up'; if ($post->post_type == bbp_get_topic_post_type()) { $action = sprintf(esc_html__('%1$s voted up to the topic %2$s by %3$s', 'bbpress'), $user_link, $post_link, $topic_author_link); } elseif ($post->post_type == bbp_get_reply_post_type()) { $action = sprintf(esc_html__('%1$s voted up to a reply by %3$s in the topic %2$s', 'bbpress'), $user_link, $post_link, $topic_author_link); } } else { $type = 'bbpvotes_voted_down'; if ($post->post_type == bbp_get_topic_post_type()) { $action = sprintf(esc_html__('%1$s voted down to the topic %2$s by %3$s', 'bbpress'), $user_link, $post_link, $topic_author_link); } elseif ($post->post_type == bbp_get_reply_post_type()) { $action = sprintf(esc_html__('%1$s voted down to a reply by %3$s in the topic %2$s', 'bbpress'), $user_link, $post_link, $topic_author_link); } } $args = array('action' => $action, 'component' => 'bbpress', 'type' => $type, 'item_id' => $topic->ID); if ($post->post_type == bbp_get_reply_post_type()) { $args['secondary_item_id'] = $post->ID; } /* if ($is_update){ $previous_activity_id = $args['id'] = $previous_activity_id; } */ bp_activity_add($args); }
/** * @covers ::bbp_reply_post_type * @covers ::bbp_get_reply_post_type */ public function test_bbp_reply_post_type() { $t = $this->factory->topic->create(); $r = $this->factory->reply->create(array('post_parent' => $t, 'reply_meta' => array('topic_id' => $t))); $robj = get_post_type_object('reply'); $this->assertInstanceOf('stdClass', $robj); $this->assertEquals('reply', $robj->name); // Test some defaults $this->assertFalse(is_post_type_hierarchical('topic')); $reply_type = bbp_reply_post_type($r); $this->expectOutputString('reply', $reply_type); $reply_type = bbp_get_reply_post_type($r); $this->assertSame('reply', $reply_type); }
/** * bbPress post types. * * @since 150821 Improving bbPress support. * * @return array All bbPress post types. */ public function bbPressPostTypes() { if (!$this->isBbPressActive()) { return []; } if (!is_null($types =& $this->cacheKey('bbPressPostTypes'))) { return $types; // Already did this. } $types = []; // Initialize. $types[] = bbp_get_forum_post_type(); $types[] = bbp_get_topic_post_type(); $types[] = bbp_get_reply_post_type(); return $types; }
/** * @covers ::bbp_reply_post_type * @covers ::bbp_get_reply_post_type */ public function test_bbp_reply_post_type() { $t = $this->factory->topic->create(); $r = $this->factory->reply->create(array('post_parent' => $t, 'reply_meta' => array('topic_id' => $t))); $robj = get_post_type_object('reply'); // WordPress 4.6 introduced `WP_Post_Type` class if (bbp_get_major_wp_version() < 4.6) { $this->assertInstanceOf('stdClass', $robj); } else { $this->assertInstanceOf('WP_Post_Type', $robj); } $this->assertEquals('reply', $robj->name); // Test some defaults $this->assertFalse(is_post_type_hierarchical('topic')); $reply_type = bbp_reply_post_type($r); $this->expectOutputString('reply', $reply_type); $reply_type = bbp_get_reply_post_type($r); $this->assertSame('reply', $reply_type); }
function widget($args, $instance) { extract($args, EXTR_SKIP); $title = !empty($instance['title']) ? $instance['title'] : __('Recent Comments'); $title = apply_filters('widget_title', $title, $instance, $this->id_base); $number = !empty($instance['number']) ? absint($instance['number']) : 5; if (!$number) { $number = 5; } $cb_qry = new WP_Query(array('post_type' => bbp_get_reply_post_type(), 'post_status' => array(bbp_get_public_status_id(), bbp_get_closed_status_id()), 'posts_per_page' => $number, 'ignore_sticky_posts' => true, 'no_found_rows' => true)); echo $before_widget; echo $before_title . $title . $after_title; ?> <ul class="cb-bbp-recent-replies"> <?php while ($cb_qry->have_posts()) { $cb_qry->the_post(); ?> <li> <?php $cb_reply_id = bbp_get_reply_id($cb_qry->post->ID); $cb_reply_url = '<a class="bbp-reply-topic-title" href="' . esc_url(bbp_get_reply_url($cb_reply_id)) . '" title="' . esc_attr(bbp_get_reply_excerpt($cb_reply_id, 50)) . '">' . bbp_get_reply_topic_title($cb_reply_id) . '</a>'; $cb_author_avatar = bbp_get_reply_author_link(array('post_id' => $cb_reply_id, 'type' => 'avatar', 'size' => 60)); $cb_author_name = bbp_get_reply_author_link(array('post_id' => $cb_reply_id, 'type' => 'name')); echo $cb_author_avatar . '<div class="cb-bbp-meta">' . $cb_author_name . ' <i class="icon-long-arrow-right"></i> ' . $cb_reply_url . '<div class="cb-bbp-recent-replies-time">' . bbp_get_time_since(get_the_time('U')) . '</div></div>'; ?> </li> <?php } ?> </ul> <?php echo $after_widget; // Reset the $post global wp_reset_postdata(); }
function check_private_groups_reply_ids($post_ids) { //Init the Array which will hold our list of allowed posts $allowed_posts = array(); //Loop through all the posts foreach ($post_ids as $post_id) { //Get the Forum ID based on Post Type Topic $reply = bbp_get_reply_post_type(); $forum_id = private_groups_get_forum_id_from_post_id($post_id, $reply); //Check if User has permissions to view this Post ID //by calling the function that checks if the user can view this forum, and hence this post if (private_groups_can_user_view_post_id($forum_id)) { //User can view this post - add it to the allowed array array_push($allowed_posts, $post_id); } } //Return the list return $allowed_posts; }
function tehnik_bpp_get_forum_id_from_post_id($post_id, $post_type) { $forum_id = 0; // Check post type switch ($post_type) { // Forum case bbp_get_forum_post_type(): $forum_id = bbp_get_forum_id($post_id); break; // Topic // Topic case bbp_get_topic_post_type(): $forum_id = bbp_get_topic_forum_id($post_id); break; // Reply // Reply case bbp_get_reply_post_type(): $forum_id = bbp_get_reply_forum_id($post_id); break; } return $forum_id; }
function bbpress_replieslist_settings_field($settings, $value) { $dependency = vc_generate_dependencies_attributes($settings); $param_name = isset($settings['param_name']) ? $settings['param_name'] : ''; $type = isset($settings['type']) ? $settings['type'] : ''; $args = array('post_type' => bbp_get_reply_post_type(), 'orderby' => 'title', 'order' => 'ASC'); $forums = new WP_Query($args); $output = ''; $output .= '<select name="' . $settings['param_name'] . '" class="wpb_vc_param_value wpb-input wpb-select ' . $settings['param_name'] . ' ' . $settings['type'] . '">'; while ($forums->have_posts()) { $forums->the_post(); if ($value != '' && get_the_ID() == $value) { $selected = ' selected="selected"'; } else { $selected = ""; } $output .= '<option class="' . get_the_ID() . '" data-id="' . get_the_ID() . '" data-value="' . get_the_title() . '" value="' . get_the_ID() . '"' . $selected . '>' . get_the_title() . '</option>'; } wp_reset_query(); $output .= '</select>'; return $output; }
/** * Can the current user see a specific UI element? * * Used when registering post-types and taxonomies to decide if 'show_ui' should * be set to true or false. Also used for fine-grained control over which admin * sections are visible under what conditions. * * This function is in bbp-core-caps.php rather than in /bbp-admin so that it * can be used during the bbp_register_post_types action. * * @since bbPress (r3944) * * @uses current_user_can() To check the 'moderate' capability * @uses bbp_get_forum_post_type() * @uses bbp_get_topic_post_type() * @uses bbp_get_reply_post_type() * @uses bbp_get_topic_tag_tax_id() * @uses is_plugin_active() * @uses is_super_admin() * @return bool Results of current_user_can( 'moderate' ) check. */ function bbp_current_user_can_see($component = '') { // Define local variable $retval = false; // Which component are we checking UI visibility for? switch ($component) { /** Everywhere ********************************************************/ case bbp_get_forum_post_type(): // Forums // Forums case bbp_get_topic_post_type(): // Topics // Topics case bbp_get_reply_post_type(): // Replies // Replies case bbp_get_topic_tag_tax_id(): // Topic-Tags $retval = current_user_can('moderate'); break; /** Admin Exclusive ***************************************************/ /** Admin Exclusive ***************************************************/ case 'bbp_settings_buddypress': // BuddyPress Extension $retval = is_plugin_active('buddypress/bp-loader.php') && defined('BP_VERSION') && is_super_admin(); break; case 'bbp_settings_akismet': // Akismet Extension $retval = is_plugin_active('akismet/akismet.php') && defined('AKISMET_VERSION') && is_super_admin(); break; case 'bbp_tools_page': // Tools Page // Tools Page case 'bbp_tools_repair_page': // Tools - Repair Page // Tools - Repair Page case 'bbp_tools_import_page': // Tools - Import Page // Tools - Import Page case 'bbp_tools_reset_page': // Tools - Reset Page // Tools - Reset Page case 'bbp_settings?page': // Settings Page // Settings Page case 'bbp_settings_main': // Settings - General // Settings - General case 'bbp_settings_theme_compat': // Settings - Theme compat // Settings - Theme compat case 'bbp_settings_root_slugs': // Settings - Root slugs // Settings - Root slugs case 'bbp_settings_single_slugs': // Settings - Single slugs // Settings - Single slugs case 'bbp_settings_per_page': // Settings - Single slugs // Settings - Single slugs case 'bbp_settings_per_page_rss': // Settings - Single slugs // Settings - Single slugs default: // Anything else $retval = current_user_can(bbpress()->admin->minimum_capability); break; } return (bool) apply_filters('bbp_current_user_can_see', (bool) $retval, $component); }
/** * Check if it's a private forum or a topic or reply of a private forum and if * the user can't view it, then sets a 404 * * @since bbPress (r2996) * * @uses current_user_can() To check if the current user can read private forums * @uses is_singular() To check if it's a singular page * @uses bbp_is_user_keymaster() To check if user is a keymaster * @uses bbp_get_forum_post_type() To get the forum post type * @uses bbp_get_topic_post_type() To get the topic post type * @uses bbp_get_reply_post_type() TO get the reply post type * @uses bbp_get_topic_forum_id() To get the topic forum id * @uses bbp_get_reply_forum_id() To get the reply forum id * @uses bbp_is_forum_private() To check if the forum is private or not * @uses bbp_set_404() To set a 404 status */ function bbp_forum_enforce_private() { // Bail if not viewing a single item or if user has caps if (!is_singular() || bbp_is_user_keymaster() || current_user_can('read_private_forums')) { return; } global $wp_query; // Define local variable $forum_id = 0; // Check post type switch ($wp_query->get('post_type')) { // Forum case bbp_get_forum_post_type(): $forum_id = bbp_get_forum_id($wp_query->post->ID); break; // Topic // Topic case bbp_get_topic_post_type(): $forum_id = bbp_get_topic_forum_id($wp_query->post->ID); break; // Reply // Reply case bbp_get_reply_post_type(): $forum_id = bbp_get_reply_forum_id($wp_query->post->ID); break; } // If forum is explicitly hidden and user not capable, set 404 if (!empty($forum_id) && bbp_is_forum_private($forum_id) && !current_user_can('read_private_forums')) { bbp_set_404(); } }
/** * Return a breadcrumb ( forum -> topic -> reply ) * * @since bbPress (r2589) * * @param string $sep Separator. Defaults to '←' * @param bool $current_page Include the current item * @param bool $root Include the root page if one exists * * @uses get_post() To get the post * @uses bbp_get_forum_permalink() To get the forum link * @uses bbp_get_topic_permalink() To get the topic link * @uses bbp_get_reply_permalink() To get the reply link * @uses get_permalink() To get the permalink * @uses bbp_get_forum_post_type() To get the forum post type * @uses bbp_get_topic_post_type() To get the topic post type * @uses bbp_get_reply_post_type() To get the reply post type * @uses bbp_get_forum_title() To get the forum title * @uses bbp_get_topic_title() To get the topic title * @uses bbp_get_reply_title() To get the reply title * @uses get_the_title() To get the title * @uses apply_filters() Calls 'bbp_get_breadcrumb' with the crumbs * @return string Breadcrumbs */ function bbp_get_breadcrumb($args = array()) { // Turn off breadcrumbs if (apply_filters('bbp_no_breadcrumb', is_front_page())) { return; } // Define variables $front_id = $root_id = 0; $ancestors = $crumbs = $tag_data = array(); $pre_root_text = $pre_front_text = $pre_current_text = ''; $pre_include_root = $pre_include_home = $pre_include_current = true; /** Home Text *********************************************************/ // No custom home text if (empty($args['home_text'])) { // Set home text to page title $front_id = get_option('page_on_front'); if (!empty($front_id)) { $pre_front_text = get_the_title($front_id); // Default to 'Home' } else { $pre_front_text = __('Home', 'bbpress'); } } /** Root Text *********************************************************/ // No custom root text if (empty($args['root_text'])) { $page = bbp_get_page_by_path(bbp_get_root_slug()); if (!empty($page)) { $root_id = $page->ID; } $pre_root_text = bbp_get_forum_archive_title(); } /** Includes **********************************************************/ // Root slug is also the front page if (!empty($front_id) && $front_id == $root_id) { $pre_include_root = false; } // Don't show root if viewing forum archive if (bbp_is_forum_archive()) { $pre_include_root = false; } // Don't show root if viewing page in place of forum archive if (!empty($root_id) && ((is_single() || is_page()) && $root_id == get_the_ID())) { $pre_include_root = false; } /** Current Text ******************************************************/ // Forum archive if (bbp_is_forum_archive()) { $pre_current_text = bbp_get_forum_archive_title(); // Topic archive } elseif (bbp_is_topic_archive()) { $pre_current_text = bbp_get_topic_archive_title(); // View } elseif (bbp_is_single_view()) { $pre_current_text = bbp_get_view_title(); // Single Forum } elseif (bbp_is_single_forum()) { $pre_current_text = bbp_get_forum_title(); // Single Topic } elseif (bbp_is_single_topic()) { $pre_current_text = bbp_get_topic_title(); // Single Topic } elseif (bbp_is_single_reply()) { $pre_current_text = bbp_get_reply_title(); // Topic Tag (or theme compat topic tag) } elseif (bbp_is_topic_tag() || get_query_var('bbp_topic_tag') && !bbp_is_topic_tag_edit()) { // Always include the tag name $tag_data[] = bbp_get_topic_tag_name(); // If capable, include a link to edit the tag if (current_user_can('manage_topic_tags')) { $tag_data[] = '<a href="' . bbp_get_topic_tag_edit_link() . '" class="bbp-edit-topic-tag-link">' . __('(Edit)', 'bbpress') . '</a>'; } // Implode the results of the tag data $pre_current_text = sprintf(__('Topic Tag: %s', 'bbpress'), implode(' ', $tag_data)); // Edit Topic Tag } elseif (bbp_is_topic_tag_edit()) { $pre_current_text = __('Edit', 'bbpress'); // Single } else { $pre_current_text = get_the_title(); } /** Parse Args ********************************************************/ // Parse args $defaults = array('before' => '<div class="bbp-breadcrumb"><p>', 'after' => '</p></div>', 'sep' => __('›', 'bbpress'), 'pad_sep' => 1, 'include_home' => $pre_include_home, 'home_text' => $pre_front_text, 'include_root' => $pre_include_root, 'root_text' => $pre_root_text, 'include_current' => $pre_include_current, 'current_text' => $pre_current_text); $r = bbp_parse_args($args, $defaults, 'get_breadcrumb'); extract($r); /** Ancestors *********************************************************/ // Get post ancestors if (is_page() || is_single() || bbp_is_forum_edit() || bbp_is_topic_edit() || bbp_is_reply_edit()) { $ancestors = array_reverse(get_post_ancestors(get_the_ID())); } // Do we want to include a link to home? if (!empty($include_home) || empty($home_text)) { $crumbs[] = '<a href="' . trailingslashit(home_url()) . '" class="bbp-breadcrumb-home">' . $home_text . '</a>'; } // Do we want to include a link to the forum root? if (!empty($include_root) || empty($root_text)) { // Page exists at root slug path, so use its permalink $page = bbp_get_page_by_path(bbp_get_root_slug()); if (!empty($page)) { $root_url = get_permalink($page->ID); // Use the root slug } else { $root_url = get_post_type_archive_link(bbp_get_forum_post_type()); } // Add the breadcrumb $crumbs[] = '<a href="' . $root_url . '" class="bbp-breadcrumb-root">' . $root_text . '</a>'; } // Ancestors exist if (!empty($ancestors)) { // Loop through parents foreach ((array) $ancestors as $parent_id) { // Parents $parent = get_post($parent_id); // Switch through post_type to ensure correct filters are applied switch ($parent->post_type) { // Forum case bbp_get_forum_post_type(): $crumbs[] = '<a href="' . bbp_get_forum_permalink($parent->ID) . '" class="bbp-breadcrumb-forum">' . bbp_get_forum_title($parent->ID) . '</a>'; break; // Topic // Topic case bbp_get_topic_post_type(): $crumbs[] = '<a href="' . bbp_get_topic_permalink($parent->ID) . '" class="bbp-breadcrumb-topic">' . bbp_get_topic_title($parent->ID) . '</a>'; break; // Reply (Note: not in most themes) // Reply (Note: not in most themes) case bbp_get_reply_post_type(): $crumbs[] = '<a href="' . bbp_get_reply_permalink($parent->ID) . '" class="bbp-breadcrumb-reply">' . bbp_get_reply_title($parent->ID) . '</a>'; break; // WordPress Post/Page/Other // WordPress Post/Page/Other default: $crumbs[] = '<a href="' . get_permalink($parent->ID) . '" class="bbp-breadcrumb-item">' . get_the_title($parent->ID) . '</a>'; break; } } // Edit topic tag } elseif (bbp_is_topic_tag_edit()) { $crumbs[] = '<a href="' . get_term_link(bbp_get_topic_tag_id(), bbp_get_topic_tag_tax_id()) . '" class="bbp-breadcrumb-topic-tag">' . sprintf(__('Topic Tag: %s', 'bbpress'), bbp_get_topic_tag_name()) . '</a>'; } /** Current ***********************************************************/ // Add current page to breadcrumb if (!empty($include_current) || empty($pre_current_text)) { $crumbs[] = '<span class="bbp-breadcrumb-current">' . $current_text . '</span>'; } /** Separator *********************************************************/ // Wrap the separator in a span before padding and filter if (!empty($sep)) { $sep = '<span class="bbp-breadcrumb-separator">' . $sep . '</span>'; } // Pad the separator if (!empty($pad_sep)) { $sep = str_pad($sep, strlen($sep) + (int) $pad_sep * 2, ' ', STR_PAD_BOTH); } /** Finish Up *********************************************************/ // Filter the separator and breadcrumb $sep = apply_filters('bbp_breadcrumb_separator', $sep); $crumbs = apply_filters('bbp_breadcrumbs', $crumbs); // Build the trail $trail = !empty($crumbs) ? $before . implode($sep, $crumbs) . $after : ''; return apply_filters('bbp_get_breadcrumb', $trail, $crumbs, $r); }
/** * Return URL to the reply edit page * * @since bbPress (r2753) * * @param int $reply_id Optional. Reply id * @uses bbp_get_reply_id() To get the reply id * @uses bbp_get_reply() To get the reply * @uses bbp_get_reply_post_type() To get the reply post type * @uses add_query_arg() To add custom args to the url * @uses apply_filters() Calls 'bbp_get_reply_edit_url' with the edit * url and reply id * @return string Reply edit url */ function bbp_get_reply_edit_url($reply_id = 0) { global $wp_rewrite; $bbp = bbpress(); $reply = bbp_get_reply(bbp_get_reply_id($reply_id)); if (empty($reply)) { return; } $reply_link = bbp_remove_view_all(bbp_get_reply_permalink($reply_id)); // Pretty permalinks if ($wp_rewrite->using_permalinks()) { $url = trailingslashit($reply_link) . $bbp->edit_id; $url = trailingslashit($url); // Unpretty permalinks } else { $url = add_query_arg(array(bbp_get_reply_post_type() => $reply->post_name, $bbp->edit_id => '1'), $reply_link); } // Maybe add view all $url = bbp_add_view_all($url); return apply_filters('bbp_get_reply_edit_url', $url, $reply_id); }
/** * Get the replies that a user created * * @since bbPress (r4225) * * @param int $user_id Optional. User id * @uses bbp_get_user_id() To get the topic id * @uses bbp_has_replies() To get the topics created by the user * @return array|bool Results if the user has created topics, otherwise false */ function bbp_get_user_replies_created($user_id = 0) { // Validate user $user_id = bbp_get_user_id($user_id); if (empty($user_id)) { return false; } // Try to get the topics $query = bbp_has_replies(array('post_type' => array(bbp_get_topic_post_type(), bbp_get_reply_post_type()), 'post_parent' => 'any', 'posts_per_page' => bbp_get_replies_per_page(), 'paged' => bbp_get_paged(), 'orderby' => 'date', 'order' => 'DESC', 'author' => $user_id, 'show_stickies' => false)); return apply_filters('bbp_get_user_replies_created', $query, $user_id); }
/** * Get the reply move template * * @since bbPress (r4521) * * @uses bbp_get_reply_post_type() * @uses bbp_get_query_template() * @return string Path to template file */ function bbp_get_reply_move_template() { $templates = array('single-' . bbp_get_reply_post_type() . '-move.php'); return bbp_get_query_template('reply_move', $templates); }
/** * Enqueue any admin scripts we might need * * @since bbPress (r4260) */ public function enqueue_scripts() { wp_enqueue_script('suggest'); // Get the version to use for JS $version = bbp_get_version(); // Post type checker (only topics and replies) if ('post' === get_current_screen()->base) { switch (get_current_screen()->post_type) { case bbp_get_reply_post_type(): case bbp_get_topic_post_type(): // Enqueue the common JS wp_enqueue_script('bbp-admin-common-js', $this->js_url . 'common.js', array('jquery'), $version); // Topics admin if (bbp_get_topic_post_type() === get_current_screen()->post_type) { wp_enqueue_script('bbp-admin-topics-js', $this->js_url . 'topics.js', array('jquery'), $version); // Replies admin } elseif (bbp_get_reply_post_type() === get_current_screen()->post_type) { wp_enqueue_script('bbp-admin-replies-js', $this->js_url . 'replies.js', array('jquery'), $version); } break; } } }
/** * Handle the processing and feedback of the admin tools page * * @since 2.0.0 bbPress (r2613) * * @uses check_admin_referer() To verify the nonce and the referer * @uses wp_cache_flush() To flush the cache * @uses bbp_get_forum_post_type() To get the forum post type * @uses bbp_get_topic_post_type() To get the topic post type * @uses bbp_get_reply_post_type() To get the reply post type */ function bbp_admin_reset_handler() { // Bail if not resetting if (!bbp_is_post_request() || empty($_POST['bbpress-are-you-sure'])) { return; } // Only keymasters can proceed if (!bbp_is_user_keymaster()) { return; } check_admin_referer('bbpress-reset'); // Stores messages $messages = array(); $failed = __('Failed!', 'bbpress'); $success = __('Success!', 'bbpress'); // Flush the cache; things are about to get ugly. wp_cache_flush(); /** Posts *****************************************************************/ // Post types and status $fpt = bbp_get_forum_post_type(); $tpt = bbp_get_topic_post_type(); $rpt = bbp_get_reply_post_type(); // Define variables $bbp_db = bbp_db(); $statement = __('Deleting Posts… %s', 'bbpress'); $sql_posts = $bbp_db->get_results("SELECT `ID` FROM `{$bbp_db->posts}` WHERE `post_type` IN ('{$fpt}', '{$tpt}', '{$rpt}')", OBJECT_K); $sql_delete = "DELETE FROM `{$bbp_db->posts}` WHERE `post_type` IN ('{$fpt}', '{$tpt}', '{$rpt}')"; $result = is_wp_error($bbp_db->query($sql_delete)) ? $failed : $success; $messages[] = sprintf($statement, $result); /** Post Meta *************************************************************/ if (!empty($sql_posts)) { $sql_meta = array(); foreach ($sql_posts as $key => $value) { $sql_meta[] = $key; } $statement = __('Deleting Post Meta… %s', 'bbpress'); $sql_meta = implode("', '", $sql_meta); $sql_delete = "DELETE FROM `{$bbp_db->postmeta}` WHERE `post_id` IN ('{$sql_meta}');"; $result = is_wp_error($bbp_db->query($sql_delete)) ? $failed : $success; $messages[] = sprintf($statement, $result); } /** Forum moderators ******************************************************/ $statement = __('Deleting Forum Moderators… %s', 'bbpress'); $sql_delete = "DELETE a,b,c FROM `{$bbp_db->terms}` AS a LEFT JOIN `{$bbp_db->term_taxonomy}` AS c ON a.term_id = c.term_id LEFT JOIN `{$bbp_db->term_relationships}` AS b ON b.term_taxonomy_id = c.term_taxonomy_id WHERE c.taxonomy = 'forum-mod';"; $result = is_wp_error($bbp_db->query($sql_delete)) ? $failed : $success; $messages[] = sprintf($statement, $result); /** Topic Tags ************************************************************/ $statement = __('Deleting Topic Tags… %s', 'bbpress'); $sql_delete = "DELETE a,b,c FROM `{$bbp_db->terms}` AS a LEFT JOIN `{$bbp_db->term_taxonomy}` AS c ON a.term_id = c.term_id LEFT JOIN `{$bbp_db->term_relationships}` AS b ON b.term_taxonomy_id = c.term_taxonomy_id WHERE c.taxonomy = 'topic-tag';"; $result = is_wp_error($bbp_db->query($sql_delete)) ? $failed : $success; $messages[] = sprintf($statement, $result); /** User ******************************************************************/ // First, if we're deleting previously imported users, delete them now if (!empty($_POST['bbpress-delete-imported-users'])) { $sql_users = $bbp_db->get_results("SELECT `user_id` FROM `{$bbp_db->usermeta}` WHERE `meta_key` = '_bbp_user_id'", OBJECT_K); if (!empty($sql_users)) { $sql_meta = array(); foreach ($sql_users as $key => $value) { $sql_meta[] = $key; } $statement = __('Deleting User… %s', 'bbpress'); $sql_meta = implode("', '", $sql_meta); $sql_delete = "DELETE FROM `{$bbp_db->users}` WHERE `ID` IN ('{$sql_meta}');"; $result = is_wp_error($bbp_db->query($sql_delete)) ? $failed : $success; $messages[] = sprintf($statement, $result); $statement = __('Deleting User Meta… %s', 'bbpress'); $sql_delete = "DELETE FROM `{$bbp_db->usermeta}` WHERE `user_id` IN ('{$sql_meta}');"; $result = is_wp_error($bbp_db->query($sql_delete)) ? $failed : $success; $messages[] = sprintf($statement, $result); } } // Next, if we still have users that were not imported delete that meta data $statement = __('Deleting User Meta… %s', 'bbpress'); $sql_delete = "DELETE FROM `{$bbp_db->usermeta}` WHERE `meta_key` LIKE '%%_bbp_%%';"; $result = is_wp_error($bbp_db->query($sql_delete)) ? $failed : $success; $messages[] = sprintf($statement, $result); /** Converter *************************************************************/ $statement = __('Deleting Conversion Table… %s', 'bbpress'); $table_name = $bbp_db->prefix . 'bbp_converter_translator'; if ($bbp_db->get_var("SHOW TABLES LIKE '{$table_name}'") === $table_name) { $bbp_db->query("DROP TABLE {$table_name}"); $result = $success; } else { $result = $failed; } $messages[] = sprintf($statement, $result); /** Options ***************************************************************/ $statement = __('Deleting Settings… %s', 'bbpress'); bbp_delete_options(); $messages[] = sprintf($statement, $success); /** Roles *****************************************************************/ $statement = __('Deleting Roles and Capabilities… %s', 'bbpress'); bbp_remove_roles(); bbp_remove_caps(); $messages[] = sprintf($statement, $success); /** Output ****************************************************************/ if (count($messages)) { foreach ($messages as $message) { bbp_admin_tools_feedback($message); } } }
/** * Return value of topic tags field * * @since 2.0.0 bbPress (r2976) * * @uses bbp_is_topic_edit() To check if it's the topic edit page * @uses apply_filters() Calls 'bbp_get_form_topic_tags' with the tags * @return string Value of topic tags field */ function bbp_get_form_topic_tags() { // Default return value $topic_tags = ''; // Get _POST data if ((bbp_is_topic_form_post_request() || bbp_is_reply_form_post_request()) && isset($_POST['bbp_topic_tags'])) { $topic_tags = wp_unslash($_POST['bbp_topic_tags']); // Get edit data } elseif (bbp_is_single_topic() || bbp_is_single_reply() || bbp_is_topic_edit() || bbp_is_reply_edit()) { // Determine the topic id based on the post type switch (get_post_type()) { // Post is a topic case bbp_get_topic_post_type(): $topic_id = bbp_get_topic_id(get_the_ID()); break; // Post is a reply // Post is a reply case bbp_get_reply_post_type(): $topic_id = bbp_get_reply_topic_id(get_the_ID()); break; } // Topic exists if (!empty($topic_id)) { // Topic is spammed so display pre-spam terms if (bbp_is_topic_spam($topic_id)) { // Get pre-spam terms $spam_terms = get_post_meta($topic_id, '_bbp_spam_topic_tags', true); $topic_tags = !empty($spam_terms) ? implode(', ', $spam_terms) : ''; // Topic is not spam so get real terms } else { $topic_tags = bbp_get_topic_tag_names($topic_id); } } } return apply_filters('bbp_get_form_topic_tags', $topic_tags); }
/** * Called before trashing a topic * * This function is supplemental to the actual topic being trashed which is * handled by WordPress core API functions. It is used to clean up after * a topic that is being trashed. * * @uses bbp_get_topic_id() To get the topic id * @uses bbp_is_topic() To check if the passed id is a topic * @uses do_action() Calls 'bbp_trash_topic' with the topic id * @uses wp_trash_post() To trash the reply * @uses update_post_meta() To save a list of just trashed replies for future use */ function bbp_trash_topic($topic_id = 0) { // Validate topic ID $topic_id = bbp_get_topic_id($topic_id); if (empty($topic_id) || !bbp_is_topic($topic_id)) { return false; } do_action('bbp_trash_topic', $topic_id); // Topic is being trashed, so its replies are trashed too $replies = new WP_Query(array('suppress_filters' => true, 'post_type' => bbp_get_reply_post_type(), 'post_status' => bbp_get_public_status_id(), 'post_parent' => $topic_id, 'posts_per_page' => -1, 'nopaging' => true, 'fields' => 'id=>parent')); if (!empty($replies->posts)) { // Prevent debug notices $pre_trashed_replies = array(); // Loop through replies, trash them, and add them to array foreach ($replies->posts as $reply) { wp_trash_post($reply->ID); $pre_trashed_replies[] = $reply->ID; } // Set a post_meta entry of the replies that were trashed by this action. // This is so we can possibly untrash them, without untrashing replies // that were purposefully trashed before. update_post_meta($topic_id, '_bbp_pre_trashed_replies', $pre_trashed_replies); // Reset the $post global wp_reset_postdata(); } // Cleanup unset($replies); }
/** * Mark a users topics and replies as spam when the user is marked as spam * * @since bbPress (r3405) * * @global WPDB $wpdb * @param int $user_id Optional. User ID to unspam. Defaults to displayed user. * * @uses bbp_is_single_user() * @uses bbp_is_user_home() * @uses bbp_get_displayed_user_id() * @uses bbp_is_user_keymaster() * @uses get_blogs_of_user() * @uses bbp_get_topic_post_type() * @uses bbp_get_reply_post_type() * @uses switch_to_blog() * @uses get_post_type() * @uses bbp_unspam_topic() * @uses bbp_unspam_reply() * @uses restore_current_blog() * * @return If no user ID passed */ function bbp_make_ham_user($user_id = 0) { // Use displayed user if it's not yourself if (empty($user_id) && bbp_is_single_user() && !bbp_is_user_home()) { $user_id = bbp_get_displayed_user_id(); } // Bail if no user ID if (empty($user_id)) { return false; } // Bail if user ID is keymaster if (bbp_is_user_keymaster($user_id)) { return false; } // Arm the torpedos global $wpdb; // Get the blog IDs of the user to mark as spam $blogs = get_blogs_of_user($user_id, true); // If user has no blogs, they are a guest on this site if (empty($blogs)) { $blogs[$wpdb->blogid] = array(); } // Make array of post types to mark as spam $post_types = array(bbp_get_topic_post_type(), bbp_get_reply_post_type()); $post_types = "'" . implode("', '", $post_types) . "'"; // Loop through blogs and remove their posts foreach ((array) array_keys($blogs) as $blog_id) { // Switch to the blog ID switch_to_blog($blog_id); // Get topics and replies $posts = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_author = %d AND post_status = '%s' AND post_type IN ( {$post_types} )", $user_id, bbp_get_spam_status_id())); // Loop through posts and spam them if (!empty($posts)) { foreach ($posts as $post_id) { // The routines for topics ang replies are different, so use the // correct one based on the post type switch (get_post_type($post_id)) { case bbp_get_topic_post_type(): bbp_unspam_topic($post_id); break; case bbp_get_reply_post_type(): bbp_unspam_reply($post_id); break; } } } // Switch back to current blog restore_current_blog(); } // Success return true; }
/** * Reply Row actions * * Remove the quick-edit action link under the reply title and add the * content and spam link * * @since 2.0.0 bbPress (r2577) * * @param array $actions Actions * @param array $reply Reply object * @uses bbp_get_reply_post_type() To get the reply post type * @uses bbp_reply_content() To output reply content * @uses bbp_get_reply_url() To get the reply link * @uses bbp_get_reply_title() To get the reply title * @uses current_user_can() To check if the current user can edit or * delete the reply * @uses bbp_is_reply_spam() To check if the reply is marked as spam * @uses get_post_type_object() To get the reply 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 reply * @return array $actions Actions */ public function row_actions($actions, $reply) { if ($this->bail()) { return $actions; } unset($actions['inline hide-if-no-js']); // Reply view links to topic $actions['view'] = '<a href="' . esc_url(bbp_get_reply_url($reply->ID)) . '" title="' . esc_attr(sprintf(__('View “%s”', 'bbpress'), bbp_get_reply_title($reply->ID))) . '" rel="permalink">' . esc_html__('View', 'bbpress') . '</a>'; // User cannot view replies in trash if (bbp_get_trash_status_id() === $reply->post_status && !current_user_can('view_trash')) { unset($actions['view']); } // Only show the actions if the user is capable of viewing them if (current_user_can('moderate', $reply->ID)) { // Show the 'approve' link on pending posts only and 'unapprove' on published posts only $approve_uri = wp_nonce_url(add_query_arg(array('reply_id' => $reply->ID, 'action' => 'bbp_toggle_reply_approve'), remove_query_arg(array('bbp_reply_toggle_notice', 'reply_id', 'failed', 'super'))), 'approve-reply_' . $reply->ID); if (bbp_is_reply_published($reply->ID)) { $actions['unapproved'] = '<a href="' . esc_url($approve_uri) . '" title="' . esc_attr__('Unapprove this reply', 'bbpress') . '">' . _x('Unapprove', 'Unapprove reply', 'bbpress') . '</a>'; } elseif (!bbp_is_reply_private($reply->ID)) { $actions['approved'] = '<a href="' . esc_url($approve_uri) . '" title="' . esc_attr__('Approve this reply', 'bbpress') . '">' . _x('Approve', 'Approve reply', 'bbpress') . '</a>'; } // Show the 'spam' link on published and pending replies and 'not spam' on spammed replies if (in_array($reply->post_status, array(bbp_get_public_status_id(), bbp_get_pending_status_id(), bbp_get_spam_status_id()))) { $spam_uri = wp_nonce_url(add_query_arg(array('reply_id' => $reply->ID, 'action' => 'bbp_toggle_reply_spam'), remove_query_arg(array('bbp_reply_toggle_notice', 'reply_id', 'failed', 'super'))), 'spam-reply_' . $reply->ID); if (bbp_is_reply_spam($reply->ID)) { $actions['spam'] = '<a href="' . esc_url($spam_uri) . '" title="' . esc_attr__('Mark the reply as not spam', 'bbpress') . '">' . esc_html__('Not spam', 'bbpress') . '</a>'; } else { $actions['spam'] = '<a href="' . esc_url($spam_uri) . '" title="' . esc_attr__('Mark this reply as spam', 'bbpress') . '">' . esc_html__('Spam', 'bbpress') . '</a>'; } } } // Trash if (current_user_can('delete_reply', $reply->ID)) { if (bbp_get_trash_status_id() === $reply->post_status) { $post_type_object = get_post_type_object(bbp_get_reply_post_type()); $actions['untrash'] = "<a title='" . esc_attr__('Restore this item from the Trash', 'bbpress') . "' href='" . esc_url(add_query_arg(array('_wp_http_referer' => add_query_arg(array('post_type' => bbp_get_reply_post_type()), admin_url('edit.php'))), wp_nonce_url(admin_url(sprintf($post_type_object->_edit_link . '&action=untrash', $reply->ID)), 'untrash-' . $reply->post_type . '_' . $reply->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_reply_post_type()), admin_url('edit.php'))), get_delete_post_link($reply->ID))) . "'>" . esc_html__('Trash', 'bbpress') . "</a>"; } if (bbp_get_trash_status_id() === $reply->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_reply_post_type()), admin_url('edit.php'))), get_delete_post_link($reply->ID, '', true))) . "'>" . esc_html__('Delete Permanently', 'bbpress') . "</a>"; } elseif (bbp_get_spam_status_id() === $reply->post_status) { unset($actions['trash']); } } return $actions; }
/** * Recount topic replied by the users * * @since bbPress (r2613) * * @uses bbp_get_reply_post_type() To get the reply post type * @uses wpdb::query() To run our recount sql queries * @uses is_wp_error() To check if the executed query returned {@link WP_Error} * @return array An array of the status code and the message */ function bbp_admin_repair_user_reply_count() { global $wpdb; $statement = __('Counting the number of topics to which each user has replied… %s', 'bbpress'); $result = __('Failed!', 'bbpress'); $sql_select = "SELECT `post_author`, COUNT(DISTINCT `ID`) as `_count` FROM `{$wpdb->posts}` WHERE `post_type` = '" . bbp_get_reply_post_type() . "' AND `post_status` = '" . bbp_get_public_status_id() . "' GROUP BY `post_author`;"; $insert_rows = $wpdb->get_results($sql_select); if (is_wp_error($insert_rows)) { return array(1, sprintf($statement, $result)); } $key = $wpdb->prefix . '_bbp_reply_count'; $insert_values = array(); foreach ($insert_rows as $insert_row) { $insert_values[] = "('{$insert_row->post_author}', '{$key}', '{$insert_row->_count}')"; } if (!count($insert_values)) { return array(2, sprintf($statement, $result)); } $sql_delete = "DELETE FROM `{$wpdb->usermeta}` WHERE `meta_key` = '{$key}';"; if (is_wp_error($wpdb->query($sql_delete))) { return array(3, sprintf($statement, $result)); } foreach (array_chunk($insert_values, 10000) as $chunk) { $chunk = "\n" . implode(",\n", $chunk); $sql_insert = "INSERT INTO `{$wpdb->usermeta}` (`user_id`, `meta_key`, `meta_value`) VALUES {$chunk};"; if (is_wp_error($wpdb->query($sql_insert))) { return array(4, sprintf($statement, $result)); } } return array(0, sprintf($statement, __('Complete!', 'bbpress'))); }
/** * Removes post stylesheets support for certain post types created by plugins. * * @since 0.3.0 * @access public * @return void */ function post_stylesheets_remove_post_type_support() { /* Removes post stylesheets support of the bbPress 'topic' post type. */ if (function_exists('bbp_get_topic_post_type')) { remove_post_type_support(bbp_get_topic_post_type(), 'post-stylesheets'); } /* Removes post stylesheets support of the bbPress 'reply' post type. */ if (function_exists('bbp_get_reply_post_type')) { remove_post_type_support(bbp_get_reply_post_type(), 'post-stylesheets'); } }
/** * Force comments_status to 'closed' for bbPress post types * * @since bbPress (r3589) * @param bool $open True if open, false if closed * @param int $post_id ID of the post to check * @return bool True if open, false if closed */ function bbp_force_comment_status($open, $post_id = 0) { // Get the post type of the post ID $post_type = get_post_type($post_id); // Default return value is what is passed in $open $retval = $open; // Only force for bbPress post types switch ($post_type) { case bbp_get_forum_post_type(): case bbp_get_topic_post_type(): case bbp_get_reply_post_type(): $retval = false; break; } // Allow override of the override return apply_filters('bbp_force_comment_status', $retval, $open, $post_id, $post_type); }
/** * Removes theme layouts support from specific post types created by plugins. * * @since 0.4.0 * @return void */ function theme_layouts_remove_post_type_support() { /* Removes theme layouts support of the bbPress 'reply' post type. */ if (function_exists('bbp_get_reply_post_type')) { remove_post_type_support(bbp_get_reply_post_type(), 'theme-layouts'); } }
/** * The main search loop. WordPress does the heavy lifting. * * @since bbPress (r4579) * * @param mixed $args All the arguments supported by {@link WP_Query} * @uses bbp_get_view_all() Are we showing all results? * @uses bbp_get_public_status_id() To get the public status id * @uses bbp_get_closed_status_id() To get the closed status id * @uses bbp_get_spam_status_id() To get the spam status id * @uses bbp_get_trash_status_id() To get the trash status id * @uses bbp_get_forum_post_type() To get the forum post type * @uses bbp_get_topic_post_type() To get the topic post type * @uses bbp_get_reply_post_type() To get the reply post type * @uses bbp_get_replies_per_page() To get the replies per page option * @uses bbp_get_paged() To get the current page value * @uses bbp_get_search_terms() To get the search terms * @uses WP_Query To make query and get the search results * @uses WP_Rewrite::using_permalinks() To check if the blog is using permalinks * @uses bbp_get_search_url() To get the forum search url * @uses paginate_links() To paginate search results * @uses apply_filters() Calls 'bbp_has_search_results' with * bbPress::search_query::have_posts() * and bbPress::reply_query * @return object Multidimensional array of search information */ function bbp_has_search_results($args = '') { global $wp_rewrite; /** Defaults **************************************************************/ $default_post_type = array(bbp_get_forum_post_type(), bbp_get_topic_post_type(), bbp_get_reply_post_type()); // Default query args $default = array('post_type' => $default_post_type, 'posts_per_page' => bbp_get_replies_per_page(), 'paged' => bbp_get_paged(), 'orderby' => 'date', 'order' => 'DESC', 'ignore_sticky_posts' => true, 's' => bbp_get_search_terms()); // What are the default allowed statuses (based on user caps) if (bbp_get_view_all()) { // Default view=all statuses $post_statuses = array(bbp_get_public_status_id(), bbp_get_closed_status_id(), bbp_get_spam_status_id(), bbp_get_trash_status_id()); // Add support for private status if (current_user_can('read_private_topics')) { $post_statuses[] = bbp_get_private_status_id(); } // Join post statuses together $default['post_status'] = implode(',', $post_statuses); // Lean on the 'perm' query var value of 'readable' to provide statuses } else { $default['perm'] = 'readable'; } /** Setup *****************************************************************/ // Parse arguments against default values $r = bbp_parse_args($args, $default, 'has_search_results'); // Get bbPress $bbp = bbpress(); // Call the query if (!empty($r['s'])) { $bbp->search_query = new WP_Query($r); } // Add pagination values to query object $bbp->search_query->posts_per_page = $r['posts_per_page']; $bbp->search_query->paged = $r['paged']; // Never home, regardless of what parse_query says $bbp->search_query->is_home = false; // Only add pagination is query returned results if (!empty($bbp->search_query->found_posts) && !empty($bbp->search_query->posts_per_page)) { // Array of arguments to add after pagination links $add_args = array(); // If pretty permalinks are enabled, make our pagination pretty if ($wp_rewrite->using_permalinks()) { // Shortcode territory if (is_page() || is_single()) { $base = trailingslashit(get_permalink()); // Default search location } else { $base = trailingslashit(bbp_get_search_results_url()); } // Add pagination base $base = $base . user_trailingslashit($wp_rewrite->pagination_base . '/%#%/'); // Unpretty permalinks } else { $base = add_query_arg('paged', '%#%'); } // Add args if (bbp_get_view_all()) { $add_args['view'] = 'all'; } // Add pagination to query object $bbp->search_query->pagination_links = paginate_links(apply_filters('bbp_search_results_pagination', array('base' => $base, 'format' => '', 'total' => ceil((int) $bbp->search_query->found_posts / (int) $r['posts_per_page']), 'current' => (int) $bbp->search_query->paged, 'prev_text' => is_rtl() ? '→' : '←', 'next_text' => is_rtl() ? '←' : '→', 'mid_size' => 1, 'add_args' => $add_args))); // Remove first page from pagination if ($wp_rewrite->using_permalinks()) { $bbp->search_query->pagination_links = str_replace($wp_rewrite->pagination_base . '/1/', '', $bbp->search_query->pagination_links); } else { $bbp->search_query->pagination_links = str_replace('&paged=1', '', $bbp->search_query->pagination_links); } } // Return object return apply_filters('bbp_has_search_results', $bbp->search_query->have_posts(), $bbp->search_query); }