PluginProbe
Disable Comments & Delete All Comments / 1.3.0
Disable Comments & Delete All Comments v1.3.0
1.3.3 1.3.2 trunk 1.0.0 1.0.4 1.0.5 1.0.8 1.0.9 1.1.1 1.1.3 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.3.0 1.3.1
comments-plus / libs / factory / core / includes / class-factory-requirements.php

class-factory-requirements.php in Disable Comments & Delete All Comments 1.3.0, at libs/factory/core/includes/class-factory-requirements.php

294 lines 7.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Class to check if the current WordPress and PHP versions meet our requirements
5 *
6 * @see Docs https://webcraftic.atlassian.net/wiki/spaces/FFD/pages/21692485/WFF+Requirements
7 *
8 * @author Alex Kovalev <[email protected]>, repo: https://github.com/alexkovalevv
9 * @author Webcraftic <[email protected]>, site: https://webcraftic.com
10 *
11 * @version 2.0.0
12 * @since 4.0.9
13 */
14 // @formatter:off
15 if ( ! class_exists( 'Wbcr_Factory480_Requirements' ) ) {
16 class Wbcr_Factory480_Requirements {
17
18 /**
19 * Factory framework version
20 *
21 * @var string
22 */
23 protected $factory_version;
24
25 /**
26 * @var string
27 */
28 protected $plugin_version;
29
30 /**
31 * Plugin file path
32 *
33 * @var string
34 */
35 protected $plugin_file;
36
37 /**
38 * Plugin dir
39 *
40 * @var string
41 */
42 protected $plugin_abs_path;
43
44 /**
45 * Plugin base dir
46 *
47 * @var string
48 */
49 protected $plugin_basename;
50
51 /**
52 * Plugin url
53 *
54 * @var string
55 */
56 protected $plugin_url;
57
58 /**
59 * Plugin prefix
60 *
61 * @var string
62 */
63 protected $plugin_prefix;
64
65 /**
66 * Plugin name
67 *
68 * @var string
69 */
70 protected $plugin_name;
71
72 /**
73 * Plugin title
74 *
75 * @var string
76 */
77 protected $plugin_title = "(no title)";
78
79 /**
80 * @var string
81 */
82 protected $plugin_text_domain;
83
84 /**
85 * Required PHP version
86 *
87 * @var string
88 */
89 protected $required_php_version = '5.3';
90
91 /**
92 * Required WordPress version
93 *
94 * @var string
95 */
96 protected $required_wp_version = '4.2.0';
97
98 /**
99 * Is this plugin already activated?
100 *
101 * @var bool
102 */
103 protected $plugin_already_activate = false;
104
105 /**
106 * WFF_Requirements constructor.
107 *
108 * @param string $plugin_file
109 * @param array $plugin_info
110 */
111 public function __construct( $plugin_file, array $plugin_info ) {
112
113 foreach ( (array) $plugin_info as $property => $value ) {
114 if ( property_exists( $this, $property ) ) {
115 $this->$property = $value;
116 }
117 }
118
119 $this->plugin_file = $plugin_file;
120 $this->plugin_abs_path = dirname( $plugin_file );
121 $this->plugin_basename = plugin_basename( $plugin_file );
122 $this->plugin_url = plugins_url( '', $plugin_file );
123
124 $plugin_info = get_file_data( $this->plugin_file, array(
125 'Version' => 'Version',
126 'FrameworkVersion' => 'Framework Version',
127 'TextDomain' => 'Text Domain'
128 ), 'plugin' );
129
130 if ( isset( $plugin_info['FrameworkVersion'] ) ) {
131 $this->factory_version = $plugin_info['FrameworkVersion'];
132 }
133
134 if ( isset( $plugin_info['Version'] ) ) {
135 $this->plugin_version = $plugin_info['Version'];
136 }
137
138 if ( isset( $plugin_info['TextDomain'] ) ) {
139 $this->plugin_text_domain = $plugin_info['TextDomain'];
140 }
141
142 add_action( 'admin_init', array( $this, 'register_notices' ) );
143 }
144
145 public function get_plugin_version() {
146 return $this->plugin_version;
147 }
148
149 public function get_text_domain() {
150 return $this->plugin_text_domain;
151 }
152
153 /**
154 * @since 4.1.1
155 * @return void
156 */
157 public function register_notices() {
158 if ( current_user_can( 'activate_plugins' ) && current_user_can( 'edit_plugins' ) && current_user_can( 'install_plugins' ) ) {
159
160 if ( is_multisite() ) {
161 add_action( 'network_admin_notices', array( $this, 'show_notice' ) );
162
163 if ( ! empty( $this->plugin_basename ) && in_array( $this->plugin_basename, (array) get_option( 'active_plugins', array() ) ) ) {
164 add_action( 'admin_notices', array( $this, 'show_notice' ) );
165 }
166 } else {
167 add_action( 'admin_notices', array( $this, 'show_notice' ) );
168 }
169 }
170 }
171
172 /**
173 * Shows the incompatibility notification.
174 *
175 * @since 4.1.1
176 * @return void
177 */
178 public function show_notice() {
179 if ( $this->check() ) {
180 return;
181 }
182
183 echo '<div class="notice notice-error"><p>' . wp_kses($this->get_notice_text(), 'default') . '</p></div>';
184 }
185
186
187 /**
188 * The method checks the compatibility of the plugin with php and wordpress version.
189 *
190 * @since 4.1.1
191 * @return bool
192 */
193 public function check() {
194
195 // Fix for ithemes sync. When the ithemes sync plugin accepts the request, set the WP_ADMIN constant,
196 // after which the plugin Clearfy begins to create errors, and how the logic of its work is broken.
197 // Solution to simply terminate the plugin if there is a request from ithemes sync
198 // --------------------------------------
199 if ( defined( 'DOING_AJAX' ) && DOING_AJAX && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'ithemes_sync_request' ) {
200 return false;
201 }
202
203 if ( isset( $_GET['ithemes-sync-request'] ) && ! empty( $_GET['ithemes-sync-request'] ) ) {
204 return false;
205 }
206 // ----------------------------------------
207
208 if ( ! $this->check_php_compat() || ! $this->check_wp_compat() || $this->plugin_already_activate ) {
209 return false;
210 }
211
212 return true;
213 }
214
215 /**
216 * The method checks the compatibility of the plugin with the php version of the server.
217 *
218 * @return mixed
219 */
220 public function check_php_compat() {
221 return version_compare( PHP_VERSION, $this->required_php_version, '>=' );
222 }
223
224 /**
225 * The method checks the compatibility of the plugin with the Wordpress version of the site.
226 *
227 * @return mixed
228 */
229 public function check_wp_compat() {
230 // Get the WP Version global.
231 global $wp_version;
232
233 return version_compare( $wp_version, $this->required_wp_version, '>=' );
234 }
235
236 /**
237 * Method returns notification text
238 *
239 * @return string
240 */
241 protected function get_notice_text() {
242 $notice_text = $notice_default_text = '';
243 $notice_default_text .= '<b>' . $this->plugin_title . ' ' . __( 'warning', '' ) . ':</b>' . '<br>';
244
245 $notice_default_text .= sprintf( __( 'The %s plugin has stopped.', 'wbcr_factory_templates_134' ), $this->plugin_title ) . ' ';
246 $notice_default_text .= __( 'Possible reasons:', '' ) . ' <br>';
247
248 $has_one = false;
249
250 if ( ! $this->check_php_compat() ) {
251 $has_one = true;
252 $notice_text .= '- ' . $this->get_php_incompat_text() . '<br>';
253 }
254
255 if ( ! $this->check_wp_compat() ) {
256 $has_one = true;
257 $notice_text .= '- ' . $this->get_wp_incompat_text() . '<br>';
258 }
259
260 if ( $this->plugin_already_activate ) {
261 $has_one = true;
262 $notice_text = '- ' . $this->get_plugin_already_activate_text() . '<br>';
263 }
264
265 if ( $has_one ) {
266 $notice_text = $notice_default_text . $notice_text;
267 }
268
269 return $notice_text;
270 }
271
272 /**
273 * @return string
274 */
275 protected function get_php_incompat_text() {
276 return sprintf( __( 'You need to update the PHP version to %s or higher!', 'wbcr_factory_480' ), $this->required_php_version );
277 }
278
279 /**
280 * @return string
281 */
282 protected function get_wp_incompat_text() {
283 return sprintf( __( 'You need to update WordPress to %s or higher!', 'wbcr_factory_480' ), $this->required_wp_version );
284 }
285
286 /**
287 * @return string
288 */
289 protected function get_plugin_already_activate_text() {
290 return sprintf( __( 'Plugin %s is already activated, you are trying to activate it again.', 'wbcr_factory_480' ), $this->plugin_title );
291 }
292 }
293 }
294 // @formatter:on