: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
$current = wp_get_comment_status( $comment );
if ( isset( $_POST['new'] ) && $_POST['new'] === $current ) {
check_ajax_referer( "approve-comment_$id" );
if ( in_array( $current, array( 'unapproved', 'spam' ), true ) ) {
$result = wp_set_comment_status( $comment, 'approve', true );
$result = wp_set_comment_status( $comment, 'hold', true );
if ( is_wp_error( $result ) ) {
$x = new WP_Ajax_Response(
// Decide if we need to send back '1' or a more complicated response including page links and comment counts.
_wp_ajax_delete_comment_response( $comment->comment_ID );
* Handles adding a link category via AJAX.
* @param string $action Action to perform.
function wp_ajax_add_link_category( $action ) {
if ( empty( $action ) ) {
$action = 'add-link-category';
check_ajax_referer( $action );
$taxonomy_object = get_taxonomy( 'link_category' );
if ( ! current_user_can( $taxonomy_object->cap->manage_terms ) ) {
$names = explode( ',', wp_unslash( $_POST['newcat'] ) );
$x = new WP_Ajax_Response();
foreach ( $names as $cat_name ) {
$cat_name = trim( $cat_name );
$slug = sanitize_title( $cat_name );
$cat_id = wp_insert_term( $cat_name, 'link_category' );
if ( ! $cat_id || is_wp_error( $cat_id ) ) {
$cat_id = $cat_id['term_id'];
$cat_name = esc_html( $cat_name );
'what' => 'link-category',
'data' => "<li id='link-category-$cat_id'><label for='in-link-category-$cat_id' class='selectit'><input value='" . esc_attr( $cat_id ) . "' type='checkbox' checked='checked' name='link_category[]' id='in-link-category-$cat_id'/> $cat_name</label></li>",
* Handles adding a tag via AJAX.
function wp_ajax_add_tag() {
check_ajax_referer( 'add-tag', '_wpnonce_add-tag' );
$taxonomy = ! empty( $_POST['taxonomy'] ) ? $_POST['taxonomy'] : 'post_tag';
$taxonomy_object = get_taxonomy( $taxonomy );
if ( ! current_user_can( $taxonomy_object->cap->edit_terms ) ) {
$x = new WP_Ajax_Response();
$tag = wp_insert_term( $_POST['tag-name'], $taxonomy, $_POST );
if ( $tag && ! is_wp_error( $tag ) ) {
$tag = get_term( $tag['term_id'], $taxonomy );
if ( ! $tag || is_wp_error( $tag ) ) {
$message = __( 'An error has occurred. Please reload the page and try again.' );
if ( is_wp_error( $tag ) && $tag->get_error_message() ) {
$message = $tag->get_error_message();
if ( is_wp_error( $tag ) && $tag->get_error_code() ) {
$error_code = $tag->get_error_code();
'data' => new WP_Error( $error_code, $message ),
$wp_list_table = _get_list_table( 'WP_Terms_List_Table', array( 'screen' => $_POST['screen'] ) );
if ( is_taxonomy_hierarchical( $taxonomy ) ) {
$level = count( get_ancestors( $tag->term_id, $taxonomy, 'taxonomy' ) );
$wp_list_table->single_row( $tag, $level );
$noparents = ob_get_clean();
$wp_list_table->single_row( $tag );
$parents = ob_get_clean();
require ABSPATH . 'wp-admin/includes/edit-tag-messages.php';
if ( isset( $messages[ $taxonomy_object->name ][1] ) ) {
$message = $messages[ $taxonomy_object->name ][1];
} elseif ( isset( $messages['_item'][1] ) ) {
$message = $messages['_item'][1];
'noparents' => $noparents,
'supplemental' => (array) $tag,
* Handles getting a tagcloud via AJAX.
function wp_ajax_get_tagcloud() {
if ( ! isset( $_POST['tax'] ) ) {
$taxonomy = sanitize_key( $_POST['tax'] );
$taxonomy_object = get_taxonomy( $taxonomy );
if ( ! $taxonomy_object ) {
if ( ! current_user_can( $taxonomy_object->cap->assign_terms ) ) {
wp_die( $taxonomy_object->labels->not_found );
if ( is_wp_error( $tags ) ) {
wp_die( $tags->get_error_message() );
foreach ( $tags as $key => $tag ) {
$tags[ $key ]->link = '#';
$tags[ $key ]->id = $tag->term_id;
// We need raw tag names here, so don't filter the output.
$return = wp_generate_tag_cloud(
if ( empty( $return ) ) {
* Handles getting comments via AJAX.
* @param string $action Action to perform.
function wp_ajax_get_comments( $action ) {
if ( empty( $action ) ) {
$action = 'get-comments';
check_ajax_referer( $action );
if ( empty( $post_id ) && ! empty( $_REQUEST['p'] ) ) {
$id = absint( $_REQUEST['p'] );
if ( empty( $post_id ) ) {
$wp_list_table = _get_list_table( 'WP_Post_Comments_List_Table', array( 'screen' => 'edit-comments' ) );
if ( ! current_user_can( 'edit_post', $post_id ) ) {
$wp_list_table->prepare_items();
if ( ! $wp_list_table->has_items() ) {
$x = new WP_Ajax_Response();
foreach ( $wp_list_table->items as $comment ) {
if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) && 0 === $comment->comment_approved ) {
$wp_list_table->single_row( $comment );
$comment_list_item = ob_get_clean();
'data' => $comment_list_item,
* Handles replying to a comment via AJAX.
* @param string $action Action to perform.
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 ( ! current_user_can( 'edit_post', $comment_post_id ) ) {
if ( empty( $post->post_status ) ) {
} elseif ( in_array( $post->post_status, array( 'draft', 'pending', 'trash' ), true ) ) {
wp_die( __( 'You cannot reply to a comment on a draft post.' ) );
$user = wp_get_current_user();
$comment_author = wp_slash( $user->display_name );
$comment_author_email = wp_slash( $user->user_email );
$comment_author_url = wp_slash( $user->user_url );
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.
remove_filter( 'pre_comment_content', 'wp_filter_post_kses' );
add_filter( 'pre_comment_content', 'wp_filter_kses' );
wp_die( __( 'Sorry, you must be logged in to reply to a comment.' ) );
$comment_content = trim( $_POST['content'] );
if ( '' === $comment_content ) {
wp_die( __( 'Please type your comment text.' ) );
$comment_type = isset( $_POST['comment_type'] ) ? trim( $_POST['comment_type'] ) : 'comment';
if ( isset( $_POST['comment_ID'] ) ) {
$comment_parent = absint( $_POST['comment_ID'] );
$comment_auto_approved = false;
'comment_post_ID' => $comment_post_id,
// Automatically approve parent comment.
if ( ! empty( $_POST['approve_parent'] ) ) {
$parent = get_comment( $comment_parent );
if ( $parent && '0' === $parent->comment_approved && (int) $parent->comment_post_ID === $comment_post_id ) {
if ( ! current_user_can( 'edit_comment', $parent->comment_ID ) ) {
if ( wp_set_comment_status( $parent, 'approve' ) ) {
$comment_auto_approved = true;
$comment_id = wp_new_comment( $commentdata );
if ( is_wp_error( $comment_id ) ) {
wp_die( $comment_id->get_error_message() );
$comment = get_comment( $comment_id );
$position = ( isset( $_POST['position'] ) && (int) $_POST['position'] ) ? (int) $_POST['position'] : '-1';
if ( isset( $_REQUEST['mode'] ) && 'dashboard' === $_REQUEST['mode'] ) {
require_once ABSPATH . 'wp-admin/includes/dashboard.php';
_wp_dashboard_recent_comments_row( $comment );
if ( isset( $_REQUEST['mode'] ) && 'single' === $_REQUEST['mode'] ) {
$wp_list_table = _get_list_table( 'WP_Post_Comments_List_Table', array( 'screen' => 'edit-comments' ) );
$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();
'id' => $comment->comment_ID,
'data' => $comment_list_item,
$counts = wp_count_comments();
$response['supplemental'] = array(
'in_moderation' => $counts->moderated,
'i18n_comments_text' => sprintf(
/* translators: %s: Number of comments. */
_n( '%s Comment', '%s Comments', $counts->approved ),
number_format_i18n( $counts->approved )
'i18n_moderation_text' => sprintf(
/* translators: %s: Number of comments. */
_n( '%s Comment in moderation', '%s Comments in moderation', $counts->moderated ),
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();
* Handles editing a comment via AJAX.
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 ) ) {
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_list_table->single_row( $comment );