get_results( $wpdb->prepare( 'SELECT TABLE_NAME AS name, COALESCE(DATA_LENGTH + INDEX_LENGTH, 0) AS bytes FROM information_schema.TABLES WHERE TABLE_SCHEMA = %s', DB_NAME ), ARRAY_A ); if ( ! is_array( $rows ) || empty( $rows ) ) { $names = $wpdb->get_col( 'SHOW TABLES' ); $rows = array(); foreach ( (array) $names as $name ) { $rows[] = array( 'name' => $name, 'bytes' => 0, ); } } $prefix = $wpdb->prefix; $out = array(); foreach ( $rows as $row ) { $name = (string) ( $row['name'] ?? '' ); if ( '' === $name || ! Security::is_install_table( $name ) ) { continue; } $out[] = array( 'name' => $name, 'size' => size_format( (int) ( $row['bytes'] ?? 0 ) ), 'is_prefixed' => str_starts_with( $name, $prefix ), 'is_multisite' => (bool) preg_match( '/_[0-9]+_/', $name ), ); } return $out; } /** * List every post type that actually has rows in wp_posts — fully dynamic, * including WordPress internal types (attachment, wp_global_styles, * wp_navigation, wp_template…) and orphaned types left by removed plugins. * Types with no data are omitted, and * each entry carries its row count for display. * * @return array */ public static function get_post_types(): array { global $wpdb; $rows = $wpdb->get_results( $wpdb->prepare( 'SELECT post_type, COUNT(*) AS num FROM %i GROUP BY post_type ORDER BY post_type ASC', $wpdb->posts ), ARRAY_A ); $out = array(); foreach ( (array) $rows as $row ) { $name = (string) ( $row['post_type'] ?? '' ); if ( '' === $name ) { continue; } $count = (int) ( $row['num'] ?? 0 ); $obj = get_post_type_object( $name ); if ( $obj && ! empty( $obj->labels->name ) ) { $label = (string) $obj->labels->name; } elseif ( $obj && ! empty( $obj->label ) ) { $label = (string) $obj->label; } else { $label = self::prettify_slug( $name ); } $out[] = array( 'name' => $name, 'label' => $label, 'count' => $count, 'size' => number_format_i18n( $count ), // Rendered as "Label (count)" by the check-list. ); } return $out; } /** * Turn an unregistered post-type slug into a readable fallback label. * * @param string $slug Post-type slug. * @return string */ private static function prettify_slug( string $slug ): string { return ucwords( trim( str_replace( array( '_', '-' ), ' ', $slug ) ) ); } /** * Get themes. */ public static function get_themes(): array { $themes = wp_get_themes(); $template = get_option( 'stylesheet' ); $out = array(); foreach ( $themes as $slug => $theme ) { $out[] = array( 'slug' => $slug, 'name' => $theme->get( 'Name' ), 'is_active' => $slug === $template, ); } return $out; } /** * Get plugins. */ public static function get_plugins(): array { require_once ABSPATH . 'wp-admin/includes/plugin.php'; $all = get_plugins(); $active = get_option( 'active_plugins', array() ); $out = array(); foreach ( $all as $file => $plugin ) { $slug = dirname( $file ); if ( '.' === $slug ) { $slug = basename( $file, '.php' ); } $out[] = array( 'file' => $file, 'slug' => $slug, 'name' => $plugin['Name'], 'is_active' => in_array( $file, $active, true ), ); } return $out; } }