PluginProbe
WP Server Health Stats / 1.7.7
WP Server Health Stats v1.7.7
1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.0 1.6.1 1.6.10 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.6.9.1 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 All 63 releases
wp-server-stats / wp-server-stats.php

wp-server-stats.php in WP Server Health Stats 1.7.7, at wp-server-stats.php

1,578 lines 68.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: WP Server Stats
4 Plugin URI: https://wordpress.org/plugins/wp-server-stats/
5 Description: Show up the memory limit and current memory usage in the dashboard and admin footer
6 Author: Saumya Majumder
7 Author URI: https://isaumya.com/
8 Version: 1.7.7
9 Text Domain: wp-server-stats
10 License: GPLv2 or later
11 License URI: http://www.gnu.org/licenses/gpl-2.0.html
12 */
13
14 /*
15 Copyright 2012-2024 by Saumya Majumder
16
17 This program is free software; you can redistribute it and/or modify
18 it under the terms of the GNU General Public License as published by
19 the Free Software Foundation; either version 2 of the License, or
20 (at your option) any later version.
21
22 This program is distributed in the hope that it will be useful,
23 but WITHOUT ANY WARRANTY; without even the implied warranty of
24 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 GNU General Public License for more details.
26
27 You should have received a copy of the GNU General Public License
28 along with this program; if not, write to the Free Software
29 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30 */
31
32 defined('ABSPATH') or die('No script kiddies please!');
33
34 /* Define Constants */
35 define('WP_SERVER_STATS_BASE', plugin_basename(__FILE__));
36
37 if (is_admin()) {
38
39 if (!class_exists("wp_server_stats")) {
40
41 class wp_server_stats
42 {
43
44 var $memory = false;
45 // declaring the protected variables
46 protected $refresh_interval, $memcache_host, $memcache_port, $use_ipapi_pro, $ipapi_pro_key, $bg_color_good, $bg_color_average, $bg_color_bad, $footer_text_color, $server_load_nonce;
47
48 public function __construct()
49 {
50 add_action('init', array(&$this, 'check_limit'));
51 add_action('wp_dashboard_setup', array(&$this, 'add_dashboard'));
52 add_filter('admin_footer_text', array(&$this, 'add_footer'));
53 add_action('admin_enqueue_scripts', array(&$this, 'load_admin_scripts'));
54 add_action('wp_ajax_process_ajax', array(&$this, 'process_ajax'));
55
56 // Adding the `Settings Option beside Edit & Deactivation link inside WP Dashboard's Installed Plugin Page
57 add_filter('plugin_action_links_' . WP_SERVER_STATS_BASE, array($this, 'add_action_link'));
58
59 // Purge Cahce Admin bar Section
60 add_action('admin_bar_menu', array(&$this, 'add_admin_bar_menu_item'), 100);
61 add_action('wp_ajax_wpss_cache_purge', array(&$this, 'wpss_cache_purge_callback'));
62
63 /* First lets initialize an admin settings link inside WP dashboard */
64 /* It will show under the SETTINGS section */
65 add_action('admin_menu', array($this, 'create_admin_menu'));
66 // Register page options
67 add_action('admin_init', array($this, 'register_page_options'));
68 // Welcome Donate Notice
69 add_action('wp_ajax_handle_wpss_donate_notice', array($this, 'handle_wpss_donate_notice'));
70 add_action('wp_ajax_nopriv_handle_wpss_donate_notice', array($this, 'handle_wpss_donate_notice'));
71 // Admin notice
72 add_action('admin_notices', array($this, 'show_admin_notice'));
73
74 $this->memory = array();
75 //Create the nonce to be used by process_ajax()
76 $this->server_load_nonce = wp_create_nonce('wpss_slc_nonce');
77 }
78
79 public function add_admin_bar_menu_item($admin_bar)
80 {
81 if( defined( 'WPSERVERSTATS_ADMINBAR_DISABLE' ) ) {
82 if( constant( 'WPSERVERSTATS_ADMINBAR_DISABLE' ) ) {
83 // Do nothing as the user don't need the purge cache option
84 } else {
85 $admin_bar->add_menu(
86 array(
87 'id' => 'wpss-cache-purge',
88 'title' => 'Purge Cache - WP Server Stats',
89 'href' => '#'
90 )
91 );
92 }
93 } else {
94 $admin_bar->add_menu(
95 array(
96 'id' => 'wpss-cache-purge',
97 'title' => 'Purge Cache - WP Server Stats',
98 'href' => '#'
99 )
100 );
101 }
102 }
103
104 public function wpss_cache_purge_callback()
105 {
106 if (!isset($_POST['wpss_nonce']) || !wp_verify_nonce($_POST['wpss_nonce'], 'wpss_slc_nonce')) {
107 die('Permission Check Failed');
108 }
109
110 global $wpdb; /* this is how you get access to the database */
111 /* You cache purge logic should go here. */
112 delete_option('wpss_db_advanced_info');
113 delete_site_option('wpss_db_advanced_info');
114
115 // Delete transients
116 delete_transient('wpss_server_location');
117 delete_transient('wpss_cpu_count');
118 delete_transient('wpss_cpu_core_count');
119 delete_transient('wpss_server_os');
120 delete_transient('wpss_db_software');
121 delete_transient('wpss_db_version');
122 delete_transient('wpss_db_max_connection');
123 delete_transient('wpss_db_max_packet_size');
124 delete_transient('wpss_db_disk_usage');
125 delete_transient('wpss_db_index_disk_usage');
126 delete_transient('wpss_php_max_upload_size');
127 delete_transient('wpss_php_max_post_size');
128 delete_transient('wpss_total_ram');
129
130 // Delete option for multisite
131 delete_site_transient('wpss_server_location');
132 delete_site_transient('wpss_cpu_count');
133 delete_site_transient('wpss_cpu_core_count');
134 delete_site_transient('wpss_server_os');
135 delete_site_transient('wpss_db_software');
136 delete_site_transient('wpss_db_version');
137 delete_site_transient('wpss_db_max_connection');
138 delete_site_transient('wpss_db_max_packet_size');
139 delete_site_transient('wpss_db_disk_usage');
140 delete_site_transient('wpss_db_index_disk_usage');
141 delete_site_transient('wpss_php_max_upload_size');
142 delete_site_transient('wpss_php_max_post_size');
143
144 $response = "WP Server Stats Cache has been purged successfully!";
145 echo $response;
146 wp_die(); /* this is required to terminate immediately and return a proper response */
147 }
148
149 public function check_limit()
150 {
151 $memory_limit = ini_get('memory_limit');
152 if (preg_match('/^(\d+)(.)$/', $memory_limit, $matches)) {
153 if ($matches[2] == 'G') {
154 $memory_limit = $matches[1] . ' ' . 'GB'; // nnnG -> nnn GB
155 } else if ($matches[2] == 'M') {
156 $memory_limit = $matches[1] . ' ' . 'MB'; // nnnM -> nnn MB
157 } else if ($matches[2] == 'K') {
158 $memory_limit = $matches[1] . ' ' . 'KB'; // nnnK -> nnn KB
159 } else if ($matches[2] == 'T') {
160 $memory_limit = $matches[1] . ' ' . 'TB'; // nnnT -> nnn TB
161 } else if ($matches[2] == 'P') {
162 $memory_limit = $matches[1] . ' ' . 'PB'; // nnnP -> nnn PB
163 }
164 }
165 return $memory_limit;
166 }
167
168 public function format_filesize($bytes)
169 {
170 if (($bytes / pow(1024, 5)) > 1) {
171 return number_format_i18n(($bytes / pow(1024, 5)), 0) . ' ' . __('PB', 'wp-server-stats');
172 } elseif (($bytes / pow(1024, 4)) > 1) {
173 return number_format_i18n(($bytes / pow(1024, 4)), 0) . ' ' . __('TB', 'wp-server-stats');
174 } elseif (($bytes / pow(1024, 3)) > 1) {
175 return number_format_i18n(($bytes / pow(1024, 3)), 0) . ' ' . __('GB', 'wp-server-stats');
176 } elseif (($bytes / pow(1024, 2)) > 1) {
177 return number_format_i18n(($bytes / pow(1024, 2)), 0) . ' ' . __('MB', 'wp-server-stats');
178 } elseif ($bytes / 1024 > 1) {
179 return number_format_i18n($bytes / 1024, 0) . ' ' . __('KB', 'wp-server-stats');
180 } elseif ($bytes >= 0) {
181 return number_format_i18n($bytes, 0) . ' ' . __('bytes', 'wp-server-stats');
182 } else {
183 return __('Unknown', 'wp-server-stats');
184 }
185 }
186
187 public function format_filesize_kB($kiloBytes)
188 {
189 if (($kiloBytes / pow(1024, 4)) > 1) {
190 return number_format_i18n(($kiloBytes / pow(1024, 4)), 0) . ' ' . __('PB', 'wp-server-stats');
191 } elseif (($kiloBytes / pow(1024, 3)) > 1) {
192 return number_format_i18n(($kiloBytes / pow(1024, 3)), 0) . ' ' . __('TB', 'wp-server-stats');
193 } elseif (($kiloBytes / pow(1024, 2)) > 1) {
194 return number_format_i18n(($kiloBytes / pow(1024, 2)), 0) . ' ' . __('GB', 'wp-server-stats');
195 } elseif (($kiloBytes / 1024) > 1) {
196 return number_format_i18n($kiloBytes / 1024, 0) . ' ' . __('MB', 'wp-server-stats');
197 } elseif ($kiloBytes >= 0) {
198 return number_format_i18n($kiloBytes / 1, 0) . ' ' . __('KB', 'wp-server-stats');
199 } else {
200 return __('Unknown', 'wp-server-stats');
201 }
202 }
203
204 public function format_php_size($size)
205 {
206 if (!is_numeric($size)) {
207 if (strpos($size, 'M') !== false) {
208 $size = intval($size) * 1024 * 1024;
209 } elseif (strpos($size, 'K') !== false) {
210 $size = intval($size) * 1024;
211 } elseif (strpos($size, 'G') !== false) {
212 $size = intval($size) * 1024 * 1024 * 1024;
213 }
214 }
215 return is_numeric($size) ? $this->format_filesize($size) : $size;
216 }
217
218 public function check_memory_limit_cal()
219 {
220 return (int)ini_get('memory_limit');
221 }
222
223 public function check_server_ip()
224 {
225 return trim(gethostbyname(gethostname()));
226 }
227
228 public function check_server_location()
229 {
230 $this->fetch_data();
231 $ipapi_pro_key = trim($this->ipapi_pro_key);
232 //get the server ip
233 $ip = $this->check_server_ip();
234
235 $server_location = get_transient('wpss_server_location');
236
237 if ($server_location === false) {
238 // lets validate the ip
239 if ($this->validate_ip_address($ip)) {
240 if ($this->use_ipapi_pro == 'Yes' && !empty($ipapi_pro_key)) { // Use the pro version of IP-API query
241 $query = @unserialize( file_get_contents('https://pro.ip-api.com/php/' . $ip . '?key=' . $ipapi_pro_key), [ 'allowed_classes' => false ] );
242 } else { // Use the free version of IP-API
243 $query = @unserialize( file_get_contents('http://ip-api.com/php/' . $ip), [ 'allowed_classes' => false ] );
244 }
245 if ($query && $query['status'] == 'success') {
246 $server_location = esc_html( $query['city'] . ', ' . $query['country'] );
247 set_transient('wpss_server_location', $server_location, WEEK_IN_SECONDS);
248 } else {
249 if (empty($query['message'])) {
250 if ($this->use_ipapi_pro == 'Yes') {
251 $server_location = 'You\'ve provided a wrong IP-API Pro Key';
252 } else {
253 $server_location = esc_html( $query['status'] );
254 }
255 } else {
256 $server_location = esc_html( $query['message'] );
257 }
258 }
259 } else {
260 $server_location = "ERROR IP096T";
261 }
262 }
263
264 return $server_location;
265 }
266
267 //function to validate IP address
268 public function validate_ip_address($ip)
269 {
270 if (!filter_var($ip, FILTER_VALIDATE_IP) === false) {
271 return true; // $ip is a valid IP address
272 } else {
273 return false; // $ip is NOT a valid IP address
274 }
275 }
276
277 public function isShellEnabled()
278 {
279 /*Check if shell_exec() is enabled on this server*/
280 if (function_exists('shell_exec') && !in_array('shell_exec', array_map('trim', explode(', ', ini_get('disable_functions'))))) {
281 /*If enabled, check if shell_exec() actually have execution power*/
282 $returnVal = shell_exec('cat /proc/cpuinfo');
283 if (!empty($returnVal)) {
284 return true;
285 } else {
286 return false;
287 }
288 } else {
289 return false;
290 }
291 }
292
293 public function check_cpu_count()
294 {
295
296 $cpu_count = get_transient('wpss_cpu_count');
297
298 if ($cpu_count === false) {
299 if ($this->isShellEnabled()) {
300 $cpu_count = shell_exec('cat /proc/cpuinfo |grep "physical id" | sort | uniq | wc -l');
301 set_transient('wpss_cpu_count', $cpu_count, WEEK_IN_SECONDS);
302 } else {
303 $cpu_count = 'ERROR EXEC096T';
304 }
305 }
306
307 return $cpu_count;
308 }
309
310 public function check_core_count()
311 {
312
313 $cpu_core_count = get_transient('wpss_cpu_core_count');
314
315 if ($cpu_core_count === false) {
316 if ($this->isShellEnabled()) {
317 $cpu_core_count = shell_exec("echo \"$((`cat /proc/cpuinfo | grep cores | grep -o -E '[0-9]+' | uniq` * `cat /proc/cpuinfo |grep 'physical id' | sort | uniq | wc -l`))\"");
318 set_transient('wpss_cpu_core_count', $cpu_core_count, WEEK_IN_SECONDS);
319 } else {
320 $cpu_core_count = 'ERROR EXEC096T';
321 }
322 }
323
324 return $cpu_core_count;
325 }
326
327 public function check_total_ram()
328 {
329 $total_ram = get_transient('wpss_total_ram');
330
331 if ($total_ram === false) {
332 if ($this->isShellEnabled()) {
333 $total_ram = shell_exec("grep -w 'MemTotal' /proc/meminfo | grep -o -E '[0-9]+'");
334 set_transient('wpss_total_ram', $total_ram, WEEK_IN_SECONDS);
335 } else {
336 $total_ram = 'ERROR EXEC096T';
337 }
338 }
339
340 return trim($total_ram);
341 }
342
343 /**
344 * @return int|null|string
345 **/
346 public function check_ram_cache() {
347 if ($this->isShellEnabled()) {
348 $ram_cache = shell_exec("grep -w 'Cached' /proc/meminfo | grep -o -E '[0-9]+'");
349 } else {
350 $ram_cache= 'ERROR EXEC096T';
351 }
352
353 return trim($ram_cache);
354 }
355
356 /**
357 * @return int|null|string
358 **/
359 public function check_ram_buffer() {
360 if ($this->isShellEnabled()) {
361 $ram_buffer = shell_exec("grep -w 'Buffers' /proc/meminfo | grep -o -E '[0-9]+'");
362 } else {
363 $ram_buffer= 'ERROR EXEC096T';
364 }
365
366 return trim($ram_buffer);
367 }
368
369 public function check_free_ram()
370 {
371 if ($this->isShellEnabled()) {
372 $free_ram = shell_exec("grep -w 'MemFree' /proc/meminfo | grep -o -E '[0-9]+'");
373
374 if( !is_null( $this->check_ram_cache() ) || !is_null( $this->check_ram_buffer() ) ) {
375 $ram_cache = is_null( $this->check_ram_cache() ) ? 0 : (int) $this->check_ram_cache();
376 $ram_buffer = is_null( $this->check_ram_buffer() ) ? 0 : (int) $this->check_ram_buffer();
377 $free_ram_final = (int) $free_ram + $ram_cache + $ram_buffer;
378 } else {
379 $free_ram_final = $free_ram;
380 }
381 } else {
382 $free_ram_final = 'ERROR EXEC096T';
383 }
384
385 return trim($free_ram_final);
386 }
387
388 public function server_os()
389 {
390
391 $server_os = get_transient('wpss_server_os');
392
393 if ($server_os === false) {
394 $os_detail = php_uname();
395 $just_os_name = explode(" ", trim($os_detail));
396 $server_os = $just_os_name[0];
397 set_transient('wpss_server_os', $server_os, WEEK_IN_SECONDS);
398 }
399
400 return $server_os;
401 }
402
403 public function database_software()
404 {
405
406 $db_software = get_transient('wpss_db_software');
407
408 if ($db_software === false) {
409 global $wpdb;
410 $db_software_query = $wpdb->get_row("SHOW VARIABLES LIKE 'version_comment'");
411 $db_software_dump = $db_software_query->Value;
412 if (!empty($db_software_dump)) {
413 $db_soft_array = explode(" ", trim($db_software_dump));
414 $db_software = $db_soft_array[0];
415 set_transient('wpss_db_software', $db_software, WEEK_IN_SECONDS);
416 } else {
417 $db_software = __('N/A', 'wp-server-stats');
418 }
419 }
420
421 return $db_software;
422 }
423
424 public function database_version()
425 {
426
427 $db_version = get_transient('wpss_db_version');
428
429 if ($db_version === false) {
430 global $wpdb;
431 $db_version_dump = $wpdb->get_var("SELECT VERSION() AS version from DUAL");
432 if (preg_match('/\d+(?:\.\d+)+/', $db_version_dump, $matches)) {
433 $db_version = $matches[0]; //returning the first match
434 set_transient('wpss_db_version', $db_version, WEEK_IN_SECONDS);
435 } else {
436 $db_version = __('N/A', 'wp-server-stats');
437 }
438 }
439
440 return $db_version;
441 }
442
443 public function database_max_no_connection()
444 {
445
446 $db_max_connection = get_transient('wpss_db_max_connection');
447
448 if ($db_max_connection === false) {
449 global $wpdb;
450 $connection_max_query = $wpdb->get_row("SHOW VARIABLES LIKE 'max_connections'");
451 $db_max_connection = $connection_max_query->Value;
452 if (empty($db_max_connection)) {
453 $db_max_connection = __('N/A', 'wp-server-stats');
454 } else {
455 $db_max_connection = number_format_i18n($db_max_connection, 0);
456 set_transient('wpss_db_max_connection', $db_max_connection, WEEK_IN_SECONDS);
457 }
458 }
459
460 return $db_max_connection;
461 }
462
463 public function database_max_packet_size()
464 {
465
466 $db_max_packet_size = get_transient('wpss_db_max_packet_size');
467
468 if ($db_max_packet_size === false) {
469 global $wpdb;
470 $packet_max_query = $wpdb->get_row("SHOW VARIABLES LIKE 'max_allowed_packet'");
471 $db_max_packet_size = $packet_max_query->Value;
472 if (empty($db_max_packet_size)) {
473 $db_max_packet_size = __('N/A', 'wp-server-stats');
474 } else {
475 $db_max_packet_size = $this->format_filesize($db_max_packet_size);
476 set_transient('wpss_db_max_packet_size', $db_max_packet_size, WEEK_IN_SECONDS);
477 }
478 }
479
480 return $db_max_packet_size;
481 }
482
483 public function database_disk_usage()
484 {
485
486 $db_disk_usage = get_transient('wpss_db_disk_usage');
487
488 if ($db_disk_usage === false) {
489 global $wpdb;
490 $db_disk_usage = 0;
491 $tablesstatus = $wpdb->get_results("SHOW TABLE STATUS");
492 foreach ($tablesstatus as $tablestatus) {
493 $db_disk_usage += $tablestatus->Data_length;
494 }
495 if (empty($db_disk_usage)) {
496 $db_disk_usage = __('N/A', 'wp-server-stats');
497 } else {
498 $db_disk_usage = $this->format_filesize($db_disk_usage);
499 set_transient('wpss_db_disk_usage', $db_disk_usage, WEEK_IN_SECONDS);
500 }
501 }
502
503 return $db_disk_usage;
504 }
505
506 public function index_disk_usage()
507 {
508
509 $db_index_disk_usage = get_transient('wpss_db_index_disk_usage');
510
511 if ($db_index_disk_usage === false) {
512 global $wpdb;
513 $db_index_disk_usage = 0;
514 $tablesstatus = $wpdb->get_results("SHOW TABLE STATUS");
515 foreach ($tablesstatus as $tablestatus) {
516 $db_index_disk_usage += $tablestatus->Index_length;
517 }
518 if (empty($db_index_disk_usage)) {
519 $db_index_disk_usage = __('N/A', 'wp-server-stats');
520 } else {
521 $db_index_disk_usage = $this->format_filesize($db_index_disk_usage);
522 set_transient('wpss_db_index_disk_usage', $db_index_disk_usage, WEEK_IN_SECONDS);
523 }
524 }
525
526 return $db_index_disk_usage;
527 }
528
529 public function php_max_upload_size()
530 {
531
532 $php_max_upload_size = get_transient('wpss_php_max_upload_size');
533
534 if ($php_max_upload_size === false) {
535 if (ini_get('upload_max_filesize')) {
536 $php_max_upload_size = ini_get('upload_max_filesize');
537 $php_max_upload_size = $this->format_php_size($php_max_upload_size);
538 set_transient('wpss_php_max_upload_size', $php_max_upload_size, WEEK_IN_SECONDS);
539 } else {
540 $php_max_upload_size = __('N/A', 'wp-server-stats');
541 }
542 }
543
544 return $php_max_upload_size;
545 }
546
547 public function php_max_post_size()
548 {
549
550 $php_max_post_size = get_transient('wpss_php_max_post_size');
551
552 if ($php_max_post_size === false) {
553 if (ini_get('post_max_size')) {
554 $php_max_post_size = ini_get('post_max_size');
555 $php_max_post_size = $this->format_php_size($php_max_post_size);
556 set_transient('wpss_php_max_post_size', $php_max_post_size, WEEK_IN_SECONDS);
557 } else {
558 $php_max_post_size = __('N/A', 'wp-server-stats');
559 }
560 }
561
562 return $php_max_post_size;
563 }
564
565 public function php_max_execution_time()
566 {
567 if (ini_get('max_execution_time')) {
568 $max_execute = ini_get('max_execution_time');
569 } else {
570 $max_execute = __('N/A', 'wp-server-stats');
571 }
572 return $max_execute;
573 }
574
575 public function php_short_tag()
576 {
577 if (ini_get('short_open_tag')) {
578 $short_tag = __('On', 'wp-server-stats');
579 } else {
580 $short_tag = __('Off', 'wp-server-stats');
581 }
582 return $short_tag;
583 }
584
585 public function load_admin_scripts()
586 {
587 /* CSS Calls */
588 wp_enqueue_style('flipclock', plugin_dir_url(__FILE__) . 'assets/css/flipclock.min.css', array(), '0.7.3');
589 wp_enqueue_style('wp-server-stats-admin', plugin_dir_url(__FILE__) . 'assets/css/wp-server-stats-admin.min.css', array(), '1.0.0');
590 // CSS rules for Color Picker
591 wp_enqueue_style('wp-color-picker');
592
593 /* JS Calls */
594 wp_register_script('server-load-check-ajax', plugin_dir_url(__FILE__) . 'assets/js/server-load-check.min.js', array('jquery', 'wp-color-picker'), '2.1.0', true);
595 wp_enqueue_script('server-load-check-ajax');
596 wp_localize_script('server-load-check-ajax', 'server_load_check_vars', array(
597 'server_load_check_nonce' => $this->server_load_nonce
598 ));
599 wp_register_script('flipclock', plugin_dir_url(__FILE__) . 'assets/js/flipclock.min.js', array('jquery'), '0.7.3', true);
600 wp_enqueue_script('flipclock');
601 }
602
603 public function process_ajax()
604 {
605 if (!isset($_POST['wpss_nonce']) || !wp_verify_nonce($_POST['wpss_nonce'], 'wpss_slc_nonce')) {
606 die('Permission Check Failed');
607 }
608
609 /* Let's call the fetch data function */
610 $this->fetch_data();
611
612 /* If Shell is enablelled then execute the CPU Load, Memory Load, RAM Load and Uptime */
613 if ($this->isShellEnabled()) {
614 $cpu_load = trim(shell_exec("echo $((`ps aux|awk 'NR > 0 { s +=$3 }; END {print s}'| cut -d . -f 1` / `cat /proc/cpuinfo | grep cores | grep -o '[0-9]' | wc -l`))"));
615 $memory_usage_MB = function_exists('memory_get_usage') ? round(memory_get_usage() / 1024 / 1024, 2) : 0;
616 $memory_usage_pos = round((($memory_usage_MB / (int)$this->check_memory_limit_cal()) * 100), 0);
617 $total_ram_server = (is_numeric($this->check_total_ram()) ? (int) $this->check_total_ram() : 0);
618 $free_ram_server = (is_numeric($this->check_free_ram()) ? (int) $this->check_free_ram() : 0);
619 $free_ram_server_formatted = (is_numeric($free_ram_server) ? $this->format_filesize_kB($free_ram_server) : "0 KB");
620 $used_ram_server = ($total_ram_server - $free_ram_server);
621 $used_ram_server_formatted = (is_numeric($used_ram_server) ? $this->format_filesize_kB($used_ram_server) : "0 KB");
622 $ram_usage_pos = round((($used_ram_server / $total_ram_server) * 100), 0);
623
624 $uptime = trim(shell_exec("cut -d. -f1 /proc/uptime"));
625 $json_out = array(
626 'cpu_load' => $cpu_load,
627 'memory_usage_MB' => $memory_usage_MB,
628 'memory_usage_pos' => $memory_usage_pos,
629 'total_ram' => $total_ram_server,
630 'free_ram' => $free_ram_server_formatted,
631 'used_ram' => $used_ram_server_formatted,
632 'ram_usage_pos' => $ram_usage_pos,
633 'uptime' => $uptime,
634 'refresh_interval' => $this->refresh_interval,
635 'bg_color_good' => $this->bg_color_good,
636 'bg_color_average' => $this->bg_color_average,
637 'bg_color_bad' => $this->bg_color_bad
638 );
639 echo json_encode($json_out);
640 /* Otherwise just run the memory load check */
641 } else {
642 $memory_usage_MB = function_exists('memory_get_usage') ? round(memory_get_usage() / 1024 / 1024, 2) : 0;
643 $memory_usage_pos = round($memory_usage_MB / (int)$this->check_memory_limit_cal() * 100, 0);
644 $json_out = array(
645 'cpu_load' => null,
646 'memory_usage_MB' => $memory_usage_MB,
647 'memory_usage_pos' => $memory_usage_pos,
648 'uptime' => null,
649 'refresh_interval' => $this->refresh_interval,
650 'bg_color_good' => $this->bg_color_good,
651 'bg_color_average' => $this->bg_color_average,
652 'bg_color_bad' => $this->bg_color_bad
653 );
654 echo json_encode($json_out);
655 }
656 die();
657 }
658
659 public function dashboard_output()
660 {
661 if (current_user_can('manage_options')) :
662 ?>
663 <ul>
664 <li><strong><?php _e('Server OS', 'wp-server-stats'); ?></strong> : <span><?php echo $this->server_os(); ?>&nbsp;/&nbsp;<?php echo (PHP_INT_SIZE * 8) . __('Bit OS', 'wp-server-stats'); ?></span></li>
665 <li><strong><?php _e('Server Software', 'wp-server-stats'); ?></strong> : <span><?php echo $_SERVER['SERVER_SOFTWARE']; ?></span></li>
666 <li><strong><?php _e('Server IP', 'wp-server-stats'); ?></strong> : <span><?php echo ($this->validate_ip_address($this->check_server_ip()) ? $this->check_server_ip() : "ERROR IP096T"); ?></span></li>
667 <li><strong><?php _e('Server Port', 'wp-server-stats'); ?></strong> : <span><?php echo $_SERVER['SERVER_PORT']; ?></span></li>
668 <li><strong><?php _e('Server Location', 'wp-server-stats'); ?></strong> : <span><?php echo $this->check_server_location(); ?></span></li>
669 <li><strong><?php _e('Server Hostname', 'wp-server-stats'); ?></strong> : <span><?php echo gethostname(); ?></span></li>
670 <li><strong><?php _e('Site\'s Document Root', 'wp-server-stats'); ?></strong> : <span><?php echo $_SERVER['DOCUMENT_ROOT'] . '/'; ?></span></li>
671 <li><strong><?php _e('Memcached Enabled', 'wp-server-stats'); ?></strong> : <span><?php echo (class_exists('Memcache') ? __('Yes', 'wp-sever-stats') : __('No', 'wp-server-stats')); ?></span></li>
672 <?php if ($this->isShellEnabled()) : ?>
673 <li><strong><?php _e('Total CPUs', 'wp-server-stats'); ?></strong> : <span><?php echo $this->check_cpu_count() . ' / ' . $this->check_core_count() . __('Cores', 'wp-server-stats'); ?></span></li>
674 <li><strong><?php _e('Total RAM', 'wp-server-stats'); ?></strong> : <span><?php echo (is_numeric($this->check_total_ram()) ? $this->format_filesize_kB($this->check_total_ram()) : $this->check_total_ram()); ?></span></li>
675 <li><strong><?php _e('Real Time Free RAM', 'wp-server-stats'); ?></strong> : <span id="realtime_free_ram"></span></li>
676 <li><strong><?php _e('Real Time RAM Usage', 'wp-server-stats'); ?></strong> : <span id="realtime_ram_usage"></span></li>
677 <?php endif; ?>
678 <ul>
679 <?php if ($this->isShellEnabled()) : ?>
680 <div class="progressbar">
681 <div style="border:1px solid #DDDDDD; background-color:#F9F9F9; border-color: rgb(223, 223, 223); box-shadow: 0px 1px 0px rgb(255, 255, 255) inset; border-radius: 3px;">
682 <div id="ram-usage-upper-div" style="padding: 0px; border-width:0px; color:#FFFFFF;text-align:right; border-color: rgb(223, 223, 223); box-shadow: 0px 1px 0px rgb(255, 255, 255) inset; border-radius: 3px; margin-top: -1px;">
683 <div id="ram-usage" style="padding:2px;"></div>
684 </div>
685 </div>
686 </div>
687
688 <span style="line-height: 2.5em;"><strong><?php _e('Real Time CPU Load', 'wp-server-stats') ?>:</strong></span>
689 <div class="progressbar">
690 <div style="border:1px solid #DDDDDD; background-color:#F9F9F9; border-color: rgb(223, 223, 223); box-shadow: 0px 1px 0px rgb(255, 255, 255) inset; border-radius: 3px;">
691 <div id="server-load-upper-div" style="padding: 0px; border-width:0px; color:#FFFFFF;text-align:right; border-color: rgb(223, 223, 223); box-shadow: 0px 1px 0px rgb(255, 255, 255) inset; border-radius: 3px; margin-top: -1px;">
692 <div id="server-load" style="padding:2px;"></div>
693 </div>
694 </div>
695 </div>
696 <?php endif; ?>
697 <?php if (class_exists('Memcache')) : ?>
698 <div class="wpss_show_buttons content-center">
699 <a href="<?php echo get_admin_url(); ?>admin.php?page=wpss_memcache_info" title="Checkout Memcached Info" class="wpss_btn button button-small"><?php _e('Check More Memcached Info', 'wp-server-stats'); ?></a>
700 </div>
701 <?php endif; ?>
702 <hr />
703 <ul>
704 <li><strong><?php _e('Database Software', 'wp-server-stats'); ?></strong> : <span><?php echo $this->database_software(); ?></span></li>
705 <li><strong><?php _e('Database Version', 'wp-server-stats'); ?></strong> : <span><?php echo $this->database_version(); ?></span></li>
706 <li><strong><?php _e('Maximum No. of Connections', 'wp-server-stats'); ?></strong> : <span><?php echo $this->database_max_no_connection(); ?></span></li>
707 <li><strong><?php _e('Maximum Packet Size', 'wp-server-stats'); ?></strong> : <span><?php echo $this->database_max_packet_size(); ?></span></li>
708 <li><strong><?php _e('Database Disk Usage', 'wp-server-stats'); ?></strong> : <span><?php echo $this->database_disk_usage(); ?></span></li>
709 <li><strong><?php _e('Index Disk Usage', 'wp-server-stats'); ?></strong> : <span><?php echo $this->index_disk_usage(); ?></span></li>
710 </ul>
711 <div class="wpss_show_buttons content-center">
712 <a href="<?php echo get_admin_url(); ?>admin.php?page=wpss_sql_info" title="Checkout More Database Info" class="wpss_btn button button-small"><?php _e('Check More Database Info', 'wp-server-stats'); ?></a>
713 </div>
714 <hr />
715 <ul>
716 <li><strong><?php _e('PHP Version', 'wp-server-stats'); ?></strong> : <span><?php echo PHP_VERSION; ?></span></li>
717 <li><strong><?php _e('PHP Max Upload Size', 'wp-server-stats'); ?></strong> : <span><?php echo $this->php_max_upload_size(); ?></span></li>
718 <li><strong><?php _e('PHP Max Post Size', 'wp-server-stats'); ?></strong> : <span><?php echo $this->php_max_post_size(); ?></span></li>
719 <li><strong><?php _e('PHP Max Execution Time', 'wp-server-stats'); ?></strong> : <span><?php echo $this->php_max_execution_time() . " " . __("sec", "wp-server-stats"); ?></span></li>
720 <li><strong><?php _e('PHP Short Tag', 'wp-server-stats'); ?></strong> : <span><?php echo $this->php_short_tag(); ?></span></li>
721 <li><strong><?php _e('PHP Memory Limit', 'wp-server-stats'); ?></strong> : <span><?php echo $this->check_limit(); ?></span></li>
722 <li><strong><?php _e('Real Time PHP Memory Usage', 'wp-server-stats'); ?></strong> : <span id="mem_usage_mb"></span></li>
723 </ul>
724 <div class="progressbar">
725 <div style="border:1px solid #DDDDDD; background-color:#F9F9F9; border-color: rgb(223, 223, 223); box-shadow: 0px 1px 0px rgb(255, 255, 255) inset; border-radius: 3px;">
726 <div id="memory-load-upper-div" style="padding: 0px; border-width:0px; color:#FFFFFF;text-align:right; border-color: rgb(223, 223, 223); box-shadow: 0px 1px 0px rgb(255, 255, 255) inset; border-radius: 3px; margin-top: -1px;">
727 <div id="memory-usage-pos" style="padding:2px;"></div>
728 </div>
729 </div>
730 </div>
731 <div class="wpss_show_buttons content-center">
732 <a href="<?php echo get_admin_url(); ?>admin.php?page=wpss_php_info" title="Checkout More PHP Info" class="wpss_btn button button-small"><?php _e('Check More PHP Info', 'wp-server-stats'); ?></a>
733 </div>
734 <?php if ($this->isShellEnabled()) : ?>
735 <hr style="margin-top: 15px; margin-bottom: 0px;" />
736 <span style="line-height: 2.5em; margin-left: auto; margin-right: auto; display: table;"><strong><?php _e('Server Uptime', 'wp-server-stats') ?></strong></span>
737 <div style="margin-top: 20px;">
738 <div class="uptime" style="font-size: 20px;"></div>
739 </div>
740 <?php
741 else : ?>
742 <hr style="margin-top: 15px; margin-bottom: 15px;" />
743 <p style="text-align: justify;"><strong><?php _e('Special Note', 'wp-server-stats'); ?>:</strong> <?php _e('Hi, please note that PHP
744 <code>shell_exec()</code> function is either not enable in your hosting environment or not been given executable permission,
745 hence you won\'t be seeing the following results above: CPU/Core count, Real Time CPU Usage, Server Uptime, RAM details, Real Time RAM Usage. To see these details,
746 please ask your host to enable <code>shell_exec()</code> function and give it executable permission.', 'wp-server-stats'); ?></p>
747 <?php endif;
748 endif;
749 }
750
751 public function add_dashboard()
752 {
753 wp_add_dashboard_widget('wp_memory_dashboard', 'Server Overview', array(&$this, 'dashboard_output'));
754 }
755
756 public function add_footer($content)
757 {
758 if (current_user_can('manage_options')) :
759 /* Let's call the fetch data function */
760 $this->fetch_data();
761
762 //check if the content is empty or not
763 if (!empty($content)) {
764 $start = " | ";
765 } else {
766 $start = "";
767 }
768
769 if ($this->isShellEnabled()) {
770 $content .= $start . '<strong style="color: ' . $this->footer_text_color . ';">' . __('PHP Memory', 'wp-server-stats') . ' : <span id="mem_usage_mb_footer"></span>'
771 . ' ' . __('of', 'wp-server-stats') . ' ' . $this->check_limit() . ' (<span id="memory-usage-pos-footer"></span> '
772 . __('used', 'wp-server-stats') . ')</strong> | <strong style="color: ' . $this->footer_text_color . ';">' . __('RAM', 'wp-server-stats') . ' : <span id="ram_usage_footer"></span> ' . __('of', 'wp-server-stats') . ' ' . (is_numeric($this->check_total_ram()) ? $this->format_filesize_kB($this->check_total_ram()) : $this->check_total_ram()) . ' (<span id="ram-usage-pos-footer"></span> ' . __('used', 'wp-server-stats') . ')</strong> | <strong style="color: ' . $this->footer_text_color . ';">' . __('CPU Load', 'wp-server-stats')
773 . ': <span id="cpu_load_footer"></span></strong>';
774 } else {
775 $content .= $start . '<strong style="color: ' . $this->footer_text_color . ';">' . __('Memory', 'wp-server-stats') . ' : <span id="mem_usage_mb_footer"></span>'
776 . ' ' . __('of', 'wp-server-stats') . ' ' . $this->check_limit() . ' (<span id="memory-usage-pos-footer"></span> '
777 . __('used', 'wp-server-stats') . ')</strong>';
778 }
779 return $content;
780 endif;
781 }
782
783 public function create_admin_menu()
784 {
785 add_menu_page(
786 __('WP Server Stats', 'wp-server-stats'),
787 __('WP Server Stats', 'wp-server-stats'),
788 'manage_options',
789 'wp_server_stats',
790 '',
791 'dashicons-chart-area',
792 81
793 );
794
795 add_submenu_page(
796 'wp_server_stats',
797 __('WP Server Stats - General Settings', 'wp-server-stats'),
798 __('General Settings', 'wp-server-stats'),
799 'manage_options',
800 'wp_server_stats',
801 array($this, 'admin_page_design')
802 );
803
804 add_submenu_page(
805 'wp_server_stats',
806 __('WP Server Stats - PHP Information', 'wp-server-stats'),
807 __('PHP Information', 'wp-server-stats'),
808 'manage_options',
809 'wpss_php_info',
810 array($this, 'php_details')
811 );
812
813 add_submenu_page(
814 'wp_server_stats',
815 __('WP Server Stats - Database Information', 'wp-server-stats'),
816 __('Database Information', 'wp-server-stats'),
817 'manage_options',
818 'wpss_sql_info',
819 array($this, 'sql_details')
820 );
821
822 if (class_exists('Memcache')) {
823 add_submenu_page(
824 'wp_server_stats',
825 __('WP Server Stats - Memcache Information', 'wp-server-stats'),
826 __('Memcache Information', 'wp-server-stats'),
827 'manage_options',
828 'wpss_memcache_info',
829 array($this, 'memcache_details')
830 );
831 }
832 }
833
834 /* Function that will show the indepth PHP information */
835 public function php_details()
836 {
837 ?>
838 <div class="wrap wpss_info">
839 <h1><?php _e('PHP Information - WP Server Stats', 'wp-server-stats'); ?></h1>
840 <h3><?php _e('This page will show you the in-depth information about the PHP installasion on your server', 'wp-server-stats'); ?></h3>
841 <hr />
842 <?php
843 if (!class_exists('DOMDocument')) {
844 echo '<p>You need <a href="http://php.net/manual/en/class.domdocument.php" target="_blank">DOMDocument extension</a> to be enabled.</p>';
845 } else {
846 ob_start();
847 phpinfo();
848 $phpinfo = ob_get_contents();
849 ob_end_clean();
850
851 // Use DOMDocument to parse phpinfo()
852 libxml_use_internal_errors(true);
853 $html = new DOMDocument('1.0', 'UTF-8');
854 $html->loadHTML($phpinfo);
855
856 // Style process
857 $tables = $html->getElementsByTagName('table');
858 foreach ($tables as $table) {
859 $table->setAttribute('class', 'widefat');
860 }
861
862 // We only need the <body>
863 $xpath = new DOMXPath($html);
864 $body = $xpath->query('/html/body');
865
866 // Save HTML fragment
867 libxml_use_internal_errors(false);
868 $phpinfo_html = $html->saveXml($body->item(0));
869
870 echo $phpinfo_html;
871 }
872 ?>
873 </div>
874 <?php
875
876 }
877
878 /* Function to show up SQL Server Information */
879 public function sql_details()
880 {
881 ?>
882 <div class="wrap wpss_info">
883 <h1><?php _e('Database Information - WP Server Stats', 'wp-server-stats'); ?></h1>
884 <h3><?php _e('This page will show you the in-depth information about your database', 'wp-server-stats'); ?></h3>
885 <hr />
886 <h2><?php _e('Basic Database Information', 'wp-server-stats'); ?></h2>
887 <table class="widefat">
888 <thead>
889 <tr>
890 <th><?php _e('Variable Name', 'wp-server-stats'); ?></th>
891 <th><?php _e('Value', 'wp-server-stats'); ?></th>
892 </tr>
893 </thead>
894 <tfoot>
895 <tr>
896 <td class="e"><?php _e('Variable Name', 'wp-server-stats'); ?></td>
897 <td><?php _e('Value', 'wp-server-stats'); ?></td>
898 </tr>
899 </tfoot>
900 <tbody>
901 <tr>
902 <td class="e"><?php _e('Database Software', 'wp-server-stats'); ?></td>
903 <td class="v"><?php echo $this->database_software(); ?></td>
904 </tr>
905 <tr>
906 <td class="e"><?php _e('Database Version', 'wp-server-stats'); ?></td>
907 <td class="v"><?php echo $this->database_version(); ?></td>
908 </tr>
909 <tr>
910 <td class="e"><?php _e('Maximum No. of Connections', 'wp-server-stats'); ?></td>
911 <td class="v"><?php echo $this->database_max_no_connection(); ?></td>
912 </tr>
913 <tr>
914 <td class="e"><?php _e('Maximum Packet Size', 'wp-server-stats'); ?></td>
915 <td class="v"><?php echo $this->database_max_packet_size(); ?></td>
916 </tr>
917 <tr>
918 <td class="e"><?php _e('Database Disk Usage', 'wp-server-stats'); ?></td>
919 <td class="v"><?php echo $this->database_disk_usage(); ?></td>
920 </tr>
921 <tr>
922 <td class="e"><?php _e('Index Disk Usage', 'wp-server-stats'); ?></td>
923 <td class="v"><?php echo $this->index_disk_usage(); ?></td>
924 </tr>
925 </tbody>
926 </table>
927 <div class="clear give-some-space"></div>
928 <hr />
929 <h2><?php _e('Advanced Database Information', 'wp-server-stats'); ?></h2>
930 <table class="widefat">
931 <thead>
932 <tr>
933 <th><?php _e('Variable Name', 'wp-server-stats'); ?></th>
934 <th><?php _e('Value', 'wp-server-stats'); ?></th>
935 </tr>
936 </thead>
937 <tfoot>
938 <tr>
939 <td><?php _e('Variable Name', 'wp-server-stats'); ?></td>
940 <td><?php _e('Value', 'wp-server-stats'); ?></td>
941 </tr>
942 </tfoot>
943 <tbody>
944 <?php
945 if (get_option('wpss_db_advanced_info')) {
946 $dbinfo = get_option('wpss_db_advanced_info');
947 } else {
948 global $wpdb;
949 $dbversion = $wpdb->get_var("SELECT VERSION() AS version");
950 $dbinfo = $wpdb->get_results("SHOW VARIABLES");
951 update_option('wpss_db_advanced_info', $dbinfo);
952 }
953
954 if (!empty($dbinfo)) {
955 foreach ($dbinfo as $info) {
956 echo '<tr><td class="e">' . $info->Variable_name . '</td><td class="v">' . htmlspecialchars($info->Value) . '</td></tr>';
957 }
958 } else {
959 echo '<tr><td>' . __('Something went wrong!', 'wp-server-stats') . '</td><td>' . __('Something went wrong!', 'wp-server-stats') . '</td></tr>';
960 }
961 ?>
962 </tbody>
963 </table>
964 </div>
965 <?php
966
967 }
968
969 /* Function to show up Memcache details */
970 public function memcache_details()
971 {
972 if (class_exists('Memcache')) {
973 $this->fetch_data(); //fetching data
974 $memcached_obj = new Memcache;
975 $memcached_obj->addServer($this->memcache_host, $this->memcache_port);
976 $memcachedinfo = $memcached_obj->getStats();
977 if (!empty($memcachedinfo)) {
978 $cache_hit = (($memcachedinfo['get_hits'] / $memcachedinfo['cmd_get']) * 100);
979 $cache_hit = round($cache_hit, 2);
980 $cache_miss = 100 - $cache_hit;
981 $usage = round((($memcachedinfo['bytes'] / $memcachedinfo['limit_maxbytes']) * 100), 2);
982 $uptime = number_format_i18n(($memcachedinfo['uptime'] / 60 / 60 / 24));
983 }
984
985 ?>
986 <div class="wrap wpss_info">
987 <h1><?php _e('Memcached Information - WP Server Stats', 'wp-server-stats'); ?></h1>
988 <h3><?php _e('This page will show you the in-depth information about your memcache server', 'wp-server-stats'); ?></h3>
989 <hr />
990 <table class="widefat">
991 <thead>
992 <tr>
993 <th><?php _e('Variable Name', 'wp-server-stats'); ?></th>
994 <th><?php _e('Value', 'wp-server-stats'); ?></th>
995 <th><?php _e('Description', 'wp-server-stats'); ?></th>
996 </tr>
997 </thead>
998 <tfoot>
999 <tr>
1000 <td><?php _e('Variable Name', 'wp-server-stats'); ?></td>
1001 <td><?php _e('Value', 'wp-server-stats'); ?></td>
1002 <td><?php _e('Description', 'wp-server-stats'); ?></td>
1003 </tr>
1004 </tfoot>
1005 <tbody>
1006 <tr>
1007 <td class="e"><?php _e('pid', 'wp-server-stats'); ?></td>
1008 <td class="v"><?php echo $memcachedinfo['pid']; ?></td>
1009 <td class="v"><?php _e('Process ID', 'wp-server-stats'); ?></td>
1010 </tr>
1011 <tr>
1012 <td class="e"><?php _e('vptime', 'wp-server-stats'); ?></td>
1013 <td class="v"><?php echo $uptime; ?></td>
1014 <td class="v"><?php _e('Number of days since the process was started', 'wp-server-stats'); ?></td>
1015 </tr>
1016 <tr>
1017 <td class="e"><?php _e('version', 'wp-server-stats'); ?></td>
1018 <td class="v"><?php echo $memcachedinfo['version']; ?></td>
1019 <td class="v"><?php _e('Memcached Version', 'wp-server-stats'); ?></td>
1020 </tr>
1021 <tr>
1022 <td class="e"><?php _e('rusage_user', 'wp-server-stats'); ?></td>
1023 <td class="v"><?php echo $memcachedinfo['rusage_user']; ?></td>
1024 <td class="v"><?php _e('Number of seconds the cpu has devoted to the process as the user', 'wp-server-stats'); ?></td>
1025 </tr>
1026 <tr>
1027 <td class="e"><?php _e('rusage_system', 'wp-server-stats'); ?></td>
1028 <td class="v"><?php echo $memcachedinfo['rusage_system']; ?></td>
1029 <td class="v"><?php _e('Number of seconds the cpu has devoted to the process as the system', 'wp-server-stats'); ?></td>
1030 </tr>
1031 <tr>
1032 <td class="e"><?php _e('curr_items', 'wp-server-stats'); ?></td>
1033 <td class="v"><?php echo number_format_i18n($memcachedinfo['curr_items']); ?></td>
1034 <td class="v"><?php _e('Total number of items currently in memcached', 'wp-server-stats'); ?></td>
1035 </tr>
1036 <tr>
1037 <td class="e"><?php _e('total_items', 'wp-server-stats'); ?></td>
1038 <td class="v"><?php echo number_format_i18n($memcachedinfo['total_items']); ?></td>
1039 <td class="v"><?php _e('Total number of items that have passed through memcached', 'wp-server-stats'); ?></td>
1040 </tr>
1041 <tr>
1042 <td class="e"><?php _e('bytes', 'wp-server-stats'); ?></td>
1043 <td class="v"><?php echo $this->format_filesize($memcachedinfo['bytes']); ?></td>
1044 <td class="v"><?php _e('Memory size currently used by <code>curr_items</code>', 'wp-server-stats'); ?></td>
1045 </tr>
1046 <tr>
1047 <td class="e"><?php _e('limit_maxbytes', 'wp-server-stats'); ?></td>
1048 <td class="v"><?php echo $this->format_filesize($memcachedinfo['limit_maxbytes']); ?></td>
1049 <td class="v"><?php _e('Maximum memory size allocated to memcached', 'wp-server-stats'); ?></td>
1050 </tr>
1051 <tr>
1052 <td class="e"><?php _e('curr_connections', 'wp-server-stats'); ?></td>
1053 <td class="v"><?php echo number_format_i18n($memcachedinfo['curr_connections']); ?></td>
1054 <td class="v"><?php _e('Total number of open connections to memcached', 'wp-server-stats'); ?></td>
1055 </tr>
1056 <tr>
1057 <td class="e"><?php _e('total_connections', 'wp-server-stats'); ?></td>
1058 <td class="v"><?php echo number_format_i18n($memcachedinfo['total_connections']); ?></td>
1059 <td class="v"><?php _e('Total number of connections opened since memcached started running', 'wp-server-stats'); ?></td>
1060 </tr>
1061 <tr>
1062 <td class="e"><?php _e('connection_structures', 'wp-server-stats'); ?></td>
1063 <td class="v"><?php echo number_format_i18n($memcachedinfo['connection_structures']); ?></td>
1064 <td class="v"><?php _e('Number of connection structures allocated by the server', 'wp-server-stats'); ?></td>
1065 </tr>
1066 <tr>
1067 <td class="e"><?php _e('cmd_get', 'wp-server-stats'); ?></td>
1068 <td class="v"><?php echo number_format_i18n($memcachedinfo['cmd_get']); ?></td>
1069 <td class="v"><?php _e('Total GET commands issued to the server', 'wp-server-stats'); ?></td>
1070 </tr>
1071 <tr>
1072 <td class="e"><?php _e('cmd_set', 'wp-server-stats'); ?></td>
1073 <td class="v"><?php echo number_format_i18n($memcachedinfo['cmd_set']); ?></td>
1074 <td class="v"><?php _e('Total SET commands issued to the server', 'wp-server-stats'); ?></td>
1075 </tr>
1076 <tr>
1077 <td class="e"><?php _e('cmd_flush', 'wp-server-stats'); ?></td>
1078 <td class="v"><?php echo number_format_i18n($memcachedinfo['cmd_flush']); ?></td>
1079 <td class="v"><?php _e('Total FLUSH commands issued to the server', 'wp-server-stats'); ?></td>
1080 </tr>
1081 <tr>
1082 <td class="e"><?php _e('get_hits', 'wp-server-stats'); ?></td>
1083 <td class="v"><?php echo number_format_i18n($memcachedinfo['get_hits']) . '(' . $cache_hit . '%)'; ?></td>
1084 <td class="v"><?php _e('Total number of times a GET command was <strong>able</strong> to retrieve and return data', 'wp-server-stats'); ?></td>
1085 </tr>
1086 <tr>
1087 <td class="e"><?php _e('get_misses', 'wp-server-stats'); ?></td>
1088 <td class="v"><?php echo number_format_i18n($memcachedinfo['get_misses']) . '(' . $cache_miss . '%)'; ?></td>
1089 <td class="v"><?php _e('Total number of times a GET command was <strong>unable</strong> to retrieve and return data', 'wp-server-stats'); ?></td>
1090 </tr>
1091 <tr>
1092 <td class="e"><?php _e('delete_hits', 'wp-server-stats'); ?></td>
1093 <td class="v"><?php echo number_format_i18n($memcachedinfo['delete_hits']); ?></td>
1094 <td class="v"><?php _e('Total number of times a DELETE command was <strong>able</strong> to delete data', 'wp-server-stats'); ?></td>
1095 </tr>
1096 <tr>
1097 <td class="e"><?php _e('delete_misses', 'wp-server-stats'); ?></td>
1098 <td class="v"><?php echo number_format_i18n($memcachedinfo['delete_misses']); ?></td>
1099 <td class="v"><?php _e('Total number of times a DELETE command was <strong>unable</strong> to delete data', 'wp-server-stats'); ?></td>
1100 </tr>
1101 <tr>
1102 <td class="e"><?php _e('incr_hits', 'wp-server-stats'); ?></td>
1103 <td class="v"><?php echo number_format_i18n($memcachedinfo['incr_hits']); ?></td>
1104 <td class="v"><?php _e('Total number of times a INCR command was <strong>able</strong> to increment a value', 'wp-server-stats'); ?></td>
1105 </tr>
1106 <tr>
1107 <td class="e"><?php _e('incr_misses', 'wp-server-stats'); ?></td>
1108 <td class="v"><?php echo number_format_i18n($memcachedinfo['incr_misses']); ?></td>
1109 <td class="v"><?php _e('Total number of times a INCR command was <strong>unable</strong> to increment a value', 'wp-server-stats'); ?></td>
1110 </tr>
1111 <tr>
1112 <td class="e"><?php _e('decr_hits', 'wp-server-stats'); ?></td>
1113 <td class="v"><?php echo number_format_i18n($memcachedinfo['decr_hits']); ?></td>
1114 <td class="v"><?php _e('Total number of times a DECR command was <strong>able</strong> to decrement a value', 'wp-server-stats'); ?></td>
1115 </tr>
1116 <tr>
1117 <td class="e"><?php _e('decr_misses', 'wp-server-stats'); ?></td>
1118 <td class="v"><?php echo number_format_i18n($memcachedinfo['decr_misses']); ?></td>
1119 <td class="v"><?php _e('Total number of times a DECR command was <strong>unable</strong> to decrement a value', 'wp-server-stats'); ?></td>
1120 </tr>
1121 <tr>
1122 <td class="e"><?php _e('cas_hits', 'wp-server-stats'); ?></td>
1123 <td class="v"><?php echo number_format_i18n($memcachedinfo['cas_hits']); ?></td>
1124 <td class="v"><?php _e('Total number of times a CAS command was <strong>able</strong> to compare and swap data', 'wp-server-stats'); ?></td>
1125 </tr>
1126 <tr>
1127 <td class="e"><?php _e('cas_misses', 'wp-server-stats'); ?></td>
1128 <td class="v"><?php echo number_format_i18n($memcachedinfo['cas_misses']); ?></td>
1129 <td class="v"><?php _e('Total number of times a CAS command was <strong>unable</strong> to compare and swap data', 'wp-server-stats'); ?></td>
1130 </tr>
1131 <tr>
1132 <td class="e"><?php _e('cas_badval', 'wp-server-stats'); ?></td>
1133 <td class="v"><?php echo number_format_i18n($memcachedinfo['cas_badval']); ?></td>
1134 <td class="v"><?php _e('The "cas" command is some kind of Memcached\'s way to avoid locking. "cas" calls with bad identifier are counted in this stats key', 'wp-server-stats'); ?></td>
1135 </tr>
1136 <tr>
1137 <td class="e"><?php _e('bytes_read', 'wp-server-stats'); ?></td>
1138 <td class="v"><?php echo $this->format_filesize($memcachedinfo['bytes_read']); ?></td>
1139 <td class="v"><?php _e('Total number of bytes input into the server', 'wp-server-stats'); ?></td>
1140 </tr>
1141 <tr>
1142 <td class="e"><?php _e('bytes_written', 'wp-server-stats'); ?></td>
1143 <td class="v"><?php echo $this->format_filesize($memcachedinfo['bytes_written']); ?></td>
1144 <td class="v"><?php _e('Total number of bytes written by the server', 'wp-server-stats'); ?></td>
1145 </tr>
1146 <tr>
1147 <td class="e"><?php _e('evictions', 'wp-server-stats'); ?></td>
1148 <td class="v"><?php echo number_format_i18n($memcachedinfo['evictions']); ?></td>
1149 <td class="v"><?php _e('Number of valid items removed from cache to free memory for new items', 'wp-server-stats'); ?></td>
1150 </tr>
1151 <tr>
1152 <td class="e"><?php _e('reclaimed', 'wp-server-stats'); ?></td>
1153 <td class="v"><?php echo number_format_i18n($memcachedinfo['reclaimed']); ?></td>
1154 <td class="v"><?php _e('Number of items reclaimed', 'wp-server-stats'); ?></td>
1155 </tr>
1156 </tbody>
1157 </table>
1158 </div>
1159 <?php
1160 } // end if class_exists( 'Memcache' )
1161 }
1162
1163 /* Now lets create the function to design the admin page */
1164 public function admin_page_design()
1165 {
1166 /* Now lets do the admin page design */
1167 ?>
1168 <div class="wrap">
1169 <h1><?php _e('WP Server Stats Settings', 'wp-server-stats'); ?></h1>
1170 <h3><?php _e('On this page you will be able to change some critical settings of WP Server Stats', 'wp-server-stats'); ?></h3>
1171 <h4><?php _e('Please note the below form uses HTML5, so, make sure you are using any of the HTML5 compliance browsers like IE v11+, Microsoft Edge, Chrome v49+, Firefix v47+, Safari v9.1+, Opera v39+', 'wp-server-stats'); ?></h4>
1172 <hr />
1173 <div id="wpss-main">
1174 <form action="options.php" method="post" accept-charset="utf-8">
1175 <?php
1176 //Populate the admin settings page using WordPress Settings API
1177 settings_fields('wp_server_stats');
1178 do_settings_sections('wp_server_stats');
1179 submit_button();
1180
1181 //print_r( get_option( 'wpss_settings_options') );
1182 ?>
1183 </form>
1184 </div>
1185 <div id="wpss-sidebar">
1186 <h2>
1187 <?php
1188 _e('Some info about the settings options', 'wp-server-stats');
1189 ?>
1190 </h2>
1191 <ul class="user-info">
1192 <li>
1193 <strong class="highlight"><?php _e('Refresh Interval', 'wp-server-stats'); ?></strong>
1194 <?php _e('This denotes the interval time after which the shell commands will execute again to give you the current load details. By default it is set to 200ms, but if you are seeing CPU load increase after instealling this plugin, try to increase the interval time to 1000ms, 2000ms, 3000ms or more until you see a normal CPU load. Generally it is not recommended to change the value unless you are having extremely high CPU load due to this plugin.', 'wp-server-stats'); ?>
1195 </li>
1196 <li>
1197 <strong class="highlight"><?php _e('Status Bar & Footer Text Color', 'wp-server-stats'); ?></strong>
1198 <?php _e('In case you do not like the color scheme I have used on this plugin, you can easily change those colors.', 'wp-server-stats'); ?>
1199 </li>
1200 <li>
1201 <strong class="highlight"><?php _e('Memcached Server Host & Port', 'wp-server-stats'); ?></strong>
1202 <?php _e('Memcached is a general-purpose distributed memory caching system. It is often used to speed up dynamic database-driven websites by caching data and objects in RAM to reduce the number of times an external data source must be read. But in most Shared Hosting servers Memcached will not be enabled. This generally used in personal VPS or Dedicated servers.', 'wp-server-stats'); ?>
1203 <br />
1204 <?php _e('So, if you are using a shared hosting server, chances are Memcached is not enabled on your server. In this case you don\'t need to change any of the Memcached settings on the left side. But if you are using a VPS or dedicated server which has Memcached enabled, make sure the Memcached Host & Port details has been provided properly on the settings. If you don\'t have these details, please contact your host and ask them about it.', 'wp-server-stats'); ?>
1205 </li>
1206 </ul>
1207 <hr />
1208 <h2><?php _e('Support the plugin', 'wp-server-stats'); ?></h2>
1209 <p><?php _e('Believe it or not, developing a WorPress plugin really takes quite a lot of time to develop, test and to do continuous bugfix. Moreover as I\'m sharing this plugin for free, so all those times I\'ve spent coding this plugin yeild no revenue. So, overtime it become really hard to keep spending time on this plugin. So, if you like this plugin, I will really appriciate if you consider donating some amount for this plugin. Which will help me keep spending time on this plugin and make it even better. Please donate, if you can.', 'wp-server-stats'); ?></p>
1210 </div>
1211 </div>
1212 <?php
1213
1214 }
1215
1216 /**
1217 * Function that will register admin page options.
1218 */
1219 public function register_page_options()
1220 {
1221 /* Let's call the fetch data function */
1222 $this->fetch_data();
1223
1224 // Add Section for option fields
1225 add_settings_section('wpss_section', __('Change the WP Server Stats Settings', 'wp-server-stats'), array($this, 'display_section'), 'wp_server_stats'); // id, title, display cb, page
1226
1227 // Add Title Field
1228 add_settings_field('wpss_refresh_interval_field', __('Set the realtime script refresh inverval (in ms) [1sec = 1000ms]', 'wp-server-stats'), array($this, 'refresh_interval_settings_field'), 'wp_server_stats', 'wpss_section'); // id, title, display cb, page, section
1229
1230 // Files for Memcache Server Details
1231 add_settings_field('wpss_memcache_host_field', __('Memcached Server Host (Only if you have Memcached installed in your server)', 'wp-server-stats'), array($this, 'memcache_host_field'), 'wp_server_stats', 'wpss_section'); // id, title, display cb, page, section
1232 add_settings_field('wpss_memcache_port_field', __('Memcached Server Port (Only if you have Memcached installed in your server)', 'wp-server-stats'), array($this, 'memcache_port_field'), 'wp_server_stats', 'wpss_section'); // id, title, display cb, page, section
1233
1234 // Fields for ip-api.com pro support section
1235 add_settings_field('wpss_use_ipapi_pro', __('Do you want to use the IP-API Pro key?', 'wp-server-stats'), array($this, 'use_ipapi_pro'), 'wp_server_stats', 'wpss_section'); // id, title, display cb, page, section
1236 add_settings_field('wpss_ipapi_pro_key', __('Provide your IP-API Pro key', 'wp-server-stats'), array($this, 'ipapi_pro_key'), 'wp_server_stats', 'wpss_section'); // id, title, display cb, page, section
1237
1238 // Add Background Color Field
1239 add_settings_field('wpss_bg_field_good', __('Realtime Status Bar Background Color - For Good Status', 'wp-server-stats'), array($this, 'bg_settings_field_good'), 'wp_server_stats', 'wpss_section'); // id, title, display cb, page, section
1240
1241 add_settings_field('wpss_bg_field_average', __('Realtime Status Bar Background Color - For Near Critical Status', 'wp-server-stats'), array($this, 'bg_settings_field_avg'), 'wp_server_stats', 'wpss_section');
1242
1243 add_settings_field('wpss_bg_field_bad', __('Realtime Status Bar Background Color - For Super Critical Status', 'wp-server-stats'), array($this, 'bg_settings_field_bad'), 'wp_server_stats', 'wpss_section');
1244
1245 add_settings_field('wpss_footer_text_color', __('Footer Text Color', 'wp-server-stats'), array($this, 'footer_text_color'), 'wp_server_stats', 'wpss_section');
1246
1247 // Register Settings
1248 register_setting('wp_server_stats', 'wpss_settings_options', array($this, 'validate_options')); // option group, option name, sanitize cb
1249 }
1250
1251 /**
1252 * Callback function for settings section
1253 **/
1254 public function display_section()
1255 { /* Leave blank */
1256 }
1257
1258 /**
1259 * Functions that display the fields.
1260 */
1261 public function refresh_interval_settings_field()
1262 {
1263 echo '<input type="number" name="wpss_settings_options[refresh_interval]" value="' . esc_attr( $this->refresh_interval ) . '" />';
1264 }
1265
1266 public function memcache_host_field()
1267 {
1268 echo '<input type="text" name="wpss_settings_options[memcache_host]" value="' . esc_attr( $this->memcache_host ) . '" />';
1269 }
1270
1271 public function memcache_port_field()
1272 {
1273 echo '<input type="number" name="wpss_settings_options[memcache_port]" value="' . esc_attr( $this->memcache_port ) . '" />';
1274 }
1275
1276 public function use_ipapi_pro()
1277 {
1278 $this->fetch_data();
1279 $options = get_option('wpss_settings_options');
1280 ?>
1281 <input type="radio" name="wpss_settings_options[use_ipapi_pro]" value="Yes" <?php checked(empty($options['use_ipapi_pro']) ? $this->use_ipapi_pro : $options['use_ipapi_pro'], 'Yes') ?> />
1282 <span><?php _e('Yes', 'wp-server-stats'); ?></span>
1283
1284 <input type="radio" name="wpss_settings_options[use_ipapi_pro]" value="No" <?php checked(empty($options['use_ipapi_pro']) ? $this->use_ipapi_pro : $options['use_ipapi_pro'], 'No') ?> />
1285 <span><?php _e('No', 'wp-server-stats'); ?></span>
1286 <br />
1287 <p><?php printf(
1288 __('By default this plugin uses the free API from %1$sIP-API.com%2$s which allows %3$s150 requests/min%4$s. But for high traffic websites, this might be very small and may generate %3$s503 Error%4$s if you try to do more than %3$s150 req/min%4$s. To resolve this problem, you can use the %5$sPaid Version of IP-API%6$s and provide your paid key below which will allow you to do %7$sUnlimited%8$s nuber of requests.', 'wp-server-stats'),
1289 '<a href="http://ip-api.com/" target="_blank" rel="external nofollow">',
1290 '</a>',
1291 '<code>',
1292 '</code>',
1293 '<strong><a href="https://signup.ip-api.com/" target="_blank" rel="external nofollow">',
1294 '</a></strong>',
1295 '<strong>',
1296 '</strong>'
1297 ); ?>
1298 </p>
1299 <?php
1300
1301 }
1302
1303 public function ipapi_pro_key()
1304 {
1305 $this->fetch_data();
1306 ?>
1307 <input type="text" name="wpss_settings_options[ipapi_pro_key]" value="<?php echo esc_attr( $this->ipapi_pro_key ); ?>" placeholder="AbcDEFGhiJ0KL1m">
1308 <p><?php printf(
1309 __('Please provide your paid API key of ip-api.com which you have %1$sreceived over email%2$s after %3$spurchasing the paid IP-API subscription%4$s. %5$sCheck this screenshot%6$s to understand what key I\'m talking about.', 'wp-server-stats'),
1310 '<strong>',
1311 '</strong>',
1312 '<a href="https://signup.ip-api.com/" target="_blank" rel="external nofollow">',
1313 '</a>',
1314 '<strong><a href="https://i.imgur.com/gp2mXiH.jpg" target="_blank" rel="external nofollow">',
1315 '</a></strong>'
1316 ); ?>
1317 </p>
1318 <?php
1319
1320 }
1321
1322 public function bg_settings_field_good()
1323 {
1324 echo '<input type="text" name="wpss_settings_options[bg_color_good]" value="' . esc_attr( $this->bg_color_good ) . '" class="wpss-color-picker" />';
1325 }
1326
1327 public function bg_settings_field_avg()
1328 {
1329 echo '<input type="text" name="wpss_settings_options[bg_color_average]" value="' . esc_attr( $this->bg_color_average ) . '" class="wpss-color-picker" />';
1330 }
1331
1332 public function bg_settings_field_bad()
1333 {
1334 echo '<input type="text" name="wpss_settings_options[bg_color_bad]" value="' . esc_attr( $this->bg_color_bad ) . '" class="wpss-color-picker" />';
1335 }
1336
1337 public function footer_text_color()
1338 {
1339 echo '<input type="text" name="wpss_settings_options[footer_text_color]" value="' . esc_attr( $this->footer_text_color ) . '" class="wpss-color-picker" />';
1340 }
1341
1342 /**
1343 * Function that will validate all fields.
1344 */
1345 public function validate_options($fields)
1346 {
1347
1348 $valid_fields = array();
1349
1350 // Validate Title Field
1351 $refresh_interval = trim($fields['refresh_interval']);
1352 $valid_fields['refresh_interval'] = strip_tags(stripslashes($refresh_interval));
1353
1354 $memcache_host = trim($fields['memcache_host']);
1355 $valid_fields['memcache_host'] = strip_tags(stripslashes($memcache_host));
1356
1357 $memcache_port = trim($fields['memcache_port']);
1358 $valid_fields['memcache_port'] = strip_tags(stripslashes($memcache_port));
1359
1360 $valid_fields['use_ipapi_pro'] = strip_tags(stripslashes(trim($fields['use_ipapi_pro'])));
1361
1362 $valid_fields['ipapi_pro_key'] = strip_tags(stripslashes(trim($fields['ipapi_pro_key'])));
1363
1364 // Validate color section
1365 foreach ($fields as $key => $value) {
1366 if (preg_match('/_color/', $key)) {
1367 $color[$key] = trim($value);
1368 $color[$key] = strip_tags(stripslashes($color[$key]));
1369
1370 // Check if is a valid hex color
1371 if (false === $this->check_color($color[$key])) {
1372
1373 if ($key == "bg_color_good") {
1374 $error_text = __("Insert a valid color for Realtime Status Bar Background Color - For Good Status", "wp-server-stats");
1375 } elseif ($key == "bg_color_average") {
1376 $error_text = __("Insert a valid color for Realtime Status Bar Background Color - For Near Critical Status", "wp-server-stats");
1377 } elseif ($key == "bg_color_bad") {
1378 $error_text = __("Insert a valid color for Realtime Status Bar Background Color - For Super Critical Status", "wp-server-stats");
1379 } elseif ($key == "footer_text_color") {
1380 $error_text = __("Insert a valid color for the footer text color", "wp-server-stats");
1381 }
1382 // Set the error message
1383 add_settings_error('wpss_settings_options', 'wpss_bg_error', $error_text, 'error'); // $setting, $code, $message, $type
1384
1385 // Get the previous valid value
1386 $valid_fields[$key] = $this->{$key};
1387
1388 } else {
1389
1390 $valid_fields[$key] = $color[$key];
1391
1392 }
1393 }
1394 }
1395
1396 return apply_filters('validate_options', $valid_fields, $fields);
1397 }
1398
1399 /**
1400 * Function that will check if value is a valid HEX color.
1401 */
1402 public function check_color($value)
1403 {
1404
1405 if (preg_match('/^#[a-f0-9]{6}$/i', $value)) { // if user insert a HEX color with #
1406 return true;
1407 }
1408
1409 return false;
1410 }
1411
1412 public function show_admin_notice()
1413 {
1414 settings_errors('wpss_settings_options');
1415
1416 $class = 'notice notice-success is-dismissible wpss_donate_notice';
1417 $message = sprintf(
1418 __('%1$sThank you%2$s for installing %1$sWP Server Stats%2$s. It took 450+ hours to code, design, test and include many useful server info that you like so much to show up in your WordPress dashboard. But as this is a <strong>free plugin</strong>, all of these time and effort does not generate any revenue. Also as I\'m not a very privileged person, so earning revenue matters to me for keeping my lights on and keep me motivated to do the work I love. %3$s So, if you enjoy this plugin and understand the huge effort I put into this, please consider %1$s%4$sdonating some amount%5$s (no matter how small)%2$s for keeping aliave the development of this plugin. Thank you again for using my plugin. Also if you love using this plugin, I would really appiciate if you take 2 minutes out of your busy schedule to %1$s%6$sshare your review%7$s%2$s about this plugin.', 'wp-server-stats'),
1419 '<strong>',
1420 '</strong>',
1421 '<br /> <br />',
1422 '<a href="https://paypal.me/acnamhq" target="_blank" rel="external nofollow noreferrer noopener" title="WP Server Stats - Plugin Donation">',
1423 '</a>',
1424 '<a href="https://wordpress.org/support/plugin/wp-server-stats/reviews/" target="_blank" rel="external" title="WP Server Stats - Post your Plugin Review">',
1425 '</a>'
1426 );
1427 $welcome_notice_curr_state = get_option('wpss_donate_notice');
1428 if (empty($welcome_notice_curr_state)) {
1429 printf('<div id="wpss_donate_notice" class="%1$s"><p>%2$s</p></div>', $class, $message);
1430 echo "<script>
1431 (function($){
1432 $('#wpss_donate_notice').on('click', '.notice-dismiss', function(){
1433 jQuery.ajax({
1434 type: 'POST',
1435 url: '" . admin_url('admin-ajax.php') . "',
1436 data: {
1437 \"action\": \"handle_wpss_donate_notice\",
1438 \"nonce\": \"" . wp_create_nonce("wpss_wn_nonce") . "\"
1439 },
1440 success: function( data ){
1441 $('#wpss_donate_notice').hide();
1442 }
1443 });
1444 });
1445 })(jQuery);
1446 </script>";
1447 }
1448 }
1449
1450 public function handle_wpss_donate_notice()
1451 {
1452 check_ajax_referer('wpss_wn_nonce', 'nonce');
1453 update_option('wpss_donate_notice', 'hide');
1454 $result = get_option('wpss_donate_notice');
1455 return $result;
1456 }
1457
1458 /**
1459 * Function that will fetch the user entered data in the settings page from database
1460 **/
1461 public function fetch_data()
1462 {
1463 // assuming our wpss_settings_option entry in database's option table is already there
1464 // so lets try to fetch it
1465 $fetched_data = get_option('wpss_settings_options'); // $fetched_data will be an array
1466
1467 if (!empty($fetched_data)) {
1468
1469 // fetching the refresh_interval data
1470 if (!empty($fetched_data['refresh_interval'])) {
1471 $this->refresh_interval = $fetched_data['refresh_interval'];
1472 } else {
1473 $this->refresh_interval = 200; // default refresh interval is 200ms
1474 }
1475
1476 // fetching memcache host
1477 if (!empty($fetched_data['memcache_host'])) {
1478 $this->memcache_host = $fetched_data['memcache_host'];
1479 } else {
1480 $this->memcache_host = 'localhost'; // default memcache host localhost
1481 }
1482
1483 // fetching memcache port
1484 if (!empty($fetched_data['memcache_port'])) {
1485 $this->memcache_port = $fetched_data['memcache_port'];
1486 } else {
1487 $this->memcache_port = 11211; // default memcache port 11211
1488 }
1489
1490 // fetching if using ip-api
1491 if (!empty($fetched_data['use_ipapi_pro'])) {
1492 $this->use_ipapi_pro = $fetched_data['use_ipapi_pro'];
1493 } else {
1494 $this->use_ipapi_pro = 'No';
1495 }
1496
1497 // fetching the ip-api key
1498 if (!empty($fetched_data['ipapi_pro_key'])) {
1499 $this->ipapi_pro_key = $fetched_data['ipapi_pro_key'];
1500 } else {
1501 $this->ipapi_pro_key = '';
1502 }
1503
1504 // fetching the bg_color_good
1505 if (!empty($fetched_data['bg_color_good'])) {
1506 $this->bg_color_good = $fetched_data['bg_color_good'];
1507 } else {
1508 $this->bg_color_good = "#37BF91";
1509 }
1510
1511 // fetching the bg_color_average
1512 if (!empty($fetched_data['bg_color_average'])) {
1513 $this->bg_color_average = $fetched_data['bg_color_average'];
1514 } else {
1515 $this->bg_color_average = "#d35400";
1516 }
1517
1518 // fetching the bg_color_bad
1519 if (!empty($fetched_data['bg_color_bad'])) {
1520 $this->bg_color_bad = $fetched_data['bg_color_bad'];
1521 } else {
1522 $this->bg_color_bad = "#e74c3c";
1523 }
1524
1525 // fetching footer text color
1526 if (!empty($fetched_data['footer_text_color'])) {
1527 $this->footer_text_color = $fetched_data['footer_text_color'];
1528 } else {
1529 $this->footer_text_color = "#8e44ad";
1530 }
1531 } else {
1532 $this->refresh_interval = 200; // default refresh interval is 200ms
1533 $this->bg_color_good = "#37BF91";
1534 $this->bg_color_average = "#d35400";
1535 $this->bg_color_bad = "#e74c3c";
1536 $this->footer_text_color = "#8e44ad";
1537 $this->memcache_host = 'localhost';
1538 $this->memcache_port = 11211;
1539 $this->use_ipapi_pro = 'No';
1540 $this->ipapi_pro_key = '';
1541 }
1542 }
1543
1544 // Adding the `Settings Option beside Edit & Deactivation link inside WP Dashboard's Installed Plugin Page
1545 public static function add_action_link($data)
1546 {
1547 // check permission
1548 if (!current_user_can('manage_options')) {
1549 return $data;
1550 }
1551
1552 return array_merge(
1553 $data,
1554 array(
1555 sprintf(
1556 '<a href="%s">%s</a>',
1557 add_query_arg(
1558 array(
1559 'page' => 'wp_server_stats'
1560 ),
1561 admin_url('admin.php')
1562 ),
1563 __("Settings", "wp-server-stats")
1564 )
1565 )
1566 );
1567 }
1568
1569 } //end of class
1570 } //end of checking if wp_server_stats already existsi or not
1571
1572 // Start this plugin once all other plugins are fully loaded
1573 function wpss_create_obj()
1574 {
1575 $memory = new wp_server_stats();
1576 }
1577 add_action('plugins_loaded', 'wpss_create_obj');
1578 }