__( 'A measurement is already running.', '360-orbit-speed-optimizer' ), 'hint' => __( 'Wait a minute and try again.', '360-orbit-speed-optimizer' ), ); case 'invalid_target': return array( 'message' => __( 'That address does not belong to this website.', '360-orbit-speed-optimizer' ), 'hint' => __( 'Choose a page of your own site.', '360-orbit-speed-optimizer' ), ); case 'timeout': return array( 'message' => __( 'Your site did not answer in time.', '360-orbit-speed-optimizer' ), 'hint' => __( 'The page may be very slow, or the server blocks calls to itself.', '360-orbit-speed-optimizer' ) . ' ' . $manual, ); case 'connection': return array( 'message' => __( 'Your site could not reach itself.', '360-orbit-speed-optimizer' ), 'hint' => __( 'Some hosts do not allow a site to call itself.', '360-orbit-speed-optimizer' ) . ' ' . $manual, ); case 'access': return array( 'message' => __( 'The check was turned away by a password protection or a firewall.', '360-orbit-speed-optimizer' ), 'hint' => $manual, ); case 'not_found': return array( 'message' => __( 'That page does not exist (error 404).', '360-orbit-speed-optimizer' ), 'hint' => __( 'Choose another page.', '360-orbit-speed-optimizer' ), ); case 'maintenance': return array( 'message' => __( 'Your site is in maintenance mode right now.', '360-orbit-speed-optimizer' ), 'hint' => __( 'Try again after the update has finished.', '360-orbit-speed-optimizer' ), ); case 'server_error': return array( 'message' => __( 'Your site answered with a server error.', '360-orbit-speed-optimizer' ), 'hint' => __( 'Open the page in a new browser tab to see whether it works, then try again.', '360-orbit-speed-optimizer' ), ); case 'redirect': return array( 'message' => __( 'The page forwards visitors to another address.', '360-orbit-speed-optimizer' ), 'hint' => __( 'Choose the address the page forwards to.', '360-orbit-speed-optimizer' ), ); case 'cache_hit': return array( 'message' => __( 'The page came from a cache, so there was nothing to measure.', '360-orbit-speed-optimizer' ), 'hint' => __( 'That is good news for your visitors. To measure how long the page takes to build, clear the cache or measure while logged in.', '360-orbit-speed-optimizer' ) . ' ' . $manual, ); case 'no_data': return array( 'message' => __( 'The page answered, but no measurement came back.', '360-orbit-speed-optimizer' ), 'hint' => __( 'A cache, firewall or security plugin may have removed the measurement key from the address.', '360-orbit-speed-optimizer' ) . ' ' . $manual, ); } return array( 'message' => $status > 0 /* translators: %d: HTTP status code */ ? sprintf( __( 'Your site answered unexpectedly (code %d).', '360-orbit-speed-optimizer' ), $status ) : __( 'The check could not be completed.', '360-orbit-speed-optimizer' ), 'hint' => $manual, ); } /** * Texte einer Empfehlung: title, figures (Zahlenzeile), why, steps. * Faellt auf die Kennung zurueck, wenn es keinen Eintrag gibt, damit * nie ein leerer Kasten erscheint. * * @param array $finding Empfehlung des Ratgebers. * @return array{title:string,figures:string,why:string,steps:list} */ public static function for_finding( array $finding ) { $id = isset( $finding['id'] ) ? (string) $finding['id'] : ''; $data = isset( $finding['data'] ) && is_array( $finding['data'] ) ? $finding['data'] : array(); $catalog = self::catalog(); if ( isset( $catalog[ $id ] ) ) { $entry = call_user_func( $catalog[ $id ], $data ); if ( is_array( $entry ) ) { return $entry + array( 'title' => $id, 'figures' => '', 'why' => '', 'steps' => array(), ); } } return array( 'title' => $id, 'figures' => '', 'why' => '', 'steps' => array(), ); } /** * Eintraege je Regelkennung. Jeder Eintrag ist eine Funktion, die aus den * Zahlen der Empfehlung die Texte baut. * * @return array */ public static function catalog() { return array( 'slow_plugin' => array( __CLASS__, 'text_slow_plugin' ), 'slow_theme' => array( __CLASS__, 'text_slow_theme' ), 'many_queries' => array( __CLASS__, 'text_many_queries' ), 'duplicate_queries' => array( __CLASS__, 'text_duplicate_queries' ), 'slow_query' => array( __CLASS__, 'text_slow_query' ), 'autoload' => array( __CLASS__, 'text_autoload' ), 'no_page_cache' => array( __CLASS__, 'text_no_page_cache' ), 'slow_hosting' => array( __CLASS__, 'text_slow_hosting' ), 'old_php' => array( __CLASS__, 'text_old_php' ), 'low_memory' => array( __CLASS__, 'text_low_memory' ), 'compression' => array( __CLASS__, 'text_compression' ), 'browser_cache' => array( __CLASS__, 'text_browser_cache' ), 'heartbeat' => array( __CLASS__, 'text_heartbeat' ), 'emoji' => array( __CLASS__, 'text_emoji' ), 'query_strings' => array( __CLASS__, 'text_query_strings' ), ); } public static function text_compression( array $data ) { return array( 'title' => __( 'Your pages are sent without compression', '360-orbit-speed-optimizer' ), /* translators: %s: size of the page */ 'figures' => sprintf( __( 'This page of %s was sent uncompressed.', '360-orbit-speed-optimizer' ), self::size( $data['bytes'] ) ), 'why' => __( 'Compression packs pages, styles and scripts into a much smaller package before they travel to the visitor, usually to a quarter of their size. Without it, every visit downloads more data than needed, which is slow on mobile connections.', '360-orbit-speed-optimizer' ), 'steps' => array( __( 'Click "Fix now": the Speed Optimizer adds compression rules to your .htaccess file. It makes a backup first, tests your site afterwards and undoes the change if something goes wrong.', '360-orbit-speed-optimizer' ), __( 'If the button is not available, your server does not allow this change from WordPress. Ask your hosting provider to enable gzip or Brotli compression.', '360-orbit-speed-optimizer' ), ), ); } public static function text_browser_cache( array $data ) { return array( 'title' => __( 'Visitors download your files again on every visit', '360-orbit-speed-optimizer' ), /* translators: 1: number of files without browser caching, 2: number of files checked */ 'figures' => sprintf( __( '%1$s of %2$s checked files (style sheets, scripts, images) do not tell the browser to keep them.', '360-orbit-speed-optimizer' ), self::num( $data['uncached'] ), self::num( $data['checked'] ) ), 'why' => __( 'Browser caching lets a visitor keep files like styles, scripts and images for a while. Without it, every page view downloads them again, even though they hardly ever change.', '360-orbit-speed-optimizer' ), 'steps' => array( __( 'Click "Fix now": the Speed Optimizer adds browser caching rules to your .htaccess file. It makes a backup first, tests your site afterwards and undoes the change if something goes wrong.', '360-orbit-speed-optimizer' ), __( 'If the button is not available, ask your hosting provider to set cache lifetimes for static files.', '360-orbit-speed-optimizer' ), ), ); } public static function text_heartbeat( array $data ) { return array( 'title' => __( 'Your admin area keeps calling the server', '360-orbit-speed-optimizer' ), /* translators: 1: number of heartbeat calls, 2: minutes */ 'figures' => sprintf( __( 'During %2$s minutes of measuring, the admin area made %1$s background calls (Heartbeat).', '360-orbit-speed-optimizer' ), self::num( $data['calls'] ), self::num( $data['minutes'] ) ), 'why' => __( 'WordPress regularly asks the server in the background, for example to keep a login alive or to save drafts. Many open admin tabs multiply this, and on a small server it can slow down the whole site.', '360-orbit-speed-optimizer' ), 'steps' => array( __( 'Click "Fix now" to make WordPress ask less often. Saving drafts still works.', '360-orbit-speed-optimizer' ), __( 'Close admin tabs you are not using.', '360-orbit-speed-optimizer' ), ), ); } public static function text_emoji( array $data ) { return array( 'title' => __( 'A script for emoji is loaded on every page', '360-orbit-speed-optimizer' ), /* translators: %s: number of emoji script tags found */ 'figures' => sprintf( __( 'Found %s emoji script tag(s) in the page.', '360-orbit-speed-optimizer' ), self::num( $data['tags'] ) ), 'why' => __( 'WordPress adds a small script so that emoji look the same in old browsers. Modern browsers do not need it, but it is still loaded on every page.', '360-orbit-speed-optimizer' ), 'steps' => array( __( 'Click "Fix now" to remove the emoji script. Emoji still show; they just use the browser\'s own symbols.', '360-orbit-speed-optimizer' ), ), ); } public static function text_query_strings( array $data ) { return array( 'title' => __( 'Many file addresses carry a version number', '360-orbit-speed-optimizer' ), /* translators: 1: number of addresses with ?ver=, 2: number of style sheets and scripts */ 'figures' => sprintf( __( '%1$s of %2$s style sheets and scripts have "?ver=" in their address.', '360-orbit-speed-optimizer' ), self::num( $data['urls'] ), self::num( $data['assets'] ) ), 'why' => __( 'WordPress adds the version to file addresses so that browsers fetch a new file after an update. Some caches and networks do not store files with such an address at all, so they are downloaded again each time.', '360-orbit-speed-optimizer' ), 'steps' => array( __( 'Click "Fix now" to remove the version from the addresses. After an update, clear your cache so visitors get the new files.', '360-orbit-speed-optimizer' ), ), ); } /** Dateigroesse in lesbarer Form (KB oder MB). */ private static function size( $bytes ) { $bytes = (float) $bytes; return $bytes >= 1048576 ? self::num( $bytes / 1048576, 1 ) . ' MB' : self::num( $bytes / 1024, 0 ) . ' KB'; } public static function text_autoload( array $data ) { $steps = array( __( 'Find out which plugins left large entries behind. Entries from plugins you removed long ago can usually be deleted.', '360-orbit-speed-optimizer' ), __( 'Remove plugins you no longer use.', '360-orbit-speed-optimizer' ), ); $steps[] = ! empty( $data['cleaner_active'] ) ? __( 'Open 360 Orbit Database Cleaner and review the autoloaded options. Make a backup first.', '360-orbit-speed-optimizer' ) : __( 'Use a database cleaning tool or ask your hosting provider to review the autoloaded options. Make a backup first.', '360-orbit-speed-optimizer' ); return array( 'title' => __( 'WordPress loads too much data on every request', '360-orbit-speed-optimizer' ), /* translators: 1: size of the autoloaded data, 2: recommended maximum */ 'figures' => sprintf( __( 'Autoloaded data is %1$s; WordPress recommends staying below %2$s.', '360-orbit-speed-optimizer' ), self::size( $data['bytes'] ), self::size( $data['limit'] ) ), 'why' => __( 'WordPress loads certain database entries (options marked as "autoload") into memory on every single page view. The more there is, the slower each page starts, no matter how simple it is.', '360-orbit-speed-optimizer' ), 'steps' => $steps, ); } public static function text_no_page_cache( array $data ) { return array( 'title' => __( 'Your pages are built from scratch on every visit', '360-orbit-speed-optimizer' ), /* translators: %s: milliseconds */ 'figures' => sprintf( __( 'Building the page took %s ms and no page cache was detected in the response.', '360-orbit-speed-optimizer' ), self::num( $data['server_ms'] ) ), 'why' => __( 'A page cache keeps a finished copy of each page and hands it out instantly. Without one, WordPress runs all its code and database queries again for every visitor.', '360-orbit-speed-optimizer' ), 'steps' => array( __( 'Check your hosting dashboard: many hosts offer a built-in page cache that you can switch on with one click.', '360-orbit-speed-optimizer' ), __( 'If your host has none, install a page cache plugin and follow its quick setup.', '360-orbit-speed-optimizer' ), __( 'Measure again afterwards. Logged-in visits are usually not cached, so test as a visitor too.', '360-orbit-speed-optimizer' ), ), ); } public static function text_slow_hosting( array $data ) { return array( 'title' => __( 'Your hosting takes a long time to answer', '360-orbit-speed-optimizer' ), /* translators: 1: milliseconds until the first byte, 2: milliseconds spent inside WordPress, 3: milliseconds spent outside WordPress */ 'figures' => sprintf( __( 'The first byte arrived after %1$s ms, but WordPress itself needed only %2$s ms. About %3$s ms passed outside of WordPress.', '360-orbit-speed-optimizer' ), self::num( $data['ttfb_ms'] ), self::num( $data['server_ms'] ), self::num( $data['gap_ms'] ) ), 'why' => __( 'This time is spent before WordPress starts and after it finishes: connecting, the web server and PHP start-up. It is not caused by your plugins or theme, so changes inside WordPress will not help.', '360-orbit-speed-optimizer' ), 'steps' => array( __( 'Measure again at a quiet time to rule out a short load peak on the server.', '360-orbit-speed-optimizer' ), __( 'Ask your hosting provider whether the server is overloaded or whether a faster plan is available.', '360-orbit-speed-optimizer' ), __( 'Choose a server location close to your visitors, or consider moving to a faster host.', '360-orbit-speed-optimizer' ), ), ); } public static function text_old_php( array $data ) { return array( 'title' => __( 'Your site runs on an outdated PHP version', '360-orbit-speed-optimizer' ), /* translators: 1: installed PHP version, 2: recommended PHP version */ 'figures' => sprintf( __( 'Your site uses PHP %1$s. PHP %2$s or newer is recommended.', '360-orbit-speed-optimizer' ), $data['version'], (string) Wp360_Speed_Optimizer_Doctor_Thresholds::get( 'min_php_version' ) ), 'why' => __( 'Newer PHP versions run WordPress noticeably faster and receive security fixes. Old versions no longer get security updates.', '360-orbit-speed-optimizer' ), 'steps' => array( __( 'Update all plugins and your theme first, so they work with a newer PHP version.', '360-orbit-speed-optimizer' ), __( 'Make a backup of your site.', '360-orbit-speed-optimizer' ), __( 'Switch to PHP 8.3 in your hosting dashboard, then check your site. You can switch back if something breaks.', '360-orbit-speed-optimizer' ), ), ); } public static function text_low_memory( array $data ) { $steps = array( __( 'Ask your hosting provider to raise the PHP memory limit to at least 256 MB, or change it in your hosting dashboard.', '360-orbit-speed-optimizer' ), __( 'Deactivate plugins you do not need; each one uses some memory.', '360-orbit-speed-optimizer' ), ); if ( isset( $data['top_name'], $data['top_bytes'] ) ) { /* translators: 1: plugin name, 2: memory it needs */ $steps[] = sprintf( __( 'The plugin that needs the most memory here is %1$s (about %2$s). Check whether you need all of its features, or ask its makers how to make it lighter.', '360-orbit-speed-optimizer' ), $data['top_name'], self::size( $data['top_bytes'] ) ); } return array( 'title' => __( 'PHP has little memory available', '360-orbit-speed-optimizer' ), /* translators: 1: peak memory used, 2: memory limit, 3: percent of the limit */ 'figures' => sprintf( __( 'This page used up to %1$s of the %2$s allowed (%3$s%%).', '360-orbit-speed-optimizer' ), self::size( $data['peak'] ), self::size( $data['limit'] ), self::percent( $data['usage'] ) ), 'why' => __( 'When a page comes close to the memory limit, PHP can stop with an error or has to work harder. A low limit also leaves no room for larger pages and plugins.', '360-orbit-speed-optimizer' ), 'steps' => $steps, ); } /** Zahl mit Tausenderpunkt in der Sprache der Website. */ private static function num( $value, $decimals = 0 ) { return function_exists( 'number_format_i18n' ) ? number_format_i18n( (float) $value, $decimals ) : number_format( (float) $value, $decimals ); } /** Anteil (0 bis 1) als ganze Prozent. */ private static function percent( $share ) { return self::num( (float) $share * 100, 0 ); } /** Verursacher in lesbarer Form, z. B. "plugin:woocommerce" wird "woocommerce". */ private static function who( $source ) { $source = (string) $source; $pos = strpos( $source, ':' ); $name = false === $pos ? $source : substr( $source, $pos + 1 ); // "core" und "other" haben keinen Namen: gefragt hat WordPress selbst. return '' === $name || in_array( $source, array( 'core', 'other' ), true ) ? __( 'WordPress itself', '360-orbit-speed-optimizer' ) : $name; } public static function text_slow_plugin( array $data ) { return array( 'title' => __( 'One plugin needs a large share of the loading time', '360-orbit-speed-optimizer' ), /* translators: 1: plugin name, 2: milliseconds, 3: percent of the server time */ 'figures' => sprintf( __( '%1$s needs %2$s ms, which is %3$s%% of the server time.', '360-orbit-speed-optimizer' ), $data['name'], self::num( $data['ms'] ), self::percent( $data['share'] ) ), 'why' => __( 'Every active plugin runs code each time a page is built. A plugin that needs much more time than the others slows down every visit, even if you rarely use its features.', '360-orbit-speed-optimizer' ), 'steps' => array( __( 'Ask yourself whether you still need this plugin on every page. If not, deactivate it and measure again.', '360-orbit-speed-optimizer' ), __( 'Update the plugin and look through its settings for features you do not use, such as statistics, widgets or external services.', '360-orbit-speed-optimizer' ), __( 'If you need it, look for a lighter alternative or ask its author why it needs this much time.', '360-orbit-speed-optimizer' ), ), ); } public static function text_slow_theme( array $data ) { return array( 'title' => __( 'Your theme needs a large share of the loading time', '360-orbit-speed-optimizer' ), /* translators: 1: theme name, 2: milliseconds, 3: percent of the server time */ 'figures' => sprintf( __( 'The theme %1$s needs %2$s ms, which is %3$s%% of the server time.', '360-orbit-speed-optimizer' ), $data['name'], self::num( $data['ms'] ), self::percent( $data['share'] ) ), 'why' => __( 'The theme builds the look of every page. Themes with many built-in features, sliders or page builders do a lot of work before anything is shown.', '360-orbit-speed-optimizer' ), 'steps' => array( __( 'Open the theme settings and switch off features you do not use, such as sliders, animations or extra widgets.', '360-orbit-speed-optimizer' ), __( 'Update the theme to its latest version.', '360-orbit-speed-optimizer' ), __( 'To compare, activate a default WordPress theme on a test copy of your site and measure again.', '360-orbit-speed-optimizer' ), ), ); } public static function text_many_queries( array $data ) { $figures = sprintf( /* translators: 1: number of database queries, 2: milliseconds */ __( 'This page asked the database %1$s times, which took %2$s ms in total.', '360-orbit-speed-optimizer' ), self::num( $data['count'] ), self::num( $data['total_ms'] ) ); if ( isset( $data['top_name'] ) ) { $figures .= ' ' . sprintf( /* translators: 1: plugin or theme name, 2: number of database queries */ __( 'Most of them (%2$s) came from %1$s.', '360-orbit-speed-optimizer' ), $data['top_name'], self::num( $data['top_count'] ) ); } return array( 'title' => __( 'This page asks the database very often', '360-orbit-speed-optimizer' ), 'figures' => $figures, 'why' => __( 'Each database question takes a little time. When a page needs hundreds of them, the time adds up, and a busy database server slows down all visitors.', '360-orbit-speed-optimizer' ), 'steps' => array( __( 'Check the plugin or theme named above: deactivate it briefly and measure again to see how much it changes.', '360-orbit-speed-optimizer' ), __( 'Remove plugins you do not use. Fewer plugins usually mean fewer database questions.', '360-orbit-speed-optimizer' ), __( 'Ask your hosting provider about a persistent object cache (Redis or Memcached), which answers repeated questions from memory.', '360-orbit-speed-optimizer' ), ), ); } public static function text_duplicate_queries( array $data ) { return array( 'title' => __( 'The same kind of database question is asked again and again', '360-orbit-speed-optimizer' ), /* translators: 1: how many times, 2: who asked, 3: the query without values */ 'figures' => sprintf( __( 'One kind of query ran %1$s times on this page (asked by %2$s): %3$s', '360-orbit-speed-optimizer' ), self::num( $data['count'] ), self::who( $data['cause'] ), $data['sql'] ), 'why' => __( 'Every database question costs a little time, and asking the same kind of question again and again adds up. Well-written code asks once for everything it needs, or remembers the answer.', '360-orbit-speed-optimizer' ), 'steps' => array( __( 'Update the plugin or theme named above; the author may already have fixed this.', '360-orbit-speed-optimizer' ), __( 'If it still happens after the update, send the author the query shown here. It contains no personal data.', '360-orbit-speed-optimizer' ), __( 'A persistent object cache from your hosting provider hides much of the cost.', '360-orbit-speed-optimizer' ), ), ); } public static function text_slow_query( array $data ) { return array( 'title' => __( 'One database question takes a long time', '360-orbit-speed-optimizer' ), /* translators: 1: milliseconds, 2: who asked, 3: the query without values */ 'figures' => sprintf( __( 'The slowest query took %1$s ms (asked by %2$s): %3$s', '360-orbit-speed-optimizer' ), self::num( $data['ms'] ), self::who( $data['cause'] ), $data['sql'] ), 'why' => __( 'A slow query usually means the database has too much data to search through, or a table that is missing an index. The page has to wait for the answer.', '360-orbit-speed-optimizer' ), 'steps' => array( __( 'Clean up old data: expired transients, post revisions and leftover options from removed plugins.', '360-orbit-speed-optimizer' ), __( 'Update the plugin or theme named above.', '360-orbit-speed-optimizer' ), __( 'If the query stays slow, ask your hosting provider or the plugin author. Make a backup before any change to the database.', '360-orbit-speed-optimizer' ), ), ); } }