-
Notifications
You must be signed in to change notification settings - Fork 81
/
system-checks.php
88 lines (67 loc) · 2.14 KB
/
system-checks.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
class Brizy_SystemChecks {
/**
* @var
*/
private $required = [
'php' => '5.6',
'extension' => [
'xml' => 'https://www.php.net/manual/en/book.xml.php',
'gd' => 'https://www.php.net/manual/en/book.image.php',
'fileinfo' => 'https://www.php.net/manual/en/book.fileinfo.php',
'zip' => 'https://www.php.net/manual/en/book.zip.php',
'curl' => 'https://www.php.net/manual/en/book.curl.php',
'json' => 'https://www.php.net/manual/en/book.json.php'
]
];
static public function run() {
return new self();
}
private function __construct() {
$this->checkPhpVersion();
add_action( 'admin_notices', array( $this, 'checkPlatformReqs' ) );
}
public function checkPlatformReqs() {
$this->checkExtensions( $this->required['extension'] );
}
private function checkPhpVersion() {
if ( version_compare( PHP_VERSION, '5.6.0' ) < 0 ) {
$this->notification( sprintf(
__( '%1$s requires PHP version 5.6+, you currently running PHP %2$s. <b>%3$s IS NOT RUNNING.</b>', 'brizy' ),
__bt( 'brizy', 'Brizy' ),
PHP_VERSION,
strtoupper( __bt( 'brizy', 'Brizy' ) )
) );
throw new Exception('Invalid PHP version');
}
}
private function checkExtensions( $extensions ) {
$notFoundExtensions = [];
foreach ( $extensions as $key => $url ) {
if ( ! extension_loaded( $key ) ) {
$notFoundExtensions[ $key ] = $url;
}
}
if ( count( $notFoundExtensions ) ) {
$this->notFoundExtensionsNotification( $notFoundExtensions );
}
}
private function notFoundExtensionsNotification( $extensions ) {
$message = "The following extensions are required for " . __bt( 'brizy', 'Brizy' ) . " plugins properly work: <br>";
foreach ( $extensions as $key => $url ) {
$message .= '<a href="' . $url . '">extension-' . $key . '</a><br>';
}
$message .= '<br>';
$message .= 'Please contact your hosting company for support.';
$this->notification( $message );
}
private function notification( $text, $type = 'error' ) {
?>
<div class="notice notice-<?php echo $type ?> is-dismissible">
<p>
<?php echo $text; ?>
</p>
</div>
<?php
}
}