/**
 * Get a list of an item's docs for display in the parent dropdown
 *
 * @package BuddyPress Docs
 * @since 1.0-beta
 */
function bp_docs_edit_parent_dropdown()
{
    global $bp;
    // Get the item docs to use as Include arguments
    $q = new BP_Docs_Query();
    $q->current_view = 'list';
    $qt = $q->build_query();
    // Make sure we don't limit the posts displayed
    $qt['showposts'] = -1;
    // Order them by name, no matter what
    $qt['orderby'] = 'post_title';
    $qt['order'] = 'ASC';
    $include_posts = new WP_Query($qt);
    $include = array();
    if ($include_posts->have_posts()) {
        while ($include_posts->have_posts()) {
            $include_posts->the_post();
            $include[] = get_the_ID();
        }
    }
    // Exclude the current doc, if this is 'edit' and not 'create' mode
    $exclude = !empty($bp->bp_docs->current_post->ID) ? array($bp->bp_docs->current_post->ID) : false;
    // Highlight the existing parent doc, if any
    $parent = !empty($bp->bp_docs->current_post->post_parent) ? $bp->bp_docs->current_post->post_parent : false;
    $pages = wp_dropdown_pages(array('post_type' => $bp->bp_docs->post_type_name, 'exclude' => $exclude, 'include' => $include, 'selected' => $parent, 'name' => 'parent_id', 'show_option_none' => __('(no parent)', 'bp-docs'), 'sort_column' => 'menu_order, post_title', 'echo' => 0));
    echo $pages;
}
 /**
  * Update the groupmeta containing the current group's Docs count.
  *
  * Instead of incrementing, which has the potential to be error-prone, I do a fresh query
  * on each Doc save to get an accurate count. This adds some overhead, but Doc editing is
  * rare enough that it shouldn't be a huge issue.
  *
  * @package BuddyPress Docs
  * @since 1.0.8
  */
 function update_doc_count()
 {
     global $bp;
     // If this is not a group Doc, skip it
     if (!bp_is_group()) {
         return;
     }
     // Get a fresh doc count for the group
     // Set up the arguments
     $doc_count = new BP_Docs_Query();
     $query = $doc_count->build_query();
     // Fire the query
     $this_group_docs = new WP_Query($query);
     $this_group_docs_count = $this_group_docs->found_posts;
     // BP has a stupid bug that makes it delete groupmeta when it equals 0. We'll save
     // a string instead of zero to work around this
     if (!$this_group_docs_count) {
         $this_group_docs_count = '0';
     }
     // Save the count
     groups_update_groupmeta($bp->groups->current_group->id, 'bp-docs-count', $this_group_docs_count);
 }