Skip to content

Instantly share code, notes, and snippets.

@justlevine
Last active May 8, 2019 14:17
Show Gist options
  • Save justlevine/a5a1c834e25bbf4c0c9c966dc28a9624 to your computer and use it in GitHub Desktop.
Save justlevine/a5a1c834e25bbf4c0c9c966dc28a9624 to your computer and use it in GitHub Desktop.
Wordpress: Add dependency to preregistered script
/**
* Add dependency to a preregistered script. Returns false if script hasnt been registered.
*
* @param string $handle
* @param string $dependency
* @return bool
*/
function jl_add_script_dependency( $handle, $dependency ) {
global $wp_scripts;
$registered_script = $wp_scripts->query( $handle, 'registered' );
if ( ! $registered_script )
return false; //script isnt registered
if ( ! in_array( $dependency, $registered_script->deps ) ) { //checks if dependency is already listed
$script->deps[] = $dep;
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment