On this page
wp_ajax_get_comments( string $action )
Ajax handler for getting comments.
Parameters
$actionstring Required-
Action to perform.
Source
File: wp-admin/includes/ajax-actions.php. View all references
function wp_ajax_get_comments( $action ) {
global $post_id;
if ( empty( $action ) ) {
$action = 'get-comments';
}
check_ajax_referer( $action );
if ( empty( $post_id ) && ! empty( $_REQUEST['p'] ) ) {
$id = absint( $_REQUEST['p'] );
if ( ! empty( $id ) ) {
$post_id = $id;
}
}
if ( empty( $post_id ) ) {
wp_die( -1 );
}
$wp_list_table = _get_list_table( 'WP_Post_Comments_List_Table', array( 'screen' => 'edit-comments' ) );
if ( ! current_user_can( 'edit_post', $post_id ) ) {
wp_die( -1 );
}
$wp_list_table->prepare_items();
if ( ! $wp_list_table->has_items() ) {
wp_die( 1 );
}
$x = new WP_Ajax_Response();
ob_start();
foreach ( $wp_list_table->items as $comment ) {
if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) && 0 === $comment->comment_approved ) {
continue;
}
get_comment( $comment );
$wp_list_table->single_row( $comment );
}
$comment_list_item = ob_get_clean();
$x->add(
array(
'what' => 'comments',
'data' => $comment_list_item,
)
);
$x->send();
}
Related
Uses
| Uses | Description |
|---|---|
| WP_List_Table::single_row() wp-admin/includes/class-wp-list-table.php | Generates content for a single row of the table. |
| WP_List_Table::prepare_items() wp-admin/includes/class-wp-list-table.php | Prepares the list of items for displaying. |
| WP_List_Table::has_items() wp-admin/includes/class-wp-list-table.php | Whether the table has items to display or not |
| _get_list_table() wp-admin/includes/list-table.php | Fetches an instance of a WP_List_Table class. |
| WP_Ajax_Response::__construct() wp-includes/class-wp-ajax-response.php | Constructor – Passes args to WP_Ajax_Response::add(). |
| current_user_can() wp-includes/capabilities.php | Returns whether the current user has the specified capability. |
| check_ajax_referer() wp-includes/pluggable.php | Verifies the Ajax request to prevent processing requests external of the blog. |
| absint() wp-includes/functions.php | Converts a value to non-negative integer. |
| wp_die() wp-includes/functions.php | Kills WordPress execution and displays HTML page with an error message. |
| get_comment() wp-includes/comment.php | Retrieves comment data given a comment ID or comment object. |
Changelog
| Version | Description |
|---|---|
| 3.1.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/wp_ajax_get_comments