Widgets: Improve extensibility of the Gallery widget and of media widgets generally.

* Introduce a `widget_{$id_base}_instance_schema` filter for plugins to add new properties to a media widget's instance schema.
* Pass all of a gallery widget's instance props to the gallery media frame, not just the ones that core supports.

See #32417, #41914.
Fixes #42285.


git-svn-id: https://develop.svn.wordpress.org/trunk@41951 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Weston Ruter
2017-10-19 23:43:22 +00:00
parent 8206a9d225
commit d204ba3c00
4 changed files with 57 additions and 8 deletions
@@ -164,6 +164,29 @@ class Test_WP_Widget_Media extends WP_UnitTestCase {
$this->assertEquals( $result, 'foo ibar NO' );
}
/**
* Instance schema args.
*
* @var array
*/
protected $filter_instance_schema_args;
/**
* Filter instance schema.
*
* @param array $schema Schema.
* @param WP_Widget_Media $widget Widget.
*
* @return array
*/
public function filter_instance_schema( $schema, $widget ) {
$this->filter_instance_schema_args = compact( 'schema', 'widget' );
$schema['injected'] = array(
'type' => 'boolean',
);
return $schema;
}
/**
* Test get_instance_schema method.
*
@@ -178,6 +201,15 @@ class Test_WP_Widget_Media extends WP_UnitTestCase {
'title',
'url',
), array_keys( $schema ) );
// Check filter usage.
$this->filter_instance_schema_args = null;
add_filter( 'widget_mocked_instance_schema', array( $this, 'filter_instance_schema' ), 10, 2 );
$schema = $widget->get_instance_schema();
$this->assertInternalType( 'array', $this->filter_instance_schema_args );
$this->assertSame( $widget, $this->filter_instance_schema_args['widget'] );
$this->assertEqualSets( array( 'attachment_id', 'title', 'url' ), array_keys( $this->filter_instance_schema_args['schema'] ) );
$this->assertArrayHasKey( 'injected', $schema );
}
/**