Make WordPress Core


Ignore:
Timestamp:
01/29/2018 11:55:44 PM (8 years ago)
Author:
westonruter
Message:

Customize: Ensure media playlists get initialized after selective refresh; expose new wp.playlist.initialize() API.

In particular allows audio and video playlists to be added to the Text widget and previewed.

Props bpayton, westonruter.
See #40854.
Fixes #42495.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/widgets/class-wp-widget-text.php

    r42545 r42613  
    5757
    5858        wp_add_inline_script( 'text-widgets', sprintf( 'wp.textWidgets.idBases.push( %s );', wp_json_encode( $this->id_base ) ) );
     59
     60        if ( $this->is_preview() ) {
     61            add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_preview_scripts' ) );
     62        }
    5963
    6064        // Note that the widgets component in the customizer will also do the 'admin_print_scripts-widgets.php' action in WP_Customize_Widgets::print_scripts().
     
    392396
    393397        return $instance;
     398    }
     399
     400    /**
     401     * Enqueue preview scripts.
     402     *
     403     * These scripts normally are enqueued just-in-time when a playlist shortcode is used.
     404     * However, in the customizer, a playlist shortcode may be used in a text widget and
     405     * dynamically added via selective refresh, so it is important to unconditionally enqueue them.
     406     *
     407     * @since 4.9.3
     408     */
     409    public function enqueue_preview_scripts() {
     410        require_once dirname( dirname( __FILE__ ) ) . '/media.php';
     411
     412        wp_playlist_scripts( 'audio' );
     413        wp_playlist_scripts( 'video' );
    394414    }
    395415
Note: See TracChangeset for help on using the changeset viewer.