Skip to content

Commit 86c13c9

Browse files
committed
Merge branch 'trunk' of https://github.com/WordPress/wordpress-develop into add/dependent-fetchpriority-harmony
2 parents 95789ba + 217d39a commit 86c13c9

File tree

5 files changed

+65
-42
lines changed

5 files changed

+65
-42
lines changed

src/wp-admin/admin.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,26 +72,30 @@
7272
* @param bool $do_mu_upgrade Whether to perform the Multisite upgrade routine. Default true.
7373
*/
7474
if ( apply_filters( 'do_mu_upgrade', true ) ) {
75-
$c = get_blog_count();
75+
$blog_count = get_blog_count();
7676

7777
/*
7878
* If there are 50 or fewer sites, run every time. Otherwise, throttle to reduce load:
7979
* attempt to do no more than threshold value, with some +/- allowed.
8080
*/
81-
if ( $c <= 50 || ( $c > 50 && mt_rand( 0, (int) ( $c / 50 ) ) === 1 ) ) {
81+
if ( $blog_count <= 50 || ( $blog_count > 50 && mt_rand( 0, (int) ( $blog_count / 50 ) ) === 1 ) ) {
8282
require_once ABSPATH . WPINC . '/http.php';
83+
8384
$response = wp_remote_get(
8485
admin_url( 'upgrade.php?step=1' ),
8586
array(
8687
'timeout' => 120,
8788
'httpversion' => '1.1',
8889
)
8990
);
91+
9092
/** This action is documented in wp-admin/network/upgrade.php */
9193
do_action( 'after_mu_upgrade', $response );
94+
9295
unset( $response );
9396
}
94-
unset( $c );
97+
98+
unset( $blog_count );
9599
}
96100
}
97101

src/wp-admin/plugins.php

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818

1919
$action = $wp_list_table->current_action();
2020

21-
$plugin = isset( $_REQUEST['plugin'] ) ? wp_unslash( $_REQUEST['plugin'] ) : '';
22-
$s = isset( $_REQUEST['s'] ) ? urlencode( wp_unslash( $_REQUEST['s'] ) ) : '';
21+
$plugin = isset( $_REQUEST['plugin'] ) ? wp_unslash( $_REQUEST['plugin'] ) : '';
22+
$search_term = isset( $_REQUEST['s'] ) ? urlencode( wp_unslash( $_REQUEST['s'] ) ) : '';
2323

2424
// Clean up request URI from temporary args for screen options/paging uri's to work as expected.
2525
$query_args_to_remove = array(
@@ -51,7 +51,7 @@
5151
}
5252

5353
if ( is_multisite() && ! is_network_admin() && is_network_only_plugin( $plugin ) ) {
54-
wp_redirect( self_admin_url( "plugins.php?plugin_status=$status&paged=$page&s=$s" ) );
54+
wp_redirect( self_admin_url( "plugins.php?plugin_status=$status&paged=$page&s=$search_term" ) );
5555
exit;
5656
}
5757

@@ -60,7 +60,7 @@
6060
$result = activate_plugin( $plugin, self_admin_url( 'plugins.php?error=true&plugin=' . urlencode( $plugin ) ), is_network_admin() );
6161
if ( is_wp_error( $result ) ) {
6262
if ( 'unexpected_output' === $result->get_error_code() ) {
63-
$redirect = self_admin_url( 'plugins.php?error=true&charsout=' . strlen( $result->get_error_data() ) . '&plugin=' . urlencode( $plugin ) . "&plugin_status=$status&paged=$page&s=$s" );
63+
$redirect = self_admin_url( 'plugins.php?error=true&charsout=' . strlen( $result->get_error_data() ) . '&plugin=' . urlencode( $plugin ) . "&plugin_status=$status&paged=$page&s=$search_term" );
6464
wp_redirect( add_query_arg( '_error_nonce', wp_create_nonce( 'plugin-activation-error_' . $plugin ), $redirect ) );
6565
exit;
6666
} else {
@@ -85,7 +85,7 @@
8585
wp_redirect( self_admin_url( 'press-this.php' ) );
8686
} else {
8787
// Overrides the ?error=true one above.
88-
wp_redirect( self_admin_url( "plugins.php?activate=true&plugin_status=$status&paged=$page&s=$s" ) );
88+
wp_redirect( self_admin_url( "plugins.php?activate=true&plugin_status=$status&paged=$page&s=$search_term" ) );
8989
}
9090
exit;
9191

@@ -119,7 +119,7 @@
119119
}
120120

121121
if ( empty( $plugins ) ) {
122-
wp_redirect( self_admin_url( "plugins.php?plugin_status=$status&paged=$page&s=$s" ) );
122+
wp_redirect( self_admin_url( "plugins.php?plugin_status=$status&paged=$page&s=$search_term" ) );
123123
exit;
124124
}
125125

@@ -141,7 +141,7 @@
141141
update_site_option( 'recently_activated', $recent );
142142
}
143143

144-
wp_redirect( self_admin_url( "plugins.php?activate-multi=true&plugin_status=$status&paged=$page&s=$s" ) );
144+
wp_redirect( self_admin_url( "plugins.php?activate-multi=true&plugin_status=$status&paged=$page&s=$search_term" ) );
145145
exit;
146146

147147
case 'update-selected':
@@ -204,7 +204,7 @@
204204
check_admin_referer( 'deactivate-plugin_' . $plugin );
205205

206206
if ( ! is_network_admin() && is_plugin_active_for_network( $plugin ) ) {
207-
wp_redirect( self_admin_url( "plugins.php?plugin_status=$status&paged=$page&s=$s" ) );
207+
wp_redirect( self_admin_url( "plugins.php?plugin_status=$status&paged=$page&s=$search_term" ) );
208208
exit;
209209
}
210210

@@ -217,9 +217,9 @@
217217
}
218218

219219
if ( headers_sent() ) {
220-
echo "<meta http-equiv='refresh' content='" . esc_attr( "0;url=plugins.php?deactivate=true&plugin_status=$status&paged=$page&s=$s" ) . "' />";
220+
echo "<meta http-equiv='refresh' content='" . esc_attr( "0;url=plugins.php?deactivate=true&plugin_status=$status&paged=$page&s=$search_term" ) . "' />";
221221
} else {
222-
wp_redirect( self_admin_url( "plugins.php?deactivate=true&plugin_status=$status&paged=$page&s=$s" ) );
222+
wp_redirect( self_admin_url( "plugins.php?deactivate=true&plugin_status=$status&paged=$page&s=$search_term" ) );
223223
}
224224
exit;
225225

@@ -246,7 +246,7 @@
246246
}
247247
}
248248
if ( empty( $plugins ) ) {
249-
wp_redirect( self_admin_url( "plugins.php?plugin_status=$status&paged=$page&s=$s" ) );
249+
wp_redirect( self_admin_url( "plugins.php?plugin_status=$status&paged=$page&s=$search_term" ) );
250250
exit;
251251
}
252252

@@ -263,7 +263,7 @@
263263
update_site_option( 'recently_activated', $deactivated + (array) get_site_option( 'recently_activated' ) );
264264
}
265265

266-
wp_redirect( self_admin_url( "plugins.php?deactivate-multi=true&plugin_status=$status&paged=$page&s=$s" ) );
266+
wp_redirect( self_admin_url( "plugins.php?deactivate-multi=true&plugin_status=$status&paged=$page&s=$search_term" ) );
267267
exit;
268268

269269
case 'delete-selected':
@@ -276,21 +276,21 @@
276276
// $_POST = from the plugin form; $_GET = from the FTP details screen.
277277
$plugins = isset( $_REQUEST['checked'] ) ? (array) wp_unslash( $_REQUEST['checked'] ) : array();
278278
if ( empty( $plugins ) ) {
279-
wp_redirect( self_admin_url( "plugins.php?plugin_status=$status&paged=$page&s=$s" ) );
279+
wp_redirect( self_admin_url( "plugins.php?plugin_status=$status&paged=$page&s=$search_term" ) );
280280
exit;
281281
}
282282

283283
$plugins = array_filter( $plugins, 'is_plugin_inactive' ); // Do not allow to delete activated plugins.
284284
if ( empty( $plugins ) ) {
285-
wp_redirect( self_admin_url( "plugins.php?error=true&main=true&plugin_status=$status&paged=$page&s=$s" ) );
285+
wp_redirect( self_admin_url( "plugins.php?error=true&main=true&plugin_status=$status&paged=$page&s=$search_term" ) );
286286
exit;
287287
}
288288

289289
// Bail on all if any paths are invalid.
290290
// validate_file() returns truthy for invalid files.
291291
$invalid_plugin_files = array_filter( $plugins, 'validate_file' );
292292
if ( $invalid_plugin_files ) {
293-
wp_redirect( self_admin_url( "plugins.php?plugin_status=$status&paged=$page&s=$s" ) );
293+
wp_redirect( self_admin_url( "plugins.php?plugin_status=$status&paged=$page&s=$search_term" ) );
294294
exit;
295295
}
296296

@@ -432,7 +432,7 @@
432432
// Store the result in an option rather than a URL param due to object type & length.
433433
// Cannot use transient/cache, as that could get flushed if any plugin flushes data on uninstall/delete.
434434
update_option( 'plugins_delete_result_' . $user_ID, $delete_result, false );
435-
wp_redirect( self_admin_url( "plugins.php?deleted=$plugins_to_delete&plugin_status=$status&paged=$page&s=$s" ) );
435+
wp_redirect( self_admin_url( "plugins.php?deleted=$plugins_to_delete&plugin_status=$status&paged=$page&s=$search_term" ) );
436436
exit;
437437
case 'clear-recent-list':
438438
if ( ! is_network_admin() ) {
@@ -453,13 +453,13 @@
453453

454454
check_admin_referer( 'resume-plugin_' . $plugin );
455455

456-
$result = resume_plugin( $plugin, self_admin_url( "plugins.php?error=resuming&plugin_status=$status&paged=$page&s=$s" ) );
456+
$result = resume_plugin( $plugin, self_admin_url( "plugins.php?error=resuming&plugin_status=$status&paged=$page&s=$search_term" ) );
457457

458458
if ( is_wp_error( $result ) ) {
459459
wp_die( $result );
460460
}
461461

462-
wp_redirect( self_admin_url( "plugins.php?resume=true&plugin_status=$status&paged=$page&s=$s" ) );
462+
wp_redirect( self_admin_url( "plugins.php?resume=true&plugin_status=$status&paged=$page&s=$search_term" ) );
463463
exit;
464464
case 'enable-auto-update':
465465
case 'disable-auto-update':
@@ -473,7 +473,7 @@
473473
wp_die( __( 'Please connect to your network admin to manage plugins automatic updates.' ) );
474474
}
475475

476-
$redirect = self_admin_url( "plugins.php?plugin_status={$status}&paged={$page}&s={$s}" );
476+
$redirect = self_admin_url( "plugins.php?plugin_status={$status}&paged={$page}&s={$search_term}" );
477477

478478
if ( 'enable-auto-update' === $action || 'disable-auto-update' === $action ) {
479479
if ( empty( $plugin ) ) {
@@ -771,12 +771,12 @@
771771
<?php
772772
}
773773

774-
if ( strlen( $s ) ) {
774+
if ( strlen( $search_term ) ) {
775775
echo '<span class="subtitle">';
776776
printf(
777777
/* translators: %s: Search query. */
778778
__( 'Search results for: %s' ),
779-
'<strong>' . esc_html( urldecode( $s ) ) . '</strong>'
779+
'<strong>' . esc_html( urldecode( $search_term ) ) . '</strong>'
780780
);
781781
echo '</span>';
782782
}

src/wp-includes/cron.php

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -972,30 +972,26 @@ function spawn_cron( $gmt_time = 0 ) {
972972
}
973973

974974
/**
975-
* Registers _wp_cron() to run on the {@see 'wp_loaded'} action.
975+
* Registers _wp_cron() to run on the {@see 'shutdown'} action.
976976
*
977-
* If the {@see 'wp_loaded'} action has already fired, this function calls
978-
* _wp_cron() directly.
979-
*
980-
* Warning: This function may return Boolean FALSE, but may also return a non-Boolean
981-
* value which evaluates to FALSE. For information about casting to booleans see the
982-
* {@link https://www.php.net/manual/en/language.types.boolean.php PHP documentation}. Use
983-
* the `===` operator for testing the return value of this function.
977+
* The spawn_cron() function attempts to make a non-blocking loopback request to `wp-cron.php` (when alternative
978+
* cron is not being used). However, the wp_remote_post() function does not always respect the `timeout` and
979+
* `blocking` parameters. A timeout of `0.01` may end up taking 1 second. When this runs at the {@see 'wp_loaded'}
980+
* action, it increases the Time To First Byte (TTFB) since the HTML cannot be sent while waiting for the cron request
981+
* to initiate. Moving the spawning of cron to the {@see 'shutdown'} hook allows for the server to flush the HTML document to
982+
* the browser while waiting for the request.
984983
*
985984
* @since 2.1.0
986985
* @since 5.1.0 Return value added to indicate success or failure.
987986
* @since 5.7.0 Functionality moved to _wp_cron() to which this becomes a wrapper.
988-
*
989-
* @return false|int|void On success an integer indicating number of events spawned (0 indicates no
990-
* events needed to be spawned), false if spawning fails for one or more events or
991-
* void if the function registered _wp_cron() to run on the action.
987+
* @since 6.9.0 The _wp_cron() callback is moved from {@see 'wp_loaded'} to the {@see 'shutdown'} action; the function always returns void.
992988
*/
993-
function wp_cron() {
994-
if ( did_action( 'wp_loaded' ) ) {
995-
return _wp_cron();
989+
function wp_cron(): void {
990+
if ( doing_action( 'shutdown' ) ) {
991+
_wp_cron();
992+
} else {
993+
add_action( 'shutdown', '_wp_cron' );
996994
}
997-
998-
add_action( 'wp_loaded', '_wp_cron', 20 );
999995
}
1000996

1001997
/**

src/wp-includes/functions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7173,7 +7173,7 @@ function wp_admin_headers() {
71737173
* @since 4.9.0
71747174
* @since 4.9.5 The default value was changed to 'strict-origin-when-cross-origin'.
71757175
*
7176-
* @link https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referrer-Policy
7176+
* @link https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Referrer-Policy
71777177
*
71787178
* @param string $policy The admin referrer policy header value. Default 'strict-origin-when-cross-origin'.
71797179
*/

tests/phpunit/tests/cron.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1330,4 +1330,27 @@ static function () {
13301330
$this->assertWPError( $unscheduled );
13311331
$this->assertSame( 'could_not_set', $unscheduled->get_error_code() );
13321332
}
1333+
1334+
/**
1335+
* @ticket 63858
1336+
*
1337+
* @covers ::wp_cron
1338+
*/
1339+
public function test_wp_cron_before_shutdown() {
1340+
remove_all_actions( 'shutdown' );
1341+
wp_cron();
1342+
$this->assertSame( 10, has_action( 'shutdown', '_wp_cron' ), 'Expected _wp_cron() to be scheduled for shutdown.' );
1343+
}
1344+
1345+
/**
1346+
* @ticket 63858
1347+
*
1348+
* @covers ::wp_cron
1349+
*/
1350+
public function test_wp_cron_already_at_shutdown() {
1351+
remove_all_actions( 'shutdown' );
1352+
add_action( 'shutdown', 'wp_cron' );
1353+
do_action( 'shutdown' );
1354+
$this->assertFalse( has_action( 'shutdown', '_wp_cron' ), 'Expected wp_cron() to not add _wp_cron() to run at shutdown.' );
1355+
}
13331356
}

0 commit comments

Comments
 (0)