Skip to content

Commit

Permalink
Merge pull request #258 from 10up/fix/256-php-ver-check
Browse files Browse the repository at this point in the history
Add PHP version check for plugin.
  • Loading branch information
iamdharmesh authored Jul 28, 2023
2 parents 5fd1494 + e30968c commit b6ce9d8
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions autoshare-for-twitter.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
* @package TenUp\AutoshareForTwitter
*/

namespace TenUp\AutoshareForTwitter;

if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
Expand All @@ -25,6 +27,49 @@
define( 'AUTOSHARE_FOR_TWITTER_PATH', plugin_dir_path( __FILE__ ) );
define( 'AUTOSHARE_FOR_TWITTER_INC', AUTOSHARE_FOR_TWITTER_PATH . 'includes/' );

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

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

// Ensuring our PHP version requirement is met first before loading plugin.
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 */
__( 'Autoshare for Twitter requires PHP version %s or later. Please upgrade PHP or disable the plugin.', 'autoshare-for-twitter' ),
esc_html( minimum_php_requirement() )
)
);
?>
</p>
</div>
<?php
}
);
return;
}

/**
* Composer check.
*/
Expand Down

0 comments on commit b6ce9d8

Please sign in to comment.