public function process_edit_answer_form() { if (isset($_POST['is_answer']) && isset($_POST['submitted']) && isset($_POST['edited']) && wp_verify_nonce($_POST['nonce'], 'post_nonce-' . $_POST['answer_id'])) { $fields = $this->get_answer_fields_to_process(); $validate = $this->validate_ans_form(); if ($validate['has_error']) { if ($_POST['action'] == 'ap_submit_answer') { $result = array('action' => 'validation_falied', 'message' => __('Answer not updated, please check the form fields.', 'ap'), 'error' => $validate); return json_encode($result); } return; } $post_id = sanitize_text_field($_POST['answer_id']); $post = get_post($post_id); if (!ap_user_can_edit_ans($post->ID)) { if ($_POST['action'] == 'ap_submit_answer') { $result = array('action' => 'false', 'message' => __('You do not have permission to edit this answer.', 'ap')); return json_encode($result); } return; } global $current_user; $user_id = $current_user->ID; $answer_array = array('ID' => $post_id, 'post_content' => wp_kses($fields['post_content'], ap_form_allowed_tags()), 'post_status' => 'publish'); $post_id = wp_update_post($answer_array); if ($post_id) { // set updated meta for sorting purpose update_post_meta($post->post_parent, ANSPRESS_UPDATED_META, current_time('mysql')); do_action('ap_after_editing_answer', $post_id); ap_do_event('edit_answer', $post_id, $user_id, $post->post_parent); if ($_POST['action'] == 'ap_submit_answer') { $result = apply_filters('ap_ajax_answer_edit_result', array('action' => 'answer_edited', 'message' => __('Answer updated successfully', 'ap'), 'redirect_to' => get_permalink($post->post_parent))); return json_encode($result); } else { // Redirect wp_redirect(get_permalink($post->post_parent)); exit; } } } }
public function edit_answer($question) { global $ap_errors, $validate; // return if user do not have permission to edit this answer if (!ap_user_can_edit_ans($this->fields['edit_post_id'])) { $this->result = ap_ajax_responce('no_permission'); return; } $answer = get_post($this->fields['edit_post_id']); $status = 'publish'; if (ap_opt('edit_answer_status') == 'moderate' || ap_opt('edit_answer_status') == 'point' && ap_get_points(get_current_user_id()) < ap_opt('new_answer_status')) { $status = 'moderate'; } if (isset($this->fields['is_private']) && $this->fields['is_private']) { $status = 'private_post'; } $answer_array = array('ID' => $this->fields['edit_post_id'], 'post_author' => $answer->post_author, 'post_content' => apply_filters('ap_form_contents_filter', $this->fields['description']), 'post_status' => $status); $answer_array = apply_filters('ap_pre_update_answer', $answer_array); $post_id = wp_update_post($answer_array); if ($post_id) { if ($this->is_ajax) { $this->result = array('action' => 'answer_edited', 'message' => 'answer_updated', 'do' => array('redirect' => get_permalink($answer->post_parent))); } $this->redirect = get_permalink($post_id); } $this->process_image_uploads($post_id, $answer->post_author); }
/** * Post actions buttons * @return string * @param array $disable * @return void * @since 2.0 */ function ap_post_actions_buttons($disable = array()) { global $post; if (!$post->post_type == 'question' || !$post->post_type == 'answer') { return; } $actions = array(); /** * Select answer button * @var string */ if ($post->post_type == 'answer') { $actions['select_answer'] = ap_select_answer_btn_html($post->ID); } /** * Comment button */ if (ap_user_can_comment()) { $actions['comment'] = ap_comment_btn_html(); } $actions['status'] = ap_post_change_status_btn_html($post->ID); /** * edit question link */ if (ap_user_can_edit_question($post->ID) && $post->post_type == 'question') { $actions['dropdown']['edit_question'] = ap_edit_post_link_html(); } if (ap_user_can_edit_ans($post->ID) && $post->post_type == 'answer') { $actions['dropdown']['edit_answer'] = ap_edit_post_link_html(); } if (is_user_logged_in()) { $actions['dropdown']['flag'] = ap_flag_btn_html(); } if (is_super_admin() && $post->post_type == 'question') { $actions['dropdown']['featured'] = ap_featured_post_btn(); } if (ap_user_can_delete($post->ID) && $post->post_status != 'trash') { $actions['dropdown']['delete'] = ap_post_delete_btn_html(); } if (ap_user_can_delete($post->ID)) { $actions['dropdown']['permanent_delete'] = ap_post_permanent_delete_btn_html(); } /** * FILTER: ap_post_actions_buttons * For filtering post actions buttons * @var string * @since 2.0 */ $actions = apply_filters('ap_post_actions_buttons', $actions); if (!empty($actions) && count($actions) > 0) { echo '<ul id="ap_post_actions_' . $post->ID . '" class="ap-q-actions ap-ul-inline clearfix">'; foreach ($actions as $k => $action) { if (!empty($action) && $k != 'dropdown' && !in_array($k, $disable)) { echo '<li class="ap-post-action ap-action-' . $k . '">' . $action . '</li>'; } } if (!empty($actions['dropdown'])) { echo '<li class="ap-post-action dropdown">'; echo '<div id="ap_post_action_' . $post->ID . '" class="ap-dropdown">'; echo '<a class="apicon-ellipsis more-actions ap-tip ap-dropdown-toggle" title="' . __('More action', 'ap') . '" href="#"></a>'; echo '<ul class="ap-dropdown-menu">'; foreach ($actions['dropdown'] as $sk => $sub) { echo '<li class="ap-post-action ap-action-' . $sk . '">' . $sub . '</li>'; } echo '</ul>'; echo '</div>'; echo '</li>'; } echo '</ul>'; } }
function ap_answer_edit_link() { $post_id = get_the_ID(); if (ap_user_can_edit_ans($post_id)) { $action = get_post_type($post_id) . '-' . $post_id; $nonce = wp_create_nonce($action); $edit_link = add_query_arg(array('edit_a' => $post_id, 'ap_nonce' => $nonce), get_permalink(ap_opt('base_page'))); return apply_filters('ap_answer_edit_link', $edit_link); } return; }