/** * Save thread id to following to usermeta */ public function save_following_questions($id) { global $user_ID; if (get_post_type($id) != "answer" && get_post_type($id) != "question") { return; } if (get_post_type($id) == "answer") { $answer = get_post($id); $id = $answer->post_parent; //update last author to question update_post_meta($id, 'et_last_author', $answer->post_author); } $users_follow = explode(',', get_post_meta($id, 'et_users_follow', true)); if (!in_array($user_ID, $users_follow)) { $users_follow[] = $user_ID; } $users_follow = array_unique(array_filter($users_follow)); $users_follow = implode(',', $users_follow); QA_Questions::update_field($id, 'et_users_follow', $users_follow); }
public static function report($question_id) { global $current_user; // required logged in if (!$current_user->ID) { return false; } // get reports list $reports = QA_Questions::get_field($question_id, 'et_reports'); // if (!is_array($reports)) { $reports = array(); } if (!in_array($current_user->ID, $reports)) { $reports[] = $current_user->ID; } QA_Questions::update_field($question_id, 'et_reports', $reports); return true; }
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; }