From 4317d09bc35206fe08a9477c430ddbed6f90446f Mon Sep 17 00:00:00 2001 From: Konstantinos Galanakis Date: Fri, 18 Aug 2023 14:21:53 +0300 Subject: [PATCH] Add a check to ensure we have a valid PHP version before loading plugin functionality and output an admin notice if needed --- simple-local-avatars.php | 47 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/simple-local-avatars.php b/simple-local-avatars.php index 15021494..f6baac05 100644 --- a/simple-local-avatars.php +++ b/simple-local-avatars.php @@ -15,6 +15,53 @@ * @package SimpleLocalAvatars */ +/** + * Get the minimum version of PHP required by this plugin. + * + * @since 2.7.6 + * + * @return string Minimum version required. + */ +function minimum_php_requirement(): string { + return '7.4'; +} + +/** + * Whether PHP installation meets the minimum requirements + * + * @since 2.7.6 + * + * @return bool True if meets minimum requirements, false otherwise. + */ +function site_meets_php_requirements(): bool { + return version_compare( phpversion(), minimum_php_requirement(), '>=' ); +} + +// Try to load the plugin files, ensuring our PHP version is met first. +if ( ! site_meets_php_requirements() ) { + add_action( + 'admin_notices', + function() { + ?> +
+

+ +

+
+