Skip to content

Optimization Detective's meta generator tag should indicate more reasons for why it is disabled #1977

Closed

Description

@westonruter

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):

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:

$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.

Activity

  1. added
    [Plugin] Optimization Detective
    [Type] Enhancement
    on Apr 8, 2025
  2. moved this to Not Started/Backlog 📆 in WP Performance Ongoingon Apr 8, 2025
  3. moved this from Not Started/Backlog 📆 to Done 😃 in WP Performance Ongoingon May 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Plugin] Optimization Detective[Type] Enhancement

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions