Automattic\WooCommerce\Blocks\Assets
AssetDataRegistry::add_data
See self::add() for docs.
Method of the class: AssetDataRegistry{}
No Hooks.
Returns
null. Nothing (null).
Usage
// protected - for code of main (parent) or child class $result = $this->add_data( $key, $data );
- $key(string) (required)
- Key for the data.
- $data(mixed) (required)
- Value for the data.
AssetDataRegistry::add_data() AssetDataRegistry::add data code WC 10.7.0
protected function add_data( $key, $data ) {
if ( ! is_string( $key ) ) {
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error
trigger_error( esc_html__( 'Key for the data being registered must be a string', 'woocommerce' ), E_USER_WARNING );
return;
}
if ( $this->exists( $key ) ) {
return;
}
if ( isset( $this->data[ $key ] ) ) {
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error
trigger_error( esc_html__( 'Overriding existing data with an already registered key is not allowed', 'woocommerce' ), E_USER_WARNING );
return;
}
if ( \is_callable( $data ) ) {
$this->lazy_data[ $key ] = $data;
return;
}
$this->data[ $key ] = $data;
}