WP_Scripts::add_data( string $handle, string $key, mixed $value ): bool

In this article

This overrides the add_data method from WP_Dependencies, to support normalizing of $args.

Parameters

$handlestringrequired
Name of the item. Should be unique.
$keystringrequired
The data key.
$valuemixedrequired
The data value.

Return

bool True on success, false on failure.

Source

public function add_data( $handle, $key, $value ) {
	if ( ! isset( $this->registered[ $handle ] ) ) {
		return false;
	}

	if ( 'strategy' === $key ) {
		if ( ! empty( $value ) && ! $this->is_delayed_strategy( $value ) ) {
			_doing_it_wrong(
				__METHOD__,
				sprintf(
					/* translators: 1: $strategy, 2: $handle */
					__( 'Invalid strategy `%1$s` defined for `%2$s` during script registration.' ),
					$value,
					$handle
				),
				'6.3.0'
			);
			return false;
		} elseif ( ! $this->registered[ $handle ]->src && $this->is_delayed_strategy( $value ) ) {
			_doing_it_wrong(
				__METHOD__,
				sprintf(
					/* translators: 1: $strategy, 2: $handle */
					__( 'Cannot supply a strategy `%1$s` for script `%2$s` because it is an alias (it lacks a `src` value).' ),
					$value,
					$handle
				),
				'6.3.0'
			);
			return false;
		}
	}
	return parent::add_data( $handle, $key, $value );
}

Changelog

VersionDescription
6.3.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.