[wp-trac] [WordPress Trac] #32417: Add new core media widget

WordPress Trac noreply at wordpress.org
Tue Feb 21 20:00:30 UTC 2017


#32417: Add new core media widget
-------------------------------------------------+-------------------------
 Reporter:  melchoyce                            |       Owner:  melchoyce
     Type:  feature request                      |      Status:  assigned
 Priority:  normal                               |   Milestone:  4.8
Component:  Widgets                              |     Version:  4.3
 Severity:  normal                               |  Resolution:
 Keywords:  needs-unit-tests has-patch needs-    |     Focuses:  ui,
  refresh                                        |  administration
-------------------------------------------------+-------------------------

Comment (by westonruter):

 Replying to [comment:106 gonom9]:
 > @westonruter how about adding back auto-initialization of media elements
 to `selective-refresh.js`, but this time only for widgets?

 I think it would be beneficial to add auto-initialization of media
 elements generally for any selective refresh partial, though there could
 be some cases where it might initialize a media element with ME.js against
 the wishes of the theme/plugin author. But this would also be the case for
 the media widget itself currently, right? It doesn't seem to be taking
 into account filters added for the `wp_audio_shortcode_library` or
 `wp_video_shortcode_library` filters which allow plugins to override the
 library used for initializing media elements. To properly account for
 these, it would seem that you should include something like:

 {{{#!php
 <?php
 $scripts->localize( 'wp-media-widget', 'wpMediaWidgetSettings', array(
         /** This filter is documented in wp-includes/media.php */
         'audioLibrary' => apply_filters( 'wp_audio_shortcode_library',
 'mediaelement' ),
         /** This filter is documented in wp-includes/media.php */
         'videoLibrary' => apply_filters( 'wp_video_shortcode_library',
 'mediaelement' ),
 ) );
 }}}

 And then in the JS for when the partial is refreshed that contains audio
 media it should only call initialize ME.js if `'mediaelement' ===
 wpMediaWidgetSettings.audioLibrary`. There may be a better JS object to
 attach these settings to rather than create a new global variable
 `wpMediaWidgetSettings`.

 If it is only supposed to be for widgets and not generally, then the logic
 could be added to `customize-preview-widgets.js`.

 But yeah, I think it would be best to make it apply to all partials that
 are being refreshed, and so make it part of `selective-refresh.js` and so
 perhaps the settings could be exported via:

 {{{#!diff
 --- src/wp-includes/class-wp-customize-manager.php
 +++ src/wp-includes/class-wp-customize-manager.php
 @@ -1807,6 +1807,12 @@ final class WP_Customize_Manager {
                                 'stylesheet' => $this->get_stylesheet(),
                                 'active'     => $this->is_theme_active(),
                         ),
 +                       'media' => array(
 +                               /** This filter is documented in wp-
 includes/media.php */
 +                               'audioLibrary' => apply_filters(
 'wp_audio_shortcode_library', 'mediaelement' ),
 +                               /** This filter is documented in wp-
 includes/media.php */
 +                               'videoibrary' => apply_filters(
 'wp_video_shortcode_library', 'mediaelement' ),
 +                       ),
                         'url' => array(
                                 'self' => $self_url,
                                 'allowed' => array_map( 'esc_url_raw',
 $this->get_allowed_urls() ),
 }}}

 And you'd be able to access these via
 `wp.customize.settings.media.audioLibrary` and
 `wp.customize.settings.media.videoLibrary`.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/32417#comment:107>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list