Skip to content

Commit

Permalink
Add a check to ensure we have a valid PHP version before loading plug…
Browse files Browse the repository at this point in the history
…in functionality and output an admin notice if needed
  • Loading branch information
kmgalanakis committed Aug 18, 2023
1 parent 02d6f98 commit 4317d09
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions simple-local-avatars.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
?>
<div class="notice notice-error">
<p>
<?php
echo wp_kses_post(
sprintf(
/* translators: %s: Minimum required PHP version */
__( 'Simple Local Avatars requires PHP version %s or later. Please upgrade PHP or disable the plugin.', 'simple-local-avatars' ),
esc_html( minimum_php_requirement() )
)
);
?>
</p>
</div>
<?php
}
);
return;
}

define( 'SLA_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );

require_once dirname( __FILE__ ) . '/includes/class-simple-local-avatars.php';
Expand Down

0 comments on commit 4317d09

Please sign in to comment.