Automattic\WooCommerce\Blocks\Assets

Api::register_style()publicWC 2.5.0

Registers a style according to wp_register_style.

Method of the class: Api{}

No Hooks.

Return

null. Nothing (null).

Usage

$Api = new Api();
$Api->register_style( $handle, $relative_src, $deps, $media, $rtl );
$handle(string) (required)
Name of the stylesheet. Should be unique.
$relative_src(string) (required)
Relative source of the stylesheet to the plugin path.
$deps(array)
An array of registered stylesheet handles this stylesheet depends on.
Default: empty array
$media(string)
The media for which this stylesheet has been defined. Accepts media types like 'all', 'print' and 'screen', or media queries like '(orientation: portrait)' and '(max-width: 640px)'.
Default: 'all'
$rtl(true|false)
Whether or not to register RTL styles.
Default: false

Changelog

Since 2.5.0 Introduced.
Since 2.6.0 Change src to be relative source.

Api::register_style() code WC 8.7.0

public function register_style( $handle, $relative_src, $deps = [], $media = 'all', $rtl = false ) {
	$filename = str_replace( plugins_url( '/', dirname( __DIR__ ) ), '', $relative_src );
	$src      = $this->get_asset_url( $relative_src );
	$ver      = $this->get_file_version( $filename );
	wp_register_style( $handle, $src, $deps, $ver, $media );

	if ( $rtl ) {
		wp_style_add_data( $handle, 'rtl', 'replace' );
	}
}