From ce0a690822eb6170d8224520dbaac93514a8c79b Mon Sep 17 00:00:00 2001 From: Weston Ruter Date: Wed, 20 Mar 2024 11:52:58 -0700 Subject: [PATCH] Bump minimum WP version for Optimization Detective --- .../class-od-html-tag-processor.php | 3 --- plugins/optimization-detective/load.php | 2 +- .../class-od-url-metrics-post-type.php | 22 +++++++++---------- 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/plugins/optimization-detective/class-od-html-tag-processor.php b/plugins/optimization-detective/class-od-html-tag-processor.php index 1c21ee6bb1..1c2a660087 100644 --- a/plugins/optimization-detective/class-od-html-tag-processor.php +++ b/plugins/optimization-detective/class-od-html-tag-processor.php @@ -266,9 +266,6 @@ public function open_tags(): Generator { * @param string $message Warning message. */ private function warn( string $message ) { - if ( ! function_exists( 'wp_trigger_error' ) ) { - return; - } wp_trigger_error( __CLASS__ . '::open_tags', esc_html( $message ) diff --git a/plugins/optimization-detective/load.php b/plugins/optimization-detective/load.php index 809d6b2308..70958bf024 100644 --- a/plugins/optimization-detective/load.php +++ b/plugins/optimization-detective/load.php @@ -3,7 +3,7 @@ * Plugin Name: Optimization Detective * Plugin URI: https://github.com/WordPress/performance/issues/869 * Description: Uses real user metrics to improve heuristics WordPress applies on the frontend to improve image loading priority. - * Requires at least: 6.3 + * Requires at least: 6.4 * Requires PHP: 7.0 * Version: 0.1.0 * Author: WordPress Performance Team diff --git a/plugins/optimization-detective/storage/class-od-url-metrics-post-type.php b/plugins/optimization-detective/storage/class-od-url-metrics-post-type.php index a883187523..dafe02fdfd 100644 --- a/plugins/optimization-detective/storage/class-od-url-metrics-post-type.php +++ b/plugins/optimization-detective/storage/class-od-url-metrics-post-type.php @@ -117,18 +117,16 @@ public static function get_post( string $slug ) { * @return OD_URL_Metric[] URL metrics. */ public static function get_url_metrics_from_post( WP_Post $post ): array { - $this_function = __FUNCTION__; - $trigger_error = static function ( $error ) use ( $this_function ) { - if ( function_exists( 'wp_trigger_error' ) ) { - wp_trigger_error( $this_function, esc_html( $error ), E_USER_WARNING ); - } + $this_function = __FUNCTION__; + $trigger_warning = static function ( $message ) use ( $this_function ) { + wp_trigger_error( $this_function, esc_html( $message ), E_USER_WARNING ); }; $url_metrics_data = json_decode( $post->post_content, true ); if ( json_last_error() ) { - $trigger_error( + $trigger_warning( sprintf( - /* translators: 1: Post type slug, 2: Post ID, 3: JSON error message */ + /* translators: 1: Post type slug, 2: Post ID, 3: JSON error message */ __( 'Contents of %1$s post type (ID: %2$s) not valid JSON: %3$s', 'optimization-detective' ), self::SLUG, $post->ID, @@ -137,9 +135,9 @@ public static function get_url_metrics_from_post( WP_Post $post ): array { ); $url_metrics_data = array(); } elseif ( ! is_array( $url_metrics_data ) ) { - $trigger_error( + $trigger_warning( sprintf( - /* translators: %s is post type slug */ + /* translators: %s is post type slug */ __( 'Contents of %s post type was not a JSON array.', 'optimization-detective' ), self::SLUG ) @@ -150,7 +148,7 @@ public static function get_url_metrics_from_post( WP_Post $post ): array { return array_values( array_filter( array_map( - static function ( $url_metric_data ) use ( $trigger_error ) { + static function ( $url_metric_data ) use ( $trigger_warning ) { if ( ! is_array( $url_metric_data ) ) { return null; } @@ -158,9 +156,9 @@ static function ( $url_metric_data ) use ( $trigger_error ) { try { return new OD_URL_Metric( $url_metric_data ); } catch ( OD_Data_Validation_Exception $e ) { - $trigger_error( + $trigger_warning( sprintf( - /* translators: 1: Post type slug. 2: Exception message. */ + /* translators: 1: Post type slug. 2: Exception message. */ __( 'Unexpected shape to JSON array in post_content of %1$s post type: %2$s', 'optimization-detective' ), OD_URL_Metrics_Post_Type::SLUG, $e->getMessage()