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.
Source
public function add_data( $handle, $key, $value ) {
if ( ! isset( $this->registered[ $handle ] ) ) {
return false;
}
if ( 'conditional' === $key ) {
// If a dependency is declared by a conditional script, remove it.
$this->registered[ $handle ]->deps = array();
}
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;
}
} elseif ( 'fetchpriority' === $key ) {
if ( empty( $value ) ) {
$value = 'auto';
}
if ( ! $this->is_valid_fetchpriority( $value ) ) {
_doing_it_wrong(
__METHOD__,
sprintf(
/* translators: 1: $fetchpriority, 2: $handle */
__( 'Invalid fetchpriority `%1$s` defined for `%2$s` during script registration.' ),
is_string( $value ) ? $value : gettype( $value ),
$handle
),
'6.9.0'
);
return false;
} elseif ( ! $this->registered[ $handle ]->src ) {
_doing_it_wrong(
__METHOD__,
sprintf(
/* translators: 1: $fetchpriority, 2: $handle */
__( 'Cannot supply a fetchpriority `%1$s` for script `%2$s` because it is an alias (it lacks a `src` value).' ),
is_string( $value ) ? $value : gettype( $value ),
$handle
),
'6.9.0'
);
return false;
}
}
return parent::add_data( $handle, $key, $value );
}
Changelog
| Version | Description |
|---|---|
| 6.3.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.