diff --git a/.wp-env.json b/.wp-env.json index 2c652e636..3887c95a0 100644 --- a/.wp-env.json +++ b/.wp-env.json @@ -12,6 +12,11 @@ "./plugins/webp-uploads" ], "env": { + "development": { + "config": { + "WP_DEVELOPMENT_MODE": "plugin" + } + }, "tests": { "config": { "FS_METHOD": "direct" diff --git a/plugins/optimization-detective/optimization.php b/plugins/optimization-detective/optimization.php index 11f4df10a..9fd32e1ee 100644 --- a/plugins/optimization-detective/optimization.php +++ b/plugins/optimization-detective/optimization.php @@ -98,6 +98,8 @@ function_exists( 'perflab_server_timing_use_output_buffer' ) * Determines whether the current response can be optimized. * * @since 0.1.0 + * @since n.e.x.t Response is optimized for admin users as well when in 'plugin' development mode. + * * @access private * * @return bool Whether response can be optimized. @@ -116,11 +118,12 @@ function od_can_optimize_response(): bool { is_customize_preview() || // Since the images detected in the response body of a POST request cannot, by definition, be cached. ( isset( $_SERVER['REQUEST_METHOD'] ) && 'GET' !== $_SERVER['REQUEST_METHOD'] ) || - // The aim is to optimize pages for the majority of site visitors, not those who administer the site. For admin - // users, additional elements will be present like the script from wp_customize_support_script() which will - // interfere with the XPath indices. Note that od_get_normalized_query_vars() is varied by is_user_logged_in() - // so membership sites and e-commerce sites will still be able to be optimized for their normal visitors. - current_user_can( 'customize' ) || + // The aim is to optimize pages for the majority of site visitors, not for those who administer the site, unless + // in 'plugin' development mode. For admin users, additional elements will be present, like the script from + // wp_customize_support_script(), which will interfere with the XPath indices. Note that + // od_get_normalized_query_vars() is varied by is_user_logged_in(), so membership sites and e-commerce sites + // will still be able to be optimized for their normal visitors. + ( current_user_can( 'customize' ) && ! wp_is_development_mode( 'plugin' ) ) || // Page caching plugins can only reliably be told to invalidate a cached page when a post is available to trigger // the relevant actions on. null === od_get_cache_purge_post_id() diff --git a/plugins/optimization-detective/readme.txt b/plugins/optimization-detective/readme.txt index a57d96843..0d5e0cd24 100644 --- a/plugins/optimization-detective/readme.txt +++ b/plugins/optimization-detective/readme.txt @@ -92,9 +92,10 @@ Filters whether the current response can be optimized. By default, detection and 2. It’s not a post embed template (`is_embed()`). 3. It’s not the Customizer preview (`is_customize_preview()`) 4. It’s not the response to a `POST` request. -5. The user is not an administrator (`current_user_can( 'customize' )`). +5. The user is not an administrator (`current_user_can( 'customize' )`), unless you're in plugin development mode (`wp_is_development_mode( 'plugin' )`). +6. There is at least one queried post on the page. This is used to facilitate the purging of page caches after a new URL Metric is stored. -During development, you may want to force this to always be enabled: +To force every response to be optimized regardless of the conditions above, you can do: `