AnsPress_Comment_Hooks::edit_comment()
Description #
Updates comment.
Source #
File: includes/comments.php
public static function edit_comment() { $comment_id = ap_sanitize_unslash( 'comment_ID', 'r' ); $content = ap_sanitize_unslash( 'content', 'r' ); if ( ! is_user_logged_in() || ! ap_verify_nonce( 'edit-comment-' . $comment_id ) || ! ap_user_can_edit_comment( $comment_id ) ) { ap_ajax_json( array( 'success' => false, 'snackbar' => [ 'message' => __( 'Sorry, you cannot edit this comment', 'anspress-question-answer' ) ], ) ); } $comment = get_comment( $comment_id ); // Check if content is changed. if ( $content === $comment->comment_content || empty( $content ) ) { ap_ajax_json( [ 'success' => false, 'snackbar' => [ 'message' => __( 'No change detected, edit comment and then try', 'anspress-question-answer' ) ], ] ); } $updated = wp_update_comment( array( 'comment_ID' => $comment_id, 'comment_content' => $content, ) ); if ( $updated ) { $c = get_comment( $comment_id ); $count = get_comment_count( $c->comment_post_ID ); $result = array( 'success' => true, 'comment' => ap_comment_ajax_data( $c ), 'action' => 'edit-comment', 'commentsCount' => [ 'text' => sprintf( _n( '%d Comment', '%d Comments', $count['all'], 'anspress-question-answer' ), $count['all'] ), 'number' => $count['all'], 'unapproved' => $count['awaiting_moderation'] ], 'snackbar' => [ 'message' => __( 'Comment updated successfully', 'anspress-question-answer' ) ], ); ap_ajax_json( $result ); } ap_ajax_json( array( 'success' => false, 'snackbar' => [ 'message' => __( 'Unable to update comment', 'anspress-question-answer' ) ], ) ); }
Expand full source code Collapse full source code View on GitHub: includes/comments.php:188
Add your comment