Example #1
0
 public function update_comment_form()
 {
     $args = wp_parse_args($_REQUEST['args']);
     $comment_id = sanitize_text_field($args['comment_id']);
     if (!ap_user_can_edit_comment($comment_id)) {
         $result = json_encode(array('status' => false, 'message' => __('You do not ahve permission to edit this comment.', 'ap')));
         die($result);
     }
     $action = 'save-comment-' . $comment_id;
     if (wp_verify_nonce($args['nonce'], $action)) {
         $comment_data = array('comment_ID' => $comment_id, 'comment_content' => wp_kses($args['content'], ap_form_allowed_tags()));
         $comment_saved = wp_update_comment($comment_data);
         if ($comment_saved) {
             $comment = get_comment($args['comment_id']);
             ob_start();
             ap_comment($comment);
             $html = ob_get_clean();
             $result = json_encode(array('status' => true, 'comment_ID' => $comment->comment_ID, 'comment_post_ID' => $comment->comment_post_ID, 'comment_content' => $comment->comment_content, 'html' => $html, 'message' => __('Comment updated successfully', 'ap')));
         } else {
             $result = json_encode(array('status' => false, 'message' => __('Comment not updated, please retry', 'ap')));
         }
     } else {
         $result = json_encode(array('status' => false, 'message' => __('Comment not updated, please retry', 'ap')));
     }
     die($result);
 }
 /**
  * Sanitize field using wp_kses
  * @param  string $field
  * @return void
  * @since 2.0.1
  */
 private function wp_kses($field)
 {
     $this->fields[$field] = wp_kses($this->fields[$field], ap_form_allowed_tags());
 }