From b3b3f20739c9342df728ffb1ea2a6741937bbba2 Mon Sep 17 00:00:00 2001 From: Brad Parbs Date: Tue, 3 Dec 2024 14:17:10 -0600 Subject: [PATCH 01/11] Add Health Checks --- includes/HealthCheckManager.php | 141 ++++++++++++++++++++ includes/HealthChecks.php | 230 ++++++++++++++++++++++++++++++++ includes/Performance.php | 7 + 3 files changed, 378 insertions(+) create mode 100644 includes/HealthCheckManager.php create mode 100644 includes/HealthChecks.php diff --git a/includes/HealthCheckManager.php b/includes/HealthCheckManager.php new file mode 100644 index 0000000..53ac3d2 --- /dev/null +++ b/includes/HealthCheckManager.php @@ -0,0 +1,141 @@ +container = $container; + + if ( function_exists( 'add_filter' ) ) { + $this->addHooks(); + } + } + + /** + * Add hooks. + */ + public function addHooks() { + add_filter( 'site_status_tests', array( $this, 'registerHealthChecks' ) ); + } + + /** + * Add a health check. + * + * @param array $options Health check options. + */ + public function addHealthCheck( $options ) { + $options = wp_parse_args( + $options, + array( + 'id' => '', + 'title' => '', + 'test' => '', + 'label' => false, // Setting this will override pass/fail labels. + 'pass' => '', + 'fail' => '', + 'text' => '', + 'status' => false, // Override the status of the health check: default is good for pass, critical for fail. + 'badge_label' => __( 'Performance', 'newfold-labs' ), + 'badge_color' => 'blue', + 'actions' => '', + ) + ); + + // Make sure the health check is valid. + if ( ! ( empty( $options['id'] ) || empty( $options['title'] ) || ! is_callable( $options['test'] ) ) ) { + $this->checks[ $this->prefix . $options['id'] ] = $options; + } + } + + /** + * Run a health check. + * + * @param string $id Health check ID. + * + * @return array Health check results. + */ + public function runHealthCheck( $id ) { + $check = $this->checks[ $id ]; + + // Execute the test. + $passed = call_user_func( $check['test'] ); + + // Return the health check results. + return array( + 'label' => $check['label'] ? $check['label'] : ( $passed ? $check['pass'] : $check['fail'] ), + 'status' => $check['status'] ? $check['status'] : ( $passed ? 'good' : 'critical' ), + 'description' => $check['text'] ? $check['text'] : '', + 'actions' => $check['actions'] ? $check['actions'] : '', + 'test' => $check['id'], + 'badge' => array( + 'label' => $check['badge_label'], + 'color' => $check['badge_color'], + ), + ); + } + + /** + * Add health checks. + * + * @param array $tests Site Health tests. + * + * @return array Site Health tests. + */ + public function registerHealthChecks( $tests ) { + // If there are no health checks, don't add any. + if ( ! is_array( $this->checks ) || empty( $this->checks ) ) { + return $tests; + } + + foreach ( $this->checks as $id => $check ) { + /** + * Filter to enable/disable a health check. + * + * @param bool $do_check Whether to run the health check. + */ + $do_check = apply_filters( 'newfold/features/filter/isEnabled:healthChecks:' . $id, true ); // phpcs:ignore + if ( $do_check ) { + $tests['direct'][ $id ] = array( + 'label' => $check['title'], + 'test' => function () use ( $id ) { + return $this->runHealthCheck( $id ); + }, + ); + } + } + + return $tests; + } +} diff --git a/includes/HealthChecks.php b/includes/HealthChecks.php new file mode 100644 index 0000000..d0b405c --- /dev/null +++ b/includes/HealthChecks.php @@ -0,0 +1,230 @@ +container = $container; + } + + /** + * Add health checks. + */ + public function addHealthChecks() { + $manager = $this->container->get( 'healthCheckManager' ); + + $manager->addHealthCheck( + array( + 'id' => 'autosave_interval', + 'title' => __( 'Autosave Interval', 'newfold-performance-module' ), + 'pass' => __( 'Autosaving is set to happen every 30 seconds or more.', 'newfold-performance-module' ), + 'fail' => __( 'Autosaving is set to be frequent, less than every 30 seconds.', 'newfold-performance-module' ), + 'text' => __( 'Setting the autosave interval to a longer period can reduce server load, it is recommended to set it to 30 seconds or more.', 'newfold-performance-module' ), + 'test' => function () { + return ( defined( 'AUTOSAVE_INTERVAL' ) && AUTOSAVE_INTERVAL >= 30 ); + }, + ) + ); + + $manager->addHealthCheck( + array( + 'id' => 'post-revisions', + 'title' => __( 'Post Revisions', 'newfold-performance-module' ), + 'pass' => __( 'Number of post revisions is limited to 5 or less.', 'newfold-performance-module' ), + 'fail' => __( 'Number of post revisions is set to a high number.', 'newfold-performance-module' ), + 'text' => __( 'Setting the number of post revisions to a lower number can reduce database bloat.', 'newfold-performance-module' ), + 'test' => function () { + return ( defined( 'WP_POST_REVISIONS' ) && WP_POST_REVISIONS <= 5 ); + }, + ) + ); + + $manager->addHealthCheck( + array( + 'id' => 'empty-trash-days', + 'title' => __( 'Empty Trash Days', 'newfold-performance-module' ), + 'pass' => __( 'Trash is emptied every 30 days or less.', 'newfold-performance-module' ), + 'fail' => __( 'Trash is emptied less frequently than every 30 days.', 'newfold-performance-module' ), + 'text' => __( 'Emptying the trash more frequently can reduce database bloat.', 'newfold-performance-module' ), + 'test' => function () { + return ( defined( 'EMPTY_TRASH_DAYS' ) && EMPTY_TRASH_DAYS <= 30 ); + }, + ) + ); + + $manager->addHealthCheck( + array( + 'id' => 'wp-cron-lock-timeout', + 'title' => __( 'WP Cron Lock Timeout', 'newfold-performance-module' ), + 'pass' => __( 'Cron lock timeout is set to 60 seconds or less.', 'newfold-performance-module' ), + 'fail' => __( 'Cron lock timeout is set to a high number.', 'newfold-performance-module' ), + 'text' => __( 'Cron lock timeout affects how long a cron job can run for, setting it to a lower number can improve performance.', 'newfold-performance-module' ), + 'test' => function () { + return ( defined( 'WP_CRON_LOCK_TIMEOUT' ) && WP_CRON_LOCK_TIMEOUT <= 60 ); + }, + ) + ); + + $manager->addHealthCheck( + array( + 'id' => 'permalinks', + 'title' => __( 'Permalinks', 'newfold-performance-module' ), + 'pass' => __( 'Permalinks are pretty', 'newfold-performance-module' ), + 'fail' => __( 'Permalinks are not set up', 'newfold-performance-module' ), + 'text' => __( 'Setting permalinks to anything other than plain can improve performance and SEO.', 'newfold-performance-module' ), + 'test' => function () { + return empty( get_option( 'permalink_structure' ) ); + }, + ) + ); + + $manager->addHealthCheck( + array( + 'id' => 'page-caching', + 'title' => __( 'Page Caching', 'newfold-performance-module' ), + 'pass' => __( 'Page caching is enabled', 'newfold-performance-module' ), + 'fail' => __( 'Page caching is disabled', 'newfold-performance-module' ), + 'text' => __( 'Page caching can improve performance by bypassing PHP and database queries for faster page loads.', 'newfold-performance-module' ), + 'test' => function () { + return ( get_option( 'newfold_cache_level' ) >= 1 ); + }, + ) + ); + + $manager->addHealthCheck( + array( + 'id' => 'browser-caching', + 'title' => __( 'Browser Caching', 'newfold-performance-module' ), + 'pass' => __( 'Browser caching is enabled', 'newfold-performance-module' ), + 'fail' => __( 'Browser caching is disabled', 'newfold-performance-module' ), + 'text' => __( 'Enabling browser caching can improve performance by storing static assets in the browser for faster page loads.', 'newfold-performance-module' ), + 'test' => function () { + }, + ) + ); + + $manager->addHealthCheck( + array( + 'id' => 'object-caching', + 'title' => __( 'Object Caching', 'newfold-performance-module' ), + 'pass' => __( 'Object caching is enabled', 'newfold-performance-module' ), + 'fail' => __( 'Object caching is disabled', 'newfold-performance-module' ), + 'text' => __( 'Object caching can improve performance by storing database queries in memory for faster page loads.', 'newfold-performance-module' ), + 'test' => function () { + }, + ) + ); + + $manager->addHealthCheck( + array( + 'id' => 'cloudflare_active', + 'title' => __( 'Cloudflare enabled', 'newfold-performance-module' ), + 'pass' => __( 'Cloudflare integration is enabled', 'newfold-performance-module' ), + 'fail' => __( 'Cloudflare integration is disabled', 'newfold-performance-module' ), + 'text' => __( 'Cloudflare integration can improve performance and security.', 'newfold-performance-module' ), + 'test' => function () { + // return $this->container->get( 'cacheManager' )->isEnabled( 'cloudflare' ); + }, + ) + ); + + $manager->addHealthCheck( + array( + 'id' => 'lazy-loading', + 'title' => __( 'Lazy Loading', 'newfold-performance-module' ), + 'pass' => __( 'Lazy loading is enabled', 'newfold-performance-module' ), + 'fail' => __( 'Lazy loading is disabled', 'newfold-performance-module' ), + 'text' => __( 'Lazy loading can improve performance by only loading images when they are in view.', 'newfold-performance-module' ), + 'test' => function () { + // TODO: https://github.com/newfold-labs/wp-module-performance/pull/32 + // nfd_image_optimization + }, + ) + ); + + $manager->addHealthCheck( + array( + 'id' => 'link-prefetch', + 'title' => __( 'Link Prefetching', 'newfold-performance-module' ), + 'pass' => __( 'Link prefetching is enabled', 'newfold-performance-module' ), + 'fail' => __( 'Link prefetching is disabled', 'newfold-performance-module' ), + 'text' => __( 'Link prefetching can improve performance by loading pages immediately before they are requested.', 'newfold-performance-module' ), + 'test' => function () { + // TODO: https://github.com/newfold-labs/wp-module-performance/pull/26 + // nfd_link_prefetch_settings + }, + ) + ); + + + $manager->addHealthCheck( + array( + 'id' => 'prioritize-critical-css', + 'title' => __( 'Prioritize Critical CSS', 'newfold-performance-module' ), + 'pass' => __( 'Critical CSS is prioritized', 'newfold-performance-module' ), + 'fail' => __( 'Critical CSS is not prioritized', 'newfold-performance-module' ), + 'text' => __( 'Prioritizing critical CSS can improve performance by loading the most important CSS first.', 'newfold-performance-module' ), + 'test' => function () { + // TODO: https://github.com/newfold-labs/wp-module-performance/pull/25 + }, + ) + ); + + $manager->addHealthCheck( + array( + 'id' => 'defer-non-essential-javascript', + 'title' => __( 'Defer Non-Essential JavaScript', 'newfold-performance-module' ), + 'pass' => __( 'Non-essential JavaScript is deferred', 'newfold-performance-module' ), + 'fail' => __( 'Non-essential JavaScript is not deferred', 'newfold-performance-module' ), + 'text' => __( 'JavaScript can be deferred to improve performance by loading it after the page has loaded.', 'newfold-performance-module' ), + 'test' => function () { + // TODO: https://github.com/newfold-labs/wp-module-performance/pull/25 + }, + ) + ); + + $manager->addHealthCheck( + array( + 'id' => 'concatenate js', + 'title' => __( 'Concatenate JavaScript', 'newfold-performance-module' ), + 'pass' => __( 'JavaScript files are concatenated', 'newfold-performance-module' ), + 'fail' => __( 'JavaScript files are not concatenated', 'newfold-performance-module' ), + 'text' => __( 'Concatenating JavaScript can improve performance by reducing the number of requests.', 'newfold-performance-module' ), + 'test' => function () { + // TODO: https://github.com/newfold-labs/wp-module-performance/pull/25 + }, + ) + ); + + $manager->addHealthCheck( + array( + 'id' => 'concatenate-css', + 'title' => __( 'Concatenate CSS', 'newfold-performance-module' ), + 'pass' => __( 'CSS files are concatenated', 'newfold-performance-module' ), + 'fail' => __( 'CSS files are not concatenated', 'newfold-performance-module' ), + 'text' => __( 'Concatenating CSS can improve performance by reducing the number of requests.', 'newfold-performance-module' ), + 'test' => function () { + // TODO: https://github.com/newfold-labs/wp-module-performance/pull/25 + }, + ) + ); + } +} diff --git a/includes/Performance.php b/includes/Performance.php index ac50c2f..da4a805 100644 --- a/includes/Performance.php +++ b/includes/Performance.php @@ -3,6 +3,7 @@ namespace NewfoldLabs\WP\Module\Performance; use NewfoldLabs\WP\Module\Performance\CacheTypes\Browser; +use NewfoldLabs\WP\Module\Performance\CacheTypes\Cloudflare; use NewfoldLabs\WP\Module\Performance\CacheTypes\File; use NewfoldLabs\WP\Module\Performance\CacheTypes\Skip404; use NewfoldLabs\WP\ModuleLoader\Container; @@ -71,6 +72,8 @@ public function __construct( Container $container ) { $cacheManager = new CacheManager( $container ); $cachePurger = new CachePurgingService( $cacheManager->getInstances() ); + $healthCheckManager = new HealthCheckManager( $container ); + $healthChecks = new HealthChecks( $container ); // Ensure that purgeable cache types are enabled before showing the UI. if ( $cachePurger->canPurge() ) { @@ -80,6 +83,10 @@ public function __construct( Container $container ) { $container->set( 'cachePurger', $cachePurger ); $container->set( 'hasMustUsePlugin', file_exists( WPMU_PLUGIN_DIR . '/endurance-page-cache.php' ) ); + + $container->set( 'healthCheckManager', $healthCheckManager ); + + $healthChecks->addHealthChecks(); } /** From 7e384b322aeb3fb86475297b8bd441e361f1f4b8 Mon Sep 17 00:00:00 2001 From: Brad Parbs Date: Tue, 10 Dec 2024 11:40:54 -0600 Subject: [PATCH 02/11] Tidy up --- includes/HealthChecks.php | 9 ++++----- includes/Performance.php | 6 +++--- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/includes/HealthChecks.php b/includes/HealthChecks.php index d0b405c..0d12f98 100644 --- a/includes/HealthChecks.php +++ b/includes/HealthChecks.php @@ -33,7 +33,7 @@ public function addHealthChecks() { $manager->addHealthCheck( array( - 'id' => 'autosave_interval', + 'id' => 'autosave-interval', 'title' => __( 'Autosave Interval', 'newfold-performance-module' ), 'pass' => __( 'Autosaving is set to happen every 30 seconds or more.', 'newfold-performance-module' ), 'fail' => __( 'Autosaving is set to be frequent, less than every 30 seconds.', 'newfold-performance-module' ), @@ -135,7 +135,7 @@ public function addHealthChecks() { $manager->addHealthCheck( array( - 'id' => 'cloudflare_active', + 'id' => 'cloudflare-active', 'title' => __( 'Cloudflare enabled', 'newfold-performance-module' ), 'pass' => __( 'Cloudflare integration is enabled', 'newfold-performance-module' ), 'fail' => __( 'Cloudflare integration is disabled', 'newfold-performance-module' ), @@ -174,7 +174,6 @@ public function addHealthChecks() { ) ); - $manager->addHealthCheck( array( 'id' => 'prioritize-critical-css', @@ -203,14 +202,14 @@ public function addHealthChecks() { $manager->addHealthCheck( array( - 'id' => 'concatenate js', + 'id' => 'concatenate-js', 'title' => __( 'Concatenate JavaScript', 'newfold-performance-module' ), 'pass' => __( 'JavaScript files are concatenated', 'newfold-performance-module' ), 'fail' => __( 'JavaScript files are not concatenated', 'newfold-performance-module' ), 'text' => __( 'Concatenating JavaScript can improve performance by reducing the number of requests.', 'newfold-performance-module' ), 'test' => function () { // TODO: https://github.com/newfold-labs/wp-module-performance/pull/25 - }, + }, ) ); diff --git a/includes/Performance.php b/includes/Performance.php index da4a805..24545c8 100644 --- a/includes/Performance.php +++ b/includes/Performance.php @@ -70,10 +70,10 @@ public function __construct( Container $container ) { $this->hooks( $container ); - $cacheManager = new CacheManager( $container ); - $cachePurger = new CachePurgingService( $cacheManager->getInstances() ); + $cacheManager = new CacheManager( $container ); + $cachePurger = new CachePurgingService( $cacheManager->getInstances() ); $healthCheckManager = new HealthCheckManager( $container ); - $healthChecks = new HealthChecks( $container ); + $healthChecks = new HealthChecks( $container ); // Ensure that purgeable cache types are enabled before showing the UI. if ( $cachePurger->canPurge() ) { From a39d90247829889aa05c3eb5fc66fb3be5d04697 Mon Sep 17 00:00:00 2001 From: Brad Parbs Date: Tue, 10 Dec 2024 12:41:27 -0600 Subject: [PATCH 03/11] Update text --- includes/HealthChecks.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/includes/HealthChecks.php b/includes/HealthChecks.php index 0d12f98..53a6825 100644 --- a/includes/HealthChecks.php +++ b/includes/HealthChecks.php @@ -48,8 +48,8 @@ public function addHealthChecks() { array( 'id' => 'post-revisions', 'title' => __( 'Post Revisions', 'newfold-performance-module' ), - 'pass' => __( 'Number of post revisions is limited to 5 or less.', 'newfold-performance-module' ), - 'fail' => __( 'Number of post revisions is set to a high number.', 'newfold-performance-module' ), + 'pass' => __( 'Number of post revisions is limited to 5 or less', 'newfold-performance-module' ), + 'fail' => __( 'Number of post revisions is set to a high number', 'newfold-performance-module' ), 'text' => __( 'Setting the number of post revisions to a lower number can reduce database bloat.', 'newfold-performance-module' ), 'test' => function () { return ( defined( 'WP_POST_REVISIONS' ) && WP_POST_REVISIONS <= 5 ); @@ -61,7 +61,7 @@ public function addHealthChecks() { array( 'id' => 'empty-trash-days', 'title' => __( 'Empty Trash Days', 'newfold-performance-module' ), - 'pass' => __( 'Trash is emptied every 30 days or less.', 'newfold-performance-module' ), + 'pass' => __( 'Trash is emptied every 30 days or less', 'newfold-performance-module' ), 'fail' => __( 'Trash is emptied less frequently than every 30 days.', 'newfold-performance-module' ), 'text' => __( 'Emptying the trash more frequently can reduce database bloat.', 'newfold-performance-module' ), 'test' => function () { @@ -78,7 +78,7 @@ public function addHealthChecks() { 'fail' => __( 'Cron lock timeout is set to a high number.', 'newfold-performance-module' ), 'text' => __( 'Cron lock timeout affects how long a cron job can run for, setting it to a lower number can improve performance.', 'newfold-performance-module' ), 'test' => function () { - return ( defined( 'WP_CRON_LOCK_TIMEOUT' ) && WP_CRON_LOCK_TIMEOUT <= 60 ); + return ( defined( 'WP_CRON_LOCK_TIMEOUT' ) && WP_CRON_LOCK_TIMEOUT <= 300 ); }, ) ); From cccc5bb2a776bf9ab607ad64200f497e87a57b8e Mon Sep 17 00:00:00 2001 From: Brad Parbs Date: Tue, 10 Dec 2024 13:20:11 -0600 Subject: [PATCH 04/11] Implement remaining checks --- includes/HealthChecks.php | 52 +++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/includes/HealthChecks.php b/includes/HealthChecks.php index 53a6825..35f74f2 100644 --- a/includes/HealthChecks.php +++ b/includes/HealthChecks.php @@ -104,7 +104,7 @@ public function addHealthChecks() { 'fail' => __( 'Page caching is disabled', 'newfold-performance-module' ), 'text' => __( 'Page caching can improve performance by bypassing PHP and database queries for faster page loads.', 'newfold-performance-module' ), 'test' => function () { - return ( get_option( 'newfold_cache_level' ) >= 1 ); + return ( get_option( 'newfold_cache_level' ) >= 2 ); }, ) ); @@ -117,21 +117,26 @@ public function addHealthChecks() { 'fail' => __( 'Browser caching is disabled', 'newfold-performance-module' ), 'text' => __( 'Enabling browser caching can improve performance by storing static assets in the browser for faster page loads.', 'newfold-performance-module' ), 'test' => function () { + return ( get_option( 'newfold_cache_level' ) >= 1 ); }, ) ); - $manager->addHealthCheck( - array( - 'id' => 'object-caching', - 'title' => __( 'Object Caching', 'newfold-performance-module' ), - 'pass' => __( 'Object caching is enabled', 'newfold-performance-module' ), - 'fail' => __( 'Object caching is disabled', 'newfold-performance-module' ), - 'text' => __( 'Object caching can improve performance by storing database queries in memory for faster page loads.', 'newfold-performance-module' ), - 'test' => function () { - }, - ) - ); + // Only show object caching health check for Bluehost brand. + if ( 'bluehost' === $this->container->plugin()->brand ) { + $manager->addHealthCheck( + array( + 'id' => 'persistent_object_cache', // Replaces the default test. + 'title' => __( 'Object Caching', 'newfold-performance-module' ), + 'pass' => __( 'Object caching is enabled', 'newfold-performance-module' ), + 'fail' => __( 'Object caching is disabled', 'newfold-performance-module' ), + 'text' => __( 'Object caching saves results from frequent database queries, reducing load times by avoiding repetitive query processing. Object caching is available in all tiers of Bluehost Cloud.', 'newfold-performance-module' ), + 'test' => function () { + return wp_using_ext_object_cache(); + }, + ) + ); + } $manager->addHealthCheck( array( @@ -141,7 +146,7 @@ public function addHealthChecks() { 'fail' => __( 'Cloudflare integration is disabled', 'newfold-performance-module' ), 'text' => __( 'Cloudflare integration can improve performance and security.', 'newfold-performance-module' ), 'test' => function () { - // return $this->container->get( 'cacheManager' )->isEnabled( 'cloudflare' ); + return isset( $_SERVER['HTTP_CF_RAY'] ); }, ) ); @@ -154,8 +159,8 @@ public function addHealthChecks() { 'fail' => __( 'Lazy loading is disabled', 'newfold-performance-module' ), 'text' => __( 'Lazy loading can improve performance by only loading images when they are in view.', 'newfold-performance-module' ), 'test' => function () { - // TODO: https://github.com/newfold-labs/wp-module-performance/pull/32 - // nfd_image_optimization + $enabled = get_option( 'nfd_image_optimization', array() ); + return ( isset( $enabled['lazy_loading'], $enabled['lazy_loading']['enabled'] ) && $enabled['lazy_loading']['enabled'] ); }, ) ); @@ -168,8 +173,9 @@ public function addHealthChecks() { 'fail' => __( 'Link prefetching is disabled', 'newfold-performance-module' ), 'text' => __( 'Link prefetching can improve performance by loading pages immediately before they are requested.', 'newfold-performance-module' ), 'test' => function () { - // TODO: https://github.com/newfold-labs/wp-module-performance/pull/26 - // nfd_link_prefetch_settings + https://github.com/newfold-labs/wp-module-performance/pull/26 + $enabled = get_option( 'nfd_link_prefetch_settings', array() ); + return ( isset( $enabled['activeOnDesktop'] ) && $enabled['activeOnDesktop'] ); }, ) ); @@ -182,7 +188,8 @@ public function addHealthChecks() { 'fail' => __( 'Critical CSS is not prioritized', 'newfold-performance-module' ), 'text' => __( 'Prioritizing critical CSS can improve performance by loading the most important CSS first.', 'newfold-performance-module' ), 'test' => function () { - // TODO: https://github.com/newfold-labs/wp-module-performance/pull/25 + https://github.com/newfold-labs/wp-module-performance/pull/25 + return get_option( 'jetpack_boost_status_critical-css', false ); }, ) ); @@ -195,7 +202,8 @@ public function addHealthChecks() { 'fail' => __( 'Non-essential JavaScript is not deferred', 'newfold-performance-module' ), 'text' => __( 'JavaScript can be deferred to improve performance by loading it after the page has loaded.', 'newfold-performance-module' ), 'test' => function () { - // TODO: https://github.com/newfold-labs/wp-module-performance/pull/25 + https://github.com/newfold-labs/wp-module-performance/pull/25 + return get_option( 'jetpack_boost_status_render-blocking-js', false ); }, ) ); @@ -208,7 +216,8 @@ public function addHealthChecks() { 'fail' => __( 'JavaScript files are not concatenated', 'newfold-performance-module' ), 'text' => __( 'Concatenating JavaScript can improve performance by reducing the number of requests.', 'newfold-performance-module' ), 'test' => function () { - // TODO: https://github.com/newfold-labs/wp-module-performance/pull/25 + https://github.com/newfold-labs/wp-module-performance/pull/25 + return ( ! empty( get_option( 'jetpack_boost_status_minify-js', array() ) ) ); }, ) ); @@ -221,7 +230,8 @@ public function addHealthChecks() { 'fail' => __( 'CSS files are not concatenated', 'newfold-performance-module' ), 'text' => __( 'Concatenating CSS can improve performance by reducing the number of requests.', 'newfold-performance-module' ), 'test' => function () { - // TODO: https://github.com/newfold-labs/wp-module-performance/pull/25 + https://github.com/newfold-labs/wp-module-performance/pull/25 + return ( ! empty( get_option( 'jetpack_boost_status_minify-css', array() ) ) ); }, ) ); From 84f195c474673390f3249c08992421891e9b2dfd Mon Sep 17 00:00:00 2001 From: Brad Parbs Date: Tue, 10 Dec 2024 13:21:39 -0600 Subject: [PATCH 05/11] Comment each check --- includes/HealthChecks.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/includes/HealthChecks.php b/includes/HealthChecks.php index 35f74f2..e0b2708 100644 --- a/includes/HealthChecks.php +++ b/includes/HealthChecks.php @@ -31,6 +31,7 @@ public function __construct( Container $container ) { public function addHealthChecks() { $manager = $this->container->get( 'healthCheckManager' ); + // PRESS7-108: Autosave Interval. $manager->addHealthCheck( array( 'id' => 'autosave-interval', @@ -44,6 +45,7 @@ public function addHealthChecks() { ) ); + // PRESS7-109: Post Revisions. $manager->addHealthCheck( array( 'id' => 'post-revisions', @@ -57,6 +59,7 @@ public function addHealthChecks() { ) ); + // PRESS7-110: Empty Trash Days. $manager->addHealthCheck( array( 'id' => 'empty-trash-days', @@ -70,6 +73,7 @@ public function addHealthChecks() { ) ); + // PRESS7-111: Cron Lock Timeout. $manager->addHealthCheck( array( 'id' => 'wp-cron-lock-timeout', @@ -83,6 +87,7 @@ public function addHealthChecks() { ) ); + // PRESS7-118: Permalinks. $manager->addHealthCheck( array( 'id' => 'permalinks', @@ -96,6 +101,7 @@ public function addHealthChecks() { ) ); + // PRESS7-112: Page Caching. $manager->addHealthCheck( array( 'id' => 'page-caching', @@ -109,6 +115,7 @@ public function addHealthChecks() { ) ); + // PRESS7-113: Browser Caching. $manager->addHealthCheck( array( 'id' => 'browser-caching', @@ -122,6 +129,7 @@ public function addHealthChecks() { ) ); + // PRESS7-121: Object Caching. // Only show object caching health check for Bluehost brand. if ( 'bluehost' === $this->container->plugin()->brand ) { $manager->addHealthCheck( @@ -138,6 +146,7 @@ public function addHealthChecks() { ); } + // PRESS7-107: Cloudflare. $manager->addHealthCheck( array( 'id' => 'cloudflare-active', @@ -151,6 +160,7 @@ public function addHealthChecks() { ) ); + // PRESS7-119: Lazy Loading. $manager->addHealthCheck( array( 'id' => 'lazy-loading', @@ -165,6 +175,7 @@ public function addHealthChecks() { ) ); + // PRESS7-120: Link Prefetching. $manager->addHealthCheck( array( 'id' => 'link-prefetch', @@ -180,6 +191,7 @@ public function addHealthChecks() { ) ); + // PRESS7-114: Prioritize Critical CSS. $manager->addHealthCheck( array( 'id' => 'prioritize-critical-css', @@ -194,6 +206,7 @@ public function addHealthChecks() { ) ); + // PRESS7-115: Defer Non-Essential JavaScript. $manager->addHealthCheck( array( 'id' => 'defer-non-essential-javascript', @@ -208,6 +221,7 @@ public function addHealthChecks() { ) ); + // PRESS7-116: Concatenate JavaScript. $manager->addHealthCheck( array( 'id' => 'concatenate-js', @@ -222,6 +236,7 @@ public function addHealthChecks() { ) ); + // PRESS7-117: Concatenate CSS. $manager->addHealthCheck( array( 'id' => 'concatenate-css', From 63facc4d55238d9cf8bf8fbbb1e43bae6a679816 Mon Sep 17 00:00:00 2001 From: Brad Parbs Date: Tue, 10 Dec 2024 13:21:47 -0600 Subject: [PATCH 06/11] Disabled checks for non-merged PRs --- includes/HealthChecks.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/includes/HealthChecks.php b/includes/HealthChecks.php index e0b2708..e665826 100644 --- a/includes/HealthChecks.php +++ b/includes/HealthChecks.php @@ -160,6 +160,8 @@ public function addHealthChecks() { ) ); + /* // phpcs:ignore Squiz.PHP.CommentedOutCode + Enable when https://github.com/newfold-labs/wp-module-performance/pull/32 is merged. // PRESS7-119: Lazy Loading. $manager->addHealthCheck( array( @@ -174,7 +176,10 @@ public function addHealthChecks() { }, ) ); + */ + /* // phpcs:ignore Squiz.PHP.CommentedOutCode + Enable when https://github.com/newfold-labs/wp-module-performance/pull/26 is merged. // PRESS7-120: Link Prefetching. $manager->addHealthCheck( array( @@ -189,8 +194,10 @@ public function addHealthChecks() { return ( isset( $enabled['activeOnDesktop'] ) && $enabled['activeOnDesktop'] ); }, ) - ); + );*/ + /* // phpcs:ignore Squiz.PHP.CommentedOutCode + Enable when https://github.com/newfold-labs/wp-module-performance/pull/25 is merged. // PRESS7-114: Prioritize Critical CSS. $manager->addHealthCheck( array( @@ -249,6 +256,6 @@ public function addHealthChecks() { return ( ! empty( get_option( 'jetpack_boost_status_minify-css', array() ) ) ); }, ) - ); + );*/ } } From df09f81180cab56ce71f5f6ae2751e54004a91f5 Mon Sep 17 00:00:00 2001 From: Brad Parbs Date: Tue, 10 Dec 2024 17:56:05 -0600 Subject: [PATCH 07/11] Update docblock --- includes/HealthCheckManager.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/includes/HealthCheckManager.php b/includes/HealthCheckManager.php index 53ac3d2..7dadf51 100644 --- a/includes/HealthCheckManager.php +++ b/includes/HealthCheckManager.php @@ -53,6 +53,22 @@ public function addHooks() { /** * Add a health check. * + * To add a health check, simply call this with the options you want to use. + * + * Example: + * + * $healthCheckManager->addHealthCheck( [ + * 'id' => 'example', + * 'title' => 'Example Health Check', + * 'pass' => 'This is the user-facing text for a passing health check', + * 'fail' => 'This is the user-facing text for a failing health check', + * 'text' => 'This is the user-facing description of the health check', + * 'badge_label' => 'Label', // Optional, defaults to 'Performance'. + * 'badge_color' => 'blue', // Optional, defaults to 'blue'. + * 'test' => function() { + * return true; // This is the test that will be run. and should return true or false for pass/fail. + * ] ); + * * @param array $options Health check options. */ public function addHealthCheck( $options ) { From b1fb76c7d2cc9f9c6f10f1ca169e7da468363761 Mon Sep 17 00:00:00 2001 From: Brad Parbs Date: Tue, 10 Dec 2024 17:56:37 -0600 Subject: [PATCH 08/11] Update text --- includes/HealthChecks.php | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/includes/HealthChecks.php b/includes/HealthChecks.php index e665826..88fac4e 100644 --- a/includes/HealthChecks.php +++ b/includes/HealthChecks.php @@ -36,8 +36,8 @@ public function addHealthChecks() { array( 'id' => 'autosave-interval', 'title' => __( 'Autosave Interval', 'newfold-performance-module' ), - 'pass' => __( 'Autosaving is set to happen every 30 seconds or more.', 'newfold-performance-module' ), - 'fail' => __( 'Autosaving is set to be frequent, less than every 30 seconds.', 'newfold-performance-module' ), + 'pass' => __( 'Autosaving is set to happen every 30 seconds or more', 'newfold-performance-module' ), + 'fail' => __( 'Autosaving is set to be frequent, less than every 30 seconds', 'newfold-performance-module' ), 'text' => __( 'Setting the autosave interval to a longer period can reduce server load, it is recommended to set it to 30 seconds or more.', 'newfold-performance-module' ), 'test' => function () { return ( defined( 'AUTOSAVE_INTERVAL' ) && AUTOSAVE_INTERVAL >= 30 ); @@ -134,12 +134,20 @@ public function addHealthChecks() { if ( 'bluehost' === $this->container->plugin()->brand ) { $manager->addHealthCheck( array( - 'id' => 'persistent_object_cache', // Replaces the default test. - 'title' => __( 'Object Caching', 'newfold-performance-module' ), - 'pass' => __( 'Object caching is enabled', 'newfold-performance-module' ), - 'fail' => __( 'Object caching is disabled', 'newfold-performance-module' ), - 'text' => __( 'Object caching saves results from frequent database queries, reducing load times by avoiding repetitive query processing. Object caching is available in all tiers of Bluehost Cloud.', 'newfold-performance-module' ), - 'test' => function () { + 'id' => 'persistent_object_cache', // Replaces the default test. + 'title' => __( 'Object Caching', 'newfold-performance-module' ), + 'pass' => __( 'Object caching is enabled', 'newfold-performance-module' ), + 'fail' => __( 'Object caching is disabled', 'newfold-performance-module' ), + 'text' => __( 'Object caching saves results from frequent database queries, reducing load times by avoiding repetitive query processing. Object caching is available in all tiers of Bluehost Cloud.', 'newfold-performance-module' ), + 'actions' => sprintf( + '%1$s%2$s', + __( 'Learn more about Bluehost Cloud Hosting.', 'newfold-performance-module' ), + sprintf( + ' (%s)', + __( 'opens in a new tab', 'newfold-performance-module' ) + ) + ), + 'test' => function () { return wp_using_ext_object_cache(); }, ) From 629d15be73e5c0773577f117b7a0df65567ea6b7 Mon Sep 17 00:00:00 2001 From: Brad Parbs Date: Tue, 10 Dec 2024 21:11:46 -0600 Subject: [PATCH 09/11] Update text, remove extra PR links --- includes/HealthChecks.php | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/includes/HealthChecks.php b/includes/HealthChecks.php index 88fac4e..d617d29 100644 --- a/includes/HealthChecks.php +++ b/includes/HealthChecks.php @@ -135,10 +135,10 @@ public function addHealthChecks() { $manager->addHealthCheck( array( 'id' => 'persistent_object_cache', // Replaces the default test. - 'title' => __( 'Object Caching', 'newfold-performance-module' ), - 'pass' => __( 'Object caching is enabled', 'newfold-performance-module' ), - 'fail' => __( 'Object caching is disabled', 'newfold-performance-module' ), - 'text' => __( 'Object caching saves results from frequent database queries, reducing load times by avoiding repetitive query processing. Object caching is available in all tiers of Bluehost Cloud.', 'newfold-performance-module' ), + 'title' => __( 'Object Caching', 'newfold-performance-module' ), + 'pass' => __( 'Object caching is enabled', 'newfold-performance-module' ), + 'fail' => __( 'Object caching is disabled', 'newfold-performance-module' ), + 'text' => __( 'Object caching saves results from frequent database queries, reducing load times by avoiding repetitive query processing. Object caching is available in all tiers of Bluehost Cloud.', 'newfold-performance-module' ), 'actions' => sprintf( '%1$s%2$s', __( 'Learn more about Bluehost Cloud Hosting.', 'newfold-performance-module' ), @@ -147,7 +147,7 @@ public function addHealthChecks() { __( 'opens in a new tab', 'newfold-performance-module' ) ) ), - 'test' => function () { + 'test' => function () { return wp_using_ext_object_cache(); }, ) @@ -197,7 +197,6 @@ public function addHealthChecks() { 'fail' => __( 'Link prefetching is disabled', 'newfold-performance-module' ), 'text' => __( 'Link prefetching can improve performance by loading pages immediately before they are requested.', 'newfold-performance-module' ), 'test' => function () { - https://github.com/newfold-labs/wp-module-performance/pull/26 $enabled = get_option( 'nfd_link_prefetch_settings', array() ); return ( isset( $enabled['activeOnDesktop'] ) && $enabled['activeOnDesktop'] ); }, @@ -215,7 +214,6 @@ public function addHealthChecks() { 'fail' => __( 'Critical CSS is not prioritized', 'newfold-performance-module' ), 'text' => __( 'Prioritizing critical CSS can improve performance by loading the most important CSS first.', 'newfold-performance-module' ), 'test' => function () { - https://github.com/newfold-labs/wp-module-performance/pull/25 return get_option( 'jetpack_boost_status_critical-css', false ); }, ) @@ -230,7 +228,6 @@ public function addHealthChecks() { 'fail' => __( 'Non-essential JavaScript is not deferred', 'newfold-performance-module' ), 'text' => __( 'JavaScript can be deferred to improve performance by loading it after the page has loaded.', 'newfold-performance-module' ), 'test' => function () { - https://github.com/newfold-labs/wp-module-performance/pull/25 return get_option( 'jetpack_boost_status_render-blocking-js', false ); }, ) @@ -245,7 +242,6 @@ public function addHealthChecks() { 'fail' => __( 'JavaScript files are not concatenated', 'newfold-performance-module' ), 'text' => __( 'Concatenating JavaScript can improve performance by reducing the number of requests.', 'newfold-performance-module' ), 'test' => function () { - https://github.com/newfold-labs/wp-module-performance/pull/25 return ( ! empty( get_option( 'jetpack_boost_status_minify-js', array() ) ) ); }, ) @@ -260,7 +256,6 @@ public function addHealthChecks() { 'fail' => __( 'CSS files are not concatenated', 'newfold-performance-module' ), 'text' => __( 'Concatenating CSS can improve performance by reducing the number of requests.', 'newfold-performance-module' ), 'test' => function () { - https://github.com/newfold-labs/wp-module-performance/pull/25 return ( ! empty( get_option( 'jetpack_boost_status_minify-css', array() ) ) ); }, ) From 0c27530175ceb5838fcdc5ad6513ff9c7664432a Mon Sep 17 00:00:00 2001 From: Brad Parbs Date: Wed, 11 Dec 2024 13:40:17 -0600 Subject: [PATCH 10/11] Update HealthCheckManager to allow passing an array of url, label, and external to build the links automatically. --- includes/HealthCheckManager.php | 57 ++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 19 deletions(-) diff --git a/includes/HealthCheckManager.php b/includes/HealthCheckManager.php index 7dadf51..5e65899 100644 --- a/includes/HealthCheckManager.php +++ b/includes/HealthCheckManager.php @@ -53,22 +53,6 @@ public function addHooks() { /** * Add a health check. * - * To add a health check, simply call this with the options you want to use. - * - * Example: - * - * $healthCheckManager->addHealthCheck( [ - * 'id' => 'example', - * 'title' => 'Example Health Check', - * 'pass' => 'This is the user-facing text for a passing health check', - * 'fail' => 'This is the user-facing text for a failing health check', - * 'text' => 'This is the user-facing description of the health check', - * 'badge_label' => 'Label', // Optional, defaults to 'Performance'. - * 'badge_color' => 'blue', // Optional, defaults to 'blue'. - * 'test' => function() { - * return true; // This is the test that will be run. and should return true or false for pass/fail. - * ] ); - * * @param array $options Health check options. */ public function addHealthCheck( $options ) { @@ -95,6 +79,41 @@ public function addHealthCheck( $options ) { } } + /** + * Concatenate actions array into a string. + * + * @param array $actions Actions to concatenate. Should contain an array of 'label', 'url', and 'external'. + * + * @return string Concatenated actions. + */ + public function concatActions( $actions ) { + $actions_string = ''; + + foreach ( $actions as $action ) { + $action = wp_parse_args( + $action, + array( + 'label' => '', + 'url' => '', + 'external' => false, + ) + ); + + $actions_string .= sprintf( + '%2$s%4$s', + esc_url( $action['url'] ), + esc_html( $action['label'] ), + $action['external'] ? 'target="_blank" rel="noopener"' : '', + $action['external'] ? sprintf( + ' (%s)', + __( 'opens in a new tab', 'newfold-performance-module' ) + ) : '' + ); + } + + return $actions_string; + } + /** * Run a health check. * @@ -111,9 +130,9 @@ public function runHealthCheck( $id ) { // Return the health check results. return array( 'label' => $check['label'] ? $check['label'] : ( $passed ? $check['pass'] : $check['fail'] ), - 'status' => $check['status'] ? $check['status'] : ( $passed ? 'good' : 'critical' ), - 'description' => $check['text'] ? $check['text'] : '', - 'actions' => $check['actions'] ? $check['actions'] : '', + 'status' => $passed ? 'good' : ( 'critical' === $check['status'] ? 'critical' : 'recommended' ), // Will default to 'recommended', unless 'critical' is passed. + 'description' => sprintf( '

%s

', $check['text'] ? $check['text'] : '' ), + 'actions' => is_array( $check['actions'] ) ? $this->concatActions( $check['actions'] ) : ( $check['actions'] ? $check['actions'] : '' ), 'test' => $check['id'], 'badge' => array( 'label' => $check['badge_label'], From 9871e74851ca49e58485bc9f126651ee649d51b2 Mon Sep 17 00:00:00 2001 From: Brad Parbs Date: Wed, 11 Dec 2024 13:40:25 -0600 Subject: [PATCH 11/11] Update Health Checks with consistent punctuation, link directly to the settings --- includes/HealthChecks.php | 188 ++++++++++++++++++++++++++------------ 1 file changed, 128 insertions(+), 60 deletions(-) diff --git a/includes/HealthChecks.php b/includes/HealthChecks.php index d617d29..2c58a37 100644 --- a/includes/HealthChecks.php +++ b/includes/HealthChecks.php @@ -67,6 +67,13 @@ public function addHealthChecks() { 'pass' => __( 'Trash is emptied every 30 days or less', 'newfold-performance-module' ), 'fail' => __( 'Trash is emptied less frequently than every 30 days.', 'newfold-performance-module' ), 'text' => __( 'Emptying the trash more frequently can reduce database bloat.', 'newfold-performance-module' ), + 'actions' => array( + array( + 'label' => __( 'Configure trash settings.', 'newfold-performance-module' ), + 'url' => admin_url( 'admin.php?page=' . $this->container->plugin()->id . '&nfd-target=content-section#/performance' ), + 'external' => false, + ), + ), 'test' => function () { return ( defined( 'EMPTY_TRASH_DAYS' ) && EMPTY_TRASH_DAYS <= 30 ); }, @@ -95,6 +102,13 @@ public function addHealthChecks() { 'pass' => __( 'Permalinks are pretty', 'newfold-performance-module' ), 'fail' => __( 'Permalinks are not set up', 'newfold-performance-module' ), 'text' => __( 'Setting permalinks to anything other than plain can improve performance and SEO.', 'newfold-performance-module' ), + 'actions' => array( + array( + 'label' => __( 'Set up permalinks.', 'newfold-performance-module' ), + 'url' => admin_url( 'options-permalink.php' ), + 'external' => false, + ), + ), 'test' => function () { return empty( get_option( 'permalink_structure' ) ); }, @@ -104,11 +118,18 @@ public function addHealthChecks() { // PRESS7-112: Page Caching. $manager->addHealthCheck( array( - 'id' => 'page-caching', - 'title' => __( 'Page Caching', 'newfold-performance-module' ), - 'pass' => __( 'Page caching is enabled', 'newfold-performance-module' ), - 'fail' => __( 'Page caching is disabled', 'newfold-performance-module' ), - 'text' => __( 'Page caching can improve performance by bypassing PHP and database queries for faster page loads.', 'newfold-performance-module' ), + 'id' => 'page-caching', + 'title' => __( 'Page Caching', 'newfold-performance-module' ), + 'pass' => __( 'Page caching is enabled', 'newfold-performance-module' ), + 'fail' => __( 'Page caching is disabled', 'newfold-performance-module' ), + 'text' => __( 'Page caching can improve performance by bypassing PHP and database queries for faster page loads.', 'newfold-performance-module' ), + 'actions' => array( + array( + 'label' => __( 'Configure caching.', 'newfold-performance-module' ), + 'url' => admin_url( 'admin.php?page=' . $this->container->plugin()->id . '&nfd-target=cache-type#/performance' ), + 'external' => false, + ), + ), 'test' => function () { return ( get_option( 'newfold_cache_level' ) >= 2 ); }, @@ -118,12 +139,19 @@ public function addHealthChecks() { // PRESS7-113: Browser Caching. $manager->addHealthCheck( array( - 'id' => 'browser-caching', - 'title' => __( 'Browser Caching', 'newfold-performance-module' ), - 'pass' => __( 'Browser caching is enabled', 'newfold-performance-module' ), - 'fail' => __( 'Browser caching is disabled', 'newfold-performance-module' ), - 'text' => __( 'Enabling browser caching can improve performance by storing static assets in the browser for faster page loads.', 'newfold-performance-module' ), - 'test' => function () { + 'id' => 'browser-caching', + 'title' => __( 'Browser Caching', 'newfold-performance-module' ), + 'pass' => __( 'Browser caching is enabled', 'newfold-performance-module' ), + 'fail' => __( 'Browser caching is disabled', 'newfold-performance-module' ), + 'text' => __( 'Enabling browser caching can improve performance by storing static assets in the browser for faster page loads.', 'newfold-performance-module' ), + 'actions' => array( + array( + 'label' => __( 'Configure caching.', 'newfold-performance-module' ), + 'url' => admin_url( 'admin.php?page=' . $this->container->plugin()->id . '&nfd-target=cache-type#/performance' ), + 'external' => false, + ), + ), + 'test' => function () { return ( get_option( 'newfold_cache_level' ) >= 1 ); }, ) @@ -135,19 +163,18 @@ public function addHealthChecks() { $manager->addHealthCheck( array( 'id' => 'persistent_object_cache', // Replaces the default test. - 'title' => __( 'Object Caching', 'newfold-performance-module' ), - 'pass' => __( 'Object caching is enabled', 'newfold-performance-module' ), - 'fail' => __( 'Object caching is disabled', 'newfold-performance-module' ), - 'text' => __( 'Object caching saves results from frequent database queries, reducing load times by avoiding repetitive query processing. Object caching is available in all tiers of Bluehost Cloud.', 'newfold-performance-module' ), - 'actions' => sprintf( - '%1$s%2$s', - __( 'Learn more about Bluehost Cloud Hosting.', 'newfold-performance-module' ), - sprintf( - ' (%s)', - __( 'opens in a new tab', 'newfold-performance-module' ) - ) + 'title' => __( 'Object Caching', 'newfold-performance-module' ), + 'pass' => __( 'Object caching is enabled', 'newfold-performance-module' ), + 'fail' => __( 'Object caching is disabled', 'newfold-performance-module' ), + 'text' => __( 'Object caching saves results from frequent database queries, reducing load times by avoiding repetitive query processing. Object caching is available in all tiers of Bluehost Cloud.', 'newfold-performance-module' ), + 'actions' => array( + array( + 'label' => __( 'Learn more about Bluehost Cloud Hosting.', 'newfold-performance-module' ), + 'url' => 'https://www.bluehost.com/hosting/cloud', + 'external' => true, + ), ), - 'test' => function () { + 'test' => function () { return wp_using_ext_object_cache(); }, ) @@ -169,50 +196,70 @@ public function addHealthChecks() { ); /* // phpcs:ignore Squiz.PHP.CommentedOutCode - Enable when https://github.com/newfold-labs/wp-module-performance/pull/32 is merged. + // Enable when https://github.com/newfold-labs/wp-module-performance/pull/32 is merged. // PRESS7-119: Lazy Loading. $manager->addHealthCheck( array( - 'id' => 'lazy-loading', - 'title' => __( 'Lazy Loading', 'newfold-performance-module' ), - 'pass' => __( 'Lazy loading is enabled', 'newfold-performance-module' ), - 'fail' => __( 'Lazy loading is disabled', 'newfold-performance-module' ), - 'text' => __( 'Lazy loading can improve performance by only loading images when they are in view.', 'newfold-performance-module' ), + 'id' => 'lazy-loading', + 'title' => __( 'Lazy Loading', 'newfold-performance-module' ), + 'pass' => __( 'Lazy loading is enabled', 'newfold-performance-module' ), + 'fail' => __( 'Lazy loading is disabled', 'newfold-performance-module' ), + 'text' => __( 'Lazy loading can improve performance by only loading images when they are in view.', 'newfold-performance-module' ), + 'actions' => array( + array( + 'label' => __( 'Configure lazy loading.', 'newfold-performance-module' ), + 'url' => admin_url( 'admin.php?page=' . $this->container->plugin()->id . '&nfd-target=lazy-loading-enabled#/performance' ), + 'external' => false, + ), + ), 'test' => function () { $enabled = get_option( 'nfd_image_optimization', array() ); return ( isset( $enabled['lazy_loading'], $enabled['lazy_loading']['enabled'] ) && $enabled['lazy_loading']['enabled'] ); }, ) - ); - */ + ); */ /* // phpcs:ignore Squiz.PHP.CommentedOutCode - Enable when https://github.com/newfold-labs/wp-module-performance/pull/26 is merged. + // Enable when https://github.com/newfold-labs/wp-module-performance/pull/26 is merged. // PRESS7-120: Link Prefetching. $manager->addHealthCheck( array( - 'id' => 'link-prefetch', - 'title' => __( 'Link Prefetching', 'newfold-performance-module' ), - 'pass' => __( 'Link prefetching is enabled', 'newfold-performance-module' ), - 'fail' => __( 'Link prefetching is disabled', 'newfold-performance-module' ), - 'text' => __( 'Link prefetching can improve performance by loading pages immediately before they are requested.', 'newfold-performance-module' ), + 'id' => 'link-prefetch', + 'title' => __( 'Link Prefetching', 'newfold-performance-module' ), + 'pass' => __( 'Link prefetching is enabled', 'newfold-performance-module' ), + 'fail' => __( 'Link prefetching is disabled', 'newfold-performance-module' ), + 'text' => __( 'Link prefetching can improve performance by loading pages immediately before they are requested.', 'newfold-performance-module' ), + 'actions' => array( + array( + 'label' => __( 'Configure Link prefetching.', 'newfold-performance-module' ), + 'url' => admin_url( 'admin.php?page=' . $this->container->plugin()->id . '&nfd-target=link-prefetch-behavior#/performance' ), + 'external' => false, + ), + ), 'test' => function () { $enabled = get_option( 'nfd_link_prefetch_settings', array() ); return ( isset( $enabled['activeOnDesktop'] ) && $enabled['activeOnDesktop'] ); }, ) - );*/ + ); */ /* // phpcs:ignore Squiz.PHP.CommentedOutCode - Enable when https://github.com/newfold-labs/wp-module-performance/pull/25 is merged. + // Enable when https://github.com/newfold-labs/wp-module-performance/pull/25 is merged. // PRESS7-114: Prioritize Critical CSS. $manager->addHealthCheck( array( - 'id' => 'prioritize-critical-css', - 'title' => __( 'Prioritize Critical CSS', 'newfold-performance-module' ), - 'pass' => __( 'Critical CSS is prioritized', 'newfold-performance-module' ), - 'fail' => __( 'Critical CSS is not prioritized', 'newfold-performance-module' ), - 'text' => __( 'Prioritizing critical CSS can improve performance by loading the most important CSS first.', 'newfold-performance-module' ), + 'id' => 'prioritize-critical-css', + 'title' => __( 'Prioritize Critical CSS', 'newfold-performance-module' ), + 'pass' => __( 'Critical CSS is prioritized', 'newfold-performance-module' ), + 'fail' => __( 'Critical CSS is not prioritized', 'newfold-performance-module' ), + 'text' => __( 'Prioritizing critical CSS can improve performance by loading the most important CSS first.', 'newfold-performance-module' ), + 'actions' => array( + array( + 'label' => __( 'Configure Critical CSS.', 'newfold-performance-module' ), + 'url' => admin_url( 'admin.php?page=' . $this->container->plugin()->id . '&nfd-target=critical-css#/performance' ), + 'external' => false, + ), + ), 'test' => function () { return get_option( 'jetpack_boost_status_critical-css', false ); }, @@ -222,11 +269,18 @@ public function addHealthChecks() { // PRESS7-115: Defer Non-Essential JavaScript. $manager->addHealthCheck( array( - 'id' => 'defer-non-essential-javascript', - 'title' => __( 'Defer Non-Essential JavaScript', 'newfold-performance-module' ), - 'pass' => __( 'Non-essential JavaScript is deferred', 'newfold-performance-module' ), - 'fail' => __( 'Non-essential JavaScript is not deferred', 'newfold-performance-module' ), - 'text' => __( 'JavaScript can be deferred to improve performance by loading it after the page has loaded.', 'newfold-performance-module' ), + 'id' => 'defer-non-essential-javascript', + 'title' => __( 'Defer Non-Essential JavaScript', 'newfold-performance-module' ), + 'pass' => __( 'Non-essential JavaScript is deferred', 'newfold-performance-module' ), + 'fail' => __( 'Non-essential JavaScript is not deferred', 'newfold-performance-module' ), + 'text' => __( 'JavaScript can be deferred to improve performance by loading it after the page has loaded.', 'newfold-performance-module' ), + 'actions' => array( + array( + 'label' => __( 'Configure JavaScript deferral.', 'newfold-performance-module' ), + 'url' => admin_url( 'admin.php?page=' . $this->container->plugin()->id . '&nfd-target=render-blocking-js#/performance' ), + 'external' => false, + ), + ), 'test' => function () { return get_option( 'jetpack_boost_status_render-blocking-js', false ); }, @@ -236,11 +290,18 @@ public function addHealthChecks() { // PRESS7-116: Concatenate JavaScript. $manager->addHealthCheck( array( - 'id' => 'concatenate-js', - 'title' => __( 'Concatenate JavaScript', 'newfold-performance-module' ), - 'pass' => __( 'JavaScript files are concatenated', 'newfold-performance-module' ), - 'fail' => __( 'JavaScript files are not concatenated', 'newfold-performance-module' ), - 'text' => __( 'Concatenating JavaScript can improve performance by reducing the number of requests.', 'newfold-performance-module' ), + 'id' => 'concatenate-js', + 'title' => __( 'Concatenate JavaScript', 'newfold-performance-module' ), + 'pass' => __( 'JavaScript files are concatenated', 'newfold-performance-module' ), + 'fail' => __( 'JavaScript files are not concatenated', 'newfold-performance-module' ), + 'text' => __( 'Concatenating JavaScript can improve performance by reducing the number of requests.', 'newfold-performance-module' ), + 'actions' => array( + array( + 'label' => __( 'Configure JavaScript deferral.', 'newfold-performance-module' ), + 'url' => admin_url( 'admin.php?page=' . $this->container->plugin()->id . '&nfd-target=minify-js#/performance' ), + 'external' => false, + ), + ), 'test' => function () { return ( ! empty( get_option( 'jetpack_boost_status_minify-js', array() ) ) ); }, @@ -250,15 +311,22 @@ public function addHealthChecks() { // PRESS7-117: Concatenate CSS. $manager->addHealthCheck( array( - 'id' => 'concatenate-css', - 'title' => __( 'Concatenate CSS', 'newfold-performance-module' ), - 'pass' => __( 'CSS files are concatenated', 'newfold-performance-module' ), - 'fail' => __( 'CSS files are not concatenated', 'newfold-performance-module' ), - 'text' => __( 'Concatenating CSS can improve performance by reducing the number of requests.', 'newfold-performance-module' ), + 'id' => 'concatenate-css', + 'title' => __( 'Concatenate CSS', 'newfold-performance-module' ), + 'pass' => __( 'CSS files are concatenated', 'newfold-performance-module' ), + 'fail' => __( 'CSS files are not concatenated', 'newfold-performance-module' ), + 'text' => __( 'Concatenating CSS can improve performance by reducing the number of requests.', 'newfold-performance-module' ), + 'actions' => array( + array( + 'label' => __( 'Configure JavaScript deferral.', 'newfold-performance-module' ), + 'url' => admin_url( 'admin.php?page=' . $this->container->plugin()->id . '&nfd-target=minify-csss#/performance' ), + 'external' => false, + ), + ), 'test' => function () { return ( ! empty( get_option( 'jetpack_boost_status_minify-css', array() ) ) ); }, ) - );*/ + ); */ } }