diff --git a/plugins/optimization-detective/optimization.php b/plugins/optimization-detective/optimization.php index e47d7813e2..66a97591f2 100644 --- a/plugins/optimization-detective/optimization.php +++ b/plugins/optimization-detective/optimization.php @@ -107,6 +107,11 @@ function od_can_optimize_response(): bool { // Since there is no predictability in whether posts in the loop will have featured images assigned or not. If a // theme template for search results doesn't even show featured images, then this wouldn't be an issue. is_search() || + // Avoid optimizing embed responses because the Post Embed iframes include a sandbox attribute with the value of + // "allow-scripts" but without "allow-same-origin". This can result in an error in the console: + // > Access to script at '.../detect.js?ver=0.4.1' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. + // So it's better to just avoid attempting to optimize Post Embed responses (which don't need optimization anyway). + is_embed() || // Since injection of inline-editing controls interfere with breadcrumbs, while also just not necessary in this context. is_customize_preview() || // Since the images detected in the response body of a POST request cannot, by definition, be cached. diff --git a/plugins/optimization-detective/readme.txt b/plugins/optimization-detective/readme.txt index 5bf5a01c9c..0bb7601ec5 100644 --- a/plugins/optimization-detective/readme.txt +++ b/plugins/optimization-detective/readme.txt @@ -48,10 +48,11 @@ The default breakpoints are reused from Gutenberg which appear to be used the mo Filters whether the current response can be optimized. By default, detection and optimization are only performed when: -1. It’s not a search template (i.e. `is_search()`). -2. It’s not the Customizer preview. -3. It’s not the response to a `POST` request. -4. The user is not an administrator (i.e. the `customize` capability). +1. It’s not a search template (`is_search()`). +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' )`). During development, you may want to force this to always be enabled: diff --git a/plugins/performance-lab/includes/admin/plugins.php b/plugins/performance-lab/includes/admin/plugins.php index a94c4d10bf..eb69aca044 100644 --- a/plugins/performance-lab/includes/admin/plugins.php +++ b/plugins/performance-lab/includes/admin/plugins.php @@ -96,23 +96,15 @@ function perflab_render_plugins_ui(): void { require_once ABSPATH . 'wp-admin/includes/plugin.php'; $plugins = array(); + $errors = array(); - foreach ( perflab_get_standalone_plugin_data() as $plugin_slug => $plugin_data ) { + $standalone_plugin_data = perflab_get_standalone_plugin_data(); + foreach ( $standalone_plugin_data as $plugin_slug => $plugin_data ) { $api_data = perflab_query_plugin_info( $plugin_slug ); // Data from wordpress.org. // Skip if the plugin is not on WordPress.org or there was a network error. if ( $api_data instanceof WP_Error ) { - wp_admin_notice( - esc_html( - sprintf( - /* translators: 1: plugin slug. 2: error message. */ - __( 'Failed to query WordPress.org Plugin Directory for plugin "%1$s". %2$s', 'performance-lab' ), - $plugin_slug, - $api_data->get_error_message() - ) - ), - array( 'type' => 'error' ) - ); + $errors[ $plugin_slug ] = $api_data; } else { $plugins[ $plugin_slug ] = array_merge( array( @@ -124,6 +116,61 @@ function perflab_render_plugins_ui(): void { } } + if ( count( $errors ) > 0 ) { + $active_plugins = array_map( + static function ( string $file ) { + return strtok( $file, '/' ); + }, + array_keys( get_plugins() ) + ); + $plugin_list = '
%s
%s' . esc_html( + _n( 'Failed to query WordPress.org Plugin Directory for the following plugin:', 'Failed to query WordPress.org Plugin Directory for the following plugins:', count( $errors ), 'performance-lab' ) + ) . '
' . + $plugin_list . + '' . esc_html( _n( 'The following error occurred:', 'The following errors occurred:', count( $error_messages ), 'performance-lab' ) ) . '
' . + '' . esc_html__( 'Please consider manual plugin installation and activation. You can then access each plugin\'s settings via its respective "Settings" link on the Plugins screen.', 'performance-lab' ) . '
', + array( + 'type' => 'error', + 'paragraph_wrap' => false, + ) + ); + } + /* * Sort plugins alphabetically, with experimental ones coming last. * Even though `experimental` is a boolean flag, the underlying