PluginProbe ʕ •ᴥ•ʔ
YITH WooCommerce Wishlist / 4.0.1
YITH WooCommerce Wishlist v4.0.1
trunk 2.1.0 2.1.1 2.1.2 2.2.0 2.2.1 2.2.10 2.2.11 2.2.12 2.2.13 2.2.14 2.2.15 2.2.16 2.2.17 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9 3.0.0 3.0.1 3.0.10 3.0.11 3.0.12 3.0.13 3.0.14 3.0.15 3.0.16 3.0.17 3.0.18 3.0.19 3.0.2 3.0.20 3.0.21 3.0.22 3.0.23 3.0.25 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.10.0 3.11.0 3.12.0 3.13.0 3.14.0 3.15.0 3.16.0 3.17.0 3.18.0 3.19.0 3.2.0 3.20.0 3.21.0 3.22.0 3.23.0 3.24.0 3.25.0 3.26.0 3.27.0 3.28.0 3.29.0 3.3.0 3.30.0 3.31.0 3.32.0 3.33.0 3.34.0 3.35.0 3.36.0 3.37.0 3.38.0 3.4.0 3.5.0 3.6.0 3.7.0 3.8.0 3.9.0 4.0.0 4.0.1 4.1.0 4.10.0 4.10.1 4.10.2 4.11.0 4.12.0 4.13.0 4.14.0 4.15.0 4.2.0 4.3.0 4.4.0 4.5.0 4.6.0 4.7.0 4.8.0 4.9.0
yith-woocommerce-wishlist / plugin-fw / includes / class-yith-system-status.php
yith-woocommerce-wishlist / plugin-fw / includes Last commit date
builders 2 years ago privacy 2 years ago class-yit-ajax.php 2 years ago class-yit-assets.php 2 years ago class-yit-cpt-unlimited.php 5 years ago class-yit-gradients.php 2 years ago class-yit-help-desk.php 2 years ago class-yit-icons.php 2 years ago class-yit-metabox.php 2 years ago class-yit-plugin-common.php 5 years ago class-yit-plugin-licence.php 2 years ago class-yit-plugin-panel-woocommerce.php 1 year ago class-yit-plugin-panel.php 1 year ago class-yit-plugin-subpanel.php 2 years ago class-yit-pointers.php 2 years ago class-yit-theme-licence.php 2 years ago class-yit-upgrade.php 5 years ago class-yit-video.php 5 years ago class-yith-bh-onboarding.php 3 years ago class-yith-dashboard.php 4 years ago class-yith-debug.php 2 years ago class-yith-external-services.php 1 year ago class-yith-post-type-admin.php 2 years ago class-yith-system-status.php 1 year ago
class-yith-system-status.php
830 lines
1 <?php
2 /**
3 * YITH System Status Class
4 * handle System Status panel
5 *
6 * @class YITH_System_Status
7 * @package YITH\PluginFramework\Classes
8 */
9
10 defined( 'ABSPATH' ) || exit; // Exit if accessed directly.
11
12 if ( ! class_exists( 'YITH_System_Status' ) ) {
13 /**
14 * YITH_System_Status class.
15 *
16 * @author YITH <plugins@yithemes.com>
17 */
18 class YITH_System_Status {
19 /**
20 * The page slug
21 *
22 * @var string
23 */
24 protected $page = 'yith_system_info';
25
26 /**
27 * Plugins requirements list
28 *
29 * @var array
30 */
31 protected $plugins_requirements = array();
32
33 /**
34 * Plugins tables list
35 *
36 * @var array
37 */
38 protected $plugins_tables = array();
39
40 /**
41 * Requirements labels
42 *
43 * @var array
44 */
45 public $requirement_labels = array();
46
47 /**
48 * Recommended memory amount 134217728 = 128M
49 *
50 * @var integer
51 */
52 private $recommended_memory = 134217728;
53
54 /**
55 * Single instance of the class
56 *
57 * @since 1.0.0
58 * @var YITH_System_Status
59 */
60 protected static $instance = null;
61
62 /**
63 * Main plugin Instance
64 *
65 * @return YITH_System_Status
66 * @since 1.0.0
67 */
68 public static function instance() {
69 if ( is_null( self::$instance ) ) {
70 self::$instance = new self();
71 }
72
73 return self::$instance;
74 }
75
76 /**
77 * Constructor
78 *
79 * @return void
80 * @since 1.0.0
81 */
82 public function __construct() {
83
84 if ( ! is_admin() ) {
85 return;
86 }
87
88 /**
89 * Add to prevent trigger admin_init called directly
90 * wp-admin/admin-post.php?page=yith_system_info
91 */
92 if ( ! is_user_logged_in() ) {
93 return;
94 }
95 add_filter( 'admin_body_class', array( $this, 'add_body_class' ) );
96 add_action( 'admin_menu', array( $this, 'add_submenu_page' ), 99 );
97 add_action( 'admin_init', array( $this, 'check_system_status' ) );
98 add_action( 'admin_notices', array( $this, 'activate_system_notice' ), 15 );
99 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 20 );
100 add_action( 'init', array( $this, 'set_requirements_labels' ) );
101 add_action( 'wp_ajax_yith_create_log_file', array( $this, 'create_log_file' ) );
102 }
103
104 /**
105 * Add body classes in Panel pages
106 *
107 * @param string $classes Body classes.
108 *
109 * @return string
110 * @since 1.0.0
111 */
112 public function add_body_class( $classes ) {
113 global $pagenow;
114
115 if ( ( 'admin.php' === $pagenow && strpos( get_current_screen()->id, $this->page ) !== false ) ) {
116 $to_add = array( 'yith-plugin-fw-panel', 'yith-plugin-fw-panel--version-2' );
117 foreach ( $to_add as $class_to_add ) {
118 $classes = ! substr_count( $classes, " $class_to_add " ) ? $classes . " $class_to_add " : $classes;
119 }
120 }
121
122 return $classes;
123 }
124
125 /**
126 * Set requirements labels
127 *
128 * @return void
129 * @since 1.0.0
130 */
131 public function set_requirements_labels() {
132
133 $this->requirement_labels = array(
134 'min_wp_version' => esc_html__( 'WordPress Version', 'yith-plugin-fw' ),
135 'min_wc_version' => esc_html__( 'WooCommerce Version', 'yith-plugin-fw' ),
136 'wp_memory_limit' => esc_html__( 'Available Memory', 'yith-plugin-fw' ),
137 'min_php_version' => esc_html__( 'PHP Version', 'yith-plugin-fw' ),
138 'min_tls_version' => esc_html__( 'TLS Version', 'yith-plugin-fw' ),
139 'wp_cron_enabled' => esc_html__( 'WordPress Cron', 'yith-plugin-fw' ),
140 'simplexml_enabled' => esc_html__( 'SimpleXML', 'yith-plugin-fw' ),
141 'mbstring_enabled' => esc_html__( 'MultiByte String', 'yith-plugin-fw' ),
142 'imagick_version' => esc_html__( 'ImageMagick Version', 'yith-plugin-fw' ),
143 'gd_enabled' => esc_html__( 'GD Library', 'yith-plugin-fw' ),
144 'iconv_enabled' => esc_html__( 'Iconv Module', 'yith-plugin-fw' ),
145 'opcache_enabled' => esc_html__( 'OPCache Save Comments', 'yith-plugin-fw' ),
146 'url_fopen_enabled' => esc_html__( 'URL FOpen', 'yith-plugin-fw' ),
147 );
148 }
149
150 /**
151 * Add "System Information" submenu page under YITH Plugins
152 *
153 * @return void
154 * @since 1.0.0
155 */
156 public function add_submenu_page() {
157 $system_info = get_option( 'yith_system_info', array() );
158 $error_notice = ( isset( $system_info['errors'] ) && true === $system_info['errors'] ? ' <span class="yith-system-info-menu update-plugins">!</span>' : '' );
159 $settings = array(
160 'parent_page' => 'yith_plugin_panel',
161 'page_title' => esc_html__( 'System Status', 'yith-plugin-fw' ),
162 'menu_title' => esc_html__( 'System Status', 'yith-plugin-fw' ) . $error_notice,
163 'capability' => 'manage_options',
164 'page' => $this->page,
165 );
166
167 add_submenu_page(
168 $settings['parent_page'],
169 $settings['page_title'],
170 $settings['menu_title'],
171 $settings['capability'],
172 $settings['page'],
173 array( $this, 'show_information_panel' )
174 );
175 }
176
177 /**
178 * Add "System Information" page template under YITH Plugins
179 *
180 * @return void
181 * @since 1.0.0
182 */
183 public function show_information_panel() {
184 $path = defined( 'YIT_CORE_PLUGIN_PATH' ) ? YIT_CORE_PLUGIN_PATH : get_template_directory() . '/core/plugin-fw/';
185 $tabs = array(
186 'main' => array(
187 'title' => esc_html__( 'System Status', 'yith-plugin-fw' ),
188 'icon' => '<svg fill="none" stroke="currentColor" stroke-width="1.5" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"><path stroke-linecap="round" stroke-linejoin="round" d="M9 17.25v1.007a3 3 0 01-.879 2.122L7.5 21h9l-.621-.621A3 3 0 0115 18.257V17.25m6-12V15a2.25 2.25 0 01-2.25 2.25H5.25A2.25 2.25 0 013 15V5.25m18 0A2.25 2.25 0 0018.75 3H5.25A2.25 2.25 0 003 5.25m18 0V12a2.25 2.25 0 01-2.25 2.25H5.25A2.25 2.25 0 013 12V5.25"></path></svg>',
189 ),
190 'php-info' => array(
191 'title' => esc_html__( 'PHPInfo', 'yith-plugin-fw' ),
192 'icon' => '<svg fill="currentColor" data-slot="icon" role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>PHP</title><path d="M7.01 10.207h-.944l-.515 2.648h.838c.556 0 .97-.105 1.242-.314.272-.21.455-.559.55-1.049.092-.47.05-.802-.124-.995-.175-.193-.523-.29-1.047-.29zM12 5.688C5.373 5.688 0 8.514 0 12s5.373 6.313 12 6.313S24 15.486 24 12c0-3.486-5.373-6.312-12-6.312zm-3.26 7.451c-.261.25-.575.438-.917.551-.336.108-.765.164-1.285.164H5.357l-.327 1.681H3.652l1.23-6.326h2.65c.797 0 1.378.209 1.744.628.366.418.476 1.002.33 1.752a2.836 2.836 0 0 1-.305.847c-.143.255-.33.49-.561.703zm4.024.715l.543-2.799c.063-.318.039-.536-.068-.651-.107-.116-.336-.174-.687-.174H11.46l-.704 3.625H9.388l1.23-6.327h1.367l-.327 1.682h1.218c.767 0 1.295.134 1.586.401s.378.7.263 1.299l-.572 2.944h-1.389zm7.597-2.265a2.782 2.782 0 0 1-.305.847c-.143.255-.33.49-.561.703a2.44 2.44 0 0 1-.917.551c-.336.108-.765.164-1.286.164h-1.18l-.327 1.682h-1.378l1.23-6.326h2.649c.797 0 1.378.209 1.744.628.366.417.477 1.001.331 1.751zM17.766 10.207h-.943l-.516 2.648h.838c.557 0 .971-.105 1.242-.314.272-.21.455-.559.551-1.049.092-.47.049-.802-.125-.995s-.524-.29-1.047-.29z"/></svg>',
193 ),
194 'db-info' => array(
195 'title' => esc_html__( 'Database', 'yith-plugin-fw' ),
196 'icon' => '<svg data-slot="icon" fill="none" stroke-width="1.5" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"><path stroke-linecap="round" stroke-linejoin="round" d="M21.75 17.25v-.228a4.5 4.5 0 0 0-.12-1.03l-2.268-9.64a3.375 3.375 0 0 0-3.285-2.602H7.923a3.375 3.375 0 0 0-3.285 2.602l-2.268 9.64a4.5 4.5 0 0 0-.12 1.03v.228m19.5 0a3 3 0 0 1-3 3H5.25a3 3 0 0 1-3-3m19.5 0a3 3 0 0 0-3-3H5.25a3 3 0 0 0-3 3m16.5 0h.008v.008h-.008v-.008Zm-3 0h.008v.008h-.008v-.008Z"></path></svg>',
197 ),
198 'error-log' => array(
199 'title' => esc_html__( 'Log Files', 'yith-plugin-fw' ),
200 'icon' => '<svg data-slot="icon" fill="none" stroke-width="1.5" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"><path stroke-linecap="round" stroke-linejoin="round" d="M19.5 14.25v-2.625a3.375 3.375 0 0 0-3.375-3.375h-1.5A1.125 1.125 0 0 1 13.5 7.125v-1.5a3.375 3.375 0 0 0-3.375-3.375H8.25m2.25 0H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 0 0-9-9Z"></path></svg>',
201 ),
202 );
203 require_once $path . '/templates/sysinfo/system-information-panel.php';
204 }
205
206 /**
207 * Perform system status check
208 *
209 * @return void
210 * @since 1.0.0
211 */
212 public function check_system_status() {
213
214 if ( '' === get_option( 'yith_system_info' ) || ( isset( $_GET['page'] ) && $_GET['page'] === $this->page ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
215
216 $this->add_requirements(
217 esc_html__( 'YITH Plugins', 'yith-plugin-fw' ),
218 array(
219 'min_wp_version' => '6.2',
220 'min_wc_version' => '8.5',
221 'min_php_version' => '7.4',
222 )
223 );
224 $this->add_requirements(
225 esc_html__( 'WooCommerce', 'yith-plugin-fw' ),
226 array(
227 'wp_memory_limit' => '64M',
228 )
229 );
230
231 $system_info = $this->get_system_info();
232 $check_results = array();
233 $table_check = array();
234 $errors = 0;
235
236 foreach ( $system_info as $key => $value ) {
237 $check_results[ $key ] = array( 'value' => $value );
238
239 if ( isset( $this->plugins_requirements[ $key ] ) ) {
240 foreach ( $this->plugins_requirements[ $key ] as $plugin_name => $required_value ) {
241 switch ( $key ) {
242 case 'wp_cron_enabled':
243 case 'mbstring_enabled':
244 case 'simplexml_enabled':
245 case 'gd_enabled':
246 case 'iconv_enabled':
247 case 'url_fopen_enabled':
248 case 'opcache_enabled':
249 if ( ! $value ) {
250 $check_results[ $key ]['errors'][ $plugin_name ] = $required_value;
251 ++$errors;
252 }
253 break;
254 case 'wp_memory_limit':
255 $required_memory = $this->memory_size_to_num( $required_value );
256
257 if ( $required_memory > $value ) {
258 $check_results[ $key ]['errors'][ $plugin_name ] = $required_value;
259 ++$errors;
260
261 } elseif ( $this->recommended_memory > $value && $value > $required_value ) {
262 $check_results[ $key ]['warnings'] = 'yes';
263 }
264 break;
265 default:
266 if ( 'imagick_version' === $key ) {
267 if ( ! version_compare( $value, $required_value, '>=' ) ) {
268 $check_results[ $key ]['errors'][ $plugin_name ] = $required_value;
269 ++$errors;
270 }
271 } else {
272 if ( 'n/a' !== $value ) {
273 if ( ! version_compare( $value, $required_value, '>=' ) ) {
274 $check_results[ $key ]['errors'][ $plugin_name ] = $required_value;
275 ++$errors;
276 }
277 } else {
278 if ( 'min_wc_version' !== $key ) {
279 $check_results[ $key ]['warnings'][ $plugin_name ] = $required_value;
280 }
281 }
282 }
283 }
284 }
285 }
286 }
287
288 update_option(
289 'yith_system_info',
290 array(
291 'system_info' => $check_results,
292 'errors' => $errors > 0,
293 'tables' => $table_check,
294 )
295 );
296
297 }
298 }
299
300 /**
301 * Handle plugin requirements
302 *
303 * @param string $plugin_name The name of the plugin.
304 * @param array $requirements Array of plugin requirements.
305 *
306 * @return void
307 * @since 1.0.0
308 */
309 public function add_requirements( $plugin_name, $requirements = array() ) {
310 if ( ! empty( $requirements ) ) {
311 $allowed_requirements = array_keys( $this->requirement_labels );
312
313 foreach ( $requirements as $requirement => $value ) {
314 if ( in_array( $requirement, $allowed_requirements, true ) ) {
315 $this->plugins_requirements[ $requirement ][ $plugin_name ] = $value;
316 }
317 }
318 }
319 }
320
321 /**
322 * Manages notice dismissing
323 *
324 * @return void
325 * @since 1.0.0
326 */
327 public function enqueue_scripts() {
328 $script_path = defined( 'YIT_CORE_PLUGIN_URL' ) ? YIT_CORE_PLUGIN_URL : get_template_directory_uri() . '/core/plugin-fw';
329 wp_register_script( 'yith-system-info', yit_load_js_file( $script_path . '/assets/js/yith-system-info.js' ), array( 'jquery' ), '1.0.0', true );
330
331 if ( isset( $_GET['page'] ) && 'yith_system_info' === $_GET['page'] ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
332 wp_enqueue_style( 'yith-plugin-panel' );
333 wp_enqueue_style( 'yith-plugin-fw-fields' );
334 wp_enqueue_script( 'yith-system-info' );
335
336 $params = array(
337 'ajax_url' => admin_url( 'admin-ajax.php' ),
338 );
339
340 wp_localize_script( 'yith-system-info', 'yith_sysinfo', $params );
341
342 }
343 }
344
345 /**
346 * Show system notice
347 *
348 * @return void
349 * @since 1.0.0
350 */
351 public function activate_system_notice() {
352
353 $system_info = get_option( 'yith_system_info', '' );
354
355 if ( ( isset( $_GET['page'] ) && $_GET['page'] === $this->page ) || ( ! empty( $_COOKIE['hide_yith_system_alert'] ) && 'yes' === $_COOKIE['hide_yith_system_alert'] ) || ( '' === $system_info ) || ( '' !== $system_info && false === $system_info['errors'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended
356 return;
357 }
358
359 $show_notice = true;
360
361 if ( true === $show_notice ) {
362 wp_enqueue_script( 'yith-system-info' );
363 ?>
364 <div id="yith-system-alert" class="notice notice-error is-dismissible" style="position: relative;">
365 <p>
366 <span class="yith-logo"><img src="<?php echo esc_attr( yith_plugin_fw_get_default_logo() ); ?>"/></span>
367 <b>
368 <?php esc_html_e( 'Warning!', 'yith-plugin-fw' ); ?>
369 </b><br/>
370 <?php
371 /* translators: %1$s open link tag, %2$s open link tag*/
372 printf( esc_html__( 'The system check has detected some compatibility issues on your installation.%1$sClick here%2$s to know more', 'yith-plugin-fw' ), '<a href="' . esc_url( add_query_arg( array( 'page' => $this->page ), admin_url( 'admin.php' ) ) ) . '">', '</a>' );
373 ?>
374 </p>
375 <span class="notice-dismiss"></span>
376
377 </div>
378 <?php
379 }
380 }
381
382 /**
383 * Get system information
384 *
385 * @return array
386 * @since 1.0.0
387 */
388 public function get_system_info() {
389 $tls = $this->get_tls_version();
390 $imagick_version = 'n/a';
391
392 // Get PHP version.
393 preg_match( '#^\d+(\.\d+)*#', PHP_VERSION, $match );
394 $php_version = $match[0];
395
396 // WP memory limit.
397 $wp_memory_limit = $this->memory_size_to_num( WP_MEMORY_LIMIT );
398 if ( function_exists( 'memory_get_usage' ) ) {
399 $wp_memory_limit = max( $wp_memory_limit, $this->memory_size_to_num( @ini_get( 'memory_limit' ) ) ); //phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
400 }
401
402 if ( class_exists( 'Imagick' ) && is_callable( array( 'Imagick', 'getVersion' ) ) ) {
403 preg_match( '/([0-9]+\.[0-9]+\.[0-9]+)/', Imagick::getVersion()['versionString'], $imatch );
404 $imagick_version = $imatch[0];
405 }
406
407 return apply_filters(
408 'yith_system_additional_check',
409 array(
410 'min_wp_version' => get_bloginfo( 'version' ),
411 'min_wc_version' => function_exists( 'WC' ) ? WC()->version : 'n/a',
412 'wp_memory_limit' => $wp_memory_limit,
413 'min_php_version' => $php_version,
414 'min_tls_version' => $tls,
415 'imagick_version' => $imagick_version,
416 'wp_cron_enabled' => ( ! ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON ) || apply_filters( 'yith_system_status_server_cron', false ) ),
417 'mbstring_enabled' => extension_loaded( 'mbstring' ),
418 'simplexml_enabled' => extension_loaded( 'simplexml' ),
419 'gd_enabled' => extension_loaded( 'gd' ) && function_exists( 'gd_info' ),
420 'iconv_enabled' => extension_loaded( 'iconv' ),
421 'opcache_enabled' => ini_get( 'opcache.save_comments' ),
422 'url_fopen_enabled' => ini_get( 'allow_url_fopen' ),
423 )
424 );
425 }
426
427 /**
428 * Get log file
429 *
430 * @return void
431 * @since 1.0.0
432 */
433 public function create_log_file() {
434 if ( ! current_user_can( 'manage_options' ) || ! isset( $_POST['nonce'], $_POST['file'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce'] ) ), 'yith-export-log' ) ) {
435 wp_send_json( array( 'file' => false ) );
436 exit;
437 }
438
439 try {
440
441 global $wp_filesystem;
442
443 if ( empty( $wp_filesystem ) ) {
444 require_once ABSPATH . '/wp-admin/includes/file.php';
445 WP_Filesystem();
446 }
447
448 $download_file = false;
449 $file_content = '';
450 $requested_file = sanitize_text_field( wp_unslash( $_POST['file'] ) );
451
452 switch ( $requested_file ) {
453 case 'error_log':
454 $file_content = $wp_filesystem->get_contents( ABSPATH . 'error_log' );
455 break;
456 case 'debug.log':
457 $file_content = $wp_filesystem->get_contents( WP_CONTENT_DIR . '/debug.log' );
458 break;
459 }
460
461 if ( '' !== $file_content ) {
462 $domain = str_replace( array( 'http://', 'https://' ), '', network_site_url() );
463 $hash = substr( wp_hash( $domain ), 0, 16 );
464 $file = wp_upload_dir()['basedir'] . '/log-' . $hash . '.txt';
465 $download_file = wp_upload_dir()['baseurl'] . '/log-' . $hash . '.txt';
466
467 $r = $wp_filesystem->put_contents( $file, $file_content );
468 }
469
470 wp_send_json( array( 'file' => $download_file ) );
471 } catch ( Exception $e ) {
472 wp_send_json( array( 'file' => false ) );
473 }
474 }
475
476 /**
477 * Convert size into number
478 *
479 * @param string $memory_size Memory size to convert.
480 *
481 * @return integer
482 * @since 1.0.0
483 */
484 public function memory_size_to_num( $memory_size ) {
485 $unit = strtoupper( substr( $memory_size, -1 ) );
486 $size = substr( $memory_size, 0, -1 );
487
488 $multiplier = array(
489 'P' => 5,
490 'T' => 4,
491 'G' => 3,
492 'M' => 2,
493 'K' => 1,
494 );
495
496 if ( isset( $multiplier[ $unit ] ) ) {
497 for ( $i = 1; $i <= $multiplier[ $unit ]; $i++ ) {
498 $size *= 1024;
499 }
500 }
501
502 return $size;
503 }
504
505 /**
506 * Format requirement value
507 *
508 * @param string $key Requirement Key.
509 * @param mixed $value Requirement value.
510 * @param string $icon Icon to display.
511 *
512 * @return string
513 * @since 1.0.0
514 */
515 public function format_requirement_value( $key, $value, $icon ) {
516
517 if ( strpos( $key, '_enabled' ) !== false ) {
518 $output = esc_attr( $value ) ? esc_html__( 'Enabled', 'yith-plugin-fw' ) : esc_html__( 'Disabled', 'yith-plugin-fw' );
519 } elseif ( 'wp_memory_limit' === $key ) {
520 $output = esc_html( size_format( $value ) );
521 } else {
522 $output = ( 'n/a' === $value ) ? esc_html__( 'N/A', 'yith-plugin-fw' ) : esc_attr( $value );
523 }
524
525 return '<span class="dashicons dashicons-' . $icon . '"></span> ' . $output;
526 }
527
528 /**
529 * Print error messages
530 *
531 * @param string $key Requirement key.
532 * @param array $item Requirement item.
533 * @param string $label Requirement label.
534 *
535 * @return string
536 * @since 1.0.0
537 */
538 public function print_error_messages( $key, $item, $label ) {
539 $errors = array();
540 foreach ( $item['errors'] as $plugin => $requirement ) {
541 if ( strpos( $key, '_enabled' ) !== false ) {
542 /* translators: %1$s plugin name, %2$s requirement name */
543 $errors[] = sprintf( esc_html__( '%1$s needs %2$s enabled', 'yith-plugin-fw' ), '<b>' . esc_attr( $plugin ) . '</b>', '<b>' . esc_attr( $label ) . '</b>' );
544 } elseif ( 'wp_memory_limit' === $key ) {
545 /* translators: %1$s plugin name, %2$s required memory amount */
546 $errors[] = sprintf( esc_html__( '%1$s needs at least %2$s of available memory', 'yith-plugin-fw' ), '<b>' . esc_attr( $plugin ) . '</b>', '<b>' . esc_html( size_format( $this->memory_size_to_num( $requirement ) ) ) . '</b>' );
547 } else {
548 /* translators: %1$s plugin name, %2$s version number */
549 $errors[] = sprintf( esc_html__( '%1$s needs at least %2$s version', 'yith-plugin-fw' ), '<b>' . esc_attr( $plugin ) . '</b>', '<b>' . esc_attr( $requirement ) . '</b>' );
550 }
551 }
552 switch ( $key ) {
553 case 'min_wp_version':
554 case 'min_wc_version':
555 $solution = esc_html__( 'Update it to the latest version in order to benefit of all new features and security updates.', 'yith-plugin-fw' );
556 break;
557 case 'min_php_version':
558 case 'min_tls_version':
559 $solution = esc_html__( 'Contact your hosting company in order to update it.', 'yith-plugin-fw' );
560 break;
561 case 'imagick_version':
562 if ( 'n/a' === $item['value'] ) {
563 $solution = esc_html__( 'Contact your hosting company in order to install it.', 'yith-plugin-fw' );
564 } else {
565 $solution = esc_html__( 'Contact your hosting company in order to update it.', 'yith-plugin-fw' );
566 }
567 break;
568 case 'wp_cron_enabled':
569 /* translators: %1$s code, %2$s file name */
570 $solution = sprintf( esc_html__( 'Remove %1$s from %2$s file', 'yith-plugin-fw' ), '<code>define( \'DISABLE_WP_CRON\', true );</code>', '<b>wp-config.php</b>' );
571 break;
572 case 'mbstring_enabled':
573 case 'simplexml_enabled':
574 case 'gd_enabled':
575 case 'iconv_enabled':
576 case 'opcache_enabled':
577 case 'url_fopen_enabled':
578 $solution = esc_html__( 'Contact your hosting company in order to enable it.', 'yith-plugin-fw' );
579 break;
580 case 'wp_memory_limit':
581 /* translators: %1$s opening link tag, %2$s closing link tag */
582 $solution = sprintf( esc_html__( 'Read more %1$shere%2$s or contact your hosting company in order to increase it.', 'yith-plugin-fw' ), '<a href="https://codex.wordpress.org/Editing_wp-config.php#Increasing_memory_allocated_to_PHP" target="_blank">', '</a>' );
583 break;
584 default:
585 $solution = esc_attr( apply_filters( 'yith_system_generic_message', '', $key, $item, $label ) );
586 }
587 ob_start()
588 ?>
589 <div class="yith-system-info__info-error">
590 <?php echo wp_kses_post( implode( '<br />', $errors ) ); ?>
591 <div class="yith-system-info__info-solution">
592 <?php echo wp_kses_post( $solution ); ?>
593 </div>
594 </div>
595 <?php
596
597 return ob_get_clean();
598 }
599
600 /**
601 * Print warning messages
602 *
603 * @param string $key Requirement Key.
604 *
605 * @return string
606 * @since 1.0.0
607 */
608 public function print_warning_messages( $key ) {
609 $warning = '';
610 switch ( $key ) {
611 case 'wp_memory_limit':
612 /* translators: %s recommended memory amount */
613 $warning .= sprintf( esc_html__( 'For optimal functioning of our plugins, we suggest setting at least %s of available memory', 'yith-plugin-fw' ), '<span class="warning">' . esc_html( size_format( $this->recommended_memory ) ) . '</span>' );
614 $warning .= '<br/>';
615 /* translators: %1$s opening link tag, %2$s closing link tag */
616 $warning .= sprintf( esc_html__( 'Read more %1$shere%2$s or contact your hosting company in order to increase it.', 'yith-plugin-fw' ), '<a href="https://codex.wordpress.org/Editing_wp-config.php#Increasing_memory_allocated_to_PHP" target="_blank">', '</a>' );
617 break;
618 case 'min_tls_version':
619 if ( ! function_exists( 'curl_init' ) ) {
620 /* translators: %1$s TLS label, %2$s cURL label */
621 $warning = sprintf( esc_html__( 'The system check cannot determine which %1$s version is installed because %2$s module is disabled. Ask your hosting company to enable it.', 'yith-plugin-fw' ), '<b>TLS</b>', '<b>cURL</b>' );
622 } else {
623 /* translators: %1$s TLS label */
624 $warning = sprintf( esc_html__( 'The system check cannot determine which %1$s version is installed due to a connection issue between your site and our server.', 'yith-plugin-fw' ), '<b>TLS</b>' );
625 }
626 break;
627 }
628
629 return $warning;
630 }
631
632 /**
633 * Retrieve the TLS Version
634 *
635 * @return string
636 * @since 3.5
637 */
638 public function get_tls_version() {
639 $tls = get_transient( 'yith-plugin-fw-system-status-tls-version' );
640
641 if ( ! $tls && apply_filters( 'yith_system_status_check_ssl', true ) ) {
642 $services = array(
643 array(
644 'url' => 'https://www.howsmyssl.com/a/check',
645 'string_to_remove' => 'TLS ',
646 'prop' => 'tls_version',
647 ),
648 array(
649 'url' => 'https://ttl-version.yithemes.workers.dev/',
650 'string_to_remove' => 'TLSv',
651 'prop' => 'tlsVersion',
652 ),
653 );
654 $params = array(
655 'sslverify' => false,
656 'timeout' => 60,
657 'headers' => array( 'Content-Type' => 'application/json' ),
658 );
659
660 foreach ( $services as $service ) {
661 $url = $service['url'];
662 $string_to_remove = $service['string_to_remove'];
663 $prop = $service['prop'];
664
665 $response = wp_remote_get( $url, $params );
666
667 if ( ! is_wp_error( $response ) && 200 === absint( $response['response']['code'] ) && 'OK' === $response['response']['message'] ) {
668 $body = json_decode( $response['body'] );
669 $version = $body && is_object( $body ) && property_exists( $body, $prop ) ? $body->{$prop} : false;
670 if ( $version ) {
671 $tls = str_replace( $string_to_remove, '', $version );
672 break;
673 }
674 }
675 }
676 $tls = ! ! $tls ? $tls : 'n/a';
677
678 set_transient( 'yith-plugin-fw-system-status-tls-version', $tls, 300 );
679 }
680
681 return ! ! $tls ? $tls : 'n/a';
682 }
683
684 /**
685 * Retrieve the output IP Address.
686 *
687 * @return string
688 * @since 3.5
689 */
690 public function get_output_ip() {
691 $ip = get_transient( 'yith-plugin-fw-system-status-output-ip' );
692
693 if ( ! $ip && apply_filters( 'yith_system_status_check_ip', true ) ) {
694 $url = 'https://ifconfig.co/ip';
695 $params = array(
696 'sslverify' => false,
697 'timeout' => 60,
698 );
699
700 $response = wp_remote_get( $url, $params );
701
702 if ( ! is_wp_error( $response ) && 200 === absint( $response['response']['code'] ) && 'OK' === $response['response']['message'] ) {
703 $body = $response['body'];
704
705 // Check for IPv4.
706 preg_match( '/((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])/', $body, $matches );
707 // Check for IPv6.
708 if ( empty( $matches ) ) {
709 preg_match( '/(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/', $body, $matches );
710 }
711
712 $ip = ! empty( $matches ) ? $matches[0] : 'n/a';
713 }
714
715 $ip = ! ! $ip ? $ip : 'n/a';
716
717 set_transient( 'yith-plugin-fw-system-status-output-ip', $ip, 300 );
718 }
719
720 return ! ! $ip ? $ip : 'n/a';
721 }
722
723 /**
724 * Retrieve plugin-fw info, such as version and loaded-by.
725 *
726 * @return array
727 */
728 public function get_plugin_fw_info() {
729 $version = yith_plugin_fw_get_version();
730 $loaded_by = basename( dirname( YIT_CORE_PLUGIN_PATH ) );
731 $loaded_by_init = trailingslashit( dirname( YIT_CORE_PLUGIN_PATH ) ) . 'init.php';
732 if ( file_exists( $loaded_by_init ) ) {
733 $plugin_data = get_plugin_data( $loaded_by_init );
734 $loaded_by = $plugin_data['Name'] ?? $loaded_by;
735 }
736
737 return compact( 'version', 'loaded_by' );
738 }
739
740 /**
741 * Retrieve database info, such as MySQL version and database size.
742 *
743 * @return array
744 */
745 public function get_database_info() {
746
747 global $wpdb;
748
749 $database_version = $wpdb->get_row( //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
750 'SELECT
751 @@GLOBAL.version_comment AS string,
752 @@GLOBAL.version AS number',
753 ARRAY_A
754 );
755
756 $tables = array();
757 $database_size = array();
758
759 // It is not possible to get the database name from some classes that replace wpdb (e.g., HyperDB)
760 // and that is why this if condition is needed.
761 if ( defined( 'DB_NAME' ) ) {
762 $database_table_information = $wpdb->get_results( //phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
763 $wpdb->prepare(
764 "SELECT
765 table_name AS 'name',
766 engine AS 'engine',
767 round( ( data_length / 1024 / 1024 ), 2 ) 'data',
768 round( ( index_length / 1024 / 1024 ), 2 ) 'index',
769 round( ( data_free / 1024 / 1024 ), 2 ) 'free'
770 FROM information_schema.TABLES
771 WHERE table_schema = %s
772 ORDER BY name ASC;",
773 DB_NAME
774 )
775 );
776
777 $database_size = array(
778 'data' => 0,
779 'index' => 0,
780 'free' => 0,
781 );
782
783 $site_tables_prefix = $wpdb->get_blog_prefix( get_current_blog_id() );
784 $global_tables = $wpdb->tables( 'global', true );
785 foreach ( $database_table_information as $table ) {
786 // Only include tables matching the prefix of the current site, this is to prevent displaying all tables on a MS install not relating to the current.
787 if ( is_multisite() && 0 !== strpos( $table->name, $site_tables_prefix ) && ! in_array( $table->name, $global_tables, true ) ) {
788 continue;
789 }
790
791 $tables[ $table->name ] = array(
792 'data' => $table->data,
793 'index' => $table->index,
794 'free' => $table->free,
795 'engine' => $table->engine,
796 );
797
798 $database_size['data'] += $table->data;
799 $database_size['index'] += $table->index;
800 $database_size['free'] += $table->free;
801 }
802 }
803
804 return apply_filters(
805 'yith_database_info',
806 array(
807 'mysql_version' => $database_version['number'],
808 'mysql_version_string' => $database_version['string'],
809 'database_tables' => $tables,
810 'database_size' => $database_size,
811 )
812 );
813 }
814 }
815 }
816
817 if ( ! function_exists( 'YITH_System_Status' ) ) {
818 /**
819 * Single instance of YITH_System_Status
820 *
821 * @return YITH_System_Status
822 * @since 1.0
823 */
824 function YITH_System_Status() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid, Universal.Files.SeparateFunctionsFromOO.Mixed
825 return YITH_System_Status::instance();
826 }
827 }
828
829 YITH_System_Status();
830