PluginProbe
Server Info – System Health & Diagnostics Suite / 0.01
Server Info – System Health & Diagnostics Suite v0.01
1.1.0 trunk 0.01 1.0.0
server-info / server-info.php

server-info.php in Server Info – System Health & Diagnostics Suite 0.01, at server-info.php

544 lines 15.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: Server Info
4 * Plugin URI: https://github.com/usmanaliqureshi/server-info
5 * Description: This plugin will show you useful information about the hosting server you are using e.g. PHP version, MySQL version, Server OS, Server Protocol, Server IP and other useful information. You can use the information displayed by this plugin to update any settings which is crucial for your website performance and other aspects.
6 * Version: 0.0.1
7 * Requires at least: 5.2
8 * Requires PHP: 7.3
9 * Author: Usman Ali Qureshi
10 * Author URI: https://profiles.wordpress.org/usmanaliqureshi
11 * Text Domain: server-info
12 * Domain Path: /languages/
13 */
14
15 // If this file is called directly, abort.
16 if ( ! defined( 'WPINC' ) ) {
17 die;
18 }
19
20 // Set the plugin version.
21 define( 'SERVER_INFO_PLUGIN_VERSION', '0.0.1' );
22
23 // Set the plugin file.
24 define( 'SERVER_INFO_PLUGIN_FILE', __FILE__ );
25
26 // Set the absolute path for the plugin.
27 define( 'SERVER_INFO_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
28
29 // Set the plugin URL root.
30 define( 'SERVER_INFO_PLUGIN_URL', plugins_url( '/', __FILE__ ) );
31
32 /**
33 * Class ServerInfo
34 */
35 class Server_Info {
36
37 /**
38 * Singleton instance static property
39 */
40 static $instance = false;
41
42 /**
43 * If an instance exists, this returns it. If not, it creates one and returns it.
44 *
45 * @return Server_Info instance
46 */
47 public static function getInstance() {
48 if ( ! self::$instance ) {
49 self::$instance = new self;
50 }
51
52 return self::$instance;
53 }
54
55 /**
56 * Plugin constructor
57 *
58 * @return void
59 */
60 private function __construct() {
61 $this->init();
62 }
63
64 /**
65 * Plugin initiation.
66 *
67 * A helper function to initiate actions, hooks and other features needed.
68 *
69 * @return void
70 */
71 public function init() {
72 add_action( 'plugins_loaded', array( $this, 'load_i18n' ) );
73 add_action( 'wp_dashboard_setup', array( $this, 'add_dashboard_widgets' ) );
74 add_action( 'admin_menu', array( $this, 'add_plugin_menu' ) );
75 add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) );
76 }
77
78 /**
79 * Load plugin translations.
80 *
81 * Loads the textdomain needed to get translations for the plugin.
82 *
83 * @return void
84 */
85 public function load_i18n() {
86 load_plugin_textdomain( 'server-info', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
87 }
88
89 /**
90 * Adds plugin styles & scripts
91 *
92 * @return void
93 */
94 public function admin_scripts() {
95 wp_enqueue_style( 'server-info', SERVER_INFO_PLUGIN_URL . '/assets/css/style.css', array(), SERVER_INFO_PLUGIN_VERSION, 'all' );
96 }
97
98 /**
99 * Adds the plugin menu
100 *
101 * @return void
102 */
103 public function add_plugin_menu() {
104 add_options_page(
105 esc_html__( 'Server Information', 'server-info' ),
106 esc_html__( 'Server Info', 'server-info' ),
107 'manage_options',
108 'server_info_display',
109 array( 'Server_Info', 'display_server_info' )
110 );
111 }
112
113 /**
114 * Adds the plugin dashboard widget
115 *
116 * @return void
117 */
118 public function add_dashboard_widgets() {
119 wp_add_dashboard_widget(
120 'serverinfo_dashboard_widget',
121 esc_html__( 'Server Info', 'server-info' ),
122 array( 'server_info', 'display_dashboard_widget' )
123 );
124 }
125
126 /**
127 * Displays the plugin dashboard widget content
128 *
129 * @return void
130 */
131 public static function display_dashboard_widget() {
132 ?>
133 <table class="table striped infohouse_table dashboard_inf_table">
134 <?php
135 if ( function_exists( 'php_uname' ) ) {
136 ?>
137 <tr>
138 <td><?php esc_html_e( 'Operating System', 'server-info' ); ?>:</td>
139 <td><?php echo php_uname( "s" ); ?></td>
140 </tr>
141 <?php
142 }
143
144 if ( isset( $_SERVER['SERVER_ADDR'] ) ) {
145 ?>
146 <tr>
147 <td><?php esc_html_e( 'Server IP', 'server-info' ); ?>:</td>
148 <td><?php echo esc_html( $_SERVER['SERVER_ADDR'] ); ?></td>
149 </tr>
150 <?php
151 }
152
153 if ( function_exists( 'php_uname' ) ) {
154 ?>
155 <tr>
156 <td><?php esc_html_e( 'Server Hostname', 'server-info' ); ?>:</td>
157 <td><?php echo php_uname( 'n' ); ?></td>
158 </tr>
159 <?php
160 }
161
162 if ( function_exists( 'phpversion' ) ) {
163 ?>
164 <tr>
165 <td><?php esc_html_e( 'PHP Version', 'server-info' ); ?>:</td>
166 <td><?php echo phpversion(); ?></td>
167 </tr>
168 <?php
169 }
170 ?>
171 <tr>
172 <td colspan="2" class="view-more-info">
173 <a class="button button-primary" href="<?php echo admin_url( 'options-general.php?page=server_info_display' ); ?>"><?php esc_html_e( 'View More Information', 'server-info' ); ?></a>
174 </td>
175 </tr>
176 </table>
177 <?php
178 }
179
180 /**
181 * Static function for generating site info.
182 *
183 * @return array
184 */
185 public static function site_info() {
186 global $wpdb;
187
188 // Set up the array that holds all information.
189 $info = array();
190
191 $info['wp-server'] = array(
192 'label' => esc_html__( 'Hosting Server Information', 'server-info' ),
193 'fields' => array(),
194 );
195
196 if ( function_exists( 'phpversion' ) ) {
197 $php_version_debug = phpversion();
198 // Whether PHP supports 64-bit.
199 $php64bit = ( PHP_INT_SIZE * 8 === 64 );
200
201 $php_version = sprintf(
202 '%s %s',
203 $php_version_debug,
204 ( $php64bit ? esc_html__( '(Supports 64bit values)', 'server-info' ) : esc_html__( '(Does not support 64bit values)', 'server-info' ) )
205 );
206 } else {
207 $php_version = esc_html__( 'Unable to determine PHP version', 'server-info' );
208 }
209
210 if ( function_exists( 'php_uname' ) ) {
211 $server_architecture = sprintf( '%s %s %s', php_uname( 's' ), php_uname( 'r' ), php_uname( 'm' ) );
212 } else {
213 $server_architecture = 'unknown';
214 }
215 $info['wp-server']['fields']['operating_system'] = array(
216 'label' => esc_html__( 'Operating System', 'server-info' ),
217 'value' => ( 'unknown' !== $server_architecture ? $server_architecture : esc_html__( 'Unable to determine server architecture', 'server-info' ) )
218 );
219
220 if ( function_exists( 'php_uname' ) ) {
221 $info['wp-server']['fields']['server_hostname'] = array(
222 'label' => esc_html__( 'Server Hostname', 'server-info' ),
223 'value' => php_uname( 'n' )
224 );
225 }
226
227 if ( isset( $_SERVER['SERVER_ADDR'] ) ) {
228 $info['wp-server']['fields']['server_ip'] = array(
229 'label' => esc_html__( 'Server IP', 'server-info' ),
230 'value' => esc_html( $_SERVER['SERVER_ADDR'] )
231 );
232 }
233
234 if ( isset( $_SERVER['SERVER_PROTOCOL'] ) ) {
235 $info['wp-server']['fields']['server_protocol'] = array(
236 'label' => esc_html__( 'Server Protocol', 'server-info' ),
237 'value' => esc_html( $_SERVER['SERVER_PROTOCOL'] )
238 );
239 }
240
241 if ( isset( $_SERVER['SERVER_ADMIN'] ) ) {
242 $info['wp-server']['fields']['server_administrator'] = array(
243 'label' => esc_html__( 'Server Administrator', 'server-info' ),
244 'value' => esc_html( $_SERVER['SERVER_ADMIN'] )
245 );
246 }
247
248 if ( isset( $_SERVER['SERVER_PORT'] ) ) {
249 $info['wp-server']['fields']['server_web_port'] = array(
250 'label' => esc_html__( 'Server Web Port', 'server-info' ),
251 'value' => esc_html( $_SERVER['SERVER_PORT'] )
252 );
253 }
254
255 $uptime = exec( "uptime", $system );
256 if ( ! empty( $uptime ) ) {
257 $info['wp-server']['fields']['system_uptime'] = array(
258 'label' => esc_html__( 'System Uptime', 'server-info' ),
259 'value' => esc_html( $uptime )
260 );
261 }
262
263 $info['wp-server']['fields']['httpd_software'] = array(
264 'label' => esc_html__( 'Web server', 'server-info' ),
265 'value' => ( isset( $_SERVER['SERVER_SOFTWARE'] ) ? $_SERVER['SERVER_SOFTWARE'] : esc_html__( 'Unable to determine what web server software is used', 'server-info' ) )
266 );
267
268 $info['wp-server']['fields']['php_version'] = array(
269 'label' => esc_html__( 'PHP version', 'server-info' ),
270 'value' => $php_version,
271 );
272
273 // Some servers disable `ini_set()` and `ini_get()`, we check this before trying to get configuration values.
274 if ( function_exists( 'ini_get' ) ) {
275 $info['wp-server']['fields']['memory_limit'] = array(
276 'label' => esc_html__( 'PHP memory limit', 'server-info' ),
277 'value' => ini_get( 'memory_limit' ),
278 );
279 }
280
281 if ( isset( $_SERVER['GATEWAY_INTERFACE'] ) ) {
282 $info['wp-server']['fields']['CGI_version'] = array(
283 'label' => esc_html__( 'CGI Version', 'server-info' ),
284 'value' => esc_html( $_SERVER['GATEWAY_INTERFACE'] )
285 );
286 }
287
288 /**
289 * Database
290 */
291 $info['wp-database'] = array(
292 'label' => esc_html__( 'Database', 'server-info' ),
293 'fields' => array(),
294 );
295
296 // Populate the database fields.
297 if ( is_resource( $wpdb->dbh ) ) {
298 // Old mysql extension.
299 $extension = 'mysql';
300 } else if ( is_object( $wpdb->dbh ) ) {
301 // mysqli or PDO.
302 $extension = get_class( $wpdb->dbh );
303 } else {
304 // Unknown sql extension.
305 $extension = null;
306 }
307
308 $server = $wpdb->get_var( 'SELECT VERSION()' );
309
310 if ( isset( $wpdb->use_mysqli ) && $wpdb->use_mysqli ) {
311 $client_version = $wpdb->dbh->client_info;
312 } else {
313 // phpcs:ignore WordPress.DB.RestrictedFunctions.mysql_mysql_get_client_info,PHPCompatibility.Extensions.RemovedExtensions.mysql_DeprecatedRemoved
314 if ( preg_match( '|[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}|', mysql_get_client_info(), $matches ) ) {
315 $client_version = $matches[0];
316 } else {
317 $client_version = null;
318 }
319 }
320
321 $info['wp-database']['fields']['extension'] = array(
322 'label' => esc_html__( 'Extension', 'server-info' ),
323 'value' => $extension,
324 );
325
326 $info['wp-database']['fields']['server_version'] = array(
327 'label' => esc_html__( 'Server version', 'server-info' ),
328 'value' => $server,
329 );
330
331 $info['wp-database']['fields']['client_version'] = array(
332 'label' => esc_html__( 'Client version', 'server-info' ),
333 'value' => $client_version,
334 );
335
336 $info['wp-database']['fields']['database_user'] = array(
337 'label' => esc_html__( 'Database username', 'server-info' ),
338 'value' => $wpdb->dbuser,
339 'private' => true,
340 );
341
342 $info['wp-database']['fields']['database_host'] = array(
343 'label' => esc_html__( 'Database host', 'server-info' ),
344 'value' => $wpdb->dbhost,
345 'private' => true,
346 );
347
348 $info['wp-database']['fields']['database_name'] = array(
349 'label' => esc_html__( 'Database name', 'server-info' ),
350 'value' => $wpdb->dbname,
351 'private' => true,
352 );
353
354 $info['wp-database']['fields']['database_prefix'] = array(
355 'label' => esc_html__( 'Table prefix', 'server-info' ),
356 'value' => $wpdb->prefix,
357 'private' => true,
358 );
359
360 $info['wp-database']['fields']['database_charset'] = array(
361 'label' => esc_html__( 'Database charset', 'server-info' ),
362 'value' => $wpdb->charset,
363 'private' => true,
364 );
365
366 $info['wp-database']['fields']['database_collate'] = array(
367 'label' => esc_html__( 'Database collation', 'server-info' ),
368 'value' => $wpdb->collate,
369 'private' => true,
370 );
371
372 /**
373 * WordPress Information
374 */
375 $is_multisite = is_multisite();
376 $info['wp-info'] = array(
377 'label' => esc_html__( 'WordPress Information', 'server-info' ),
378 'fields' => array(
379 'multisite' => array(
380 'label' => esc_html__( 'Is this a multisite?', 'server-info' ),
381 'value' => $is_multisite ? esc_html__( 'Yes', 'server-info' ) : esc_html__( 'No', 'server-info' ),
382 ),
383 ),
384 );
385
386 if ( is_multisite() ) {
387 $network_query = new WP_Network_Query();
388 $network_ids = $network_query->query(
389 array(
390 'fields' => 'ids',
391 'number' => 100,
392 'no_found_rows' => false,
393 )
394 );
395
396 $site_count = 0;
397 foreach ( $network_ids as $network_id ) {
398 $site_count += get_blog_count( $network_id );
399 }
400
401 $info['wp-info']['fields']['user_count'] = array(
402 'label' => esc_html__( 'User count', 'server-info' ),
403 'value' => get_user_count(),
404 );
405
406 $info['wp-info']['fields']['site_count'] = array(
407 'label' => esc_html__( 'Site count', 'server-info' ),
408 'value' => $site_count,
409 );
410
411 $info['wp-info']['fields']['network_count'] = array(
412 'label' => esc_html__( 'Network count', 'server-info' ),
413 'value' => $network_query->found_networks,
414 );
415 } else {
416 $user_count = count_users();
417
418 $info['wp-info']['fields']['user_count'] = array(
419 'label' => esc_html__( 'User count', 'server-info' ),
420 'value' => $user_count['total_users'],
421 );
422 }
423
424 $active_theme = wp_get_theme();
425 $info['wp-info']['fields'] = array(
426 'name' => array(
427 'label' => esc_html__( 'Active Theme', 'server-info' ),
428 'value' => sprintf(
429 esc_html__( '%1$s (%2$s)', 'server-info' ),
430 $active_theme->name,
431 $active_theme->stylesheet
432 ),
433 ),
434 );
435
436 // List all available plugins.
437 $plugins = get_plugins();
438 $plugins_active = array();
439 $plugins_inactive = array();
440
441 foreach ( $plugins as $plugin_path => $plugin ) {
442 $plugin_author = $plugin['Author'];
443
444 if ( ! empty( $plugin_author ) ) {
445 $plugin_author = sprintf( esc_html__( 'By %s', 'server-info' ), $plugin_author );
446 } else {
447 $plugin_author = '';
448 }
449
450 if ( is_plugin_active( $plugin_path ) ) {
451 $plugins_active[ $plugin['Name'] ] = $plugin_author;
452 } else {
453 $plugins_inactive[ $plugin['Name'] ] = $plugin_author;
454 }
455 }
456
457 if ( empty( $plugins_active ) ) {
458 $plugins_active = esc_html__( 'None', 'server-info' );
459 }
460 $info['wp-info']['fields']['plugins_active'] = array(
461 'label' => esc_html__( 'Active Plugins', 'server-info' ),
462 'value' => $plugins_active,
463 );
464
465 if ( empty( $plugins_inactive ) ) {
466 $plugins_inactive = esc_html__( 'None', 'server-info' );
467 }
468 $info['wp-info']['fields']['plugins_inactive'] = array(
469 'label' => esc_html__( 'Inactive Plugins', 'server-info' ),
470 'value' => $plugins_inactive,
471 );
472
473 $info['wp-info']['fields']['WP_MEMORY_LIMIT'] = array(
474 'label' => esc_html__( 'WordPress Memory Limit', 'server-info' ),
475 'value' => WP_MEMORY_LIMIT,
476 );
477
478 $info['wp-info']['fields']['WP_MAX_MEMORY_LIMIT'] = array(
479 'label' => esc_html__( 'WordPress Max Memory Limit', 'server-info' ),
480 'value' => WP_MAX_MEMORY_LIMIT,
481 );
482
483 $info['wp-info']['fields']['WP_DEBUG'] = array(
484 'label' => esc_html__( 'WordPress Debugging', 'server-info' ),
485 'value' => WP_DEBUG ? esc_html__( 'Enabled', 'server-info' ) : esc_html__( 'Disabled', 'server-info' )
486 );
487
488 return $info;
489 }
490
491 /**
492 * Displays the plugin content
493 *
494 * @return void
495 */
496 public static function display_server_info() {
497 ?>
498 <div class="wrap server-info">
499 <h2 class="infohouse_heading"><?php esc_html_e( 'Server Information', 'server-info' ); ?></h2>
500 <hr />
501 <p><?php esc_html_e( 'Server Info plugin shows the general information about the hosting server your WordPress site is currently hosted on. You can find this information helpful for many purposes like performance improvements and so on.', 'server-info' ); ?></p><br />
502 <div class="infohouse_settings_page">
503 <div class="table-responsive">
504 <?php
505 $info = Self::site_info();
506 foreach ( $info as $details ) {
507 if ( ! isset( $details['fields'] ) || empty( $details['fields'] ) ) {
508 continue;
509 }
510 ?>
511 <table class="table widefat striped infohouse_table">
512 <tbody>
513 <tr>
514 <th colspan="2"><h3 class="server-info-heading"><?php echo esc_html( $details['label'] ); ?></h3></th>
515 </tr>
516 <?php
517 foreach ( $details['fields'] as $field ) {
518 if ( is_array( $field['value'] ) ) {
519 $values = '<ul>';
520 foreach ( $field['value'] as $name => $value ) {
521 $values .= sprintf( '<li>%s<br /><span>%s</span></li>', esc_html( $name ), esc_html( $value ) );
522 }
523 $values .= '</ul>';
524 } else {
525 $values = esc_html( $field['value'] );
526 }
527
528 printf( '<tr><td>%s</td><td>%s</td></tr>', esc_html( $field['label'] ), $values );
529 }
530 ?>
531 </tbody>
532 </table>
533 <?php
534 }
535 ?>
536 </div>
537 </div>
538 </div>
539 <?php
540 }
541 }
542
543 // Instantiate the ServerInfo class
544 $Server_Info = Server_Info::getInstance();