Skip to content

Commit

Permalink
Merge pull request #103 from 10up/feature/add-php-checks
Browse files Browse the repository at this point in the history
Add a check to ensure we have a valid PHP version before loading plugin functionality and output an admin notice if needed
  • Loading branch information
Sidsector9 authored Aug 31, 2023
2 parents fbf13ff + 7fc8316 commit 64a1e66
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions retro-webamp-block.php
Original file line number Diff line number Diff line change
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.', 'retro-winamp-block' ),
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 64a1e66

Please sign in to comment.