Tribe__Assets::print_group( string|array $group, bool $echo = true )
Prints the script (JS) and link (CSS) HTML tags associated with one or more assets groups.
Contents
The method will force the scripts and styles to print overriding their registration and conditional.
Parameters
- $group
-
(string|array) (Required) Which group(s) should be enqueued.
- $echo
-
(bool) (Optional) Whether to print the group(s) tag(s) to the page or not; default to
trueto print the HTMLscript(JS) andlink(CSS) tags to the page.Default value: true
Return
(string) The script and link HTML tags produced for the group(s).
Source
File: src/Tribe/Assets.php
public function print_group( $group, $echo = true ) {
$all_assets = $this->get();
$groups = (array) $group;
$to_print = array_filter( $all_assets, static function ( $asset ) use ( $groups ) {
return isset( $asset->groups ) && array_intersect( $asset->groups, $groups );
} );
$by_type = array_reduce( $to_print, static function ( array $acc, \stdClass $asset ) {
$acc[ $asset->type ][] = $asset->slug;
return $acc;
}, [ 'css' => [], 'js' => [] ] );
// Make sure each script is registered.
foreach ( $to_print as $slug => $data ){
if ( $data->is_registered ){
continue;
}
'js' === $data->type
? wp_register_script( $slug, $data->file, $data->deps, $data->version )
: wp_register_style( $slug, $data->file, $data->deps, $data->version );
}
ob_start();
wp_scripts()->do_items( $by_type['js'] );
wp_styles()->do_items( $by_type['css'] );
$tags = ob_get_clean();
if ( $echo ) {
echo $tags;
}
return $tags;
}
Changelog
| Version | Description |
|---|---|
| 4.12.6 | Introduced. |