Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a PHP version check and disable functionality if a site doesn't meet requirements #129

Merged
merged 2 commits into from
Jul 26, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading