Пример #1
0
function ap_user_can_ask()
{
    if (current_user_can('ap_new_question') || is_super_admin() || ap_show_form_to_guest() || ap_allow_anonymous()) {
        return true;
    }
    return false;
}
Пример #2
0
function ap_user_can_answer($question_id)
{
    if (is_super_admin()) {
        return true;
    }
    $question = get_post($question_id);
    if (!ap_opt('disallow_op_to_answer') && $question->post_author == get_current_user_id() && get_current_user_id() > 0) {
        return false;
    }
    if ($question->post_type == 'closed') {
        return false;
    }
    if (ap_allow_anonymous() && !is_user_logged_in()) {
        return true;
    }
    if (is_user_logged_in()) {
        if (!ap_opt('multiple_answers') && ap_is_user_answered($question_id, get_current_user_id()) && get_current_user_id() != '0') {
            return false;
        } else {
            return true;
        }
    }
    return false;
}
Пример #3
0
/**
 * Check if a user can answer on a question
 * @param  integer $question_id question id.
 * @return boolean
 */
function ap_user_can_answer($question_id)
{
    if (ap_opt('only_admin_can_answer') && !is_super_admin()) {
        return false;
    }
    if (is_super_admin()) {
        return true;
    }
    $question = get_post($question_id);
    // Check if user is original poster and dont allow them to answer their own question.
    if (!ap_opt('disallow_op_to_answer') && $question->post_author == get_current_user_id() && !is_user_logged_in()) {
        return false;
    }
    // Bail out if question is closed
    if ($question->post_type == 'closed') {
        return false;
    }
    // Check if user already answered and if multiple answer disabled then down't allow them to answer.
    if (current_user_can('ap_new_answer')) {
        if (!ap_opt('multiple_answers') && ap_is_user_answered($question_id, get_current_user_id())) {
            return false;
        } else {
            return true;
        }
    }
    if (ap_allow_anonymous() && !is_user_logged_in()) {
        return true;
    }
    return false;
}
Пример #4
0
 public function process_ask_form()
 {
     if (!is_user_logged_in() && !ap_allow_anonymous()) {
         return false;
     }
     if (isset($_POST['is_question']) && isset($_POST['submitted']) && isset($_POST['ask_form']) && wp_verify_nonce($_POST['ask_form'], 'post_nonce')) {
         $fields = $this->get_question_fields_to_process();
         if (!ap_user_can_ask() && ap_opt('allow_anonymous')) {
             return;
         }
         $validate = $this->validate_question_form();
         if ($validate['has_error']) {
             if ($_POST['action'] == 'ap_submit_question') {
                 $result = array('action' => 'validation_falied', 'message' => __('Question not submitted, please check the form fields.', 'ap'), 'error' => $validate);
                 return json_encode($result);
             }
             return;
         }
         do_action('process_ask_form');
         $user_id = get_current_user_id();
         $status = 'publish';
         if (ap_opt('moderate_new_question') == 'pending' || ap_opt('moderate_new_question') == 'point' && ap_get_points($user_id) < ap_opt('mod_question_point')) {
             $status = 'moderate';
         }
         if (isset($fields['private_question']) && $fields['private_question']) {
             $status = 'private_question';
         }
         $question_array = array('post_title' => $fields['post_title'], 'post_author' => $user_id, 'post_content' => wp_kses($fields['post_content'], ap_form_allowed_tags()), 'post_type' => 'question', 'post_status' => $status);
         if (isset($fields['parent_id'])) {
             $question_array['post_parent'] = (int) $fields['parent_id'];
         }
         $post_id = wp_insert_post($question_array);
         if ($post_id) {
             // Update Custom Meta
             if (isset($fields['category'])) {
                 wp_set_post_terms($post_id, $fields['category'], 'question_category');
             }
             if (isset($fields['tags'])) {
                 wp_set_post_terms($post_id, $fields['tags'], 'question_tags');
             }
             if (ap_opt('allow_anonymous') && isset($fields['name'])) {
                 update_post_meta($post_id, 'anonymous_name', $fields['name']);
             }
             if ($_POST['action'] == 'ap_submit_question') {
                 $result = apply_filters('ap_ajax_question_submit_result', array('action' => 'new_question', 'message' => __('Question submitted successfully', 'ap'), 'redirect_to' => get_permalink($post_id)));
                 return json_encode($result);
             } else {
                 // Redirect
                 wp_redirect(get_permalink($post_id));
                 exit;
             }
         }
     }
 }