示例#1
0
 /**
  * save edited comment via ajax
  */
 public function wc_save_edited_comment()
 {
     $message_array = array();
     $comment_ID = intval(filter_input(INPUT_POST, 'comment_id'));
     $comment_content = filter_input(INPUT_POST, 'comment_content');
     $comment = get_comment($comment_ID);
     $current_user = wp_get_current_user();
     $trimmed_comment_content = trim($comment_content);
     // Change messages in next version - shoud be diff. messages for each specific error
     if ($trimmed_comment_content && isset($current_user) && $comment->user_id == $current_user->ID) {
         if ($trimmed_comment_content != $comment->comment_content) {
             $comment_content = wp_kses($comment_content, $this->wc_helper->wc_allowed_tags);
             $author_ip = WC_Helper::get_real_ip_addr();
             $this->wc_user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
             $comment_content = addslashes($comment_content);
             $commentarr = array('comment_ID' => $comment_ID, 'comment_content' => apply_filters('pre_comment_content', $comment_content), 'comment_author_IP' => apply_filters('pre_comment_user_ip', $author_ip), 'comment_agent' => apply_filters('pre_comment_user_agent', $this->wc_user_agent), 'comment_approved' => $comment->comment_approved);
             if (wp_update_comment($commentarr)) {
                 $message_array['code'] = 1;
                 $message_array['message'] = $this->wc_helper->make_clickable($comment_content);
             } else {
                 $message_array['code'] = -1;
                 $message_array['phrase_message'] = $this->wc_options_serialized->wc_phrases['wc_comment_not_updated'];
             }
         } else {
             $message_array['code'] = -2;
             $message_array['phrase_message'] = $this->wc_options_serialized->wc_phrases['wc_comment_not_edited'];
         }
     } else {
         $message_array['code'] = -1;
         $message_array['phrase_message'] = $this->wc_options_serialized->wc_phrases['wc_comment_edit_not_possible'];
     }
     echo json_encode($message_array);
     exit;
 }