/**
 * Get a total doc count, for a user, a group, or the whole site
 *
 * @since 1.2
 * @todo Total sitewide doc count
 *
 * @param int $item_id The id of the item (user or group)
 * @param str $item_type 'user' or 'group'
 * @return int
 */
function bp_docs_get_doc_count($item_id = 0, $item_type = '')
{
    $doc_count = 0;
    switch ($item_type) {
        case 'user':
            $doc_count = get_user_meta($item_id, 'bp_docs_count', true);
            if ('' === $doc_count) {
                $doc_count = bp_docs_update_doc_count($item_id, 'user');
            }
            break;
        case 'group':
            $doc_count = groups_get_groupmeta($item_id, 'bp-docs-count');
            if ('' === $doc_count) {
                $doc_count = bp_docs_update_doc_count($item_id, 'group');
            }
            break;
    }
    return apply_filters('bp_docs_get_doc_count', (int) $doc_count, $item_id, $item_type);
}
 /**
  * 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.
  *
  * @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
     bp_docs_update_doc_count(bp_get_current_group_id(), 'group');
 }
 /**
  * Update's a user's Doc count
  *
  * @since 1.2
  */
 function update_doc_count()
 {
     bp_docs_update_doc_count(bp_loggedin_user_id(), 'user');
 }