Plugins: Block plugin activation if it requires a higher version of PHP or WordPress.

Introduce `validate_plugin_requirements()` for validating a plugin's WordPress and PHP version requirements.

Introduce `wp_is_wp_compatible()` and `wp_is_php_compatible()` for checking compatibility with the current WordPress or PHP version.

Props afragen, joyously, DrewAPicture, TimothyBlynJacobs, desrosj, flixos90, SergeyBiryukov.
See #43992.

git-svn-id: https://develop.svn.wordpress.org/trunk@44978 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov
2019-03-22 00:36:30 +00:00
parent f170c1dd31
commit 1586c43c8d
2 changed files with 81 additions and 0 deletions
+26
View File
@@ -6897,3 +6897,29 @@ function wp_direct_php_update_button() {
);
echo '</p>';
}
/**
* Checks compatibility with the current WordPress version.
*
* @since 5.2.0
*
* @param string $required Minimum required WordPress version.
* @return bool True if required version is compatible or empty, false if not.
*/
function wp_is_wp_compatible( $required ) {
$wp_version = get_bloginfo( 'version' );
return empty( $required ) || version_compare( $wp_version, $required, '>=' );
}
/**
* Checks compatibility with the current PHP version.
*
* @since 5.2.0
*
* @param string $required Minimum required PHP version.
* @return bool True if required version is compatible or empty, false if not.
*/
function wp_is_php_compatible( $required ) {
return empty( $required ) || version_compare( phpversion(), $required, '>=' );
}