Skip to content

Commit

Permalink
Add PHP version check for plugin.
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulsprajapati committed Jul 28, 2023
1 parent cd3975a commit f7dec6b
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions classifai.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,49 @@
* Domain Path: /languages
*/

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

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

// Ensuring our PHP version requirement is met first before loading plugin.
if ( ! classifai_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 */
__( 'ClassifAI requires PHP version %s or later. Please upgrade PHP or disable the plugin.', 'classifai' ),
esc_html( classifai_minimum_php_requirement() )
)
);
?>
</p>
</div>
<?php
}
);
return;
}

/**
* Small wrapper around PHP's define function. The defined constant is
* ignored if it has already been defined. This allows the
Expand Down

0 comments on commit f7dec6b

Please sign in to comment.