: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
number_format_i18n( $counts->moderated )
'comment_link' => $comment_link,
// Only do the expensive stuff on a page-break, and about 1 other time per page.
if ( 0 === $total % $per_page || 1 === mt_rand( 1, $per_page ) ) {
// What type of comment count are we looking for?
$parsed = parse_url( $url );
if ( isset( $parsed['query'] ) ) {
parse_str( $parsed['query'], $query_vars );
if ( ! empty( $query_vars['comment_status'] ) ) {
$status = $query_vars['comment_status'];
if ( ! empty( $query_vars['p'] ) ) {
$post_id = (int) $query_vars['p'];
if ( ! empty( $query_vars['comment_type'] ) ) {
$type = $query_vars['comment_type'];
// Only use the comment count if not filtering by a comment_type.
$comment_count = wp_count_comments( $post_id );
// We're looking for a known type of comment count.
if ( isset( $comment_count->$status ) ) {
$total = $comment_count->$status;
// Else use the decremented value from above.
// The time since the last comment count.
$comment = get_comment( $comment_id );
$counts = wp_count_comments();
$x = new WP_Ajax_Response(
'status' => $comment ? $comment->comment_approved : '',
'postId' => $comment ? $comment->comment_post_ID : '',
/* translators: %s: Number of comments. */
'total_items_i18n' => sprintf( _n( '%s item', '%s items', $total ), number_format_i18n( $total ) ),
'total_pages' => (int) ceil( $total / $per_page ),
'total_pages_i18n' => number_format_i18n( (int) ceil( $total / $per_page ) ),
'in_moderation' => $counts->moderated,
'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 )
// POST-based Ajax handlers.
* Handles adding a hierarchical term via AJAX.
function _wp_ajax_add_hierarchical_term() {
$action = $_POST['action'];
$taxonomy = get_taxonomy( substr( $action, 4 ) );
check_ajax_referer( $action, '_ajax_nonce-add-' . $taxonomy->name );
if ( ! current_user_can( $taxonomy->cap->edit_terms ) ) {
$names = explode( ',', $_POST[ 'new' . $taxonomy->name ] );
$parent = isset( $_POST[ 'new' . $taxonomy->name . '_parent' ] ) ? (int) $_POST[ 'new' . $taxonomy->name . '_parent' ] : 0;
if ( 'category' === $taxonomy->name ) {
$post_category = isset( $_POST['post_category'] ) ? (array) $_POST['post_category'] : array();
$post_category = ( isset( $_POST['tax_input'] ) && isset( $_POST['tax_input'][ $taxonomy->name ] ) ) ? (array) $_POST['tax_input'][ $taxonomy->name ] : array();
$checked_categories = array_map( 'absint', (array) $post_category );
$popular_ids = wp_popular_terms_checklist( $taxonomy->name, 0, 10, false );
foreach ( $names as $cat_name ) {
$cat_name = trim( $cat_name );
$category_nicename = sanitize_title( $cat_name );
if ( '' === $category_nicename ) {
$cat_id = wp_insert_term( $cat_name, $taxonomy->name, array( 'parent' => $parent ) );
if ( ! $cat_id || is_wp_error( $cat_id ) ) {
$cat_id = $cat_id['term_id'];
$checked_categories[] = $cat_id;
if ( $parent ) { // Do these all at once in a second.
'taxonomy' => $taxonomy->name,
'descendants_and_self' => $cat_id,
'selected_cats' => $checked_categories,
'popular_cats' => $popular_ids,
'what' => $taxonomy->name,
'data' => str_replace( array( "\n", "\t" ), '', $data ),
if ( $parent ) { // Foncy - replace the parent and all its children.
$parent = get_term( $parent, $taxonomy->name );
$term_id = $parent->term_id;
while ( $parent->parent ) { // Get the top parent.
$parent = get_term( $parent->parent, $taxonomy->name );
if ( is_wp_error( $parent ) ) {
$term_id = $parent->term_id;
'taxonomy' => $taxonomy->name,
'descendants_and_self' => $term_id,
'selected_cats' => $checked_categories,
'popular_cats' => $popular_ids,
'what' => $taxonomy->name,
'data' => str_replace( array( "\n", "\t" ), '', $data ),
'taxonomy' => $taxonomy->name,
'name' => 'new' . $taxonomy->name . '_parent',
'show_option_none' => '— ' . $taxonomy->labels->parent_item . ' —',
$add['supplemental'] = array( 'newcat_parent' => $sup );
$x = new WP_Ajax_Response( $add );
* Handles deleting a comment via AJAX.
function wp_ajax_delete_comment() {
$id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0;
$comment = get_comment( $id );
if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) ) {
check_ajax_referer( "delete-comment_$id" );
$status = wp_get_comment_status( $comment );
if ( isset( $_POST['trash'] ) && '1' === $_POST['trash'] ) {
if ( 'trash' === $status ) {
$r = wp_trash_comment( $comment );
} elseif ( isset( $_POST['untrash'] ) && '1' === $_POST['untrash'] ) {
if ( 'trash' !== $status ) {
$r = wp_untrash_comment( $comment );
// Undo trash, not in Trash.
if ( ! isset( $_POST['comment_status'] ) || 'trash' !== $_POST['comment_status'] ) {
} elseif ( isset( $_POST['spam'] ) && '1' === $_POST['spam'] ) {
if ( 'spam' === $status ) {
$r = wp_spam_comment( $comment );
} elseif ( isset( $_POST['unspam'] ) && '1' === $_POST['unspam'] ) {
if ( 'spam' !== $status ) {
$r = wp_unspam_comment( $comment );
// Undo spam, not in spam.
if ( ! isset( $_POST['comment_status'] ) || 'spam' !== $_POST['comment_status'] ) {
} elseif ( isset( $_POST['delete'] ) && '1' === $_POST['delete'] ) {
$r = wp_delete_comment( $comment );
// 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, $delta );
* Handles deleting a tag via AJAX.
function wp_ajax_delete_tag() {
$tag_id = (int) $_POST['tag_ID'];
check_ajax_referer( "delete-tag_$tag_id" );
if ( ! current_user_can( 'delete_term', $tag_id ) ) {
$taxonomy = ! empty( $_POST['taxonomy'] ) ? $_POST['taxonomy'] : 'post_tag';
$tag = get_term( $tag_id, $taxonomy );
if ( ! $tag || is_wp_error( $tag ) ) {
if ( wp_delete_term( $tag_id, $taxonomy ) ) {
* Handles deleting a link via AJAX.
function wp_ajax_delete_link() {
$id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0;
check_ajax_referer( "delete-bookmark_$id" );
if ( ! current_user_can( 'manage_links' ) ) {
$link = get_bookmark( $id );
if ( ! $link || is_wp_error( $link ) ) {
if ( wp_delete_link( $id ) ) {
* Handles deleting meta via AJAX.
function wp_ajax_delete_meta() {
$id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0;
check_ajax_referer( "delete-meta_$id" );
$meta = get_metadata_by_mid( 'post', $id );
if ( is_protected_meta( $meta->meta_key, 'post' ) || ! current_user_can( 'delete_post_meta', $meta->post_id, $meta->meta_key ) ) {
if ( delete_meta( $meta->meta_id ) ) {
* Handles deleting a post via AJAX.
* @param string $action Action to perform.
function wp_ajax_delete_post( $action ) {
if ( empty( $action ) ) {
$id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0;
check_ajax_referer( "{$action}_$id" );
if ( ! current_user_can( 'delete_post', $id ) ) {
if ( ! get_post( $id ) ) {
if ( wp_delete_post( $id ) ) {
* Handles sending a post to the Trash via AJAX.
* @param string $action Action to perform.
function wp_ajax_trash_post( $action ) {
if ( empty( $action ) ) {
$id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0;
check_ajax_referer( "{$action}_$id" );
if ( ! current_user_can( 'delete_post', $id ) ) {
if ( ! get_post( $id ) ) {
if ( 'trash-post' === $action ) {
$done = wp_trash_post( $id );
$done = wp_untrash_post( $id );
* Handles restoring a post from the Trash via AJAX.
* @param string $action Action to perform.
function wp_ajax_untrash_post( $action ) {
if ( empty( $action ) ) {
$action = 'untrash-post';
wp_ajax_trash_post( $action );
* Handles deleting a page via AJAX.
* @param string $action Action to perform.
function wp_ajax_delete_page( $action ) {
if ( empty( $action ) ) {
$id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0;
check_ajax_referer( "{$action}_$id" );
if ( ! current_user_can( 'delete_page', $id ) ) {
if ( ! get_post( $id ) ) {
if ( wp_delete_post( $id ) ) {
* Handles dimming a comment via AJAX.
function wp_ajax_dim_comment() {
$id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0;
$comment = get_comment( $id );
$x = new WP_Ajax_Response(
/* translators: %d: Comment ID. */
sprintf( __( 'Comment %d does not exist' ), $id )
if ( ! current_user_can( 'edit_comment', $comment->comment_ID ) && ! current_user_can( 'moderate_comments' ) ) {