*/ public static function collect() { $active = self::active_plugin_folders(); return array( 'php_version' => PHP_VERSION, 'memory_limit' => self::memory_limit(), 'opcache' => self::opcache(), 'object_cache' => self::object_cache(), 'wp_debug' => defined( 'WP_DEBUG' ) && WP_DEBUG, 'savequeries' => defined( 'SAVEQUERIES' ) && SAVEQUERIES && ! Wp360_Speed_Optimizer_Doctor_Collector::defined_savequeries(), 'autoload_bytes' => self::autoload_bytes(), 'active_plugin_count' => count( $active ), 'active_plugins' => array_slice( $active, 0, 100 ), 'plugins_active' => self::known_plugins( $active ), 'page_cache_plugin' => self::page_cache_plugin( $active ), 'can_write_htaccess' => self::can_write_htaccess(), 'heartbeat_throttled' => self::heartbeat_throttled(), 'css_js_revalidate' => self::css_js_revalidate(), 'server_software' => isset( $_SERVER['SERVER_SOFTWARE'] ) ? substr( sanitize_text_field( wp_unslash( $_SERVER['SERVER_SOFTWARE'] ) ), 0, 100 ) : '', ); } /** * Laeuft ein dauerhafter Objekt-Cache? null, wenn unbekannt. * * @return bool|null */ public static function object_cache() { return function_exists( 'wp_using_ext_object_cache' ) ? (bool) wp_using_ext_object_cache() : null; } /** * Speichergrenze in Byte; 0, wenn unbegrenzt oder unbekannt. * * @return int */ public static function memory_limit() { $raw = ini_get( 'memory_limit' ); if ( false === $raw || '' === $raw || '-1' === (string) $raw ) { return 0; } $bytes = function_exists( 'wp_convert_hr_to_bytes' ) ? wp_convert_hr_to_bytes( $raw ) : (int) $raw; return $bytes > 0 ? (int) $bytes : 0; } /** * @return bool|null null, wenn nicht feststellbar. */ private static function opcache() { if ( ! extension_loaded( 'Zend OPcache' ) && ! function_exists( 'opcache_get_status' ) ) { return false; } $enabled = ini_get( 'opcache.enable' ); if ( false === $enabled ) { return null; } return filter_var( $enabled, FILTER_VALIDATE_BOOLEAN ); } /** * Gesamtgroesse der Autoload-Optionen wie die Website-Zustandspruefung sie * berechnet: aus den bereits geladenen Optionen, ohne weitere Abfrage. * * @return int|null */ public static function autoload_bytes() { if ( ! function_exists( 'wp_load_alloptions' ) ) { return null; } $total = 0; foreach ( wp_load_alloptions() as $value ) { if ( is_array( $value ) || is_object( $value ) ) { $value = maybe_serialize( $value ); } $total += strlen( (string) $value ); } return $total; } /** * Ordnernamen der aktiven Plugins (ohne Datei), Netzwerk-Plugins eingeschlossen. * * @return list */ private static function active_plugin_folders() { $files = (array) get_option( 'active_plugins', array() ); if ( function_exists( 'is_multisite' ) && is_multisite() ) { $files = array_merge( $files, array_keys( (array) get_site_option( 'active_sitewide_plugins', array() ) ) ); } $folders = array(); foreach ( $files as $file ) { if ( ! is_string( $file ) || '' === $file ) { continue; } $folder = false === strpos( $file, '/' ) ? $file : strstr( $file, '/', true ); if ( false !== $folder ) { $folders[ $folder ] = true; } } return array_keys( $folders ); } /** * Die Plugins der Familie, auf die Regeln verweisen koennen. Eine * Pro-Variante ("...-pro") zaehlt wie die Free-Variante. * * @param list $active * @return array */ private static function known_plugins( array $active ) { $known = array( '360-orbit-database-cleaner', '360-orbit-media-cleaner', '360-orbit-speed-optimizer', ); $normalized = array(); foreach ( $active as $folder ) { $normalized[ preg_replace( '/-pro$/', '', $folder ) ] = true; } $result = array(); foreach ( $known as $slug ) { $result[ $slug ] = isset( $normalized[ $slug ] ); } return $result; } /** * Name (Ordner) eines aktiven Seiten-Cache-Plugins, oder ein leerer Text. * Ein vorhandenes advanced-cache.php (Drop-in) zaehlt ebenfalls. * * @param list $active * @return string */ private static function page_cache_plugin( array $active ) { foreach ( self::PAGE_CACHE_PLUGINS as $slug ) { if ( in_array( $slug, $active, true ) ) { return $slug; } } if ( defined( 'WP_CACHE' ) && WP_CACHE && defined( 'WP_CONTENT_DIR' ) && is_file( WP_CONTENT_DIR . '/advanced-cache.php' ) ) { return 'advanced-cache'; } return ''; } /** * Darf der Optimizer die .htaccess schreiben (Apache-kompatibel, schreibbar)? * * @return bool */ private static function can_write_htaccess() { if ( ! class_exists( 'Wp360_Speed_Optimizer_Htaccess' ) ) { return false; } return ! Wp360_Speed_Optimizer_Htaccess::is_nginx() && Wp360_Speed_Optimizer_Htaccess::is_supported(); } /** * Schreibt der Optimizer selbst "no-cache" fuer CSS/JS in die .htaccess? * Das tut er bei Browser-Cache plus entfernten Versionsnummern mit Absicht * (nachfragen statt ein Jahr lang veraltete Dateien), siehe Htaccess. * * @return bool */ private static function css_js_revalidate() { if ( ! class_exists( 'Wp360_Speed_Optimizer_Settings' ) ) { return false; } $settings = Wp360_Speed_Optimizer_Settings::get(); return ! empty( $settings['caching_enabled'] ) && ! empty( $settings['remove_query_strings'] ); } /** * Ist der Heartbeat im Backend schon auf zwei Minuten oder mehr gedrosselt? * * @return bool */ private static function heartbeat_throttled() { if ( ! class_exists( 'Wp360_Speed_Optimizer_Settings' ) ) { return false; } $settings = Wp360_Speed_Optimizer_Settings::get(); return isset( $settings['heartbeat_admin_secs'] ) && (int) $settings['heartbeat_admin_secs'] >= 120; } }