Ejemplo n.º 1
0
/**
 * Get an question by ID
 * @param  integer $question_id
 * @return void
 * @since 2.1
 */
function ap_get_question($question_id)
{
    $args = array('p' => $question_id);
    if (ap_user_can_view_private_post($question_id)) {
        $args['post_status'][] = 'private_post';
    }
    if (ap_user_can_view_moderate_post($question_id)) {
        $args['post_status'][] = 'moderate';
    }
    anspress()->questions = new Question_Query($args);
}
Ejemplo n.º 2
0
/**
 * Check if user can view post
 * @param  boolean|integer $post_id
 * @return boolean
 */
function ap_user_can_view_post($post_id = false)
{
    if (is_super_admin()) {
        return true;
    }
    if (!$post_id) {
        $post_id = get_the_ID();
    }
    $post = get_post($post_id);
    if ($post->post_status == 'private_post' && ap_user_can_view_private_post($post_id)) {
        return true;
    }
    if ($post->post_status == 'moderate' && ap_user_can_view_moderate_post($post_id)) {
        return true;
    }
    if ($post->post_status == 'publish' || $post->post_status == 'closed') {
        return true;
    }
    return false;
}
Ejemplo n.º 3
0
/**
 * Check if user can view post
 * @param  false|integer $post_id Question or answer ID.
 * @return boolean
 */
function ap_user_can_view_post($post_id = false)
{
    if (is_super_admin()) {
        return true;
    }
    if (false !== $post_id) {
        $post_id = get_the_ID();
    }
    $post_o = get_post($post_id);
    if ('private_post' == $post_o->post_status && ap_user_can_view_private_post($post_id)) {
        return true;
    }
    if ('moderate' == $post_o->post_status && ap_user_can_view_moderate_post($post_id)) {
        return true;
    }
    if ('publish' == $post_o->post_status || 'closed' == $post_o->post_status) {
        return true;
    }
    return false;
}