diff --git a/src/wp-admin/includes/class-wp-site-health.php b/src/wp-admin/includes/class-wp-site-health.php index eb3d89d3f8..f031e0a0f7 100644 --- a/src/wp-admin/includes/class-wp-site-health.php +++ b/src/wp-admin/includes/class-wp-site-health.php @@ -1083,6 +1083,52 @@ class WP_Site_Health { return $result; } + /** + * Test if there's an active PHP session that can affect loopback requests. + * + * @since 5.5.0 + * + * @return array The test results. + */ + public function get_test_php_sessions() { + $result = array( + 'label' => __( 'No PHP sessions detected' ), + 'status' => 'good', + 'badge' => array( + 'label' => __( 'Performance' ), + 'color' => 'blue', + ), + 'description' => sprintf( + '
%s
', + sprintf( + /* translators: 1: session_start(), 2: session_write_close() */ + __( 'PHP sessions created by a %1$s function call may interfere with REST API and loopback requests. An active session should be closed by %2$s before making any HTTP requests.' ), + 'session_start()
',
+ 'session_write_close()
'
+ )
+ ),
+ 'test' => 'php_sessions',
+ );
+
+ if ( PHP_SESSION_ACTIVE === session_status() ) {
+ $result['status'] = 'critical';
+
+ $result['label'] = __( 'An active PHP session was detected' );
+
+ $result['description'] = sprintf(
+ '%s
', + sprintf( + /* translators: 1: session_start(), 2: session_write_close() */ + __( 'A PHP session was created by a %1$s function call. This interferes with REST API and loopback requests. The session should be closed by %2$s before making any HTTP requests.' ), + 'session_start()
',
+ 'session_write_close()
'
+ )
+ );
+ }
+
+ return $result;
+ }
+
/**
* Test if the SQL server is up to date.
*
@@ -1939,6 +1985,10 @@ class WP_Site_Health {
'label' => __( 'PHP Default Timezone' ),
'test' => 'php_default_timezone',
),
+ 'php_sessions' => array(
+ 'label' => __( 'PHP Sessions' ),
+ 'test' => 'php_sessions',
+ ),
'sql_server' => array(
'label' => __( 'Database Server version' ),
'test' => 'sql_server',