Skip to content

Commit 69eca9a

Browse files
authored
Merge pull request #1700 from ShyamGadde/add/plugin-development-mode-config
Set development mode to 'plugin' in the development environment
2 parents 638c1ed + f879c22 commit 69eca9a

File tree

3 files changed

+40
-13
lines changed

3 files changed

+40
-13
lines changed

.wp-env.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
"./plugins/webp-uploads"
1313
],
1414
"env": {
15+
"development": {
16+
"config": {
17+
"WP_DEVELOPMENT_MODE": "plugin"
18+
}
19+
},
1520
"tests": {
1621
"config": {
1722
"FS_METHOD": "direct"

plugins/optimization-detective/optimization.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ function_exists( 'perflab_server_timing_use_output_buffer' )
9898
* Determines whether the current response can be optimized.
9999
*
100100
* @since 0.1.0
101+
* @since n.e.x.t Response is optimized for admin users as well when in 'plugin' development mode.
102+
*
101103
* @access private
102104
*
103105
* @return bool Whether response can be optimized.
@@ -116,11 +118,12 @@ function od_can_optimize_response(): bool {
116118
is_customize_preview() ||
117119
// Since the images detected in the response body of a POST request cannot, by definition, be cached.
118120
( isset( $_SERVER['REQUEST_METHOD'] ) && 'GET' !== $_SERVER['REQUEST_METHOD'] ) ||
119-
// The aim is to optimize pages for the majority of site visitors, not those who administer the site. For admin
120-
// users, additional elements will be present like the script from wp_customize_support_script() which will
121-
// interfere with the XPath indices. Note that od_get_normalized_query_vars() is varied by is_user_logged_in()
122-
// so membership sites and e-commerce sites will still be able to be optimized for their normal visitors.
123-
current_user_can( 'customize' ) ||
121+
// The aim is to optimize pages for the majority of site visitors, not for those who administer the site, unless
122+
// in 'plugin' development mode. For admin users, additional elements will be present, like the script from
123+
// wp_customize_support_script(), which will interfere with the XPath indices. Note that
124+
// od_get_normalized_query_vars() is varied by is_user_logged_in(), so membership sites and e-commerce sites
125+
// will still be able to be optimized for their normal visitors.
126+
( current_user_can( 'customize' ) && ! wp_is_development_mode( 'plugin' ) ) ||
124127
// Page caching plugins can only reliably be told to invalidate a cached page when a post is available to trigger
125128
// the relevant actions on.
126129
null === od_get_cache_purge_post_id()

plugins/optimization-detective/readme.txt

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,10 @@ Filters whether the current response can be optimized. By default, detection and
9292
2. It’s not a post embed template (`is_embed()`).
9393
3. It’s not the Customizer preview (`is_customize_preview()`)
9494
4. It’s not the response to a `POST` request.
95-
5. The user is not an administrator (`current_user_can( 'customize' )`).
95+
5. The user is not an administrator (`current_user_can( 'customize' )`), unless you're in plugin development mode (`wp_is_development_mode( 'plugin' )`).
96+
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.
9697

97-
During development, you may want to force this to always be enabled:
98+
To force every response to be optimized regardless of the conditions above, you can do:
9899

99100
`
100101
<?php
@@ -103,7 +104,7 @@ add_filter( 'od_can_optimize_response', '__return_true' );
103104

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

106-
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:
107+
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:
107108

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

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

128-
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:
129+
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:
129130

130131
`
131132
<?php
132-
add_filter( 'od_url_metric_freshness_ttl', '__return_zero' );
133+
add_filter( 'od_url_metric_freshness_ttl', static function (): int {
134+
return WEEK_IN_SECONDS;
135+
} );
136+
`
137+
138+
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:
139+
140+
`
141+
<?php
142+
add_filter( 'od_url_metric_freshness_ttl', static function (): int {
143+
return 0;
144+
} );
133145
`
134146

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

137149
Filters the minimum allowed viewport aspect ratio for URL Metrics.
138150

139-
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).
151+
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:
152+
153+
`
154+
<?php
155+
add_filter( 'od_minimum_viewport_aspect_ratio', static function (): int {
156+
return 0;
157+
} );
158+
`
140159

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

143162
Filters the maximum allowed viewport aspect ratio for URL Metrics.
144163

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

147-
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:
166+
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:
148167

149168
`
150169
<?php
151-
add_filter( 'od_maximum_viewport_aspect_ratio', function () {
170+
add_filter( 'od_maximum_viewport_aspect_ratio', static function (): int {
152171
return 5;
153172
} );
154173
`

0 commit comments

Comments
 (0)