Title: wp_ajax_edit_comment
Published: April 25, 2014
Last modified: February 24, 2026

---

# wp_ajax_edit_comment()

## In this article

 * [Source](https://developer.wordpress.org/reference/functions/wp_ajax_edit_comment/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/wp_ajax_edit_comment/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/wp_ajax_edit_comment/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/wp_ajax_edit_comment/?output_format=md#wp--skip-link--target)

Handles editing a comment via AJAX.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/wp_ajax_edit_comment/?output_format=md#source)󠁿

    ```php
    function wp_ajax_edit_comment() {
    	check_ajax_referer( 'replyto-comment', '_ajax_nonce-replyto-comment' );

    	$comment_id = (int) $_POST['comment_ID'];

    	if ( ! current_user_can( 'edit_comment', $comment_id ) ) {
    		wp_die( -1 );
    	}

    	if ( '' === $_POST['content'] ) {
    		wp_die( __( 'Please type your comment text.' ) );
    	}

    	if ( isset( $_POST['status'] ) ) {
    		$_POST['comment_status'] = $_POST['status'];
    	}

    	$updated = edit_comment();
    	if ( is_wp_error( $updated ) ) {
    		wp_die( $updated->get_error_message() );
    	}

    	$position = ( isset( $_POST['position'] ) && (int) $_POST['position'] ) ? (int) $_POST['position'] : '-1';
    	/*
    	 * Checkbox is used to differentiate between the Edit Comments screen (1)
    	 * and the Comments section on the Edit Post screen (0).
    	 */
    	$checkbox      = ( isset( $_POST['checkbox'] ) && '1' === $_POST['checkbox'] ) ? 1 : 0;
    	$wp_list_table = _get_list_table( $checkbox ? 'WP_Comments_List_Table' : 'WP_Post_Comments_List_Table', array( 'screen' => 'edit-comments' ) );

    	$comment = get_comment( $comment_id );

    	if ( empty( $comment->comment_ID ) ) {
    		wp_die( -1 );
    	}

    	ob_start();
    	$wp_list_table->single_row( $comment );
    	$comment_list_item = ob_get_clean();

    	$x = new WP_Ajax_Response();

    	$x->add(
    		array(
    			'what'     => 'edit_comment',
    			'id'       => $comment->comment_ID,
    			'data'     => $comment_list_item,
    			'position' => $position,
    		)
    	);

    	$x->send();
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/ajax-actions.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-admin/includes/ajax-actions.php#L1466)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-admin/includes/ajax-actions.php#L1466-L1518)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/wp_ajax_edit_comment/?output_format=md#related)󠁿

| Uses | Description | 
| [WP_List_Table::single_row()](https://developer.wordpress.org/reference/classes/wp_list_table/single_row/)`wp-admin/includes/class-wp-list-table.php` |

Generates content for a single row of the table.

  | 
| [_get_list_table()](https://developer.wordpress.org/reference/functions/_get_list_table/)`wp-admin/includes/list-table.php` |

Fetches an instance of a [WP_List_Table](https://developer.wordpress.org/reference/classes/wp_list_table/) class.

  | 
| [edit_comment()](https://developer.wordpress.org/reference/functions/edit_comment/)`wp-admin/includes/comment.php` |

Updates a comment with values provided in $_POST.

  | 
| [WP_Ajax_Response::__construct()](https://developer.wordpress.org/reference/classes/wp_ajax_response/__construct/)`wp-includes/class-wp-ajax-response.php` |

Constructor – Passes args to [WP_Ajax_Response::add()](https://developer.wordpress.org/reference/classes/wp_ajax_response/add/).

  | 
| [current_user_can()](https://developer.wordpress.org/reference/functions/current_user_can/)`wp-includes/capabilities.php` |

Returns whether the current user has the specified capability.

  | 
| [__()](https://developer.wordpress.org/reference/functions/__/)`wp-includes/l10n.php` |

Retrieves the translation of $text.

  | 
| [check_ajax_referer()](https://developer.wordpress.org/reference/functions/check_ajax_referer/)`wp-includes/pluggable.php` |

Verifies the Ajax request to prevent processing requests external of the blog.

  | 
| [wp_die()](https://developer.wordpress.org/reference/functions/wp_die/)`wp-includes/functions.php` |

Kills WordPress execution and displays HTML page with an error message.

  | 
| [get_comment()](https://developer.wordpress.org/reference/functions/get_comment/)`wp-includes/comment.php` |

Retrieves comment data given a comment ID or comment object.

  | 
| [is_wp_error()](https://developer.wordpress.org/reference/functions/is_wp_error/)`wp-includes/load.php` |

Checks whether the given variable is a WordPress Error.

  |

[Show 6 more](https://developer.wordpress.org/reference/functions/wp_ajax_edit_comment/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/wp_ajax_edit_comment/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/wp_ajax_edit_comment/?output_format=md#changelog)󠁿

| Version | Description | 
| [3.1.0](https://developer.wordpress.org/reference/since/3.1.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_ajax_edit_comment%2F)
before being able to contribute a note or feedback.