Skip to content

Commit

Permalink
Merge pull request #1700 from ShyamGadde/add/plugin-development-mode-…
Browse files Browse the repository at this point in the history
…config

Set development mode to 'plugin' in the development environment
  • Loading branch information
westonruter authored Nov 26, 2024
2 parents 638c1ed + f879c22 commit 69eca9a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .wp-env.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
"./plugins/webp-uploads"
],
"env": {
"development": {
"config": {
"WP_DEVELOPMENT_MODE": "plugin"
}
},
"tests": {
"config": {
"FS_METHOD": "direct"
Expand Down
13 changes: 8 additions & 5 deletions plugins/optimization-detective/optimization.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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()
Expand Down
35 changes: 27 additions & 8 deletions plugins/optimization-detective/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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:

`
<?php
Expand All @@ -103,7 +104,7 @@ add_filter( 'od_can_optimize_response', '__return_true' );

**Filter:** `od_url_metrics_breakpoint_sample_size` (default: 3)

Filters the sample size for a breakpoint's URL Metrics on a given URL. The sample size must be greater than zero. During development, it may be helpful to reduce the sample size to 1:
Filters the sample size for a breakpoint's URL Metrics on a given URL. The sample size must be greater than zero. You can increase the sample size if you want better guarantees that the applied optimizations will be accurate. During development, it may be helpful to reduce the sample size to 1:

`
<?php
Expand All @@ -125,30 +126,48 @@ add_filter( 'od_metrics_storage_lock_ttl', function ( int $ttl ): int {

**Filter:** `od_url_metric_freshness_ttl` (default: 1 day in seconds)

Filters the freshness age (TTL) for a given URL Metric. The freshness TTL must be at least zero, in which it considers URL Metrics to always be stale. In practice, the value should be at least an hour. During development, this can be useful to set to zero:
Filters the freshness age (TTL) for a given URL Metric. The freshness TTL must be at least zero, in which it considers URL Metrics to always be stale. In practice, the value should be at least an hour. If your site content does not change frequently, you may want to increase the TTL to a week:

`
<?php
add_filter( 'od_url_metric_freshness_ttl', '__return_zero' );
add_filter( 'od_url_metric_freshness_ttl', static function (): int {
return WEEK_IN_SECONDS;
} );
`

During development, this can be useful to set to zero so that you don't have to wait for new URL Metrics to be requested when engineering a new optimization:

`
<?php
add_filter( 'od_url_metric_freshness_ttl', static function (): int {
return 0;
} );
`

**Filter:** `od_minimum_viewport_aspect_ratio` (default: 0.4)

Filters the minimum allowed viewport aspect ratio for URL Metrics.

The 0.4 value is intended to accommodate the phone with the greatest known aspect ratio at 21:9 when rotated 90 degrees to 9:21 (0.429).
The 0.4 value is intended to accommodate the phone with the greatest known aspect ratio at 21:9 when rotated 90 degrees to 9:21 (0.429). During development when you have the DevTools console open on the right, the viewport aspect ratio will be smaller than normal. In this case, you may want to set this to 0:

`
<?php
add_filter( 'od_minimum_viewport_aspect_ratio', static function (): int {
return 0;
} );
`

**Filter:** `od_maximum_viewport_aspect_ratio` (default: 2.5)

Filters the maximum allowed viewport aspect ratio for URL Metrics.

The 2.5 value is intended to accommodate the phone with the greatest known aspect ratio at 21:9 (2.333).

During development when you have the DevTools console open, for example, the viewport aspect ratio will be wider than normal. In this case, you may want to increase the maximum aspect ratio:
During development when you have the DevTools console open on the bottom, for example, the viewport aspect ratio will be larger than normal. In this case, you may want to increase the maximum aspect ratio:

`
<?php
add_filter( 'od_maximum_viewport_aspect_ratio', function () {
add_filter( 'od_maximum_viewport_aspect_ratio', static function (): int {
return 5;
} );
`
Expand Down

0 comments on commit 69eca9a

Please sign in to comment.