Skip to content

Instantly share code, notes, and snippets.

@maheshwaghmare
Created June 8, 2020 10:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maheshwaghmare/5605d5723075463668f9bf8f4bb73437 to your computer and use it in GitHub Desktop.
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.
<?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