public function delete_comment() { if (!isset($_GET['_wpnonce']) || !wp_verify_nonce(sanitize_text_field($_GET['_wpnonce']), '_dwqa_delete_comment')) { wp_die(__('Are you cheating huh?', 'dwqa')); } if (!dwqa_current_user_can('delete_comment')) { wp_die(__('You do not have permission to edit comment.', 'dwqa')); } if (!isset($_GET['comment_id'])) { wp_die(__('Comment ID must be showed.', 'dwqa')); } wp_delete_comment(intval($_GET['comment_id'])); $comment = get_comment($_GET['comment_id']); exit(wp_safe_redirect(dwqa_get_question_link($comment->comment_post_ID))); }
public function update_comment() { global $post_submit_filter; if (isset($_POST['dwqa-edit-comment-submit'])) { if (!isset($_POST['comment_id'])) { dwqa_add_notice(__('Comment is missing', 'dwqa'), 'error'); } $comment_id = intval($_POST['comment_id']); $comment_content = isset($_POST['comment_content']) ? esc_html($_POST['comment_content']) : ''; $comment_content = apply_filters('dwqa_pre_update_comment_content', $comment_content); if (!isset($_POST['_wpnonce']) || !wp_verify_nonce(sanitize_text_field($_POST['_wpnonce']), '_dwqa_edit_comment')) { dwqa_add_notice(__('Are you cheating huh?', 'dwqa'), 'error'); } if (!dwqa_current_user_can('You do not have permission to edit answer.')) { dwqa_add_notice(__('You do not have permission to edit comment.', 'dwqa'), 'error'); } if (strlen($comment_content) <= 0 || !isset($comment_id) || (int) $comment_id <= 0) { dwqa_add_notice(__('Comment content must not be empty.', 'dwqa'), 'error'); } else { $commentarr = array('comment_ID' => $comment_id, 'comment_content' => $comment_content); $intval = wp_update_comment($commentarr); if (!is_wp_error($intval)) { $comment = get_comment($comment_id); exit(wp_safe_redirect(dwqa_get_question_link($comment->comment_post_ID))); } else { dwqa_add_wp_error_message($intval); } } } }