Skip to content

Commit

Permalink
Merge pull request #1068 from WordPress/bump/od-minimum-wp-version
Browse files Browse the repository at this point in the history
Bump minimum WP version for Optimization Detective
  • Loading branch information
westonruter authored Mar 21, 2024
2 parents 0f5f68d + c87c330 commit 26c83e7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
2 changes: 1 addition & 1 deletion plugins/optimization-detective/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
)
Expand All @@ -150,17 +148,17 @@ 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;
}

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()
Expand Down

0 comments on commit 26c83e7

Please sign in to comment.