Make WordPress Core


Ignore:
Timestamp:
10/19/2017 11:43:22 PM (8 years ago)
Author:
westonruter
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/widgets/media-widget.php

    r40674 r41951  
    166166
    167167    /**
     168     * Instance schema args.
     169     *
     170     * @var array
     171     */
     172    protected $filter_instance_schema_args;
     173
     174    /**
     175     * Filter instance schema.
     176     *
     177     * @param array           $schema Schema.
     178     * @param WP_Widget_Media $widget Widget.
     179     *
     180     * @return array
     181     */
     182    public function filter_instance_schema( $schema, $widget ) {
     183        $this->filter_instance_schema_args = compact( 'schema', 'widget' );
     184        $schema['injected'] = array(
     185            'type' => 'boolean',
     186        );
     187        return $schema;
     188    }
     189
     190    /**
    168191     * Test get_instance_schema method.
    169192     *
     
    179202            'url',
    180203        ), array_keys( $schema ) );
     204
     205        // Check filter usage.
     206        $this->filter_instance_schema_args = null;
     207        add_filter( 'widget_mocked_instance_schema', array( $this, 'filter_instance_schema' ), 10, 2 );
     208        $schema = $widget->get_instance_schema();
     209        $this->assertInternalType( 'array', $this->filter_instance_schema_args );
     210        $this->assertSame( $widget, $this->filter_instance_schema_args['widget'] );
     211        $this->assertEqualSets( array( 'attachment_id', 'title', 'url' ), array_keys( $this->filter_instance_schema_args['schema'] ) );
     212        $this->assertArrayHasKey( 'injected', $schema );
    181213    }
    182214
Note: See TracChangeset for help on using the changeset viewer.