Repository navigation
Expand file tree
/
Copy pathprompress.php
More file actions
142 lines (122 loc) · 3.81 KB
/
Copy pathprompress.php
File metadata and controls
142 lines (122 loc) · 3.81 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<?php
/**
* Plugin Name: PromPress
* Plugin URI: https://github.com/PeterBooker/prompress
* Description: Monitor your WordPress website with Prometheus.
* Version: 1.2.3
* Author: Peter Booker
* Author URI: https://peterbooker.com
* Text Domain: prompress
* License: GPL v3
* License URI: http://www.gnu.org/licenses/gpl-3.0.txt
* Domain Path: /languages
* Requires at least: 6.4
* Requires PHP: 8.1
*
* @package PromPress
*/
declare(strict_types=1);
namespace PromPress;
if ( ! \function_exists( 'add_filter' ) ) {
\header( 'Status: 403 Forbidden' );
\header( 'HTTP/1.1 403 Forbidden' );
exit();
}
\define( 'PROMPRESS_VERSION', '1.2.3' );
\define( 'PROMPRESS_DIR', \plugin_dir_path( __FILE__ ) );
\define( 'PROMPRESS_URL', \plugin_dir_url( __FILE__ ) );
\define( 'PROMPRESS_MIN_PHP_VERSION', '8.1' );
\define( 'PROMPRESS_MIN_WP_VERSION', '6.4' );
/**
* Get plugin base name.
*/
function prompress_plugin_basename(): string {
static $basename;
return $basename ??= \plugin_basename( __FILE__ );
}
/**
* Check for required PHP version.
*
* @return bool
*/
function php_version_check() {
if ( \version_compare( \PHP_VERSION, PROMPRESS_MIN_PHP_VERSION, '<' ) ) {
return false;
}
return true;
}
/**
* Check for required WordPress version.
*
* @return bool
*/
function wp_version_check() {
if ( \version_compare( $GLOBALS['wp_version'], PROMPRESS_MIN_WP_VERSION, '<' ) ) {
return false;
}
return true;
}
/**
* Check for Redis extension.
*
* @return bool
*/
function redis_extension_check() {
if ( ! \extension_loaded( 'redis' ) ) {
return false;
}
return true;
}
/**
* Admin notices if requirements aren't met.
*/
function requirements_error_notice() {
$notices = [];
if ( ! php_version_check() ) {
$notices[] = \sprintf(
/* translators: placeholder 1 is minimum required PHP version, placeholder 2 is installed PHP version. */
\esc_html__( 'PromPress plugin requires PHP %1$s or higher. You are on %2$s.', 'prompress' ),
\esc_html( PROMPRESS_MIN_PHP_VERSION ),
\esc_html( \PHP_VERSION )
);
}
if ( ! wp_version_check() ) {
$notices[] = \sprintf(
/* translators: placeholder 1 is minimum required WordPress version, placeholder 2 is installed WordPress version. */
\esc_html__( 'PromPress plugin requires at least WordPress in version %1$s, You are on %2$s.', 'prompress' ),
\esc_html( PROMPRESS_MIN_WP_VERSION ),
\esc_html( $GLOBALS['wp_version'] )
);
}
if ( ! redis_extension_check() ) {
$notices[] = \esc_html__( 'PromPress plugin requires the Redis (PECL) PHP extension.', 'prompress' );
}
foreach ( $notices as $notice ) {
echo '<div class="notice notice-error"><p>' . \esc_html( $notice ) . '</p></div>';
}
}
/**
* If either check fails, display notice and bail.
*/
if ( ! php_version_check() || ! wp_version_check() || ! redis_extension_check() ) {
\add_action( 'admin_notices', __NAMESPACE__ . '\\requirements_error_notice' );
return;
}
require_once PROMPRESS_DIR . 'vendor/autoload.php';
require_once PROMPRESS_DIR . 'inc/assets.php';
require_once PROMPRESS_DIR . 'inc/settings.php';
require_once PROMPRESS_DIR . 'inc/class-cli.php';
require_once PROMPRESS_DIR . 'inc/class-emails.php';
require_once PROMPRESS_DIR . 'inc/class-errors.php';
require_once PROMPRESS_DIR . 'inc/class-misc.php';
require_once PROMPRESS_DIR . 'inc/class-remote-requests.php';
require_once PROMPRESS_DIR . 'inc/class-queries.php';
require_once PROMPRESS_DIR . 'inc/class-options.php';
require_once PROMPRESS_DIR . 'inc/class-posts.php';
require_once PROMPRESS_DIR . 'inc/class-requests.php';
require_once PROMPRESS_DIR . 'inc/class-users.php';
require_once PROMPRESS_DIR . 'inc/class-monitor.php';
require_once PROMPRESS_DIR . 'inc/rest.php';
if ( \is_admin() ) {
require_once PROMPRESS_DIR . 'inc/admin-page.php';
}