Make WordPress Core


Ignore:
Timestamp:
01/30/2018 02:55:25 PM (6 years ago)
Author:
SergeyBiryukov
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.
Merges [42613], [42617] to the 4.9 branch.
Fixes #42495.

Location:
branches/4.9
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.9

  • branches/4.9/src/wp-includes/widgets/class-wp-widget-text.php

    r42546 r42622  
    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().
     
    388392
    389393        return $instance;
     394    }
     395
     396    /**
     397     * Enqueue preview scripts.
     398     *
     399     * These scripts normally are enqueued just-in-time when a playlist shortcode is used.
     400     * However, in the customizer, a playlist shortcode may be used in a text widget and
     401     * dynamically added via selective refresh, so it is important to unconditionally enqueue them.
     402     *
     403     * @since 4.9.3
     404     */
     405    public function enqueue_preview_scripts() {
     406        require_once dirname( dirname( __FILE__ ) ) . '/media.php';
     407
     408        wp_playlist_scripts( 'audio' );
     409        wp_playlist_scripts( 'video' );
    390410    }
    391411
Note: See TracChangeset for help on using the changeset viewer.