WP_Dependencies::add()publicWP 2.1.0

Register an item.

Registers the item if no item of that name already exists.

{} It's a method of the class: WP_Dependencies{}

No Hooks.

Return

true|false. Whether the item has been registered. True on success, false on failure.

Usage

$WP_Dependencies = new WP_Dependencies();
$WP_Dependencies->add( $handle, $src, $deps, $ver, $args );
$handle(string) (required)
Name of the item. Should be unique.
$src(string|true|false) (required)
Full URL of the item, or path of the item relative to the WordPress root directory. If source is set to false, item is an alias of other items it depends on.
$deps(string[])
An array of registered item handles this item depends on.
Default: empty array
$ver(string|true|false|null)
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
$args(mixed)
Custom property of the item. NOT the class property $args. Examples: $media, $in_footer.
Default: null

Changelog

Since 2.1.0 Introduced.
Since 2.6.0 Moved from WP_Scripts.

Code of WP_Dependencies::add() WP 6.0

public function add( $handle, $src, $deps = array(), $ver = false, $args = null ) {
	if ( isset( $this->registered[ $handle ] ) ) {
		return false;
	}
	$this->registered[ $handle ] = new _WP_Dependency( $handle, $src, $deps, $ver, $args );

	// If the item was enqueued before the details were registered, enqueue it now.
	if ( array_key_exists( $handle, $this->queued_before_register ) ) {
		if ( ! is_null( $this->queued_before_register[ $handle ] ) ) {
			$this->enqueue( $handle . '?' . $this->queued_before_register[ $handle ] );
		} else {
			$this->enqueue( $handle );
		}

		unset( $this->queued_before_register[ $handle ] );
	}

	return true;
}