From f4e57f92e4ed89b6e291974b4e729f18c0451887 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Tue, 2 Apr 2019 22:12:11 +0000 Subject: [PATCH] Widgets: Make sure changes to media widgets' instance schema via `widget_{$this->id_base}_instance_schema` filter are not overridden by subclasses. Previously, `WP_Widget_Media_Audio`, `WP_Widget_Media_Image`, and `WP_Widget_Media_Video` used to override the changes due to reversed arguments in `array_merge()` call. Props Toro_Unit, birgire. Fixes #45029. git-svn-id: https://develop.svn.wordpress.org/trunk@45100 602fd350-edb4-49c9-b593-d223f7449a82 --- .../widgets/class-wp-widget-media-audio.php | 35 ++++++------ .../widgets/class-wp-widget-media-image.php | 10 ++-- .../widgets/class-wp-widget-media-video.php | 54 +++++++++---------- .../widgets/class-wp-widget-media.php | 2 +- 4 files changed, 48 insertions(+), 53 deletions(-) diff --git a/src/wp-includes/widgets/class-wp-widget-media-audio.php b/src/wp-includes/widgets/class-wp-widget-media-audio.php index 560c6a3a64..1cf7cbe0e1 100644 --- a/src/wp-includes/widgets/class-wp-widget-media-audio.php +++ b/src/wp-includes/widgets/class-wp-widget-media-audio.php @@ -19,7 +19,7 @@ class WP_Widget_Media_Audio extends WP_Widget_Media { /** * Constructor. * - * @since 4.8.0 + * @since 4.8.0 */ public function __construct() { parent::__construct( @@ -54,7 +54,7 @@ class WP_Widget_Media_Audio extends WP_Widget_Media { /** * Get schema for properties of a widget instance (item). * - * @since 4.8.0 + * @since 4.8.0 * * @see WP_REST_Controller::get_item_schema() * @see WP_REST_Controller::get_additional_fields() @@ -62,21 +62,18 @@ class WP_Widget_Media_Audio extends WP_Widget_Media { * @return array Schema for properties. */ public function get_instance_schema() { - $schema = array_merge( - parent::get_instance_schema(), - array( - 'preload' => array( - 'type' => 'string', - 'enum' => array( 'none', 'auto', 'metadata' ), - 'default' => 'none', - 'description' => __( 'Preload' ), - ), - 'loop' => array( - 'type' => 'boolean', - 'default' => false, - 'description' => __( 'Loop' ), - ), - ) + $schema = array( + 'preload' => array( + 'type' => 'string', + 'enum' => array( 'none', 'auto', 'metadata' ), + 'default' => 'none', + 'description' => __( 'Preload' ), + ), + 'loop' => array( + 'type' => 'boolean', + 'default' => false, + 'description' => __( 'Loop' ), + ), ); foreach ( wp_get_audio_extensions() as $audio_extension ) { @@ -89,13 +86,13 @@ class WP_Widget_Media_Audio extends WP_Widget_Media { ); } - return $schema; + return array_merge( $schema, parent::get_instance_schema() ); } /** * Render the media on the frontend. * - * @since 4.8.0 + * @since 4.8.0 * * @param array $instance Widget instance props. * @return void diff --git a/src/wp-includes/widgets/class-wp-widget-media-image.php b/src/wp-includes/widgets/class-wp-widget-media-image.php index 2b9bff221b..ebc92897ac 100644 --- a/src/wp-includes/widgets/class-wp-widget-media-image.php +++ b/src/wp-includes/widgets/class-wp-widget-media-image.php @@ -19,7 +19,7 @@ class WP_Widget_Media_Image extends WP_Widget_Media { /** * Constructor. * - * @since 4.8.0 + * @since 4.8.0 */ public function __construct() { parent::__construct( @@ -53,7 +53,7 @@ class WP_Widget_Media_Image extends WP_Widget_Media { /** * Get schema for properties of a widget instance (item). * - * @since 4.8.0 + * @since 4.8.0 * * @see WP_REST_Controller::get_item_schema() * @see WP_REST_Controller::get_additional_fields() @@ -62,7 +62,6 @@ class WP_Widget_Media_Image extends WP_Widget_Media { */ public function get_instance_schema() { return array_merge( - parent::get_instance_schema(), array( 'size' => array( 'type' => 'string', @@ -161,14 +160,15 @@ class WP_Widget_Media_Image extends WP_Widget_Media { * - height (redundant when size is not custom) * - width (redundant when size is not custom) */ - ) + ), + parent::get_instance_schema() ); } /** * Render the media on the frontend. * - * @since 4.8.0 + * @since 4.8.0 * * @param array $instance Widget instance props. * @return void diff --git a/src/wp-includes/widgets/class-wp-widget-media-video.php b/src/wp-includes/widgets/class-wp-widget-media-video.php index 0be31a61ab..ff534f1005 100644 --- a/src/wp-includes/widgets/class-wp-widget-media-video.php +++ b/src/wp-includes/widgets/class-wp-widget-media-video.php @@ -19,7 +19,7 @@ class WP_Widget_Media_Video extends WP_Widget_Media { /** * Constructor. * - * @since 4.8.0 + * @since 4.8.0 */ public function __construct() { parent::__construct( @@ -55,7 +55,7 @@ class WP_Widget_Media_Video extends WP_Widget_Media { /** * Get schema for properties of a widget instance (item). * - * @since 4.8.0 + * @since 4.8.0 * * @see WP_REST_Controller::get_item_schema() * @see WP_REST_Controller::get_additional_fields() @@ -63,30 +63,28 @@ class WP_Widget_Media_Video extends WP_Widget_Media { * @return array Schema for properties. */ public function get_instance_schema() { - $schema = array_merge( - parent::get_instance_schema(), - array( - 'preload' => array( - 'type' => 'string', - 'enum' => array( 'none', 'auto', 'metadata' ), - 'default' => 'metadata', - 'description' => __( 'Preload' ), - 'should_preview_update' => false, - ), - 'loop' => array( - 'type' => 'boolean', - 'default' => false, - 'description' => __( 'Loop' ), - 'should_preview_update' => false, - ), - 'content' => array( - 'type' => 'string', - 'default' => '', - 'sanitize_callback' => 'wp_kses_post', - 'description' => __( 'Tracks (subtitles, captions, descriptions, chapters, or metadata)' ), - 'should_preview_update' => false, - ), - ) + + $schema = array( + 'preload' => array( + 'type' => 'string', + 'enum' => array( 'none', 'auto', 'metadata' ), + 'default' => 'metadata', + 'description' => __( 'Preload' ), + 'should_preview_update' => false, + ), + 'loop' => array( + 'type' => 'boolean', + 'default' => false, + 'description' => __( 'Loop' ), + 'should_preview_update' => false, + ), + 'content' => array( + 'type' => 'string', + 'default' => '', + 'sanitize_callback' => 'wp_kses_post', + 'description' => __( 'Tracks (subtitles, captions, descriptions, chapters, or metadata)' ), + 'should_preview_update' => false, + ), ); foreach ( wp_get_video_extensions() as $video_extension ) { @@ -99,13 +97,13 @@ class WP_Widget_Media_Video extends WP_Widget_Media { ); } - return $schema; + return array_merge( $schema, parent::get_instance_schema() ); } /** * Render the media on the frontend. * - * @since 4.8.0 + * @since 4.8.0 * * @param array $instance Widget instance props. * diff --git a/src/wp-includes/widgets/class-wp-widget-media.php b/src/wp-includes/widgets/class-wp-widget-media.php index e6146bf8d3..74d9491d81 100644 --- a/src/wp-includes/widgets/class-wp-widget-media.php +++ b/src/wp-includes/widgets/class-wp-widget-media.php @@ -122,7 +122,7 @@ abstract class WP_Widget_Media extends WP_Widget { /** * Get schema for properties of a widget instance (item). * - * @since 4.8.0 + * @since 4.8.0 * * @see WP_REST_Controller::get_item_schema() * @see WP_REST_Controller::get_additional_fields()