PluginProbe
Autoload Checker / 1.0
Autoload Checker v1.0
trunk 1.0 1.1 1.2
autoload-checker / autoload-checker.php

autoload-checker.php in Autoload Checker 1.0, at autoload-checker.php

113 lines 3.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: Autoload Checker
4 Version: 1.0
5 Description: Checks the autoloaded data size and lists the top autoloaded data entries sorted by size.
6 Author: Gerard Blanco
7 Author URI: https://accelerawp.com
8 License: GPLv2 or later
9 License URI: https://www.gnu.org/licenses/gpl-2.0.html
10 Text Domain: autoload-checker
11 */
12
13 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
14
15 #
16 # Main Class: GRBLNC_Autoload_Checker - Solid prefix to avoid conflicts with other plugins
17 #
18
19 if( !class_exists( 'GRBLNC_Autoload_Checker' ) ){
20
21 class GRBLNC_Autoload_Checker{
22
23 function __construct(){
24 // Call autoload_size_menu function to load plugin menu in dashboard
25 add_action( 'admin_menu', [ $this, 'autoload_size_menu' ] );
26 }
27
28 // Create WordPress admin menu
29 function autoload_size_menu() {
30 $parent_slug = 'tools.php';
31 $page_title = 'Autoload Checker';
32 $menu_title = 'Autoload Checker';
33 $capability = 'manage_options';
34 $menu_slug = 'autoload-checker';
35 $function = [ $this, 'autoload_checker' ];
36
37 add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function );
38 }
39
40 // Create WordPress plugin page
41 function autoload_checker() {
42 ?>
43 <div class="wrap">
44 <h1><?php echo esc_html__( 'Total Autoload Size','autoload-checker' ); ?></h1>
45 <?php
46 global $wpdb;
47
48 //Get table prefix
49 $options_table = $wpdb->prefix . 'options';
50
51 //Get total size
52 $result =
53 $wpdb->get_results(
54 $wpdb->prepare(
55 "SELECT SUM( LENGTH( option_value ) / 1024.0 ) as autoload_size FROM %i WHERE autoload = 'yes'",
56 $options_table
57 ),
58
59 );
60
61 //Get top 20 autoloads
62 $autoload_toplist =
63 $wpdb->get_results(
64 $wpdb->prepare(
65 "SELECT option_name, LENGTH( option_value ) / 1024.0 AS option_value_length FROM %i WHERE autoload = 'yes' ORDER BY option_value_length DESC LIMIT 20",
66 $options_table
67 ),
68
69 );
70
71 //Show total
72 foreach( $result as $object => $uno ) {
73 $size = round( $uno->autoload_size ) . ' KB';
74 ?>
75 <p style="font-weight:bold;font-size:1.5em;"><?php echo esc_html( $size ); ?></p>
76 <?php
77 }
78
79 //Show top list
80 ?>
81 <h2><?php echo esc_html__( 'Autoload top list:','autoload-checker' ); ?></h2>
82 <table style="max-width:600px;" class="widefat striped">
83 <thead><tr>
84 <th scope="col"><?php echo esc_html__( '#','autoload-checker' ); ?></th>
85 <th scope="col"><?php echo esc_html__( 'Option name','autoload-checker' ); ?></th>
86 <th scope="col"><?php echo esc_html__( 'Size','autoload-checker' ); ?></th>
87 </tr></thead>
88 <tbody>
89 <?php foreach ( $autoload_toplist as $k => $v ) :
90 $index = $k + 1;
91 $option_name = $v->option_name;
92 $size = round( $v->option_value_length ) . ' KB';
93 ?>
94 <tr>
95 <td><?php echo esc_html( $index ); ?></td>
96 <td><?php echo esc_html( $option_name ); ?></td>
97 <td><?php echo esc_html( $size ); ?></td>
98 </tr>
99 <?php endforeach; ?>
100 </tbody>
101 </table>
102 </div>
103 <?php
104 }
105 }
106
107
108 # Run the class
109 new GRBLNC_Autoload_Checker;
110
111 }
112 ?>
113