Registers the item if no item of that name already exists.
Parameters
$handlestring
Name of the item. Should be unique.
$srcstring|false
Full URL of the item, or path of the item relative to the WordPress root directory. If source is set to false, the item is an alias of other items it depends on.
$depsstring[]optional
An array of registered item handles this item depends on. Default empty array.Default: array()
$verstring|bool|nulloptional
String specifying item version number, if it has one, which is added to the URL as a query string for cache busting purposes. If version is set to false, a version number is automatically added equal to current installed WordPress version. If set to null, no version is added.Default: false
$argsmixedoptional
Custom property of the item. NOT the class property $args. Examples: $media, $in_footer.Default: null
Return
bool
Whether the item has been registered. True on success, false on failure.
281publicfunctionadd($handle,$src,$deps=array(),$ver=false,$args=null){282if(isset($this->registered[$handle])){283returnfalse;284}285$this->registered[$handle]=new_WP_Dependency($handle,$src,$deps,$ver,$args);286287// If the item was enqueued before the details were registered, enqueue it now.288if(array_key_exists($handle,$this->queued_before_register)){289if(!is_null($this->queued_before_register[$handle])){290$this->enqueue($handle.'?'.$this->queued_before_register[$handle]);291}else{292$this->enqueue($handle);293}294295unset($this->queued_before_register[$handle]);296}297298returntrue;299}
History
Introduced in 2.1.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
2.6.0
Moved from WP_Scripts.from the docblock
2.1.0
Introduced.from the docblock
About this page
Parsed data
Generated from the wordpress-develop 7.0.4 tag, from src/wp-includes/class-wp-dependencies.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.