Created
June 8, 2020 10:44
-
-
Save maheshwaghmare/5605d5723075463668f9bf8f4bb73437 to your computer and use it in GitHub Desktop.
Get the size of all options which are set as `autoload_size` in the WordPress `wp_options` ($wpdb->options) table.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Get Autoload Options Size | |
* | |
* Get the size of all options which are set as `autoload_size` in the WordPress `wp_options` ($wpdb->options) table. | |
* | |
* @todo Change the `prefix_` and with your own unique prefix. | |
* | |
* @since 1.0.0 | |
*/ | |
if( ! function_exists( 'prefix_get_autoload_options_size' ) ) : | |
function prefix_get_autoload_options_size() { | |
global $wpdb; | |
$size = $wpdb->get_col( "SELECT SUM(LENGTH(`option_value`)) as `autoload_size` FROM {$wpdb->options} WHERE `autoload`='yes'" ); | |
var_dump( $size ); | |
var_dump( size_format( $size[0] ) ); | |
// Output (Something like below:: | |
// | |
// array (size=1) 0 => string '454502' (length=6) | |
// string '444 KB' (length=6) | |
wp_die(); | |
} | |
add_action( 'wp_head', 'prefix_get_autoload_options_size' ); | |
endif; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment