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 17, 2023
1 parent e52000c commit 98c729b
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions retro-webamp-block.php
Expand Up @@ -15,6 +15,55 @@
* @package tenup\Winamp_Block
*/

namespace RetroWinampBlock;

/**
* Get the minimum version of PHP required by this plugin.
*
* @since 1.3.1
*
* @return string Minimum version required.
*/
function minimum_php_requirement(): string {
return '7.4';
}

/**
* Whether PHP installation meets the minimum requirements
*
* @since 1.3.1
*
* @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 */
__( 'Retro Winamp Block requires PHP version %s or later. Please upgrade PHP or disable the plugin.', 'safe-svg' ),
esc_html( minimum_php_requirement() )
)
);
?>
</p>
</div>
<?php
}
);
return;
}

/**
* Registers the block using the metadata loaded from the `block.json` file.
* Behind the scenes, it registers also all assets so they can be enqueued
Expand Down

0 comments on commit 98c729b

Please sign in to comment.