Hooks
Class Hooks
Source
File: src/Tribe/Views/V2/Customizer/Hooks.php
class Hooks extends \tad_DI52_ServiceProvider {
/**
* Binds and sets up implementations.
*
* @since 5.7.0
*/
public function register() {
// Register the Views V2 Customizer controls assets.
tribe_asset(
TEC::instance(),
'tribe-customizer-views-v2-controls',
'customizer-views-v2-controls.css'
);
tribe_asset(
TEC::instance(),
'tribe-customizer-views-v2-controls-js',
'customizer-views-v2-controls.js'
);
/* @todo: this will be part of the next Customizer release.
tribe_asset(
TEC::instance(),
'tribe-customizer-views-v2-live-preview-js',
'customizer-views-v2-live-preview.js',
[],
'customize_preview_init',
[
'localize' => [
'name' => 'tribe_events_customizer_live_preview_js_config',
'data' => [ $this->container->make( Configuration::class ), 'localize' ],
],
]
);
*/
$this->add_actions();
$this->add_filters();
}
/**
* Register any actions for the Customizer
*
* @since 5.9.0
*
* @return void
*/
public function add_actions() {
add_action( 'customize_controls_enqueue_scripts', [ $this, 'enqueue_customizer_control_scripts'] );
}
/**
* Register any filters for the Customizer
*
* @since 5.9.0
*
* @return void
*/
public function add_filters() {
// Register the assets for Customizer controls.
add_action( 'customize_controls_print_styles', [ $this, 'enqueue_customizer_controls_styles' ] );
// Register assets for Customizer styles.
add_filter( 'tribe_customizer_inline_stylesheets', [ $this, 'customizer_inline_stylesheets' ], 12, 2 );
add_filter( 'tribe_customizer_print_styles_action', [ $this, 'print_inline_styles_in_footer' ] );
}
/**
* Enqueues the js for our v2 Customizer controls.
*
* @since 5.9.0
*
* @return void
*/
public function enqueue_customizer_control_scripts() {
tribe_asset_enqueue( 'tribe-customizer-views-v2-controls-js' );
}
/**
* Enqueues Customizer controls styles specific to Views v2 components.
*
* @since 5.9.0
*/
public function enqueue_customizer_controls_styles() {
tribe_asset_enqueue( 'tribe-customizer-views-v2-controls' );
}
/**
* Add views stylesheets to customizer styles array to check.
* Remove unused legacy stylesheets.
*
* @since 5.1.1
*
* @param array<string> $sheets Array of sheets to search for.
* @param string $css_template String containing the inline css to add.
*
* @return array Modified array of sheets to search for.
*/
public function customizer_inline_stylesheets( $sheets, $css_template ) {
$v2_sheets = [ 'tribe-events-views-v2-full' ];
// Dequeue legacy sheets.
$keys = array_keys( $sheets, 'tribe-events-calendar-style' );
if ( ! empty( $keys ) ) {
foreach ( $keys as $key ) {
unset( $sheets[ $key ] );
}
}
return array_merge( $sheets, $v2_sheets );
}
/**
* Changes the action the Customizer should use to try and print inline styles to print the inline
* styles in the footer.
*
* @since 5.7.0
*
* @return string The action the Customizer should use to print inline styles.
*/
public function print_inline_styles_in_footer() {
return 'wp_print_footer_scripts';
}
}
Changelog
| Version | Description |
|---|---|
| 5.7.0 | Introduced. |
Methods
- add_actions — Register any actions for the Customizer
- add_filters — Register any filters for the Customizer
- body_class — Add an identifying class to the body - but only when inside the Customizer preview.
- customizer_inline_stylesheets — Add views stylesheets to customizer styles array to check.
- enqueue_customizer_control_scripts — Enqueues the js for our v2 Customizer controls.
- enqueue_customizer_controls_styles — Enqueues Customizer controls styles specific to Views v2 components.
- print_inline_styles_in_footer — Changes the action the Customizer should use to try and print inline styles to print the inline styles in the footer.
- register — Binds and sets up implementations.