Tests if the supplied PHP version is supported.
Source
public function get_test_php_version() {
$response = wp_check_php_version();
$result = array(
'label' => sprintf(
/* translators: %s: The server PHP version. */
__( 'Your site is running PHP %s' ),
PHP_VERSION
),
'status' => 'good',
'badge' => array(
'label' => __( 'Performance' ),
'color' => 'blue',
),
'description' => sprintf(
'<p>%s</p>',
__( 'PHP is one of the programming languages used to build WordPress. Newer versions of PHP receive regular security updates and may increase your site’s performance.' )
),
'actions' => sprintf(
'<p><a href="%s" target="_blank">%s<span class="screen-reader-text"> %s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a></p>',
esc_url( wp_get_update_php_url() ),
__( 'Learn more about updating PHP' ),
/* translators: Hidden accessibility text. */
__( '(opens in a new tab)' )
),
'test' => 'php_version',
);
if ( ! $response ) {
$result['label'] = sprintf(
/* translators: %s: The server PHP version. */
__( 'Unable to determine the status of the current PHP version (%s)' ),
PHP_VERSION
);
$result['status'] = 'recommended';
$result['description'] = '<p><em>' . sprintf(
/* translators: %s is the URL to the Serve Happy docs page. */
__( 'Unable to access the WordPress.org API for <a href="%s">Serve Happy</a>.' ),
'https://codex.wordpress.org/WordPress.org_API#Serve_Happy'
) . '</em></p>' . $result['description'];
return $result;
}
$result['description'] .= '<p>' . sprintf(
/* translators: %s: The minimum recommended PHP version. */
__( 'The minimum recommended version of PHP is %s.' ),
$response['recommended_version']
) . '</p>';
// PHP is up to date.
if ( version_compare( PHP_VERSION, $response['recommended_version'], '>=' ) ) {
$result['label'] = sprintf(
/* translators: %s: The server PHP version. */
__( 'Your site is running a recommended version of PHP (%s)' ),
PHP_VERSION
);
$result['status'] = 'good';
return $result;
}
// The PHP version is older than the recommended version, but still receiving active support.
if ( $response['is_supported'] ) {
$result['label'] = sprintf(
/* translators: %s: The server PHP version. */
__( 'Your site is running on an older version of PHP (%s)' ),
PHP_VERSION
);
$result['status'] = 'recommended';
return $result;
}
/*
* The PHP version is still receiving security fixes, but is lower than
* the expected minimum version that will be required by WordPress in the near future.
*/
if ( $response['is_secure'] && $response['is_lower_than_future_minimum'] ) {
// The `is_secure` array key name doesn't actually imply this is a secure version of PHP. It only means it receives security updates.
$result['label'] = sprintf(
/* translators: %s: The server PHP version. */
__( 'Your site is running on an outdated version of PHP (%s), which soon will not be supported by WordPress.' ),
PHP_VERSION
);
$result['status'] = 'critical';
$result['badge']['label'] = __( 'Requirements' );
return $result;
}
// The PHP version is only receiving security fixes.
if ( $response['is_secure'] ) {
$result['label'] = sprintf(
/* translators: %s: The server PHP version. */
__( 'Your site is running on an older version of PHP (%s), which should be updated' ),
PHP_VERSION
);
$result['status'] = 'recommended';
return $result;
}
// No more security updates for the PHP version, and lower than the expected minimum version required by WordPress.
if ( $response['is_lower_than_future_minimum'] ) {
$message = sprintf(
/* translators: %s: The server PHP version. */
__( 'Your site is running on an outdated version of PHP (%s), which does not receive security updates and soon will not be supported by WordPress.' ),
PHP_VERSION
);
} else {
// No more security updates for the PHP version, must be updated.
$message = sprintf(
/* translators: %s: The server PHP version. */
__( 'Your site is running on an outdated version of PHP (%s), which does not receive security updates. It should be updated.' ),
PHP_VERSION
);
}
$result['label'] = $message;
$result['status'] = 'critical';
$result['badge']['label'] = __( 'Security' );
return $result;
}
Changelog
| Version | Description |
|---|---|
| 5.2.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.