*/ class Adminify_Memory_Usage { public function __construct() { add_action( 'wp_dashboard_setup', [ $this, 'jltwp_adminify_memory_usage_widget' ] ); add_action( 'wp_network_dashboard_setup', [ $this, 'jltwp_adminify_memory_usage_widget' ] ); // add_action( 'admin_enqueue_scripts', array( $this, 'jltwp_adminify_memory_usage_admin_css' ) ); } // Register Memory Usage Dashboard Widget public function jltwp_adminify_memory_usage_widget() { add_meta_box( 'jltwp_adminify_memory_usage', __( 'WP Memory Usage - Adminify', 'adminify' ), [ $this, 'jltwp_adminify_memory_usage_widget_details' ], 'dashboard', 'side', 'high' ); } public function jltwp_adminify_memory_usage_admin_css() { $screen = get_current_screen(); if ( $screen->id == 'dashboard' ) { $my_site_space_css = ''; $my_site_space_css .= ''; echo ''; } } public function jltwp_adminify_memory_usage_get_memory() { $memory['memory_limit'] = ini_get( 'memory_limit' ); $memory['memory_usage'] = function_exists( 'memory_get_usage' ) ? round( memory_get_usage(), 2 ) : 0; return $memory; } // Create the function to output the contents of our Dashboard Widget public function jltwp_adminify_memory_usage_widget_details() { global $wpdb; $dbname = $wpdb->dbname; $phpversion = PHP_VERSION; $memory = $this->jltwp_adminify_memory_usage_get_memory(); $memory_limit = $memory['memory_limit']; $memory_usage = $memory['memory_usage']; // Get Memory if ( ! empty( $memory_usage ) && ! empty( $memory_limit ) ) { $memory_percent = round( (int) $memory_usage / (int) $memory_limit * 100, 0 ); } // Get Database Size $result = $wpdb->get_results( 'SHOW TABLE STATUS', ARRAY_A ); $rows = count( $result ); $dbsize = 0; if ( $wpdb->num_rows > 0 ) { foreach ( $result as $row ) { $dbsize += $row['Data_length'] + $row['Index_length']; } } // PHP version, memory, database size and entire site usage (may include not WP items) $topitems = [ 'PHP Version' => $phpversion . ' ' . ( PHP_INT_SIZE * 8 ) . ' ' . __( 'Bit OS', 'adminify' ), 'Memory' => size_format( $memory_usage, 2 ) . __( ' of ', 'adminify' ) . $memory_limit, 'Database' => size_format( $dbsize, 2 ), ]; // Check if WP_CONTENT_DIR outside of base path (ABSPATH) if ( strpos( WP_CONTENT_DIR, ABSPATH ) !== false ) { // WP_CONTENT_DIR in ABSPATH $entire_site_size = $this->jltwp_adminify_memory_usage_dir_size( ABSPATH ); if ( $entire_site_size > 0 ) { $topitems['Entire Site'] = $this->jltwp_adminify_memory_usage_dir_size_display( [ $entire_site_size ] ); } } else { // WP_CONTENT_DIR outside ABSPATH $entire_abs_size = $this->jltwp_adminify_memory_usage_dir_size( ABSPATH ); $entire_content_size = $this->jltwp_adminify_memory_usage_dir_size( WP_CONTENT_DIR ); if ( $entire_abs_size > 0 && $entire_content_size > 0 ) { $topitems['Entire Site'] = $this->jltwp_adminify_memory_usage_dir_size_display( [ $entire_abs_size, $entire_content_size ] ); } } foreach ( $topitems as $name => $value ) { echo '
' . Utils::wp_kses_custom( $name ) . ': ' . Utils::wp_kses_custom( $value ) . '
'; } echo '' . esc_html__( 'Memory Used by ', 'adminify' ) . '
'; $uploads = wp_get_upload_dir(); // Get upload directory array without creating it // WP Content and selected subfolders $contents = [ 'wp-content' => WP_CONTENT_DIR, 'plugins' => WP_PLUGIN_DIR, 'themes' => get_theme_root(), 'uploads' => $uploads['basedir'], ]; foreach ( $contents as $name => $value ) { $name = __( $name, 'adminify' ); // Make translatable if ( false === ( get_transient( $value ) ) ) { echo '' . Utils::wp_kses_custom( $name ) . ': ' . wp_kses_post( $this->jltwp_adminify_memory_usage_dir_size_display( [ $this->jltwp_adminify_memory_usage_dir_size( $value ) ] ) ) . '' . esc_html__( 'Other WP Folders', 'adminify' ) . '
'; // wp-admin and wp-includes folders $folders = [ 'wp - admin' => $wpadmin, 'wp - includes' => $wpincludes, ]; foreach ( $folders as $name => $value ) { $name = esc_html__( $name, 'adminify' ); // Make translatable if ( false === ( get_transient( $value ) ) ) { echo '' . Utils::wp_kses_custom( $name ) . ': ' . wp_kses_post( $this->jltwp_adminify_memory_usage_dir_size_display( [ $this->jltwp_adminify_memory_usage_dir_size( $value ) ] ) ) . '