Skip to content

Commit

Permalink
Merge pull request #153 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 cf83332 + 11c736c commit 22ced94
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions simple-page-ordering.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,55 @@
* @package simple-page-ordering
*/

namespace SimplePageOrdering;

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

/**
* Whether PHP installation meets the minimum requirements
*
* @since 2.5.2
*
* @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 Page Ordering requires PHP version %s or later. Please upgrade PHP or disable the plugin.', 'simple-page-ordering' ),
esc_html( minimum_php_requirement() )
)
);
?>
</p>
</div>
<?php
}
);
return;
}

// Useful global constants.
define( 'SIMPLE_PAGE_ORDERING_VERSION', '2.5.1' );

Expand Down

0 comments on commit 22ced94

Please sign in to comment.