Skip to content

Instantly share code, notes, and snippets.

@brandwaffle
Created May 15, 2012 16:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brandwaffle/2702967 to your computer and use it in GitHub Desktop.
Save brandwaffle/2702967 to your computer and use it in GitHub Desktop.
Add an array check to wp_enqueue_script and convert a single $deps passed as a string to an array with one element
<?php
function wp_enqueue_script( $handle, $src = false, $deps = array(), $ver = false, $in_footer = false ) {
global $wp_scripts;
if ( !is_a($wp_scripts, 'WP_Scripts') )
$wp_scripts = new WP_Scripts();
if ( $src ) {
$_handle = explode('?', $handle);
$wp_scripts->add( $_handle[0], $src, $deps, $ver );
if ( $in_footer )
$wp_scripts->add_data( $_handle[0], 'group', 1 );
}
$wp_scripts->enqueue( $handle );
}
function wp_enqueue_script( $handle, $src = false, $deps = array(), $ver = false, $in_footer = false ) {
global $wp_scripts;
if ( !is_a($wp_scripts, 'WP_Scripts') )
$wp_scripts = new WP_Scripts();
//if a single param is passed as the dependency, convert to an array so WP_Dependencies won't convert
//it to an empty array
if( !is_array( $deps ) )
$deps = (array) $deps;
if ( $src ) {
$_handle = explode('?', $handle);
$wp_scripts->add( $_handle[0], $src, $deps, $ver );
if ( $in_footer )
$wp_scripts->add_data( $_handle[0], 'group', 1 );
}
$wp_scripts->enqueue( $handle );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment