예제 #1
0
function bp_docs_get_doc_ids_accessible_to_current_user()
{
    global $wpdb;
    // Direct query for speeeeeeed
    $exclude = bp_docs_access_query()->get_doc_ids();
    if (empty($exclude)) {
        $exclude = array(0);
    }
    $exclude_sql = '(' . implode(',', $exclude) . ')';
    $items_sql = $wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_type = %s AND ID NOT IN {$exclude_sql}", bp_docs_get_post_type_name());
    return $wpdb->get_col($items_sql);
}
예제 #2
0
/**
 * Keep private Docs out of primary WP queries
 *
 * By catching the query at pre_get_posts, we ensure that all queries are
 * filtered appropriately, whether they originate with BuddyPress Docs or not
 * (as in the case of search)
 *
 * @since 1.2.8
 */
function bp_docs_general_access_protection($query)
{
    // Access is unlimited when viewing your own profile, or when the
    // current user is a site admin
    if (bp_is_my_profile() || current_user_can('bp_moderate')) {
        return;
    }
    // We only need to filter when BP Docs could possibly show up in the
    // results, so we check the post type, and bail if the post_type rules
    // out Docs to begin with
    $queried_post_type = $query->get('post_type');
    $pt = bp_docs_get_post_type_name();
    $is_bp_doc_query = is_array($queried_post_type) ? in_array($pt, $queried_post_type) : $pt == $queried_post_type;
    if (!$queried_post_type || 'any' == $queried_post_type || $is_bp_doc_query) {
        $bp_docs_access_query = bp_docs_access_query();
        if ($pt == $queried_post_type) {
            // Use a tax query if possible
            $tax_query = $query->get('tax_query');
            if (!$tax_query) {
                $tax_query = array();
            }
            $query->set('tax_query', array_merge($tax_query, $bp_docs_access_query->get_tax_query()));
        } else {
            // When it's not a straight bp_doc query, a tax_query
            // approach won't work (because the taxonomy in
            // question only applies to bp_docs, and conditional
            // tax_query is not supported by WP). Instead, get a
            // list of off-limits Docs and pass to post__not_in
            $exclude = $bp_docs_access_query->get_doc_ids();
            if (!empty($exclude)) {
                $not_in = $query->get('post__not_in');
                $query->set('post__not_in', array_merge((array) $not_in, $exclude));
            }
        }
    }
}
예제 #3
0
/**
 * Keep private Docs out of primary WP queries
 *
 * By catching the query at pre_get_posts, we ensure that all queries are
 * filtered appropriately, whether they originate with BuddyPress Docs or not
 * (as in the case of search)
 *
 * @since 1.2.8
 */
function bp_docs_general_access_protection($query)
{
    // Access is unlimited when viewing your own profile, or when the
    // current user is a site admin
    if (bp_is_my_profile() || current_user_can('bp_moderate')) {
        return;
    }
    $bp_docs_access_query = bp_docs_access_query();
    if (bp_docs_get_post_type_name() == $query->get('post_type')) {
        $tax_query = $query->get('tax_query');
        if (!$tax_query) {
            $tax_query = array();
        }
        $query->set('tax_query', array_merge($tax_query, $bp_docs_access_query->get_tax_query()));
    } else {
        $exclude = $bp_docs_access_query->get_doc_ids();
        if (!empty($exclude)) {
            $not_in = $query->get('post__not_in');
            $query->set('post__not_in', array_merge((array) $not_in, $exclude));
        }
    }
}