Skip to content

Commit

Permalink
Add a PHP version check. If site doesn't meet requirements, show an a…
Browse files Browse the repository at this point in the history
…dmin notice and don't run any plugin functionality
  • Loading branch information
dkotter committed Jul 24, 2023
1 parent 255b459 commit 10a7bd5
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions convert-to-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,52 @@ function convert_to_blocks_get_setting( $name ) {
return apply_filters( 'convert_to_blocks_setting_' . $name, constant( $name ), \get_current_blog_id() );
}

/**
* Get the minimum version of PHP required by this plugin.
*
* @since 1.2.1
*
* @return string Minimum version required.
*/
function convert_to_blocks_minimum_php_requirement() {
return '8.0';
}

/**
* Whether PHP installation meets the minimum requirements
*
* @since 1.2.1
*
* @return bool True if meets minimum requirements, false otherwise.
*/
function convert_to_blocks_site_meets_php_requirements() {
return version_compare( phpversion(), convert_to_blocks_minimum_php_requirement(), '>=' );
}

if ( ! convert_to_blocks_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 */
__( 'Convert to Blocks requires PHP version %s or later. Please upgrade PHP or disable the plugin.', 'convert-to-blocks' ),
esc_html( convert_to_blocks_minimum_php_requirement() )
)
);
?>
</p>
</div>
<?php
}
);
return;
}

if ( file_exists( __DIR__ . '/config.test.php' ) && defined( 'PHPUNIT_RUNNER' ) ) {
require_once __DIR__ . '/config.test.php';
}
Expand Down

0 comments on commit 10a7bd5

Please sign in to comment.