Last active
May 8, 2019 14:17
-
-
Save justlevine/a5a1c834e25bbf4c0c9c966dc28a9624 to your computer and use it in GitHub Desktop.
Wordpress: Add dependency to preregistered script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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