wp_ajax_replyto_comment
Ajax handler for replying to a comment.
Description
wp_ajax_replyto_comment( (string) $action );
Parameters (1)
- 0. $action (string)
- Action to perform.
Usage
if ( !function_exists( 'wp_ajax_replyto_comment' ) ) { require_once ABSPATH . '/wp-admin/includes/ajax-actions.php'; } // Action to perform. $action = ''; // NOTICE! Understand what this does before running. $result = wp_ajax_replyto_comment($action);
Defined (1)
The function is defined in the following location(s).
- /wp-admin/includes/ajax-actions.php
- function wp_ajax_replyto_comment( $action ) {
- if ( empty( $action ) )
- $action = 'replyto-comment';
- check_ajax_referer( $action, '_ajax_nonce-replyto-comment' );
- $comment_post_ID = (int) $_POST['comment_post_ID'];
- $post = get_post( $comment_post_ID );
- if ( ! $post )
- wp_die( -1 );
- if ( !current_user_can( 'edit_post', $comment_post_ID ) )
- wp_die( -1 );
- if ( empty( $post->post_status ) )
- wp_die( 1 );
- elseif ( in_array($post->post_status, array('draft', 'pending', 'trash') ) )
- $user = wp_get_current_user();
- if ( $user->exists() ) {
- $user_ID = $user->ID;
- $comment_author = wp_slash( $user->display_name );
- $comment_author_email = wp_slash( $user->user_email );
- $comment_author_url = wp_slash( $user->user_url );
- $comment_content = trim( $_POST['content'] );
- $comment_type = isset( $_POST['comment_type'] ) ? trim( $_POST['comment_type'] ) : '';
- if ( current_user_can( 'unfiltered_html' ) ) {
- if ( ! isset( $_POST['_wp_unfiltered_html_comment'] ) )
- $_POST['_wp_unfiltered_html_comment'] = '';
- if ( wp_create_nonce( 'unfiltered-html-comment' ) != $_POST['_wp_unfiltered_html_comment'] ) {
- kses_remove_filters(); // start with a clean slate
- kses_init_filters(); // set up the filters
- }
- }
- } else {
- }
- if ( '' == $comment_content )
- $comment_parent = 0;
- if ( isset( $_POST['comment_ID'] ) )
- $comment_parent = absint( $_POST['comment_ID'] );
- $comment_auto_approved = false;
- $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type', 'comment_parent', 'user_ID');
- // Automatically approve parent comment.
- if ( !empty($_POST['approve_parent']) ) {
- $parent = get_comment( $comment_parent );
- if ( $parent && $parent->comment_approved === '0' && $parent->comment_post_ID == $comment_post_ID ) {
- if ( ! current_user_can( 'edit_comment', $parent->comment_ID ) ) {
- wp_die( -1 );
- }
- if ( wp_set_comment_status( $parent, 'approve' ) )
- $comment_auto_approved = true;
- }
- }
- $comment_id = wp_new_comment( $commentdata );
- $comment = get_comment($comment_id);
- if ( ! $comment ) wp_die( 1 );
- $position = ( isset($_POST['position']) && (int) $_POST['position'] ) ? (int) $_POST['position'] : '-1';
- ob_start();
- if ( isset( $_REQUEST['mode'] ) && 'dashboard' == $_REQUEST['mode'] ) {
- require_once( ABSPATH . 'wp-admin/includes/dashboard.php' );
- _wp_dashboard_recent_comments_row( $comment );
- } else {
- if ( isset( $_REQUEST['mode'] ) && 'single' == $_REQUEST['mode'] ) {
- $wp_list_table = _get_list_table('WP_Post_Comments_List_Table', array( 'screen' => 'edit-comments' ) );
- } else {
- $wp_list_table = _get_list_table('WP_Comments_List_Table', array( 'screen' => 'edit-comments' ) );
- }
- $wp_list_table->single_row( $comment );
- }
- $comment_list_item = ob_get_clean();
- $response = array(
- 'what' => 'comment',
- 'id' => $comment->comment_ID,
- 'data' => $comment_list_item,
- 'position' => $position
- );
- $counts = wp_count_comments();
- $response['supplemental'] = array(
- 'in_moderation' => $counts->moderated,
- 'i18n_comments_text' => sprintf(
- _n( '%s Comment', '%s Comments', $counts->approved ),
- number_format_i18n( $counts->approved )
- ),
- 'i18n_moderation_text' => sprintf(
- _nx( '%s in moderation', '%s in moderation', $counts->moderated, 'comments' ),
- number_format_i18n( $counts->moderated )
- )
- );
- if ( $comment_auto_approved ) {
- $response['supplemental']['parent_approved'] = $parent->comment_ID;
- $response['supplemental']['parent_post_id'] = $parent->comment_post_ID;
- }
- $x = new WP_Ajax_Response();
- $x->add( $response );
- $x->send();
- }