Skip to content

Instantly share code, notes, and snippets.

@westonruter
Last active April 3, 2016 22:21
Show Gist options
  • Save westonruter/c8968edc125fd31ae2da4171ced8c62b to your computer and use it in GitHub Desktop.
Save westonruter/c8968edc125fd31ae2da4171ced8c62b to your computer and use it in GitHub Desktop.
function tryCustomizeDependency() {
try {
wp.customize.bind( 'ready', function() {
console.info( 'ready' );
} );
console.info( 'PASS' );
} catch( e ) {
console.error( 'FAIL' );
}
}
<?php
/**
* Plugin Name: Test case for WP Trac #36392: wp_add_inline_script() breaks script dependency order when using script loader (no SCRIPT_DEBUG)
* Plugin URL: https://core.trac.wordpress.org/ticket/36392
*/
add_action( 'wp_default_scripts', function( WP_Scripts $wp_scripts ) {
$handle = 'customize-dependency';
$src = plugin_dir_url( __FILE__ ) . 'customize-dependency.js';
$deps = array( 'customize-controls' );
$wp_scripts->add( $handle, $src, $deps );
} );
add_action( 'customize_controls_enqueue_scripts', function() {
if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) {
trigger_error( 'Set SCRIPT_DEBUG to false to replicate the issue.', E_USER_WARNING );
}
$handle = 'customize-dependency';
wp_enqueue_script( $handle );
wp_add_inline_script( $handle, 'tryCustomizeDependency()' );
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment