| 1 |
<?php |
| 2 |
/** |
| 3 |
* Requirements Checker for Yatra Plugin |
| 4 |
* |
| 5 |
* Handles minimum PHP, WordPress version checks and required extensions |
| 6 |
* |
| 7 |
* @package Yatra\Core |
| 8 |
*/ |
| 9 |
|
| 10 |
namespace Yatra\Core; |
| 11 |
|
| 12 |
class Requirements |
| 13 |
{ |
| 14 |
/** |
| 15 |
* Minimum PHP version required |
| 16 |
*/ |
| 17 |
private const MIN_PHP_VERSION = '7.4'; |
| 18 |
|
| 19 |
/** |
| 20 |
* Minimum WordPress version required |
| 21 |
*/ |
| 22 |
private const MIN_WP_VERSION = '6.0'; |
| 23 |
|
| 24 |
/** |
| 25 |
* Required PHP extensions |
| 26 |
*/ |
| 27 |
private const REQUIRED_EXTENSIONS = ['curl', 'json', 'mbstring']; |
| 28 |
|
| 29 |
/** |
| 30 |
* Check if all minimum requirements are met |
| 31 |
* |
| 32 |
* @return bool |
| 33 |
*/ |
| 34 |
public static function check(): bool |
| 35 |
{ |
| 36 |
global $wp_version; |
| 37 |
|
| 38 |
$errors = []; |
| 39 |
|
| 40 |
// Check PHP version |
| 41 |
if (version_compare(PHP_VERSION, self::MIN_PHP_VERSION, '<')) { |
| 42 |
$errors[] = sprintf( |
| 43 |
'PHP version %s or higher is required. You are running version %s.', |
| 44 |
self::MIN_PHP_VERSION, |
| 45 |
PHP_VERSION |
| 46 |
); |
| 47 |
} |
| 48 |
|
| 49 |
// Check WordPress version |
| 50 |
if (version_compare($wp_version, self::MIN_WP_VERSION, '<')) { |
| 51 |
$errors[] = sprintf( |
| 52 |
'WordPress version %s or higher is required. You are running version %s.', |
| 53 |
self::MIN_WP_VERSION, |
| 54 |
$wp_version |
| 55 |
); |
| 56 |
} |
| 57 |
|
| 58 |
// Check required PHP extensions |
| 59 |
foreach (self::REQUIRED_EXTENSIONS as $extension) { |
| 60 |
if (!extension_loaded($extension)) { |
| 61 |
$errors[] = sprintf( |
| 62 |
'The PHP extension %s is required but not installed.', |
| 63 |
$extension |
| 64 |
); |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
if (!empty($errors)) { |
| 69 |
add_action('admin_notices', function() use ($errors) { |
| 70 |
echo '<div class="notice notice-error"><p>'; |
| 71 |
echo '<strong>Yatra Plugin Error:</strong><br>'; |
| 72 |
foreach ($errors as $error) { |
| 73 |
echo esc_html($error) . '<br>'; |
| 74 |
} |
| 75 |
echo '</p></div>'; |
| 76 |
}); |
| 77 |
return false; |
| 78 |
} |
| 79 |
|
| 80 |
return true; |
| 81 |
} |
| 82 |
|
| 83 |
/** |
| 84 |
* Get minimum PHP version |
| 85 |
* |
| 86 |
* @return string |
| 87 |
*/ |
| 88 |
public static function getMinPhpVersion(): string |
| 89 |
{ |
| 90 |
return self::MIN_PHP_VERSION; |
| 91 |
} |
| 92 |
|
| 93 |
/** |
| 94 |
* Get minimum WordPress version |
| 95 |
* |
| 96 |
* @return string |
| 97 |
*/ |
| 98 |
public static function getMinWpVersion(): string |
| 99 |
{ |
| 100 |
return self::MIN_WP_VERSION; |
| 101 |
} |
| 102 |
|
| 103 |
/** |
| 104 |
* Get required extensions |
| 105 |
* |
| 106 |
* @return array |
| 107 |
*/ |
| 108 |
public static function getRequiredExtensions(): array |
| 109 |
{ |
| 110 |
return self::REQUIRED_EXTENSIONS; |
| 111 |
} |
| 112 |
} |
| 113 |
|