Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump minimum WP version for Optimization Detective #1068

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading