get_row( $wpdb->prepare( "SELECT COUNT(*) AS item_count, COALESCE( SUM( LENGTH( option_value ) ), 0 ) AS bytes FROM {$wpdb->options} WHERE autoload IN ( $placeholders )", $values ) ); return array( 'count' => $row ? (int) $row->item_count : 0, 'bytes' => $row ? (int) $row->bytes : 0, ); } /** * Gesamtbild plus die groessten Optionen. * * @return array{count: int, bytes: int, threshold: int, over: bool, items: array>} */ public static function analyze() { global $wpdb; $total = self::total(); $values = wp_autoload_values_to_autoload(); $placeholders = implode( ',', array_fill( 0, count( $values ), '%s' ) ); $args = array_merge( $values, array( self::TOP ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare -- Auflisten der groessten Optionen; ein Cache wuerde die Analyse verfaelschen. $rows = $wpdb->get_results( $wpdb->prepare( "SELECT option_name, autoload, LENGTH( option_value ) AS size FROM {$wpdb->options} WHERE autoload IN ( $placeholders ) ORDER BY size DESC, option_name ASC LIMIT %d", $args ) ); $plugins = self::installed_plugins(); $slugs = array_keys( $plugins ); $items = array(); foreach ( (array) $rows as $row ) { $size = (int) $row->size; $owner = Wp360_Database_Cleaner_Autoload_Classifier::guess_owner( $row->option_name, $slugs ); $items[] = array( 'name' => $row->option_name, 'size' => $size, 'raw' => $row->autoload, 'loads' => Wp360_Database_Cleaner_Autoload_Classifier::loads( $row->autoload ), 'lock_reason' => Wp360_Database_Cleaner_Autoload_Guard::lock_reason( $row->option_name ), 'risk' => Wp360_Database_Cleaner_Autoload_Classifier::risk_level( $size ), 'owner' => null === $owner ? null : $plugins[ $owner ], ); } $threshold = self::threshold(); return array( 'count' => $total['count'], 'bytes' => $total['bytes'], 'threshold' => $threshold, 'over' => $total['bytes'] >= $threshold, 'items' => $items, ); } /** * Installierte Plugins als Slug => Anzeigename. Slug ist der Ordnername, bei * Einzeldateien der Dateiname ohne ".php". * * @return array */ private static function installed_plugins() { if ( ! function_exists( 'get_plugins' ) ) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } $out = array(); foreach ( get_plugins() as $file => $data ) { $dir = dirname( $file ); $slug = '.' === $dir ? basename( $file, '.php' ) : $dir; $out[ $slug ] = '' !== $data['Name'] ? $data['Name'] : $slug; } return $out; } }