Repository navigation
Description
Feature Description
Optimization Detective currently outputs a meta generator tag with a rest_api_unavailable flag for when the REST API is unavailable (and thus Optimization Detective is disabled):
performance/plugins/optimization-detective/helper.php
Lines 71 to 81 in 9bce8c9
| function od_render_generator_meta_tag(): void { | |
| // Use the plugin slug as it is immutable. | |
| $content = 'optimization-detective ' . OPTIMIZATION_DETECTIVE_VERSION; | |
| // Indicate that the plugin will not be doing anything because the REST API is unavailable. | |
| if ( od_is_rest_api_unavailable() ) { | |
| $content .= '; rest_api_unavailable'; | |
| } | |
| echo '<meta name="generator" content="' . esc_attr( $content ) . '">' . "\n"; | |
| } |
However, there are other reasons for why Optimization Detective can be disabled:
performance/plugins/optimization-detective/optimization.php
Lines 84 to 114 in 9bce8c9
| $conditions = array( | |
| array( | |
| 'test' => od_can_optimize_response(), | |
| 'reason' => __( 'Page is not optimized because od_can_optimize_response() returned false. This can be overridden with the od_can_optimize_response filter.', 'optimization-detective' ), | |
| ), | |
| array( | |
| 'test' => ! od_is_rest_api_unavailable() || ( wp_get_environment_type() === 'local' && ! function_exists( 'tests_add_filter' ) ), | |
| 'reason' => __( 'Page is not optimized because the REST API for storing URL Metrics is not available.', 'optimization-detective' ), | |
| ), | |
| array( | |
| 'test' => ! isset( $_GET['optimization_detective_disabled'] ), // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 'reason' => __( 'Page is not optimized because the URL has the optimization_detective_disabled query parameter.', 'optimization-detective' ), | |
| ), | |
| ); | |
| $reasons = array(); | |
| foreach ( $conditions as $condition ) { | |
| if ( ! $condition['test'] ) { | |
| $reasons[] = $condition['reason']; | |
| } | |
| } | |
| if ( count( $reasons ) > 0 ) { | |
| if ( WP_DEBUG ) { | |
| add_action( | |
| 'wp_print_footer_scripts', | |
| static function () use ( $reasons ): void { | |
| od_print_disabled_reasons( $reasons ); | |
| } | |
| ); | |
| } | |
| return; | |
| } |
Namely there is the ! od_can_optimize_response() case and the isset( $_GET['optimization_detective_disabled'] ) case. These could be added as additional flags for inclusion in the meta generator tag, alongside rest_api_unavailable.
A bonus would be to extract the logic into a helper function which could be used in both places.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone 😃
Activity