public function admin_bar_menu() { global $wp_admin_bar; $wp_admin_bar->add_menu(array('id' => 'gdbb-toolbar', 'title' => __("Forums", "gd-bbpress-tools"), 'href' => get_post_type_archive_link('forum'), 'meta' => array('class' => 'icon-gdbb-toolbar'))); $wp_admin_bar->add_group(array('parent' => 'gdbb-toolbar', 'id' => 'gdbb-toolbar-public')); $query = $forums_query = array('post_parent' => 0, 'post_status' => 'publish', 'posts_per_page' => 20, 'orderby' => 'menu_order', 'order' => 'ASC'); $forums = bbp_get_forums_for_current_user($query); if (is_array($forums) && count($forums) > 0) { $wp_admin_bar->add_menu(array('parent' => 'gdbb-toolbar-public', 'id' => 'gdbb-toolbar-forums', 'title' => __("Forums", "gd-bbpress-tools"), 'href' => bbp_get_forums_url())); foreach ($forums as $forum) { $wp_admin_bar->add_menu(array('parent' => 'gdbb-toolbar-forums', 'id' => 'gdbb-toolbar-forums-' . $forum->ID, 'title' => apply_filters('the_title', $forum->post_title, $forum->ID), 'href' => get_permalink($forum->ID))); } } $views = bbp_get_views(); if (is_array($views) && count($views) > 0) { $wp_admin_bar->add_menu(array('parent' => 'gdbb-toolbar-public', 'id' => 'gdbb-toolbar-views', 'title' => __("Views", "gd-bbpress-tools"), 'href' => bbp_get_forums_url())); foreach ($views as $view => $args) { $wp_admin_bar->add_menu(array('parent' => 'gdbb-toolbar-views', 'id' => 'gdbb-toolbar-views-' . $view, 'title' => bbp_get_view_title($view), 'href' => bbp_get_view_url($view))); } } if (current_user_can(GDBBPRESSTOOLS_CAP)) { $wp_admin_bar->add_group(array('parent' => 'gdbb-toolbar', 'id' => 'gdbb-toolbar-admin')); $wp_admin_bar->add_menu(array('parent' => 'gdbb-toolbar-admin', 'id' => 'gdbb-toolbar-new', 'title' => __("New", "gd-bbpress-tools"), 'href' => '')); $wp_admin_bar->add_menu(array('parent' => 'gdbb-toolbar-new', 'id' => 'gdbb-toolbar-new-forum', 'title' => __("Forum", "gd-bbpress-tools"), 'href' => admin_url('post-new.php?post_type=forum'))); $wp_admin_bar->add_menu(array('parent' => 'gdbb-toolbar-new', 'id' => 'gdbb-toolbar-new-topic', 'title' => __("Topic", "gd-bbpress-tools"), 'href' => admin_url('post-new.php?post_type=topic'))); $wp_admin_bar->add_menu(array('parent' => 'gdbb-toolbar-new', 'id' => 'gdbb-toolbar-new-reply', 'title' => __("Reply", "gd-bbpress-tools"), 'href' => admin_url('post-new.php?post_type=reply'))); $wp_admin_bar->add_menu(array('parent' => 'gdbb-toolbar-admin', 'id' => 'gdbb-toolbar-edit', 'title' => __("Edit", "gd-bbpress-tools"), 'href' => '')); $wp_admin_bar->add_menu(array('parent' => 'gdbb-toolbar-edit', 'id' => 'gdbb-toolbar-edit-forums', 'title' => __("Forums", "gd-bbpress-tools"), 'href' => admin_url('edit.php?post_type=forum'))); $wp_admin_bar->add_menu(array('parent' => 'gdbb-toolbar-edit', 'id' => 'gdbb-toolbar-edit-topics', 'title' => __("Topics", "gd-bbpress-tools"), 'href' => admin_url('edit.php?post_type=topic'))); $wp_admin_bar->add_menu(array('parent' => 'gdbb-toolbar-edit', 'id' => 'gdbb-toolbar-edit-replies', 'title' => __("Replies", "gd-bbpress-tools"), 'href' => admin_url('edit.php?post_type=reply'))); $wp_admin_bar->add_menu(array('parent' => 'gdbb-toolbar-admin', 'id' => 'gdbb-toolbar-settings', 'title' => __("Settings", "gd-bbpress-tools"), 'href' => '')); $wp_admin_bar->add_menu(array('parent' => 'gdbb-toolbar-settings', 'id' => 'gdbb-toolbar-settings-main', 'title' => __("bbPress Settings", "gd-bbpress-tools"), 'href' => admin_url('options-general.php?page=bbpress'))); $wp_admin_bar->add_group(array('parent' => 'gdbb-toolbar-settings', 'id' => 'gdbb-toolbar-settings-third')); $wp_admin_bar->add_menu(array('parent' => 'gdbb-toolbar-settings-third', 'id' => 'gdbb-toolbar-settings-third-tools', 'title' => __("GD bbPress Tools", "gd-bbpress-tools"), 'href' => admin_url('edit.php?post_type=forum&page=gdbbpress_tools'))); if (defined('GDBBPRESSATTACHMENTS_INSTALLED')) { $wp_admin_bar->add_menu(array('parent' => 'gdbb-toolbar-settings-third', 'id' => 'gdbb-toolbar-settings-third-attachments', 'title' => __("GD bbPress Attchments", "gd-bbpress-tools"), 'href' => admin_url('edit.php?post_type=forum&page=gdbbpress_attachments'))); } $wp_admin_bar->add_menu(array('parent' => 'gdbb-toolbar-admin', 'id' => 'gdbb-toolbar-tools', 'title' => __("Tools", "gd-bbpress-tools"), 'href' => '')); $wp_admin_bar->add_menu(array('parent' => 'gdbb-toolbar-tools', 'id' => 'gdbb-toolbar-tools-recount', 'title' => __("Recount", "gd-bbpress-tools"), 'href' => admin_url('tools.php?page=bbp-recount'))); } $wp_admin_bar->add_group(array('parent' => 'gdbb-toolbar', 'id' => 'gdbb-toolbar-info', 'meta' => array('class' => 'ab-sub-secondary'))); $wp_admin_bar->add_menu(array('parent' => 'gdbb-toolbar-info', 'id' => 'gdbb-toolbar-info-links', 'title' => __("Information", "gd-bbpress-tools"))); $wp_admin_bar->add_group(array('parent' => 'gdbb-toolbar-info-links', 'id' => 'gdbb-toolbar-info-links-bbp', 'meta' => array('class' => 'ab-sub-secondary'))); $wp_admin_bar->add_group(array('parent' => 'gdbb-toolbar-info-links', 'id' => 'gdbb-toolbar-info-links-d4p', 'meta' => array('class' => 'ab-sub-secondary'))); $wp_admin_bar->add_menu(array('parent' => 'gdbb-toolbar-info-links-bbp', 'id' => 'gdbb-toolbar-bbp-home', 'title' => __("bbPress Homepage", "gd-bbpress-tools"), 'href' => 'http://bbpress.org/', 'meta' => array('target' => '_blank'))); $wp_admin_bar->add_menu(array('parent' => 'gdbb-toolbar-info-links-d4p', 'id' => 'gdbb-toolbar-d4p-home', 'title' => __("Dev4Press Homepage", "gd-bbpress-tools"), 'href' => 'http://www.dev4press.com/', 'meta' => array('target' => '_blank'))); }
/** * The main topic loop. WordPress makes this easy for us * * @since 2.0.0 bbPress (r2485) * * @param array $args All the arguments supported by {@link WP_Query} * @uses current_user_can() To check if the current user can edit other's topics * @uses bbp_get_topic_post_type() To get the topic post type * @uses WP_Query To make query and get the topics * @uses is_page() To check if it's a page * @uses bbp_is_single_forum() To check if it's a forum * @uses bbp_get_forum_id() To get the forum id * @uses bbp_get_paged() To get the current page value * @uses bbp_get_super_stickies() To get the super stickies * @uses bbp_get_stickies() To get the forum stickies * @uses bbp_use_pretty_urls() To check if the site is using pretty URLs * @uses get_permalink() To get the permalink * @uses add_query_arg() To add custom args to the url * @uses apply_filters() Calls 'bbp_topics_pagination' with the pagination args * @uses paginate_links() To paginate the links * @uses apply_filters() Calls 'bbp_has_topics' with * bbPres::topic_query::have_posts() * and bbPres::topic_query * @return object Multidimensional array of topic information */ function bbp_has_topics($args = array()) { /** Defaults **************************************************************/ // Other defaults $default_topic_search = !empty($_REQUEST['ts']) ? $_REQUEST['ts'] : false; $default_show_stickies = (bool) (bbp_is_single_forum() || bbp_is_topic_archive()) && false === $default_topic_search; $default_post_parent = bbp_is_single_forum() ? bbp_get_forum_id() : 'any'; // Default argument array $default = array('post_type' => bbp_get_topic_post_type(), 'post_parent' => $default_post_parent, 'meta_key' => '_bbp_last_active_time', 'meta_type' => 'DATETIME', 'orderby' => 'meta_value', 'order' => 'DESC', 'posts_per_page' => bbp_get_topics_per_page(), 'paged' => bbp_get_paged(), 'show_stickies' => $default_show_stickies, 'max_num_pages' => false); // Only add 's' arg if searching for topics // See https://bbpress.trac.wordpress.org/ticket/2607 if (!empty($default_topic_search)) { $default['s'] = $default_topic_search; } // 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(), bbp_get_pending_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'; } // Maybe query for topic tags if (bbp_is_topic_tag()) { $default['term'] = bbp_get_topic_tag_slug(); $default['taxonomy'] = bbp_get_topic_tag_tax_id(); } /** Setup *****************************************************************/ // Parse arguments against default values $r = bbp_parse_args($args, $default, 'has_topics'); // Get bbPress $bbp = bbpress(); // Call the query $bbp->topic_query = new WP_Query($r); // Set post_parent back to 0 if originally set to 'any' if ('any' === $r['post_parent']) { $r['post_parent'] = 0; } // Limited the number of pages shown if (!empty($r['max_num_pages'])) { $bbp->topic_query->max_num_pages = $r['max_num_pages']; } /** Stickies **************************************************************/ // Put sticky posts at the top of the posts array if (!empty($r['show_stickies']) && $r['paged'] <= 1) { // Get super stickies and stickies in this forum $stickies = bbp_get_super_stickies(); // Get stickies for current forum if (!empty($r['post_parent'])) { $stickies = array_merge($stickies, bbp_get_stickies($r['post_parent'])); } // Remove any duplicate stickies $stickies = array_unique($stickies); // We have stickies if (is_array($stickies) && !empty($stickies)) { // Start the offset at -1 so first sticky is at correct 0 offset $sticky_offset = -1; // Loop over topics and relocate stickies to the front. foreach ($stickies as $sticky_index => $sticky_ID) { // Get the post offset from the posts array $post_offsets = wp_filter_object_list($bbp->topic_query->posts, array('ID' => $sticky_ID), 'OR', 'ID'); // Continue if no post offsets if (empty($post_offsets)) { continue; } // Loop over posts in current query and splice them into position foreach (array_keys($post_offsets) as $post_offset) { $sticky_offset++; $sticky = $bbp->topic_query->posts[$post_offset]; // Remove sticky from current position array_splice($bbp->topic_query->posts, $post_offset, 1); // Move to front, after other stickies array_splice($bbp->topic_query->posts, $sticky_offset, 0, array($sticky)); // Cleanup unset($stickies[$sticky_index]); unset($sticky); } // Cleanup unset($post_offsets); } // Cleanup unset($sticky_offset); // If any posts have been excluded specifically, Ignore those that are sticky. if (!empty($stickies) && !empty($r['post__not_in'])) { $stickies = array_diff($stickies, $r['post__not_in']); } // Fetch sticky posts that weren't in the query results if (!empty($stickies)) { // Query to use in get_posts to get sticky posts $sticky_query = array('post_type' => bbp_get_topic_post_type(), 'post_parent' => 'any', 'meta_key' => '_bbp_last_active_time', 'meta_type' => 'DATETIME', 'orderby' => 'meta_value', 'order' => 'DESC', 'include' => $stickies); // Cleanup unset($stickies); // Conditionally exclude private/hidden forum ID's $exclude_forum_ids = bbp_exclude_forum_ids('array'); if (!empty($exclude_forum_ids)) { $sticky_query['post_parent__not_in'] = $exclude_forum_ids; } // What are the default allowed statuses (based on user caps) if (bbp_get_view_all()) { $sticky_query['post_status'] = $r['post_status']; // Lean on the 'perm' query var value of 'readable' to provide statuses } else { $sticky_query['post_status'] = $r['perm']; } // Get all stickies $sticky_posts = get_posts($sticky_query); if (!empty($sticky_posts)) { // Get a count of the visible stickies $sticky_count = count($sticky_posts); // Merge the stickies topics with the query topics . $bbp->topic_query->posts = array_merge($sticky_posts, $bbp->topic_query->posts); // Adjust loop and counts for new sticky positions $bbp->topic_query->found_posts = (int) $bbp->topic_query->found_posts + (int) $sticky_count; $bbp->topic_query->post_count = (int) $bbp->topic_query->post_count + (int) $sticky_count; // Cleanup unset($sticky_posts); } } } } // If no limit to posts per page, set it to the current post_count if (-1 === $r['posts_per_page']) { $r['posts_per_page'] = $bbp->topic_query->post_count; } // Add pagination values to query object $bbp->topic_query->posts_per_page = $r['posts_per_page']; $bbp->topic_query->paged = $r['paged']; // Only add pagination if query returned results if (((int) $bbp->topic_query->post_count || (int) $bbp->topic_query->found_posts) && (int) $bbp->topic_query->posts_per_page) { // Limit the number of topics shown based on maximum allowed pages if (!empty($r['max_num_pages']) && $bbp->topic_query->found_posts > $bbp->topic_query->max_num_pages * $bbp->topic_query->post_count) { $bbp->topic_query->found_posts = $bbp->topic_query->max_num_pages * $bbp->topic_query->post_count; } // If pretty permalinks are enabled, make our pagination pretty if (bbp_use_pretty_urls()) { // User's topics if (bbp_is_single_user_topics()) { $base = bbp_get_user_topics_created_url(bbp_get_displayed_user_id()); // User's favorites } elseif (bbp_is_favorites()) { $base = bbp_get_favorites_permalink(bbp_get_displayed_user_id()); // User's subscriptions } elseif (bbp_is_subscriptions()) { $base = bbp_get_subscriptions_permalink(bbp_get_displayed_user_id()); // Root profile page } elseif (bbp_is_single_user()) { $base = bbp_get_user_profile_url(bbp_get_displayed_user_id()); // View } elseif (bbp_is_single_view()) { $base = bbp_get_view_url(); // Topic tag } elseif (bbp_is_topic_tag()) { $base = bbp_get_topic_tag_link(); // Page or single post } elseif (is_page() || is_single()) { $base = get_permalink(); // Forum archive } elseif (bbp_is_forum_archive()) { $base = bbp_get_forums_url(); // Topic archive } elseif (bbp_is_topic_archive()) { $base = bbp_get_topics_url(); // Default } else { $base = get_permalink((int) $r['post_parent']); } // Use pagination base $base = trailingslashit($base) . user_trailingslashit(bbp_get_paged_slug() . '/%#%/'); // Unpretty pagination } else { $base = add_query_arg('paged', '%#%'); } // Pagination settings with filter $bbp_topic_pagination = apply_filters('bbp_topic_pagination', array('base' => $base, 'format' => '', 'total' => $r['posts_per_page'] === $bbp->topic_query->found_posts ? 1 : ceil((int) $bbp->topic_query->found_posts / (int) $r['posts_per_page']), 'current' => (int) $bbp->topic_query->paged, 'prev_text' => is_rtl() ? '→' : '←', 'next_text' => is_rtl() ? '←' : '→', 'mid_size' => 1)); // Add pagination to query object $bbp->topic_query->pagination_links = paginate_links($bbp_topic_pagination); // Remove first page from pagination $bbp->topic_query->pagination_links = str_replace(bbp_get_paged_slug() . "/1/'", "'", $bbp->topic_query->pagination_links); } // Return object return apply_filters('bbp_has_topics', $bbp->topic_query->have_posts(), $bbp->topic_query); }
/** * Ouput the forum URL * * @since bbPress (r3979) * * @uses bbp_get_forums_url() To get the forums URL * @param string $path Additional path with leading slash */ function bbp_forums_url($path = '/') { echo bbp_get_forums_url($path); }
/** * Perform a safe, local redirect somewhere inside the current site * * On some setups, passing the value of wp_get_referer() may result in an empty * value for $location, which results in an error on redirection. If $location * is empty, we can safely redirect back to the forum root. This might change * in a future version, possibly to the site root. * * @since 2.6.0 bbPress (r5658) * * @uses wp_safe_redirect() * @uses bbp_get_forums_url() * @see bbp_redirect_to_field() * * @param string $location The URL to redirect the user to. * @param int $status Optional. The numeric code to give in the redirect * headers. Default: 302. */ function bbp_redirect($location = '', $status = 302) { // Prevent errors from empty $location if (empty($location)) { $location = bbp_get_forums_url(); } // Setup the safe redirect wp_safe_redirect($location, $status); // Exit so the redirect takes place immediately exit; }
/** * Ouput the forum URL * * @since bbPress (r3979) * * @uses bbp_get_forums_url() To get the forums URL * @param string $path Additional path with leading slash */ function bbp_forums_url($path = '/') { echo esc_url(bbp_get_forums_url($path)); }