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.
Built from https://develop.svn.wordpress.org/trunk@45100


git-svn-id: http://core.svn.wordpress.org/trunk@44909 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2019-04-02 22:13:52 +00:00
parent f7357d3957
commit 2931a2d95e
5 changed files with 49 additions and 54 deletions

View File

@ -13,7 +13,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '5.2-beta1-45099'; $wp_version = '5.2-beta1-45100';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.

View File

@ -19,7 +19,7 @@ class WP_Widget_Media_Audio extends WP_Widget_Media {
/** /**
* Constructor. * Constructor.
* *
* @since 4.8.0 * @since 4.8.0
*/ */
public function __construct() { public function __construct() {
parent::__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). * 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_item_schema()
* @see WP_REST_Controller::get_additional_fields() * @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. * @return array Schema for properties.
*/ */
public function get_instance_schema() { public function get_instance_schema() {
$schema = array_merge( $schema = array(
parent::get_instance_schema(), 'preload' => array(
array( 'type' => 'string',
'preload' => array( 'enum' => array( 'none', 'auto', 'metadata' ),
'type' => 'string', 'default' => 'none',
'enum' => array( 'none', 'auto', 'metadata' ), 'description' => __( 'Preload' ),
'default' => 'none', ),
'description' => __( 'Preload' ), 'loop' => array(
), 'type' => 'boolean',
'loop' => array( 'default' => false,
'type' => 'boolean', 'description' => __( 'Loop' ),
'default' => false, ),
'description' => __( 'Loop' ),
),
)
); );
foreach ( wp_get_audio_extensions() as $audio_extension ) { 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. * Render the media on the frontend.
* *
* @since 4.8.0 * @since 4.8.0
* *
* @param array $instance Widget instance props. * @param array $instance Widget instance props.
* @return void * @return void

View File

@ -19,7 +19,7 @@ class WP_Widget_Media_Image extends WP_Widget_Media {
/** /**
* Constructor. * Constructor.
* *
* @since 4.8.0 * @since 4.8.0
*/ */
public function __construct() { public function __construct() {
parent::__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). * 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_item_schema()
* @see WP_REST_Controller::get_additional_fields() * @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() { public function get_instance_schema() {
return array_merge( return array_merge(
parent::get_instance_schema(),
array( array(
'size' => array( 'size' => array(
'type' => 'string', 'type' => 'string',
@ -161,14 +160,15 @@ class WP_Widget_Media_Image extends WP_Widget_Media {
* - height (redundant when size is not custom) * - height (redundant when size is not custom)
* - width (redundant when size is not custom) * - width (redundant when size is not custom)
*/ */
) ),
parent::get_instance_schema()
); );
} }
/** /**
* Render the media on the frontend. * Render the media on the frontend.
* *
* @since 4.8.0 * @since 4.8.0
* *
* @param array $instance Widget instance props. * @param array $instance Widget instance props.
* @return void * @return void

View File

@ -19,7 +19,7 @@ class WP_Widget_Media_Video extends WP_Widget_Media {
/** /**
* Constructor. * Constructor.
* *
* @since 4.8.0 * @since 4.8.0
*/ */
public function __construct() { public function __construct() {
parent::__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). * 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_item_schema()
* @see WP_REST_Controller::get_additional_fields() * @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. * @return array Schema for properties.
*/ */
public function get_instance_schema() { public function get_instance_schema() {
$schema = array_merge(
parent::get_instance_schema(), $schema = array(
array( 'preload' => array(
'preload' => array( 'type' => 'string',
'type' => 'string', 'enum' => array( 'none', 'auto', 'metadata' ),
'enum' => array( 'none', 'auto', 'metadata' ), 'default' => 'metadata',
'default' => 'metadata', 'description' => __( 'Preload' ),
'description' => __( 'Preload' ), 'should_preview_update' => false,
'should_preview_update' => false, ),
), 'loop' => array(
'loop' => array( 'type' => 'boolean',
'type' => 'boolean', 'default' => false,
'default' => false, 'description' => __( 'Loop' ),
'description' => __( 'Loop' ), 'should_preview_update' => false,
'should_preview_update' => false, ),
), 'content' => array(
'content' => array( 'type' => 'string',
'type' => 'string', 'default' => '',
'default' => '', 'sanitize_callback' => 'wp_kses_post',
'sanitize_callback' => 'wp_kses_post', 'description' => __( 'Tracks (subtitles, captions, descriptions, chapters, or metadata)' ),
'description' => __( 'Tracks (subtitles, captions, descriptions, chapters, or metadata)' ), 'should_preview_update' => false,
'should_preview_update' => false, ),
),
)
); );
foreach ( wp_get_video_extensions() as $video_extension ) { 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. * Render the media on the frontend.
* *
* @since 4.8.0 * @since 4.8.0
* *
* @param array $instance Widget instance props. * @param array $instance Widget instance props.
* *

View File

@ -122,7 +122,7 @@ abstract class WP_Widget_Media extends WP_Widget {
/** /**
* Get schema for properties of a widget instance (item). * 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_item_schema()
* @see WP_REST_Controller::get_additional_fields() * @see WP_REST_Controller::get_additional_fields()