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; }
function om_add_bbpress_meta_box() { global $om_bbpress_meta_box; if (function_exists('bbp_get_forum_post_type')) { ommb_add_meta_boxes($om_bbpress_meta_box, bbp_get_forum_post_type()); } }
public function get_all_forums() { $bbp_f = bbp_parse_args($args, array('post_type' => bbp_get_forum_post_type(), 'post_parent' => 'any', 'post_status' => bbp_get_public_status_id(), 'posts_per_page' => get_option('_bbp_forums_per_page', 50), 'ignore_sticky_posts' => true, 'orderby' => 'menu_order title', 'order' => 'ASC'), 'has_forums'); $bbp = bbpress(); $bbp->forum_query = new WP_Query($bbp_f); $data = array(); foreach ($bbp->forum_query->posts as $post) { $type = 'forum'; $is_parent = false; $is_category = bbp_forum_get_subforums($post->ID); if ($is_category) { $type = 'category'; $parent = true; } $settings = $this->wlm->GetOption('bbpsettings'); if ($settings && count($settings) > 0) { foreach ($settings as $setting) { if ($setting["id"] == $post->ID) { $data[$post->ID] = array("id" => $post->ID, "name" => $post->post_title, "level" => $setting["sku"], "protection" => $setting["protection"], "type" => $type, "parent" => $parent, "date" => ""); } } if (!isset($data[$post->ID])) { $data[$post->ID] = array("id" => $post->ID, "name" => $post->post_title, "level" => "", "protection" => "", "type" => $type, "parent" => $parent, "date" => ""); } } else { $data[$post->ID] = array("id" => $post->ID, "name" => $post->post_title, "level" => "", "protection" => "", "type" => $type, "parent" => $parent, "date" => ""); } } echo json_encode($data); die; }
public static function parse_query($posts_query) { // Bail if $posts_query is not the main loop if (!$posts_query->is_main_query()) { return; } // Bail if filters are suppressed on this query if (true === $posts_query->get('suppress_filters')) { return; } // Bail if in admin if (is_admin()) { return; } // Get query variables $is_write = $posts_query->get(bbp_get_write_rewrite_id()); // Write? if (!empty($is_write)) { // Get the post type from the main query loop $post_type = $posts_query->get('post_type'); // Check which post_type we are editing, if any if (!empty($post_type)) { switch ($post_type) { // We are editing a forum case bbp_get_forum_post_type(): $posts_query->bbp_is_topic_write = true; $posts_query->bbp_is_write = true; break; } } } }
function bbpress_forumslist_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'] : ''; $allforums = isset($settings['allforums']) ? $settings['allforums'] : 'false'; $value_arr = $value; $args = array('post_type' => bbp_get_forum_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'] . '">'; if ($allforums == "true") { $output .= "<option value=''>" . __("All Forums", "ts_visual_composer_extend") . "</option>"; } 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; }
/** * Displays the output, the forum list * * @since bbPress (r2653) * * @param mixed $args Arguments * @param array $instance Instance * @uses apply_filters() Calls 'bbp_forum_widget_title' with the title * @uses get_option() To get the forums per page option * @uses current_user_can() To check if the current user can read * private() To resety name * @uses bbp_has_forums() The main forum loop * @uses bbp_forums() To check whether there are more forums available * in the loop * @uses bbp_the_forum() Loads up the current forum in the loop * @uses bbp_forum_permalink() To display the forum permalink * @uses bbp_forum_title() To display the forum title */ public function widget($args, $instance) { extract($args); $title = apply_filters('bbp_forum_widget_title', $instance['title']); $parent_forum = !empty($instance['parent_forum']) ? $instance['parent_forum'] : '0'; // Note: private and hidden forums will be excluded via the // bbp_pre_get_posts_exclude_forums filter and function. $widget_query = new WP_Query(array('post_parent' => $parent_forum, 'post_type' => bbp_get_forum_post_type(), 'posts_per_page' => get_option('_bbp_forums_per_page', 50), 'orderby' => 'menu_order', 'order' => 'ASC')); if ($widget_query->have_posts()) { echo $before_widget; echo $before_title . $title . $after_title; $current_forum_id = bbp_get_forum_id(); ?> <ul> <?php while ($widget_query->have_posts()) { $widget_query->the_post(); ?> <?php $current = $widget_query->post->ID == $current_forum_id ? 'current' : ''; ?> <li> <a class="bbp-forum-title <?php echo $current; ?> " href="<?php bbp_forum_permalink($widget_query->post->ID); ?> " title="<?php bbp_forum_title($widget_query->post->ID); ?> "> <?php bbp_forum_title($widget_query->post->ID); ?> </a> <span class="topic-count"><?php bbp_forum_topic_count($widget_query->post->ID); ?> </span> </li> <?php } ?> </ul> <?php echo $after_widget; // Reset the $post global wp_reset_postdata(); } }
/** * Register the post type * * @since 1.0 * * @return void */ public function post_type() { if (!class_exists('bbPress')) { return; } $labels = array('name' => _x('Canned Replies', 'post type general name', 'bbp-canned-replies'), 'singular_name' => _x('Canned Reply', 'post type singular name', 'bbp-canned-replies'), 'add_new' => __('Add New', 'bbp-canned-replies'), 'add_new_item' => __('Add New Canned Reply', 'bbp-canned-replies'), 'edit_item' => __('Edit Canned Reply', 'bbp-canned-replies'), 'new_item' => __('New Canned Reply', 'bbp-canned-replies'), 'all_items' => __('Canned Replies', 'bbp-canned-replies'), 'view_item' => __('View Canned Reply', 'bbp-canned-replies'), 'search_items' => __('Search Canned Replies', 'bbp-canned-replies'), 'not_found' => __('No Canned Replies found', 'bbp-canned-replies'), 'not_found_in_trash' => __('No Canned Replies found in Trash', 'bbp-canned-replies'), 'parent_item_colon' => '', 'menu_name' => __('Canned Replies', 'bbp-canned-replies')); $args = array('labels' => $labels, 'public' => false, 'show_ui' => true, 'show_in_menu' => 'edit.php?post_type=' . bbp_get_forum_post_type(), 'query_var' => false, 'rewrite' => false, 'capabilities' => bbp_get_forum_caps(), 'capability_type' => array('forum', 'forums'), 'supports' => array('editor', 'title'), 'can_export' => true); register_post_type('bbp_canned_reply', $args); }
/** * Displays the output, the forum list * * @since bbPress (r2653) * * @param mixed $args Arguments * @param array $instance Instance * @uses apply_filters() Calls 'bbp_forum_widget_title' with the title * @uses get_option() To get the forums per page option * @uses current_user_can() To check if the current user can read * private() To resety name * @uses bbp_has_forums() The main forum loop * @uses bbp_forums() To check whether there are more forums available * in the loop * @uses bbp_the_forum() Loads up the current forum in the loop * @uses bbp_forum_permalink() To display the forum permalink * @uses bbp_forum_title() To display the forum title */ public function widget($args, $instance) { // Get widget settings $settings = $this->parse_settings($instance); // Typical WordPress filter $settings['title'] = apply_filters('widget_title', $settings['title'], $instance, $this->id_base); // bbPress filter $settings['title'] = apply_filters('pg_widget_title', $settings['title'], $instance, $this->id_base); // Note: private and hidden forums will be excluded via the // bbp_pre_get_posts_exclude_forums filter and function. $query_data = array('post_type' => bbp_get_forum_post_type(), 'post_parent' => $settings['parent_forum'], 'post_status' => bbp_get_public_status_id(), 'posts_per_page' => get_option('_bbp_forums_per_page', 50), 'orderby' => 'menu_order', 'order' => 'ASC'); //PRIVATE GROUPS Get an array of IDs which the current user has permissions to view $allowed_posts = private_groups_get_permitted_post_ids(new WP_Query($query_data)); // The default forum query with allowed forum ids array added $query_data['post__in'] = $allowed_posts; $widget_query = new WP_Query($query_data); // Bail if no posts if (!$widget_query->have_posts()) { return; } echo $args['before_widget']; if (!empty($settings['title'])) { echo $args['before_title'] . $settings['title'] . $args['after_title']; } ?> <ul> <?php while ($widget_query->have_posts()) { $widget_query->the_post(); ?> <li><a class="bbp-forum-title" href="<?php bbp_forum_permalink($widget_query->post->ID); ?> " title="<?php bbp_forum_title($widget_query->post->ID); ?> "><?php bbp_forum_title($widget_query->post->ID); ?> </a></li> <?php } ?> </ul> <?php echo $args['after_widget']; // Reset the $post global wp_reset_postdata(); }
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); }
/** * Setup the Genesis actions. */ public function setup_actions() { // Register forum sidebar if needed $this->register_genesis_forum_sidebar(); // Remove Genesis profile fields from front end $this->remove_profile_fields(); // We hook into 'genesis_before' because it is the most reliable hook // available to bbPress in the Genesis page load process. add_action('genesis_before', array($this, 'genesis_post_actions')); add_action('genesis_before', array($this, 'check_genesis_forum_sidebar')); // Configure which Genesis layout to apply add_filter('genesis_pre_get_option_site_layout', array($this, 'genesis_layout')); // Add Layout and SEO options to Forums add_post_type_support(bbp_get_forum_post_type(), array('genesis-layouts', 'genesis-seo', 'genesis-scripts', 'genesis-ss')); }
/** * 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; }
public static function SavePost($post_id, $post, $update) { if (wp_is_post_revision($post_id) || $post->post_status != 'publish' || $post->post_type != 'namaste_course') { return; } $meta = get_post_meta($post_id, 'buddypress_id', true); if (empty($meta)) { $group_id = groups_create_group(array('creator_id' => get_current_user_id(), 'name' => $post->post_title, 'description' => 'Обсуждение курса ' . $post->post_title, 'enable_forum' => 1)); update_post_meta($post_id, 'buddypress_id', $group_id); groups_edit_group_settings($group_id, 1, 'private', 'mods'); $forum_id = bbp_insert_forum($forum_data = array('post_status' => bbp_get_private_status_id(), 'post_type' => bbp_get_forum_post_type(), 'post_author' => bbp_get_current_user_id(), 'post_content' => 'Обсуждение курса ' . $post->post_title, 'post_title' => $post->post_title), $forum_meta = array()); bbp_update_group_forum_ids($group_id, (array) $forum_id); bbp_update_forum_group_ids($forum_id, (array) $group_id); } bbp_add_user_forum_subscription(bbp_get_current_user_id(), $forum_id); update_post_meta($forum_id, '_forum_course_id', $post_id); }
/** * @covers ::bbp_forum_post_type * @covers ::bbp_get_forum_post_type */ public function test_bbp_get_forum_post_type() { $f = $this->factory->forum->create(); $fobj = get_post_type_object('forum'); // WordPress 4.6 introduced `WP_Post_Type` class if (bbp_get_major_wp_version() < 4.6) { $this->assertInstanceOf('stdClass', $fobj); } else { $this->assertInstanceOf('WP_Post_Type', $fobj); } $this->assertEquals('forum', $fobj->name); // Test some defaults $this->assertTrue(is_post_type_hierarchical('forum')); $forum_type = bbp_forum_post_type($f); $this->expectOutputString('forum', $forum_type); $forum_type = bbp_get_forum_post_type($f); $this->assertSame('forum', $forum_type); }
function bbp_get_topic_write_url($forum_id = 0) { global $wp_rewrite; $bbp = bbpress(); $forum = bbp_get_forum(bbp_get_forum_id($forum_id)); if (empty($forum)) { return; } // Remove view=all link from edit $forum_link = bbp_get_forum_permalink($forum_id); // Pretty permalinks if ($wp_rewrite->using_permalinks()) { $url = trailingslashit($forum_link) . $bbp->write_id; $url = trailingslashit($url); // Unpretty permalinks } else { $url = add_query_arg(array(bbp_get_forum_post_type() => $forum->post_name, $bbp->write_id => '1'), $forum_link); } return apply_filters('bbp_get_topic_write_url', $url, $forum_id); }
static function nav_menu_css_class($classes, $item, $args, $depth) { if ($item->object == bbp_get_forum_post_type() && is_bbpress()) { if (bbp_is_topic_edit() || bbp_is_single_topic()) { $forum_id = bbp_get_topic_forum_id(); if ($forum_id == $item->object_id) { $classes[] = 'current-menu-parent'; $classes[] = 'current-' . bbp_get_topic_post_type() . '-parent'; } elseif ($ancestors = self::forum_ancestors($forum_id, array())) { if (in_array($item->object_id, $ancestors)) { $classes[] = 'current-menu-ancestor'; $classes[] = 'current-' . bbp_get_topic_post_type() . '-ancestor'; } } } elseif (bbp_is_reply_edit() || bbp_is_single_reply()) { $forum_id = bbp_get_reply_forum_id(); } } return $classes; }
function private_groups_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; }
static function ajax_query_attachments_args($query) { $forum_id = 0; $post_id = isset($_POST['post_id']) ? (int) $_POST['post_id'] : 0; if ($post_id) { $post_type = get_post_type($post_id); if ($post_type == bbp_get_topic_post_type()) { $forum_id = (int) bbp_get_topic_forum_id($post_id); } elseif ($post_type == bbp_get_reply_post_type()) { $forum_id = (int) bbp_get_reply_forum_id($post_id); } elseif ($post_type == bbp_get_forum_post_type()) { $forum_id = $post_id; } } if ($forum_id) { // TODO: post_id 값이 전달되지 않을 때, 포럼을 찾는 방법을 알아봐야함. add_filter('bbp_get_forum_id', create_function('$a', 'return ' . $forum_id . ';')); if (!current_user_can('edit_others_topics')) { $query['author'] = get_current_user_id(); } } return $query; }
/** * This function filters the list of forums based on the users rank as set by the Mebmers plugin */ function tehnik_bpp_filter_forums_by_permissions($args = '') { $bbp = bbpress(); // Setup possible post__not_in array $post_stati[] = bbp_get_public_status_id(); // Check if user can read private forums if (current_user_can('read_private_forums')) { $post_stati[] = bbp_get_private_status_id(); } // Check if user can read hidden forums if (current_user_can('read_hidden_forums')) { $post_stati[] = bbp_get_hidden_status_id(); } // The default forum query for most circumstances $meta_query = array('post_type' => bbp_get_forum_post_type(), 'post_parent' => bbp_is_forum_archive() ? 0 : bbp_get_forum_id(), 'post_status' => implode(',', $post_stati), 'posts_per_page' => get_option('_bbp_forums_per_page', 50), 'orderby' => 'menu_order', 'order' => 'ASC'); //Get an array of IDs which the current user has permissions to view $allowed_forums = tehnik_bpp_get_permitted_post_ids(new WP_Query($meta_query)); // The default forum query with allowed forum ids array added $meta_query['post__in'] = $allowed_forums; $bbp_f = bbp_parse_args($args, $meta_query, 'has_forums'); // Run the query $bbp->forum_query = new WP_Query($bbp_f); return apply_filters('bpp_filter_forums_by_permissions', $bbp->forum_query->have_posts(), $bbp->forum_query); }
/** * Output a select box allowing to pick which forum/topic a new * topic/reply belongs in. * * @since bbPress (r2746) * * @param mixed $args The function supports these args: * - post_type: Post type, defaults to bbp_get_forum_post_type() (bbp_forum) * - selected: Selected ID, to not have any value as selected, pass * anything smaller than 0 (due to the nature of select * box, the first value would of course be selected - * though you can have that as none (pass 'show_none' arg)) * - orderby: Defaults to 'menu_order title' * - post_parent: Post parent. Defaults to 0 * - post_status: Which all post_statuses to find in? Can be an array * or CSV of publish, category, closed, private, spam, * trash (based on post type) - if not set, these are * automatically determined based on the post_type * - posts_per_page: Retrieve all forums/topics. Defaults to -1 to get * all posts * - walker: Which walker to use? Defaults to * {@link BBP_Walker_Dropdown} * - select_id: ID of the select box. Defaults to 'bbp_forum_id' * - tab: Tabindex value. False or integer * - options_only: Show only <options>? No <select>? * - show_none: False or something like __( '(No Forum)', 'bbpress' ), * will have value="" * - none_found: False or something like * __( 'No forums to post to!', 'bbpress' ) * - disable_categories: Disable forum categories and closed forums? * Defaults to true. Only for forums and when * the category option is displayed. * @uses BBP_Walker_Dropdown() As the default walker to generate the * dropdown * @uses current_user_can() To check if the current user can read * private forums * @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 walk_page_dropdown_tree() To generate the dropdown using the * walker * @uses apply_filters() Calls 'bbp_get_dropdown' with the dropdown * and args * @return string The dropdown */ function stachestack_bbp_get_dropdown($args = '') { /** Arguments *********************************************************/ // Parse arguments against default values $r = bbp_parse_args($args, array('post_type' => bbp_get_forum_post_type(), 'post_parent' => null, 'post_status' => null, 'selected' => 0, 'exclude' => array(), 'numberposts' => -1, 'orderby' => 'menu_order title', 'order' => 'ASC', 'walker' => '', 'select_id' => 'bbp_forum_id', 'tab' => bbp_get_tab_index(), 'options_only' => false, 'show_none' => false, 'none_found' => false, 'disable_categories' => true, 'disabled' => ''), 'get_dropdown'); if (empty($r['walker'])) { $r['walker'] = new BBP_Walker_Dropdown(); $r['walker']->tree_type = $r['post_type']; } // Force 0 if (is_numeric($r['selected']) && $r['selected'] < 0) { $r['selected'] = 0; } // Force array if (!empty($r['exclude']) && !is_array($r['exclude'])) { $r['exclude'] = explode(',', $r['exclude']); } /** Setup variables ***************************************************/ $retval = ''; $posts = get_posts(array('post_type' => $r['post_type'], 'post_status' => $r['post_status'], 'exclude' => $r['exclude'], 'post_parent' => $r['post_parent'], 'numberposts' => $r['numberposts'], 'orderby' => $r['orderby'], 'order' => $r['order'], 'walker' => $r['walker'], 'disable_categories' => $r['disable_categories'])); /** Drop Down *********************************************************/ // Items found if (!empty($posts)) { // Build the opening tag for the select element if (empty($r['options_only'])) { // Should this select appear disabled? $disabled = disabled(isset(bbpress()->options[$r['disabled']]), true, false); // Setup the tab index attribute $tab = !empty($r['tab']) ? ' tabindex="' . intval($r['tab']) . '"' : ''; // Build the opening tag $retval .= '<select class="form-control" name="' . esc_attr($r['select_id']) . '" id="' . esc_attr($r['select_id']) . '"' . $disabled . $tab . '>' . "\n"; } // Get the options $retval .= !empty($r['show_none']) ? "\t<option value=\"\" class=\"level-0\">" . esc_html($r['show_none']) . '</option>' : ''; $retval .= walk_page_dropdown_tree($posts, 0, $r); // Build the closing tag for the select element if (empty($r['options_only'])) { $retval .= '</select>'; } // No items found - Display feedback if no custom message was passed } elseif (empty($r['none_found'])) { // Switch the response based on post type switch ($r['post_type']) { // Topics case bbp_get_topic_post_type(): $retval = __('No topics available', 'bbpress'); break; // Forums // Forums case bbp_get_forum_post_type(): $retval = __('No forums available', 'bbpress'); break; // Any other // Any other default: $retval = __('None available', 'bbpress'); break; } } return apply_filters('bbp_get_dropdown', $retval, $r); }
/** * Runs through the various bbPress conditional tags to check the current page being viewed. Once * a condition is met, add items to the $items array. * * @since 0.6.0 * @access public * @return void */ public function do_trail_items() { /* Add the network and site home links. */ $this->do_network_home_link(); $this->do_site_home_link(); /* Get the forum post type object. */ $post_type_object = get_post_type_object(bbp_get_forum_post_type()); /* If not viewing the forum root/archive page and a forum archive exists, add it. */ if (!empty($post_type_object->has_archive) && !bbp_is_forum_archive()) { $this->items[] = '<a href="' . get_post_type_archive_link(bbp_get_forum_post_type()) . '">' . bbp_get_forum_archive_title() . '</a>'; } /* If viewing the forum root/archive. */ if (bbp_is_forum_archive()) { if (true === $this->args['show_title']) { $this->items[] = bbp_get_forum_archive_title(); } } elseif (bbp_is_topic_archive()) { if (true === $this->args['show_title']) { $this->items[] = bbp_get_topic_archive_title(); } } elseif (bbp_is_topic_tag()) { if (true === $this->args['show_title']) { $this->items[] = bbp_get_topic_tag_name(); } } elseif (bbp_is_topic_tag_edit()) { $this->items[] = '<a href="' . bbp_get_topic_tag_link() . '">' . bbp_get_topic_tag_name() . '</a>'; if (true === $this->args['show_title']) { $this->items[] = __('Edit', 'breadcrumb-trail'); } } elseif (bbp_is_single_view()) { if (true === $this->args['show_title']) { $this->items[] = bbp_get_view_title(); } } elseif (bbp_is_single_topic()) { /* Get the queried topic. */ $topic_id = get_queried_object_id(); /* Get the parent items for the topic, which would be its forum (and possibly forum grandparents). */ $this->do_post_parents(bbp_get_topic_forum_id($topic_id)); /* If viewing a split, merge, or edit topic page, show the link back to the topic. Else, display topic title. */ if (bbp_is_topic_split() || bbp_is_topic_merge() || bbp_is_topic_edit()) { $this->items[] = '<a href="' . bbp_get_topic_permalink($topic_id) . '">' . bbp_get_topic_title($topic_id) . '</a>'; } elseif (true === $this->args['show_title']) { $this->items[] = bbp_get_topic_title($topic_id); } /* If viewing a topic split page. */ if (bbp_is_topic_split() && true === $this->args['show_title']) { $this->items[] = __('Split', 'breadcrumb-trail'); } elseif (bbp_is_topic_merge() && true === $this->args['show_title']) { $this->items[] = __('Merge', 'breadcrumb-trail'); } elseif (bbp_is_topic_edit() && true === $this->args['show_title']) { $this->items[] = __('Edit', 'breadcrumb-trail'); } } elseif (bbp_is_single_reply()) { /* Get the queried reply object ID. */ $reply_id = get_queried_object_id(); /* Get the parent items for the reply, which should be its topic. */ $this->do_post_parents(bbp_get_reply_topic_id($reply_id)); /* If viewing a reply edit page, link back to the reply. Else, display the reply title. */ if (bbp_is_reply_edit()) { $this->items[] = '<a href="' . bbp_get_reply_url($reply_id) . '">' . bbp_get_reply_title($reply_id) . '</a>'; if (true === $this->args['show_title']) { $this->items[] = __('Edit', 'breadcrumb-trail'); } } elseif (true === $this->args['show_title']) { $this->items[] = bbp_get_reply_title($reply_id); } } elseif (bbp_is_single_forum()) { /* Get the queried forum ID and its parent forum ID. */ $forum_id = get_queried_object_id(); $forum_parent_id = bbp_get_forum_parent_id($forum_id); /* If the forum has a parent forum, get its parent(s). */ if (0 !== $forum_parent_id) { $this->do_post_parents($forum_parent_id); } /* Add the forum title to the end of the trail. */ if (true === $this->args['show_title']) { $this->items[] = bbp_get_forum_title($forum_id); } } elseif (bbp_is_single_user() || bbp_is_single_user_edit()) { if (bbp_is_single_user_edit()) { $this->items[] = '<a href="' . bbp_get_user_profile_url() . '">' . bbp_get_displayed_user_field('display_name') . '</a>'; if (true === $this->args['show_title']) { $this->items[] = __('Edit', 'breadcrumb-trail'); } } elseif (true === $this->args['show_title']) { $this->items[] = bbp_get_displayed_user_field('display_name'); } } /* Return the bbPress breadcrumb trail items. */ $this->items = apply_filters('breadcrumb_trail_get_bbpress_items', $this->items, $this->args); }
/** * 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); } } }
/** * Get the forum edit template * * @since bbPress (r3566) * * @uses bbp_get_topic_post_type() * @uses bbp_get_query_template() * @return string Path to template file */ function bbp_get_forum_edit_template() { $templates = array('single-' . bbp_get_forum_post_type() . '-edit.php'); return bbp_get_query_template('forum_edit', $templates); }
/** * 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); }
/** * 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); }
/** * 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); }
/** * Clean the users' forum subscriptions * * @since bbPress (r5155) * * @uses bbp_get_forum_post_type() To get the topic 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_forum_subscriptions() { global $wpdb; $statement = __('Removing trashed forums from user subscriptions… %s', 'bbpress'); $result = __('Failed!', 'bbpress'); $key = $wpdb->prefix . '_bbp_forum_subscriptions'; $users = $wpdb->get_results("SELECT `user_id`, `meta_value` AS `subscriptions` FROM `{$wpdb->usermeta}` WHERE `meta_key` = '{$key}';"); if (is_wp_error($users)) { return array(1, sprintf($statement, $result)); } $forums = $wpdb->get_col("SELECT `ID` FROM `{$wpdb->posts}` WHERE `post_type` = '" . bbp_get_forum_post_type() . "' AND `post_status` = '" . bbp_get_public_status_id() . "';"); if (is_wp_error($forums)) { return array(2, sprintf($statement, $result)); } $values = array(); foreach ($users as $user) { if (empty($user->subscriptions) || !is_string($user->subscriptions)) { continue; } $subscriptions = array_intersect($forums, explode(',', $user->subscriptions)); if (empty($subscriptions) || !is_array($subscriptions)) { continue; } $subscriptions_joined = implode(',', $subscriptions); $values[] = "('{$user->user_id}', '{$key}', '{$subscriptions_joined}')"; // Cleanup unset($subscriptions, $subscriptions_joined); } if (!count($values)) { $result = __('Nothing to remove!', 'bbpress'); return array(0, sprintf($statement, $result)); } $sql_delete = "DELETE FROM `{$wpdb->usermeta}` WHERE `meta_key` = '{$key}';"; if (is_wp_error($wpdb->query($sql_delete))) { return array(4, sprintf($statement, $result)); } foreach (array_chunk($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(5, sprintf($statement, $result)); } } return array(0, sprintf($statement, __('Complete!', 'bbpress'))); }
protected function _bbpress_items() { $item = array(); $post_type_object = get_post_type_object(bbp_get_forum_post_type()); if (!empty($post_type_object->has_archive) && !bbp_is_forum_archive()) { $item[] = '<span typeof="v:Breadcrumb"><a href="' . get_post_type_archive_link(bbp_get_forum_post_type()) . '" property="v:title" rel="v:url"><span>' . bbp_get_forum_archive_title() . '</span></a></span>'; } if (bbp_is_forum_archive()) { $item[] = bbp_get_forum_archive_title(); } elseif (bbp_is_topic_archive()) { $item[] = bbp_get_topic_archive_title(); } elseif (bbp_is_single_view()) { $item[] = bbp_get_view_title(); } elseif (bbp_is_single_topic()) { $topic_id = get_queried_object_id(); $item = array_merge($item, $this->_get_parents(bbp_get_topic_forum_id($topic_id))); if (bbp_is_topic_split() || bbp_is_topic_merge() || bbp_is_topic_edit()) { $item[] = '<span typeof="v:Breadcrumb"><a href="' . bbp_get_topic_permalink($topic_id) . '" property="v:title" rel="v:url"><span>' . bbp_get_topic_title($topic_id) . '</span></a></span>'; } else { $item[] = bbp_get_topic_title($topic_id); } if (bbp_is_topic_split()) { $item[] = __('Split', DH_DOMAIN); } elseif (bbp_is_topic_merge()) { $item[] = __('Merge', DH_DOMAIN); } elseif (bbp_is_topic_edit()) { $item[] = __('Edit', DH_DOMAIN); } } elseif (bbp_is_single_reply()) { $reply_id = get_queried_object_id(); $item = array_merge($item, $this->_get_parents(bbp_get_reply_topic_id($reply_id))); if (!bbp_is_reply_edit()) { $item[] = bbp_get_reply_title($reply_id); } else { $item[] = '<span typeof="v:Breadcrumb"><a href="' . bbp_get_reply_url($reply_id) . '" property="v:title" rel="v:url"><span>' . bbp_get_reply_title($reply_id) . '</span></a></span>'; $item[] = __('Edit', DH_DOMAIN); } } elseif (bbp_is_single_forum()) { $forum_id = get_queried_object_id(); $forum_parent_id = bbp_get_forum_parent_id($forum_id); if (0 !== $forum_parent_id) { $item = array_merge($item, $this->_get_parents($forum_parent_id)); } $item[] = bbp_get_forum_title($forum_id); } elseif (bbp_is_single_user() || bbp_is_single_user_edit()) { if (bbp_is_single_user_edit()) { $item[] = '<span typeof="v:Breadcrumb"><a href="' . bbp_get_user_profile_url() . '" property="v:title" rel="v:url" ><span>' . bbp_get_displayed_user_field('display_name') . '</span></a></span>'; $item[] = __('Edit', DH_DOMAIN); } else { $item[] = bbp_get_displayed_user_field('display_name'); } } return $item; }