Edit File by line
/home/barbar84/www/wp-admin/includes
File: ajax-actions.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Administration API: Core Ajax handlers
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
* @subpackage Administration
[5] Fix | Delete
* @since 2.1.0
[6] Fix | Delete
*/
[7] Fix | Delete
[8] Fix | Delete
//
[9] Fix | Delete
// No-privilege Ajax handlers.
[10] Fix | Delete
//
[11] Fix | Delete
[12] Fix | Delete
/**
[13] Fix | Delete
* Ajax handler for the Heartbeat API in the no-privilege context.
[14] Fix | Delete
*
[15] Fix | Delete
* Runs when the user is not logged in.
[16] Fix | Delete
*
[17] Fix | Delete
* @since 3.6.0
[18] Fix | Delete
*/
[19] Fix | Delete
function wp_ajax_nopriv_heartbeat() {
[20] Fix | Delete
$response = array();
[21] Fix | Delete
[22] Fix | Delete
// 'screen_id' is the same as $current_screen->id and the JS global 'pagenow'.
[23] Fix | Delete
if ( ! empty( $_POST['screen_id'] ) ) {
[24] Fix | Delete
$screen_id = sanitize_key( $_POST['screen_id'] );
[25] Fix | Delete
} else {
[26] Fix | Delete
$screen_id = 'front';
[27] Fix | Delete
}
[28] Fix | Delete
[29] Fix | Delete
if ( ! empty( $_POST['data'] ) ) {
[30] Fix | Delete
$data = wp_unslash( (array) $_POST['data'] );
[31] Fix | Delete
[32] Fix | Delete
/**
[33] Fix | Delete
* Filters Heartbeat Ajax response in no-privilege environments.
[34] Fix | Delete
*
[35] Fix | Delete
* @since 3.6.0
[36] Fix | Delete
*
[37] Fix | Delete
* @param array $response The no-priv Heartbeat response.
[38] Fix | Delete
* @param array $data The $_POST data sent.
[39] Fix | Delete
* @param string $screen_id The screen ID.
[40] Fix | Delete
*/
[41] Fix | Delete
$response = apply_filters( 'heartbeat_nopriv_received', $response, $data, $screen_id );
[42] Fix | Delete
}
[43] Fix | Delete
[44] Fix | Delete
/**
[45] Fix | Delete
* Filters Heartbeat Ajax response in no-privilege environments when no data is passed.
[46] Fix | Delete
*
[47] Fix | Delete
* @since 3.6.0
[48] Fix | Delete
*
[49] Fix | Delete
* @param array $response The no-priv Heartbeat response.
[50] Fix | Delete
* @param string $screen_id The screen ID.
[51] Fix | Delete
*/
[52] Fix | Delete
$response = apply_filters( 'heartbeat_nopriv_send', $response, $screen_id );
[53] Fix | Delete
[54] Fix | Delete
/**
[55] Fix | Delete
* Fires when Heartbeat ticks in no-privilege environments.
[56] Fix | Delete
*
[57] Fix | Delete
* Allows the transport to be easily replaced with long-polling.
[58] Fix | Delete
*
[59] Fix | Delete
* @since 3.6.0
[60] Fix | Delete
*
[61] Fix | Delete
* @param array $response The no-priv Heartbeat response.
[62] Fix | Delete
* @param string $screen_id The screen ID.
[63] Fix | Delete
*/
[64] Fix | Delete
do_action( 'heartbeat_nopriv_tick', $response, $screen_id );
[65] Fix | Delete
[66] Fix | Delete
// Send the current time according to the server.
[67] Fix | Delete
$response['server_time'] = time();
[68] Fix | Delete
[69] Fix | Delete
wp_send_json( $response );
[70] Fix | Delete
}
[71] Fix | Delete
[72] Fix | Delete
//
[73] Fix | Delete
// GET-based Ajax handlers.
[74] Fix | Delete
//
[75] Fix | Delete
[76] Fix | Delete
/**
[77] Fix | Delete
* Ajax handler for fetching a list table.
[78] Fix | Delete
*
[79] Fix | Delete
* @since 3.1.0
[80] Fix | Delete
*/
[81] Fix | Delete
function wp_ajax_fetch_list() {
[82] Fix | Delete
$list_class = $_GET['list_args']['class'];
[83] Fix | Delete
check_ajax_referer( "fetch-list-$list_class", '_ajax_fetch_list_nonce' );
[84] Fix | Delete
[85] Fix | Delete
$wp_list_table = _get_list_table( $list_class, array( 'screen' => $_GET['list_args']['screen']['id'] ) );
[86] Fix | Delete
if ( ! $wp_list_table ) {
[87] Fix | Delete
wp_die( 0 );
[88] Fix | Delete
}
[89] Fix | Delete
[90] Fix | Delete
if ( ! $wp_list_table->ajax_user_can() ) {
[91] Fix | Delete
wp_die( -1 );
[92] Fix | Delete
}
[93] Fix | Delete
[94] Fix | Delete
$wp_list_table->ajax_response();
[95] Fix | Delete
[96] Fix | Delete
wp_die( 0 );
[97] Fix | Delete
}
[98] Fix | Delete
[99] Fix | Delete
/**
[100] Fix | Delete
* Ajax handler for tag search.
[101] Fix | Delete
*
[102] Fix | Delete
* @since 3.1.0
[103] Fix | Delete
*/
[104] Fix | Delete
function wp_ajax_ajax_tag_search() {
[105] Fix | Delete
if ( ! isset( $_GET['tax'] ) ) {
[106] Fix | Delete
wp_die( 0 );
[107] Fix | Delete
}
[108] Fix | Delete
[109] Fix | Delete
$taxonomy = sanitize_key( $_GET['tax'] );
[110] Fix | Delete
$tax = get_taxonomy( $taxonomy );
[111] Fix | Delete
[112] Fix | Delete
if ( ! $tax ) {
[113] Fix | Delete
wp_die( 0 );
[114] Fix | Delete
}
[115] Fix | Delete
[116] Fix | Delete
if ( ! current_user_can( $tax->cap->assign_terms ) ) {
[117] Fix | Delete
wp_die( -1 );
[118] Fix | Delete
}
[119] Fix | Delete
[120] Fix | Delete
$s = wp_unslash( $_GET['q'] );
[121] Fix | Delete
[122] Fix | Delete
$comma = _x( ',', 'tag delimiter' );
[123] Fix | Delete
if ( ',' !== $comma ) {
[124] Fix | Delete
$s = str_replace( $comma, ',', $s );
[125] Fix | Delete
}
[126] Fix | Delete
[127] Fix | Delete
if ( false !== strpos( $s, ',' ) ) {
[128] Fix | Delete
$s = explode( ',', $s );
[129] Fix | Delete
$s = $s[ count( $s ) - 1 ];
[130] Fix | Delete
}
[131] Fix | Delete
[132] Fix | Delete
$s = trim( $s );
[133] Fix | Delete
[134] Fix | Delete
/**
[135] Fix | Delete
* Filters the minimum number of characters required to fire a tag search via Ajax.
[136] Fix | Delete
*
[137] Fix | Delete
* @since 4.0.0
[138] Fix | Delete
*
[139] Fix | Delete
* @param int $characters The minimum number of characters required. Default 2.
[140] Fix | Delete
* @param WP_Taxonomy $tax The taxonomy object.
[141] Fix | Delete
* @param string $s The search term.
[142] Fix | Delete
*/
[143] Fix | Delete
$term_search_min_chars = (int) apply_filters( 'term_search_min_chars', 2, $tax, $s );
[144] Fix | Delete
[145] Fix | Delete
/*
[146] Fix | Delete
* Require $term_search_min_chars chars for matching (default: 2)
[147] Fix | Delete
* ensure it's a non-negative, non-zero integer.
[148] Fix | Delete
*/
[149] Fix | Delete
if ( ( 0 == $term_search_min_chars ) || ( strlen( $s ) < $term_search_min_chars ) ) {
[150] Fix | Delete
wp_die();
[151] Fix | Delete
}
[152] Fix | Delete
[153] Fix | Delete
$results = get_terms(
[154] Fix | Delete
array(
[155] Fix | Delete
'taxonomy' => $taxonomy,
[156] Fix | Delete
'name__like' => $s,
[157] Fix | Delete
'fields' => 'names',
[158] Fix | Delete
'hide_empty' => false,
[159] Fix | Delete
)
[160] Fix | Delete
);
[161] Fix | Delete
[162] Fix | Delete
echo implode( "\n", $results );
[163] Fix | Delete
wp_die();
[164] Fix | Delete
}
[165] Fix | Delete
[166] Fix | Delete
/**
[167] Fix | Delete
* Ajax handler for compression testing.
[168] Fix | Delete
*
[169] Fix | Delete
* @since 3.1.0
[170] Fix | Delete
*/
[171] Fix | Delete
function wp_ajax_wp_compression_test() {
[172] Fix | Delete
if ( ! current_user_can( 'manage_options' ) ) {
[173] Fix | Delete
wp_die( -1 );
[174] Fix | Delete
}
[175] Fix | Delete
[176] Fix | Delete
if ( ini_get( 'zlib.output_compression' ) || 'ob_gzhandler' === ini_get( 'output_handler' ) ) {
[177] Fix | Delete
update_site_option( 'can_compress_scripts', 0 );
[178] Fix | Delete
wp_die( 0 );
[179] Fix | Delete
}
[180] Fix | Delete
[181] Fix | Delete
if ( isset( $_GET['test'] ) ) {
[182] Fix | Delete
header( 'Expires: Wed, 11 Jan 1984 05:00:00 GMT' );
[183] Fix | Delete
header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s' ) . ' GMT' );
[184] Fix | Delete
header( 'Cache-Control: no-cache, must-revalidate, max-age=0' );
[185] Fix | Delete
header( 'Content-Type: application/javascript; charset=UTF-8' );
[186] Fix | Delete
$force_gzip = ( defined( 'ENFORCE_GZIP' ) && ENFORCE_GZIP );
[187] Fix | Delete
$test_str = '"wpCompressionTest Lorem ipsum dolor sit amet consectetuer mollis sapien urna ut a. Eu nonummy condimentum fringilla tempor pretium platea vel nibh netus Maecenas. Hac molestie amet justo quis pellentesque est ultrices interdum nibh Morbi. Cras mattis pretium Phasellus ante ipsum ipsum ut sociis Suspendisse Lorem. Ante et non molestie. Porta urna Vestibulum egestas id congue nibh eu risus gravida sit. Ac augue auctor Ut et non a elit massa id sodales. Elit eu Nulla at nibh adipiscing mattis lacus mauris at tempus. Netus nibh quis suscipit nec feugiat eget sed lorem et urna. Pellentesque lacus at ut massa consectetuer ligula ut auctor semper Pellentesque. Ut metus massa nibh quam Curabitur molestie nec mauris congue. Volutpat molestie elit justo facilisis neque ac risus Ut nascetur tristique. Vitae sit lorem tellus et quis Phasellus lacus tincidunt nunc Fusce. Pharetra wisi Suspendisse mus sagittis libero lacinia Integer consequat ac Phasellus. Et urna ac cursus tortor aliquam Aliquam amet tellus volutpat Vestibulum. Justo interdum condimentum In augue congue tellus sollicitudin Quisque quis nibh."';
[188] Fix | Delete
[189] Fix | Delete
if ( 1 == $_GET['test'] ) {
[190] Fix | Delete
echo $test_str;
[191] Fix | Delete
wp_die();
[192] Fix | Delete
} elseif ( 2 == $_GET['test'] ) {
[193] Fix | Delete
if ( ! isset( $_SERVER['HTTP_ACCEPT_ENCODING'] ) ) {
[194] Fix | Delete
wp_die( -1 );
[195] Fix | Delete
}
[196] Fix | Delete
[197] Fix | Delete
if ( false !== stripos( $_SERVER['HTTP_ACCEPT_ENCODING'], 'deflate' ) && function_exists( 'gzdeflate' ) && ! $force_gzip ) {
[198] Fix | Delete
header( 'Content-Encoding: deflate' );
[199] Fix | Delete
$out = gzdeflate( $test_str, 1 );
[200] Fix | Delete
} elseif ( false !== stripos( $_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip' ) && function_exists( 'gzencode' ) ) {
[201] Fix | Delete
header( 'Content-Encoding: gzip' );
[202] Fix | Delete
$out = gzencode( $test_str, 1 );
[203] Fix | Delete
} else {
[204] Fix | Delete
wp_die( -1 );
[205] Fix | Delete
}
[206] Fix | Delete
[207] Fix | Delete
echo $out;
[208] Fix | Delete
wp_die();
[209] Fix | Delete
} elseif ( 'no' === $_GET['test'] ) {
[210] Fix | Delete
check_ajax_referer( 'update_can_compress_scripts' );
[211] Fix | Delete
update_site_option( 'can_compress_scripts', 0 );
[212] Fix | Delete
} elseif ( 'yes' === $_GET['test'] ) {
[213] Fix | Delete
check_ajax_referer( 'update_can_compress_scripts' );
[214] Fix | Delete
update_site_option( 'can_compress_scripts', 1 );
[215] Fix | Delete
}
[216] Fix | Delete
}
[217] Fix | Delete
[218] Fix | Delete
wp_die( 0 );
[219] Fix | Delete
}
[220] Fix | Delete
[221] Fix | Delete
/**
[222] Fix | Delete
* Ajax handler for image editor previews.
[223] Fix | Delete
*
[224] Fix | Delete
* @since 3.1.0
[225] Fix | Delete
*/
[226] Fix | Delete
function wp_ajax_imgedit_preview() {
[227] Fix | Delete
$post_id = (int) $_GET['postid'];
[228] Fix | Delete
if ( empty( $post_id ) || ! current_user_can( 'edit_post', $post_id ) ) {
[229] Fix | Delete
wp_die( -1 );
[230] Fix | Delete
}
[231] Fix | Delete
[232] Fix | Delete
check_ajax_referer( "image_editor-$post_id" );
[233] Fix | Delete
[234] Fix | Delete
include_once ABSPATH . 'wp-admin/includes/image-edit.php';
[235] Fix | Delete
[236] Fix | Delete
if ( ! stream_preview_image( $post_id ) ) {
[237] Fix | Delete
wp_die( -1 );
[238] Fix | Delete
}
[239] Fix | Delete
[240] Fix | Delete
wp_die();
[241] Fix | Delete
}
[242] Fix | Delete
[243] Fix | Delete
/**
[244] Fix | Delete
* Ajax handler for oEmbed caching.
[245] Fix | Delete
*
[246] Fix | Delete
* @since 3.1.0
[247] Fix | Delete
*
[248] Fix | Delete
* @global WP_Embed $wp_embed
[249] Fix | Delete
*/
[250] Fix | Delete
function wp_ajax_oembed_cache() {
[251] Fix | Delete
$GLOBALS['wp_embed']->cache_oembed( $_GET['post'] );
[252] Fix | Delete
wp_die( 0 );
[253] Fix | Delete
}
[254] Fix | Delete
[255] Fix | Delete
/**
[256] Fix | Delete
* Ajax handler for user autocomplete.
[257] Fix | Delete
*
[258] Fix | Delete
* @since 3.4.0
[259] Fix | Delete
*/
[260] Fix | Delete
function wp_ajax_autocomplete_user() {
[261] Fix | Delete
if ( ! is_multisite() || ! current_user_can( 'promote_users' ) || wp_is_large_network( 'users' ) ) {
[262] Fix | Delete
wp_die( -1 );
[263] Fix | Delete
}
[264] Fix | Delete
[265] Fix | Delete
/** This filter is documented in wp-admin/user-new.php */
[266] Fix | Delete
if ( ! current_user_can( 'manage_network_users' ) && ! apply_filters( 'autocomplete_users_for_site_admins', false ) ) {
[267] Fix | Delete
wp_die( -1 );
[268] Fix | Delete
}
[269] Fix | Delete
[270] Fix | Delete
$return = array();
[271] Fix | Delete
[272] Fix | Delete
// Check the type of request.
[273] Fix | Delete
// Current allowed values are `add` and `search`.
[274] Fix | Delete
if ( isset( $_REQUEST['autocomplete_type'] ) && 'search' === $_REQUEST['autocomplete_type'] ) {
[275] Fix | Delete
$type = $_REQUEST['autocomplete_type'];
[276] Fix | Delete
} else {
[277] Fix | Delete
$type = 'add';
[278] Fix | Delete
}
[279] Fix | Delete
[280] Fix | Delete
// Check the desired field for value.
[281] Fix | Delete
// Current allowed values are `user_email` and `user_login`.
[282] Fix | Delete
if ( isset( $_REQUEST['autocomplete_field'] ) && 'user_email' === $_REQUEST['autocomplete_field'] ) {
[283] Fix | Delete
$field = $_REQUEST['autocomplete_field'];
[284] Fix | Delete
} else {
[285] Fix | Delete
$field = 'user_login';
[286] Fix | Delete
}
[287] Fix | Delete
[288] Fix | Delete
// Exclude current users of this blog.
[289] Fix | Delete
if ( isset( $_REQUEST['site_id'] ) ) {
[290] Fix | Delete
$id = absint( $_REQUEST['site_id'] );
[291] Fix | Delete
} else {
[292] Fix | Delete
$id = get_current_blog_id();
[293] Fix | Delete
}
[294] Fix | Delete
[295] Fix | Delete
$include_blog_users = ( 'search' === $type ? get_users(
[296] Fix | Delete
array(
[297] Fix | Delete
'blog_id' => $id,
[298] Fix | Delete
'fields' => 'ID',
[299] Fix | Delete
)
[300] Fix | Delete
) : array() );
[301] Fix | Delete
[302] Fix | Delete
$exclude_blog_users = ( 'add' === $type ? get_users(
[303] Fix | Delete
array(
[304] Fix | Delete
'blog_id' => $id,
[305] Fix | Delete
'fields' => 'ID',
[306] Fix | Delete
)
[307] Fix | Delete
) : array() );
[308] Fix | Delete
[309] Fix | Delete
$users = get_users(
[310] Fix | Delete
array(
[311] Fix | Delete
'blog_id' => false,
[312] Fix | Delete
'search' => '*' . $_REQUEST['term'] . '*',
[313] Fix | Delete
'include' => $include_blog_users,
[314] Fix | Delete
'exclude' => $exclude_blog_users,
[315] Fix | Delete
'search_columns' => array( 'user_login', 'user_nicename', 'user_email' ),
[316] Fix | Delete
)
[317] Fix | Delete
);
[318] Fix | Delete
[319] Fix | Delete
foreach ( $users as $user ) {
[320] Fix | Delete
$return[] = array(
[321] Fix | Delete
/* translators: 1: User login, 2: User email address. */
[322] Fix | Delete
'label' => sprintf( _x( '%1$s (%2$s)', 'user autocomplete result' ), $user->user_login, $user->user_email ),
[323] Fix | Delete
'value' => $user->$field,
[324] Fix | Delete
);
[325] Fix | Delete
}
[326] Fix | Delete
[327] Fix | Delete
wp_die( wp_json_encode( $return ) );
[328] Fix | Delete
}
[329] Fix | Delete
[330] Fix | Delete
/**
[331] Fix | Delete
* Handles Ajax requests for community events
[332] Fix | Delete
*
[333] Fix | Delete
* @since 4.8.0
[334] Fix | Delete
*/
[335] Fix | Delete
function wp_ajax_get_community_events() {
[336] Fix | Delete
require_once ABSPATH . 'wp-admin/includes/class-wp-community-events.php';
[337] Fix | Delete
[338] Fix | Delete
check_ajax_referer( 'community_events' );
[339] Fix | Delete
[340] Fix | Delete
$search = isset( $_POST['location'] ) ? wp_unslash( $_POST['location'] ) : '';
[341] Fix | Delete
$timezone = isset( $_POST['timezone'] ) ? wp_unslash( $_POST['timezone'] ) : '';
[342] Fix | Delete
$user_id = get_current_user_id();
[343] Fix | Delete
$saved_location = get_user_option( 'community-events-location', $user_id );
[344] Fix | Delete
$events_client = new WP_Community_Events( $user_id, $saved_location );
[345] Fix | Delete
$events = $events_client->get_events( $search, $timezone );
[346] Fix | Delete
$ip_changed = false;
[347] Fix | Delete
[348] Fix | Delete
if ( is_wp_error( $events ) ) {
[349] Fix | Delete
wp_send_json_error(
[350] Fix | Delete
array(
[351] Fix | Delete
'error' => $events->get_error_message(),
[352] Fix | Delete
)
[353] Fix | Delete
);
[354] Fix | Delete
} else {
[355] Fix | Delete
if ( empty( $saved_location['ip'] ) && ! empty( $events['location']['ip'] ) ) {
[356] Fix | Delete
$ip_changed = true;
[357] Fix | Delete
} elseif ( isset( $saved_location['ip'] ) && ! empty( $events['location']['ip'] ) && $saved_location['ip'] !== $events['location']['ip'] ) {
[358] Fix | Delete
$ip_changed = true;
[359] Fix | Delete
}
[360] Fix | Delete
[361] Fix | Delete
/*
[362] Fix | Delete
* The location should only be updated when it changes. The API doesn't always return
[363] Fix | Delete
* a full location; sometimes it's missing the description or country. The location
[364] Fix | Delete
* that was saved during the initial request is known to be good and complete, though.
[365] Fix | Delete
* It should be left intact until the user explicitly changes it (either by manually
[366] Fix | Delete
* searching for a new location, or by changing their IP address).
[367] Fix | Delete
*
[368] Fix | Delete
* If the location was updated with an incomplete response from the API, then it could
[369] Fix | Delete
* break assumptions that the UI makes (e.g., that there will always be a description
[370] Fix | Delete
* that corresponds to a latitude/longitude location).
[371] Fix | Delete
*
[372] Fix | Delete
* The location is stored network-wide, so that the user doesn't have to set it on each site.
[373] Fix | Delete
*/
[374] Fix | Delete
if ( $ip_changed || $search ) {
[375] Fix | Delete
update_user_option( $user_id, 'community-events-location', $events['location'], true );
[376] Fix | Delete
}
[377] Fix | Delete
[378] Fix | Delete
wp_send_json_success( $events );
[379] Fix | Delete
}
[380] Fix | Delete
}
[381] Fix | Delete
[382] Fix | Delete
/**
[383] Fix | Delete
* Ajax handler for dashboard widgets.
[384] Fix | Delete
*
[385] Fix | Delete
* @since 3.4.0
[386] Fix | Delete
*/
[387] Fix | Delete
function wp_ajax_dashboard_widgets() {
[388] Fix | Delete
require_once ABSPATH . 'wp-admin/includes/dashboard.php';
[389] Fix | Delete
[390] Fix | Delete
$pagenow = $_GET['pagenow'];
[391] Fix | Delete
if ( 'dashboard-user' === $pagenow || 'dashboard-network' === $pagenow || 'dashboard' === $pagenow ) {
[392] Fix | Delete
set_current_screen( $pagenow );
[393] Fix | Delete
}
[394] Fix | Delete
[395] Fix | Delete
switch ( $_GET['widget'] ) {
[396] Fix | Delete
case 'dashboard_primary':
[397] Fix | Delete
wp_dashboard_primary();
[398] Fix | Delete
break;
[399] Fix | Delete
}
[400] Fix | Delete
wp_die();
[401] Fix | Delete
}
[402] Fix | Delete
[403] Fix | Delete
/**
[404] Fix | Delete
* Ajax handler for Customizer preview logged-in status.
[405] Fix | Delete
*
[406] Fix | Delete
* @since 3.4.0
[407] Fix | Delete
*/
[408] Fix | Delete
function wp_ajax_logged_in() {
[409] Fix | Delete
wp_die( 1 );
[410] Fix | Delete
}
[411] Fix | Delete
[412] Fix | Delete
//
[413] Fix | Delete
// Ajax helpers.
[414] Fix | Delete
//
[415] Fix | Delete
[416] Fix | Delete
/**
[417] Fix | Delete
* Sends back current comment total and new page links if they need to be updated.
[418] Fix | Delete
*
[419] Fix | Delete
* Contrary to normal success Ajax response ("1"), die with time() on success.
[420] Fix | Delete
*
[421] Fix | Delete
* @since 2.7.0
[422] Fix | Delete
* @access private
[423] Fix | Delete
*
[424] Fix | Delete
* @param int $comment_id
[425] Fix | Delete
* @param int $delta
[426] Fix | Delete
*/
[427] Fix | Delete
function _wp_ajax_delete_comment_response( $comment_id, $delta = -1 ) {
[428] Fix | Delete
$total = isset( $_POST['_total'] ) ? (int) $_POST['_total'] : 0;
[429] Fix | Delete
$per_page = isset( $_POST['_per_page'] ) ? (int) $_POST['_per_page'] : 0;
[430] Fix | Delete
$page = isset( $_POST['_page'] ) ? (int) $_POST['_page'] : 0;
[431] Fix | Delete
$url = isset( $_POST['_url'] ) ? esc_url_raw( $_POST['_url'] ) : '';
[432] Fix | Delete
[433] Fix | Delete
// JS didn't send us everything we need to know. Just die with success message.
[434] Fix | Delete
if ( ! $total || ! $per_page || ! $page || ! $url ) {
[435] Fix | Delete
$time = time();
[436] Fix | Delete
$comment = get_comment( $comment_id );
[437] Fix | Delete
$comment_status = '';
[438] Fix | Delete
$comment_link = '';
[439] Fix | Delete
[440] Fix | Delete
if ( $comment ) {
[441] Fix | Delete
$comment_status = $comment->comment_approved;
[442] Fix | Delete
}
[443] Fix | Delete
[444] Fix | Delete
if ( 1 === (int) $comment_status ) {
[445] Fix | Delete
$comment_link = get_comment_link( $comment );
[446] Fix | Delete
}
[447] Fix | Delete
[448] Fix | Delete
$counts = wp_count_comments();
[449] Fix | Delete
[450] Fix | Delete
$x = new WP_Ajax_Response(
[451] Fix | Delete
array(
[452] Fix | Delete
'what' => 'comment',
[453] Fix | Delete
// Here for completeness - not used.
[454] Fix | Delete
'id' => $comment_id,
[455] Fix | Delete
'supplemental' => array(
[456] Fix | Delete
'status' => $comment_status,
[457] Fix | Delete
'postId' => $comment ? $comment->comment_post_ID : '',
[458] Fix | Delete
'time' => $time,
[459] Fix | Delete
'in_moderation' => $counts->moderated,
[460] Fix | Delete
'i18n_comments_text' => sprintf(
[461] Fix | Delete
/* translators: %s: Number of comments. */
[462] Fix | Delete
_n( '%s Comment', '%s Comments', $counts->approved ),
[463] Fix | Delete
number_format_i18n( $counts->approved )
[464] Fix | Delete
),
[465] Fix | Delete
'i18n_moderation_text' => sprintf(
[466] Fix | Delete
/* translators: %s: Number of comments. */
[467] Fix | Delete
_n( '%s Comment in moderation', '%s Comments in moderation', $counts->moderated ),
[468] Fix | Delete
number_format_i18n( $counts->moderated )
[469] Fix | Delete
),
[470] Fix | Delete
'comment_link' => $comment_link,
[471] Fix | Delete
),
[472] Fix | Delete
)
[473] Fix | Delete
);
[474] Fix | Delete
$x->send();
[475] Fix | Delete
}
[476] Fix | Delete
[477] Fix | Delete
$total += $delta;
[478] Fix | Delete
if ( $total < 0 ) {
[479] Fix | Delete
$total = 0;
[480] Fix | Delete
}
[481] Fix | Delete
[482] Fix | Delete
// Only do the expensive stuff on a page-break, and about 1 other time per page.
[483] Fix | Delete
if ( 0 == $total % $per_page || 1 == mt_rand( 1, $per_page ) ) {
[484] Fix | Delete
$post_id = 0;
[485] Fix | Delete
// What type of comment count are we looking for?
[486] Fix | Delete
$status = 'all';
[487] Fix | Delete
$parsed = parse_url( $url );
[488] Fix | Delete
[489] Fix | Delete
if ( isset( $parsed['query'] ) ) {
[490] Fix | Delete
parse_str( $parsed['query'], $query_vars );
[491] Fix | Delete
[492] Fix | Delete
if ( ! empty( $query_vars['comment_status'] ) ) {
[493] Fix | Delete
$status = $query_vars['comment_status'];
[494] Fix | Delete
}
[495] Fix | Delete
[496] Fix | Delete
if ( ! empty( $query_vars['p'] ) ) {
[497] Fix | Delete
$post_id = (int) $query_vars['p'];
[498] Fix | Delete
}
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function