function qa_mark_answer_point($question_id, $answer_id) { $answer = get_post($answer_id); if ($answer) { // answer is valid global $user_ID; if ($user_ID != $answer->post_author) { /** * get site qa badge point system */ $point = qa_get_badge_point(); /** * update use point by answer accepted point */ qa_update_user_point($answer->post_author, $point->a_accepted); QA_Answers::update_field($answer_id, 'et_best_answer_point', $point->a_accepted); /** * do action qa point answer mark answered * @param $answer the answer be mark * @param $point */ do_action('qa_point_answer_marked', $answer, $point->a_accepted); } } }
/** * static function callto set question answer * @param int $question_id * @param int $answer_id */ public static function mark_answer($question_id, $answer_id) { global $user_ID; /** * get question pre answer */ $pre_answer = self::get_field($question_id, 'et_best_answer'); /** * update question's answer */ self::update_field($question_id, 'et_best_answer', $answer_id); /** * set answer id is best answer */ QA_Answers::update_field($answer_id, 'et_is_best_answer', current_time('mysql')); /** * delete pre answer */ if ($pre_answer) { delete_post_meta($pre_answer, 'et_is_best_answer'); /** * do action when an answer was unmark best answer */ do_action('qa_remove_answer', $pre_answer); } /** * do action when an question was mark answered */ do_action('qa_mark_answer', $question_id, $answer_id); }
public function create() { try { $args = $_POST['content']; global $current_user; if (!is_user_logged_in()) { throw new Exception(__("You must log in to post question.", ET_DOMAIN)); } if (isset($args['post_title']) && $args['post_title'] != strip_tags($args['post_title'])) { throw new Exception(__("Post title should not contain any HTML Tag.", ET_DOMAIN)); } if (isset($args['qa_nonce']) && wp_verify_nonce($args['qa_nonce'], 'insert_comment')) { if (!qa_user_can('add_comment')) { throw new Exception(__("You don't have enough point to add a comment.", ET_DOMAIN)); } $args['comment_content'] = $args['post_content']; $args['comment_author'] = $current_user->user_login; $args['comment_author_email'] = $current_user->user_email; $result = QA_Comments::insert($args); $comment = QA_Comments::convert(get_comment($result)); if (is_wp_error($result)) { $resp = array('success' => false, 'msg' => __('An error occur when created comment.', ET_DOMAIN)); } else { $resp = array('success' => true, 'msg' => __('Comment has been created successfully.', ET_DOMAIN), 'data' => $comment); } } elseif (isset($args['qa_nonce']) && wp_verify_nonce($args['qa_nonce'], 'insert_answer')) { $result = QA_Answers::insert_answer($args['post_parent'], $args['post_content']); QA_Answers::update_field($result, "et_vote_count", 0); $answer = QA_Answers::convert(get_post($result)); if (is_wp_error($result)) { $resp = array('success' => false, 'msg' => __('An error occur when created answer.', ET_DOMAIN)); } else { $msg = ae_get_option('pending_answers') && !(current_user_can('manage_options') || qa_user_can('approve_answer')) ? __('Your answer has been created successfully and need to be approved by Admin before displayed!', ET_DOMAIN) : __('Answer has been created successfully.', ET_DOMAIN); $resp = array('success' => true, 'redirect' => get_permalink($answer->post_parent), 'msg' => $msg, 'data' => $answer); } } elseif (isset($args['qa_nonce']) && wp_verify_nonce($args['qa_nonce'], 'insert_question')) { //if option for captcha is enable if (ae_get_option('gg_question_captcha') && !et_load_mobile()) { $captcha = isset($args['captcha']) ? $args['captcha'] : ''; //verify captcha ae_verify_captcha($captcha, __('Please enter a valid captcha!', ET_DOMAIN)); } $cats = array('qa_tag' => isset($args['tags']) ? $args['tags'] : array(), 'question_category' => $args['question_category']); $status = ae_get_option("pending_questions") && !current_user_can('manage_options') ? "pending" : "publish"; $result = QA_Questions::insert_question($args['post_title'], $args['post_content'], $cats, $status); QA_Questions::update_field($result, "et_vote_count", 0); QA_Questions::update_field($result, "et_answers_count", 0); $post = QA_Questions::convert(get_post($result)); $msg = ae_get_option("pending_questions") && !current_user_can('manage_options') ? __('Your question has been created successfully. It\'ll appear right after being approved by admin.', ET_DOMAIN) : __('Question has been created successfully.', ET_DOMAIN); $redirect = ae_get_option("pending_questions") && !current_user_can('manage_options') ? home_url() : get_permalink($result); if (is_wp_error($result)) { $resp = array('success' => false, 'msg' => __('An error occur when created question.', ET_DOMAIN)); } else { $resp = array('success' => true, 'redirect' => $redirect, 'msg' => $msg, 'data' => $post); } } else { throw new Exception("Error Processing Request", 1); } } catch (Exception $e) { $resp = array('success' => false, 'msg' => $e->getMessage()); } return $resp; }