';
echo '';
}
/**
* callback_function AJAX called function that displays the size of each author's plugins & themes
*
* @return void AJAX ends the function passing die()
*/
function callback_function(){
$all_themes = wp_get_themes();
$authors = [];
foreach( $all_themes as $key => $val ){
$theme = get_theme_root() . '/' . $key;
$obj_filter = $this->GetThe_Size( $theme );
$Author = wp_strip_all_tags( $val->Author );
$authors[$Author]['themes'][$key] = $obj_filter;
$authors[$Author]['TOTAL_filter'] += $obj_filter;
$authors[$Author]['TOTAL_filter_KB'] += ( $obj_filter / 1000 );
$authors[$Author]['TOTAL_filter_MB'] += ( $obj_filter / 1000000 );
}
$all_plugins = get_plugins();
foreach( $all_plugins as $key => $val ){
$dir = dirname( $key );
$Author = $val['Author'];
$plugin = WP_PLUGIN_DIR . '/' . $dir;
$obj_filter = $this->GetThe_Size( $plugin );
$authors[$Author]['plugins'][$key] = $obj_filter;
$authors[$Author]['TOTAL_filter'] += $obj_filter;
$authors[$Author]['TOTAL_filter_KB'] += ( $obj_filter / 1000 );
$authors[$Author]['TOTAL_filter_MB'] += ( $obj_filter / 1000000 );
}
$render = "";
$render .= "";
foreach ( $authors as $key => $val ){
$render .= "";
$MB = round( $val['TOTAL_filter_MB'], 2 );
$MB_unit = __( 'MB', 'about-coders' );
$render .= "$key$MB $MB_unit
";
$values = ['themes' => 'Themes', 'plugins' => 'Extensions'];
foreach( $values as $type => $type_name ){
if( $val[$type] ) {
$render .= "$type_name
";
foreach ( $val[$type] as $name => $size ){
$size = number_format( $size, 0, '', ' ' );
$name = basename( $name );
$B_unit = __( 'B', 'about-coders' );
$render .= "$name$size $B_unit
";
}
}
}
$render .= " ";
}
echo $render;
die();
}
/**
* GetThe_Size will compute the size of .php .js and .css files.
*
* @param mixed $path of the main directory of plugin or theme
* @return int $bytestotal is computed by iteration in subdirectories
*/
function GetThe_Size( $path ){
$bytestotal = 0;
$path = realpath( $path );
$iterator = new RecursiveDirectoryIterator( $path, FilesystemIterator::KEY_AS_PATHNAME );
$recursiveIterator = new RecursiveIteratorIterator( $iterator );
foreach($recursiveIterator as $key => $file) {
if( strpos( $key, 'node_modules' ) === false && ( strpos( $key, '.js' ) !== false || strpos( $key, '.php' ) !== false || strpos( $key, '.css' ) !== false ) )
$bytestotal += $file->getSize();
}
return $bytestotal;
}
}