Beispiel #1
0
/**
 * Return the link of the current tag
 *
 * @since 2.0.0 bbPress (r3348)
 *
 * @uses get_term_by()
 * @uses get_queried_object()
 * @uses get_query_var()
 * @uses apply_filters()
 *
 * @return string Term Name
 */
function bbp_get_topic_tag_edit_link($tag = '')
{
    // Get the term
    if (!empty($tag)) {
        $term = get_term_by('slug', $tag, bbp_get_topic_tag_tax_id());
    } else {
        $tag = get_query_var('term');
        $term = get_queried_object();
    }
    // Add before and after if description exists
    if (!empty($term->term_id)) {
        // Pretty
        if (bbp_use_pretty_urls()) {
            $retval = user_trailingslashit(trailingslashit(bbp_get_topic_tag_link()) . bbp_get_edit_rewrite_id());
            // Ugly
        } else {
            $retval = add_query_arg(array(bbp_get_edit_rewrite_id() => '1'), bbp_get_topic_tag_link());
        }
        // No link
    } else {
        $retval = '';
    }
    return apply_filters('bbp_get_topic_tag_edit_link', $retval, $tag, $term);
}
 /**
  * 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);
 }
/**
 * Redirect if unathorized user is attempting to edit a topic tag
 *
 * @since bbPress (r3605)
 *
 * @uses bbp_is_topic_tag_edit()
 * @uses current_user_can()
 * @uses bbp_get_topic_tag_id()
 * @uses wp_safe_redirect()
 * @uses bbp_get_topic_tag_link()
 */
function bbp_check_topic_tag_edit()
{
    // Bail if not editing a topic tag
    if (!bbp_is_topic_tag_edit()) {
        return;
    }
    // Bail if current user cannot edit topic tags
    if (!current_user_can('edit_topic_tags', bbp_get_topic_tag_id())) {
        wp_safe_redirect(bbp_get_topic_tag_link());
        exit;
    }
}
/**
 * Return the link of the current tag
 *
 * @since bbPress (r3348)
 *
 * @uses get_term_by()
 * @uses get_queried_object()
 * @uses get_query_var()
 * @uses apply_filters()
 *
 * @return string Term Name
 */
function bbp_get_topic_tag_edit_link($tag = '')
{
    global $wp_rewrite;
    // Get the term
    if (!empty($tag)) {
        $term = get_term_by('slug', $tag, bbp_get_topic_tag_tax_id());
    } else {
        $tag = get_query_var('term');
        $term = get_queried_object();
    }
    // Add before and after if description exists
    if (!empty($term->term_id)) {
        $bbp = bbpress();
        // Pretty
        if ($wp_rewrite->using_permalinks()) {
            $retval = user_trailingslashit(trailingslashit(bbp_get_topic_tag_link()) . $bbp->edit_id);
            // Ugly
        } else {
            $retval = add_query_arg(array($bbp->edit_id => '1'), bbp_get_topic_tag_link());
        }
        // No link
    } else {
        $retval = '';
    }
    return apply_filters('bbp_get_topic_tag_edit_link', $retval, $tag);
}
function tehnik_bbp_has_topics($args = '')
{
    global $wp_rewrite;
    /** 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', 'orderby' => 'meta_value', 'order' => 'DESC', 'posts_per_page' => bbp_get_topics_per_page(), 'paged' => bbp_get_paged(), 's' => $default_topic_search, 'show_stickies' => $default_show_stickies, 'max_num_pages' => false);
    //Get an array of IDs which the current user has permissions to view
    $allowed_forums = tehnik_bpp_get_permitted_post_ids(new WP_Query($default));
    // The default forum query with allowed forum ids array added
    $default['post__in'] = $allowed_forums;
    // 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'] = join(',', $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', 'orderby' => 'meta_value', 'order' => 'DESC', 'include' => $stickies);
                //Get an array of IDs which the current user has permissions to view
                $allowed_forums = tehnik_bpp_get_permitted_post_ids(new WP_Query($sticky_query));
                // The default forum query with allowed forum ids array added
                $sticky_query['post__in'] = $allowed_forums;
                // Cleanup
                unset($stickies);
                // 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 ($wp_rewrite->using_permalinks()) {
            // 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();
                // 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($wp_rewrite->pagination_base . '/%#%/');
            // 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() ? '&rarr;' : '&larr;', 'next_text' => is_rtl() ? '&larr;' : '&rarr;', '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($wp_rewrite->pagination_base . "/1/'", "'", $bbp->topic_query->pagination_links);
    }
    // Return object
    return array($bbp->topic_query->have_posts(), $bbp->topic_query);
}
Beispiel #6
0
/**
 * Gets the items for the breadcrumb trail if bbPress is installed.
 *
 * @since 0.5.0
 * @access public
 * @param array $args Mixed arguments for the menu.
 * @return array List of items to be shown in the trail.
 */
function breadcrumb_trail_get_bbpress_items($args = array())
{
    /* Set up a new trail items array. */
    $trail = array();
    /* 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()) {
        $trail[] = '<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()) {
        $trail[] = "<span>" . bbp_get_forum_archive_title() . "</span>";
    } elseif (bbp_is_topic_archive()) {
        $trail[] = "<span>" . bbp_get_topic_archive_title() . "</span>";
    } elseif (bbp_is_topic_tag()) {
        $trail[] = "<span>" . bbp_get_topic_tag_name() . "</span>";
    } elseif (bbp_is_topic_tag_edit()) {
        $trail[] = '<a href="' . bbp_get_topic_tag_link() . '">' . bbp_get_topic_tag_name() . '</a>';
        $trail[] = "<span>" . __('Edit', 'kleo_framework') . "</span>";
    } elseif (bbp_is_single_view()) {
        $trail[] = '<span>' . bbp_get_view_title() . '</span>';
    } 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). */
        $trail = array_merge($trail, breadcrumb_trail_get_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()) {
            $trail[] = '<a href="' . bbp_get_topic_permalink($topic_id) . '">' . bbp_get_topic_title($topic_id) . '</a>';
        } else {
            $trail[] = '<span>' . bbp_get_topic_title($topic_id) . '</span>';
        }
        /* If viewing a topic split page. */
        if (bbp_is_topic_split()) {
            $trail[] = "<span>" . __('Split', 'kleo_framework') . "</span>";
        } elseif (bbp_is_topic_merge()) {
            $trail[] = "<span>" . __('Merge', 'kleo_framework') . "</span>";
        } elseif (bbp_is_topic_edit()) {
            $trail[] = "<span>" . __('Edit', 'kleo_framework') . "</span>";
        }
    } 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. */
        $trail = array_merge($trail, breadcrumb_trail_get_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()) {
            $trail[] = '<a href="' . bbp_get_reply_url($reply_id) . '">' . bbp_get_reply_title($reply_id) . '</a>';
            $trail[] = "<span>" . __('Edit', 'kleo_framework') . "</span>";
        } else {
            $trail[] = '<span>' . bbp_get_reply_title($reply_id) . '</span>';
        }
    } 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) {
            $trail = array_merge($trail, breadcrumb_trail_get_parents($forum_parent_id));
        }
        /* Add the forum title to the end of the trail. */
        $trail[] = '<span>' . bbp_get_forum_title($forum_id) . '</span>';
    } elseif (bbp_is_single_user() || bbp_is_single_user_edit()) {
        if (bbp_is_single_user_edit()) {
            $trail[] = '<a href="' . bbp_get_user_profile_url() . '">' . bbp_get_displayed_user_field('display_name') . '</a>';
            $trail[] = "<span>" . __('Edit', 'kleo_framework') . "</span>";
        } else {
            $trail[] = '<span>' . bbp_get_displayed_user_field('display_name') . '</span>';
        }
    }
    /* Return the bbPress breadcrumb trail items. */
    return apply_filters('breadcrumb_trail_get_bbpress_items', $trail, $args);
}
function pg_get_user_unread($user_id = 0)
{
    // Default to the displayed user
    $user_id = bbp_get_user_id($user_id);
    if (empty($user_id)) {
        return false;
    }
    // If user has unread topics, load them
    $read_ids = (string) get_user_meta($user_id, '_bbp_mar_read_ids', true);
    $read_ids = (array) explode(',', $read_ids);
    $read_ids = array_filter($read_ids);
    if (!empty($read_ids)) {
        //so we have unreads, so need to create a list of unread that the user can see
        //so first we create a list of topics the user can see
        global $wpdb;
        $topic = bbp_get_topic_post_type();
        $post_ids = $wpdb->get_col("select ID from {$wpdb->posts} where post_type = '{$topic}'");
        //check this list against those the user is allowed to see, and create a list of valid ones for the wp_query in bbp_has_topics
        $allowed_posts = check_private_groups_topic_ids($post_ids);
        //now we need to take out of that list all read topics for that user
        foreach ($read_ids as $read_id) {
            if (($key = array_search($read_id, $allowed_posts)) !== false) {
                unset($allowed_posts[$key]);
            }
        }
        //so now we have an allowed list that has only topics the user can see, but not topics the user has read
        //now we use the code from bbp_has_topics to run the list - we can't call it as PG already filters the original function
        global $wp_rewrite;
        /** 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', 'orderby' => 'meta_value', 'order' => 'DESC', 'posts_per_page' => bbp_get_topics_per_page(), 'paged' => bbp_get_paged(), 's' => $default_topic_search, 'show_stickies' => $default_show_stickies, 'max_num_pages' => false, 'post__in' => $allowed_posts);
        // 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';
        }
        // 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
        //stopped to prevent parsing
        //$r = bbp_parse_args( $args, $default, 'has_topics' );
        // Get bbPress
        $bbp = bbpress();
        // Call the query
        //now query the original default
        $bbp->topic_query = new WP_Query($default);
        // 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', '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 ($wp_rewrite->using_permalinks()) {
                // 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($wp_rewrite->pagination_base . '/%#%/');
                // 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() ? '&rarr;' : '&larr;', 'next_text' => is_rtl() ? '&larr;' : '&rarr;', '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($wp_rewrite->pagination_base . "/1/'", "'", $bbp->topic_query->pagination_links);
        }
        // Return object
        return apply_filters('pg_get_user_unread', $bbp->topic_query->have_posts(), $bbp->topic_query);
    }
    //if no unread
    return bbp_has_topics();
    // default query
}