PluginProbe ʕ •ᴥ•ʔ
Pods – Custom Content Types and Fields / 2.8.23.4
Pods – Custom Content Types and Fields v2.8.23.4
2.7.31.4 2.8.23.5 2.9.19.5 3.0.10.5 3.1.4.3 3.2.8.4 3.3.9.2 2.8.23.4 2.9.19.4 3.0.10.4 3.1.4.2 3.2.8.3 3.3.9.1 trunk 1.14.8 2.7.31.3 2.8.23.3 2.9.19.3 3.0.10.3 3.1.4.1 3.2.0 3.2.1 3.2.1.1 3.2.2 3.2.4 3.2.5 3.2.6 3.2.7 3.2.7.1 3.2.8 3.2.8.1 3.2.8.2 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9
pods / tribe-common / src / Tribe / Customizer.php
pods / tribe-common / src / Tribe Last commit date
Admin 2 weeks ago Ajax 2 weeks ago Asset 2 weeks ago Context 2 weeks ago Customizer 2 weeks ago Debug_Bar 2 weeks ago Dialog 2 weeks ago Documentation 2 weeks ago Duplicate 2 weeks ago Editor 2 weeks ago Image 2 weeks ago JSON_LD 2 weeks ago Languages 2 weeks ago Log 2 weeks ago Meta 2 weeks ago Models 2 weeks ago PUE 2 weeks ago Process 2 weeks ago Promoter 2 weeks ago REST 2 weeks ago Repository 2 weeks ago Service_Providers 2 weeks ago Shortcode 2 weeks ago Support 2 weeks ago Tabbed_View 2 weeks ago Tooltip 2 weeks ago Traits 2 weeks ago Utils 2 weeks ago Validator 2 weeks ago Widget 2 weeks ago Abstract_Deactivation.php 2 weeks ago Abstract_Plugin_Register.php 2 weeks ago App_Shop.php 2 weeks ago Assets.php 2 weeks ago Assets_Pipeline.php 2 weeks ago Autoloader.php 2 weeks ago Cache.php 2 weeks ago Cache_Listener.php 2 weeks ago Changelog_Reader.php 2 weeks ago Container.php 2 weeks ago Context.php 2 weeks ago Cost_Utils.php 2 weeks ago Credits.php 2 weeks ago Customizer.php 2 weeks ago DB_Lock.php 2 weeks ago Data.php 2 weeks ago Date_Utils.php 2 weeks ago Db.php 2 weeks ago Debug.php 2 weeks ago Dependency.php 2 weeks ago Deprecation.php 2 weeks ago Editor.php 2 weeks ago Error.php 2 weeks ago Exception.php 2 weeks ago Extension.php 2 weeks ago Extension_Loader.php 2 weeks ago Feature_Detection.php 2 weeks ago Field.php 2 weeks ago Field_Conditional.php 2 weeks ago Freemius.php 2 weeks ago Log.php 2 weeks ago Main.php 2 weeks ago Notices.php 2 weeks ago Plugin_Meta_Links.php 2 weeks ago Plugins.php 2 weeks ago Plugins_API.php 2 weeks ago Post_History.php 2 weeks ago Post_Transient.php 2 weeks ago Promise.php 2 weeks ago Repository.php 2 weeks ago Rewrite.php 2 weeks ago Settings.php 2 weeks ago Settings_Manager.php 2 weeks ago Settings_Tab.php 2 weeks ago Simple_Table.php 2 weeks ago Support.php 2 weeks ago Tabbed_View.php 2 weeks ago Template.php 2 weeks ago Template_Factory.php 2 weeks ago Template_Part_Cache.php 2 weeks ago Templates.php 2 weeks ago Terms.php 2 weeks ago Timezones.php 2 weeks ago Tracker.php 2 weeks ago Updater.php 2 weeks ago Validate.php 2 weeks ago View_Helpers.php 2 weeks ago
Customizer.php
832 lines
1 <?php
2 // Don't load directly
3 defined( 'WPINC' ) or die;
4
5 /**
6 * Tribe Customizer class
7 *
8 * @package Tribe Common
9 * @subpackage Customizer
10 * @since 4.0
11 */
12 final class Tribe__Customizer {
13 /**
14 * Static Singleton Factory Method
15 *
16 * @return self
17 *
18 * @deprecated since 4.12.6, use `tribe( 'customizer' )` instead.
19 */
20 public static function instance() {
21 return tribe( 'customizer' );
22 }
23
24 /**
25 * WP_Customize_Manager instance.
26 *
27 * @since 4.0
28 * @access public
29 * @var WP_Customize_Manager
30 */
31 public $manager;
32
33 /**
34 * Instance of Customize Panel
35 *
36 * @since 4.0
37 * @access public
38 * @var WP_Customize_Panel
39 */
40 public $panel;
41
42 /**
43 * The Panel ID
44 *
45 * @since 4.0
46 * @access public
47 * @var string
48 */
49 public $ID;
50
51 /**
52 * Array of Sections of our Panel
53 *
54 * @since 4.0
55 * @access private
56 * @var array
57 */
58 private $sections;
59
60 /**
61 * Array of Sections Classes, for non-panel pages
62 *
63 * @since 4.0
64 * @access private
65 * @var array
66 */
67 private $sections_class = [];
68
69 /**
70 * Array of Sections Classes, for non-panel pages
71 *
72 * @since 4.2
73 * @access private
74 * @var array
75 */
76 private $settings = [];
77
78 /**
79 * Inline Style has been added
80 *
81 * @since 4.7.21
82 * @access private
83 * @var boolean
84 */
85 protected $inline_style = false;
86
87 /**
88 * Loads the Basic Settings for the Class to work
89 *
90 * @since 4.0
91 *
92 * @see self::instance()
93 * @access private
94 *
95 * @return void
96 */
97 public function __construct() {
98 if ( ! $this->is_active() ) {
99 return;
100 }
101
102 /**
103 * Filters the Panel ID, which is also the `wp_option` name for the Customizer settings
104 *
105 * @since 4.4
106 *
107 * @param string $ID
108 * @param self $customizer
109 */
110 $this->ID = apply_filters( 'tribe_customizer_panel_id', 'tribe_customizer', $this );
111
112 // Hook the Registering methods
113 add_action( 'customize_register', [ $this, 'register' ], 15 );
114
115 add_action( 'wp_print_footer_scripts', [ $this, 'print_css_template' ], 15 );
116
117 // front end styles from customizer
118 add_action( 'tribe_events_pro_widget_render', [ $this, 'inline_style' ], 101 );
119 add_action( 'wp_print_footer_scripts', [ $this, 'shortcode_inline_style' ], 10 );
120 add_action( 'wp_print_footer_scripts', [ $this, 'widget_inline_style' ], 10 );
121
122 /**
123 * Allows filtering the action that will be used to trigger the printing of inline scripts.
124 *
125 * By default inline scripts will be printed on the `wp_enqueue_scripts` action, but other
126 * plugins or later iterations might require inline styles to be printed on other actions.
127 *
128 * @since 4.12.15
129 *
130 * @param string $inline_script_action_handle The handle of the action that will be used to try
131 * and attempt to print inline scripts.
132 */
133 $print_styles_action = apply_filters( 'tribe_customizer_print_styles_action', 'wp_enqueue_scripts' );
134
135 add_action( $print_styles_action, [ $this, 'inline_style' ], 15 );
136
137 add_filter( "default_option_{$this->ID}", [ $this, 'maybe_fallback_get_option' ] );
138 }
139
140 /**
141 * Backwards compatibility for the old Customizer Option Save
142 *
143 * @since 4.4
144 *
145 * @param mixed $sections
146 *
147 * @return mixed
148 */
149 public function maybe_fallback_get_option( $sections ) {
150 // Return if there is something there
151 if ( ! empty( $sections ) ) {
152 return $sections;
153 }
154
155 return get_option( 'tribe_events_pro_customizer', [] );
156 }
157
158 /**
159 * Loads a Section to the Customizer on The Events Calendar's Panel
160 *
161 * @since 4.4
162 *
163 * @param object $section An Object that extends the Abstract `Tribe__Customizer__Section`
164 *
165 * @return bool
166 */
167 public function load_section( $section ) {
168 // You can only add a section if it extends the abstract Section
169 if ( ! is_object( $section ) || ! in_array( 'Tribe__Customizer__Section', class_parents( $section ) ) ) {
170 return false;
171 }
172
173 // Add the Section
174 // Enforces the usage of `$instance->ID`
175 $this->sections_class[ $section->ID ] = $section;
176
177 return true;
178 }
179
180 /**
181 * Fetches all Section Classes
182 *
183 * @since 4.4
184 *
185 * @return array
186 */
187 public function get_loaded_sections() {
188 /**
189 * Allow developers to filter Classes from Customizer Sections
190 *
191 * @deprecated
192 * @since 4.0
193 *
194 * @param array $selection_class
195 * @param self $customizer
196 */
197 $this->sections_class = apply_filters( 'tribe_events_pro_customizer_sections_class', $this->sections_class, $this );
198
199 /**
200 * Allow developers to filter Classes from Customizer Sections
201 *
202 * @since 4.4
203 *
204 * @param array $selection_class
205 * @param self $customizer
206 */
207 $this->sections_class = apply_filters( 'tribe_customizer_sections_class', $this->sections_class, $this );
208
209 return $this->sections_class;
210 }
211
212 /**
213 * A easy way to check if customize is active
214 *
215 * @since 4.2.2
216 *
217 * @return boolean
218 */
219 public function is_active() {
220 /**
221 * Allows Developers to completely deactivate Events Calendar Customizer
222 *
223 * @deprecated
224 *
225 * @param boolean $is_active
226 */
227 $is_active = apply_filters( 'tribe_events_pro_customizer_is_active', true );
228
229 /**
230 * Allows Developers to completely deactivate Events Calendar Customizer
231 *
232 * @param boolean $is_active
233 */
234 return apply_filters( 'tribe_customizer_is_active', true );
235 }
236
237 /**
238 * A method to easily search on an array
239 *
240 * @since 4.0
241 *
242 * @param array $variable Variable to be searched
243 * @param array $indexes The index that the method will try to retrieve
244 * @param mixed $default If the variable doesn't exist, what is the default
245 *
246 * @return mixed Return the variable based on the index
247 */
248 public static function search_var( $variable = null, $indexes = [], $default = null ) {
249 if ( is_object( $variable ) ) {
250 $variable = (array) $variable;
251 }
252
253 if ( ! is_array( $variable ) ) {
254 return $variable;
255 }
256
257 foreach ( (array) $indexes as $index ) {
258 if ( ! is_array( $variable ) || ! isset( $variable[ $index ] ) ) {
259 $variable = $default;
260 break;
261 }
262
263 $variable = $variable[ $index ];
264 }
265
266 return $variable;
267 }
268
269 /**
270 * Get an option from the database, using index search you can retrieve the full panel, a section or even a setting
271 *
272 * @param array $search Index search, array( 'section_name', 'setting_name' )
273 * @param mixed $default The default, if the requested variable doesn't exits
274 * @return mixed The requested option or the default
275 */
276 public function get_option( $search = null, $default = null ) {
277 $sections = get_option( $this->ID, $default );
278
279 foreach ( $this->get_loaded_sections() as $section ) {
280 /**
281 * Allow filtering the defaults for each settings to be filtered before the Ghost options to be set
282 *
283 * @deprecated
284 * @since 4.0
285 *
286 * @param array $defaults
287 */
288 $defaults[ $section->ID ] = apply_filters( "tribe_events_pro_customizer_section_{$section->ID}_defaults", [] );
289
290 /**
291 * Allow filtering the defaults for each settings to be filtered before the Ghost options to be set
292 *
293 * @since 4.4
294 *
295 * @param array $defaults
296 */
297 $settings = isset( $sections[ $section->ID ] ) ? $sections[ $section->ID ] : [];
298 $defaults[ $section->ID ] = apply_filters( "tribe_customizer_section_{$section->ID}_defaults", $settings );
299 $sections[ $section->ID ] = wp_parse_args( $settings, $defaults[ $section->ID ] );
300 }
301
302 /**
303 * Allows Ghost Options to be inserted
304 *
305 * @deprecated
306 * @since 4.0
307 *
308 * @param array $sections
309 * @param array $search
310 */
311 $sections = apply_filters( 'tribe_events_pro_customizer_pre_get_option', $sections, $search );
312
313 /**
314 * Allows Ghost Options to be inserted
315 *
316 * @since 4.4
317 *
318 * @param array $sections
319 * @param array $search
320 */
321 $sections = apply_filters( 'tribe_customizer_pre_get_option', $sections, $search );
322
323 // Search on the Array
324 if ( ! is_null( $search ) ) {
325 $option = self::search_var( $sections, $search, $default );
326 } else {
327 $option = $sections;
328 }
329
330 /**
331 * Apply Filters After finding the variable
332 *
333 * @since 4.4
334 *
335 * @param mixed $option
336 * @param array $search
337 * @param array $sections
338 */
339 $option = apply_filters( 'tribe_customizer_get_option', $option, $search, $sections );
340
341 return $option;
342 }
343
344 /**
345 * Check if the option exists, this method is used allow only sections that were saved to be applied.
346 *
347 * @param strings Using the following structure: self::has_option( 'section_name', 'setting_name' );
348 *
349 * @return boolean Whether the option exists in the database
350 */
351 public function has_option() {
352 $search = func_get_args();
353 $option = self::get_option();
354 $real_option = get_option( $this->ID, [] );
355
356 // Get section and Settings based on keys
357 $section = reset( $search );
358 $setting = end( $search );
359
360 if ( empty( $real_option ) || empty( $real_option[ $section ] ) ) {
361 return false;
362 }
363
364 // Search on the Array
365 if ( ! is_null( $search ) ) {
366 $option = self::search_var( $option, $search, null );
367 }
368
369 return ! empty( $option );
370 }
371
372 /**
373 * Print the CSS for the customizer on `wp_print_footer_scripts`
374 *
375 * @since 4.12.6 Moved the template building code to the `get_styles_scripts` method.
376 *
377 * @return void
378 */
379 public function print_css_template() {
380
381 //Only load in Customizer
382 if ( ! is_customize_preview() ) {
383 return false;
384 }
385
386 echo $this->get_styles_scripts();
387 }
388
389 /**
390 * Print the CSS for the customizer for shortcodes.
391 *
392 * @since 4.12.6
393 */
394 public function shortcode_inline_style() {
395 /**
396 * Whether customizer styles should print for shortcodes or not.
397 *
398 * @since 4.12.6
399 *
400 * @param boolean $should_print Whether the inline styles should be printed on screen.
401 */
402 $should_print = apply_filters( 'tribe_customizer_should_print_shortcode_customizer_styles', false );
403
404 if ( empty( $should_print ) ) {
405 return;
406 }
407
408 $this->inline_style();
409 }
410
411 /**
412 * Print the CSS for the customizer for widgets.
413 *
414 * @since 4.12.14
415 */
416 public function widget_inline_style() {
417 /**
418 * Whether customizer styles should print for widgets or not.
419 *
420 * @since 4.12.14
421 *
422 * @param boolean $should_print Whether the inline styles should be printed on screen.
423 */
424 $should_print = apply_filters( 'tribe_customizer_should_print_widget_customizer_styles', false );
425
426 if ( empty( $should_print ) ) {
427 return;
428 }
429
430 $this->inline_style();
431 }
432
433 /**
434 * Print the CSS for the customizer using wp_add_inline_style
435 *
436 * @since 4.12.15 Added the `$force` parameter to force the print of the style inline.
437 *
438 * @param bool $force Whether to ignore the context to try and print the style inline, or not.
439 */
440 public function inline_style( $force = false ) {
441 // Only load once on front-end.
442 if ( ! $force && ( is_customize_preview() || is_admin() || $this->inline_style ) ) {
443 return false;
444 }
445
446 /**
447 * Use this filter to add more CSS, using Underscore Template style
448 *
449 * @since 4.4
450 *
451 * @link http://underscorejs.org/#template
452 *
453 * @param string $template
454 */
455 $css_template = trim( apply_filters( 'tribe_customizer_css_template', '' ) );
456
457 // If we don't have anything on the customizer don't print empty styles
458 if ( empty( $css_template ) ) {
459 return false;
460 }
461
462 $sheets = [
463 'tribe-common-full-style',
464 ];
465
466 /**
467 * Allow plugins to add themselves to this list.
468 *
469 * @since 4.12.1
470 *
471 * @param array<string> $sheets An array of sheets to search for.
472 * @param string $css_template String containing the inline css to add.
473 */
474 $sheets = apply_filters( 'tribe_customizer_inline_stylesheets', $sheets, $css_template );
475
476 if ( empty( $sheets ) ) {
477 return false;
478 }
479
480 // Add customizer styles inline with the latest stylesheet that is enqueued.
481 foreach ( array_reverse( $sheets ) as $sheet ) {
482 if ( wp_style_is( $sheet ) ) {
483 $inline_style = wp_strip_all_tags( $this->parse_css_template( $css_template ) );
484
485 /**
486 * Fires before a style is, possibly, printed inline depending on the stylesheet.
487 *
488 * @since 4.12.15
489 *
490 * @param string $sheet The handle of the stylesheet the style will be printed inline for.
491 * @param string $inline_style The inline style contents, as they will be printed on the page.
492 */
493 do_action( 'tribe_customizer_before_inline_style', $sheet, $inline_style );
494
495 // Just print styles if doing 'wp_print_footer_scripts' action.
496 $just_print = (bool) doing_action( 'wp_print_footer_scripts' );
497
498 if ( $just_print ) {
499 printf(
500 "<style id='%s-inline-css' type='text/css'>\n%s\n</style>\n",
501 esc_attr( $sheet ),
502 $inline_style
503 );
504 } else {
505 wp_add_inline_style( $sheet, $inline_style );
506 }
507
508 $this->inline_style = true;
509
510 break;
511 }
512 }
513 }
514
515 /**
516 * Replaces the Settings using the Underscore templating strings
517 *
518 * @param string $template The template variable, that we will look to replace the variables
519 * @return string A Valid css after replacing the variables
520 */
521 private function parse_css_template( $template ) {
522 $css = $template;
523 $sections = $this->get_option();
524
525 $search = [];
526 $replace = [];
527
528 foreach ( $sections as $section => $settings ) {
529 if ( ! is_array( $settings ) ) {
530 continue;
531 }
532 foreach ( $settings as $setting => $value ) {
533 $index = [ $section, $setting ];
534
535 // Add search based on Underscore template
536 $search[] = '<%= ' . implode( '.', $index ) . ' %>';
537
538 // Get the Replace value
539 $replace[] = $value;
540 }
541 }
542
543 // Finally Str replace
544 return str_replace( $search, $replace, $css );
545 }
546
547 /**
548 * Method to start setting up the Customizer Section and Fields
549 *
550 * @since 4.0
551 *
552 * @param WP_Customize_Manager $customizer WordPress Customizer variable
553 * @return void
554 */
555 public function register( WP_Customize_Manager $customizer ) {
556 // Set the Cutomizer on a class variable
557 $this->manager = $customizer;
558
559 /**
560 * Allow users to filter the Panel
561 *
562 * @since 4.4
563 *
564 * @param WP_Customize_Panel $panel
565 * @param Tribe__Customizer $customizer
566 */
567 $this->panel = apply_filters( 'tribe_customizer_panel', $this->register_panel(), $this );
568
569 /**
570 * Filter the Sections within our Panel before they are added to the Customize Manager
571 *
572 * @since 4.4
573 *
574 * @param array $sections
575 * @param Tribe__Customizer $customizer
576 */
577 $this->sections = apply_filters( 'tribe_customizer_pre_sections', $this->sections, $this );
578
579 foreach ( $this->sections as $id => $section ) {
580 $this->sections[ $id ] = $this->register_section( $id, $section );
581
582 /**
583 * Allows people to Register and de-register the method to register more Fields
584 *
585 * @since 4.4
586 * @since 4.12.15 Add Customizer instance as a parameter.
587 *
588 * @param array $section
589 * @param WP_Customize_Manager $manager
590 * @param Tribe__Customizer $customizer The current customizer instance.
591 */
592 do_action( "tribe_customizer_register_{$id}_settings", $this->sections[ $id ], $this->manager, $this );
593 }
594
595 /**
596 * Filter the Sections within our Panel, now using the actual WP_Customize_Section
597 *
598 * @since 4.4
599 *
600 * @param array $sections
601 * @param Tribe__Customizer $customizer
602 */
603 $this->sections = apply_filters( 'tribe_customizer_sections', $this->sections, $this );
604
605 // After everything is done, try to add Selective refresh
606 $this->maybe_selective_refresh();
607 }
608
609 /**
610 * Register the base Panel for Events Calendar Sections to be attached to
611 *
612 * @since 4.0
613 *
614 * @return WP_Customize_Panel
615 */
616 private function register_panel() {
617 $panel = $this->manager->get_panel( $this->ID );
618
619 // If the Panel already exists we leave returning it's instance
620 if ( ! empty( $panel ) ) {
621 return $panel;
622 }
623
624 $panel_args = [
625 'title' => esc_html__( 'The Events Calendar', 'tribe-common' ),
626 'description' => esc_html__( 'Use the following panel of your customizer to change the styling of your Calendar and Event pages.', 'tribe-common' ),
627
628 // After `static_front_page`
629 'priority' => 125,
630 ];
631
632 /**
633 * Filter the Panel Arguments for WP Customize
634 *
635 * @since 4.4
636 *
637 * @param array $args
638 * @param string $ID
639 * @param Tribe__Customizer $customizer
640 */
641 $panel_args = apply_filters( 'tribe_customizer_panel_args', $panel_args, $this->ID, $this );
642
643 // Actually Register the Panel
644 $this->manager->add_panel( $this->ID, $panel_args );
645
646 // Return the Panel instance
647 return $this->manager->get_panel( $this->ID );
648 }
649
650 /**
651 * Use a "alias" method to register sections to allow users to filter args and the ID
652 *
653 * @since 4.0
654 *
655 * @param string $id The Unique section ID
656 * @param array $args Arguments to register the section
657 *
658 * @link https://codex.wordpress.org/Class_Reference/WP_Customize_Manager/add_section
659 *
660 * @return WP_Customize_Section
661 */
662 public function register_section( $id, $args ) {
663 /**
664 * Filter the Section ID
665 *
666 * @since 4.4
667 *
668 * @param string $section_id
669 * @param Tribe__Customizer $customizer
670 */
671 $section_id = apply_filters( 'tribe_customizer_section_id', $id, $this );
672
673 // Tries to fetch the section
674 $section = $this->manager->get_section( $section_id );
675
676 // If the Panel already exists we leave returning it's instance
677 if ( ! empty( $section ) ) {
678 return $section;
679 }
680
681 /**
682 * Filter the Section arguments, so that developers can filter arguments based on $section_id
683 *
684 * @since 4.4
685 *
686 * @param array $args
687 * @param string $section_id
688 * @param Tribe__Customizer $customizer
689 */
690 $section_args = apply_filters( 'tribe_customizer_section_args', $args, $section_id, $this );
691
692 // Don't allow sections outside of our panel
693 $section_args['panel'] = $this->panel->id;
694
695 // Actually Register the Section
696 $this->manager->add_section( $section_id, $section_args );
697
698 // Return the Section instance
699 return $this->manager->get_section( $section_id );
700 }
701
702 /**
703 * Build the Setting name using the HTML format for Arrays
704 *
705 * @since 4.0
706 *
707 * @param string $slug The actual Setting name
708 * @param string|WP_Customize_Section $section [description]
709 *
710 * @return string HTML name Attribute name o the setting
711 */
712 public function get_setting_name( $slug, $section = null ) {
713 $name = $this->panel->id;
714
715 // If there is a section set append it
716 if ( $section instanceof WP_Customize_Section ) {
717 $name .= '[' . $section->id . ']';
718 } elseif ( is_string( $section ) ) {
719 $name .= '[' . $section . ']';
720 }
721
722 // Set the actual setting slug
723 $name .= '[' . esc_attr( $slug ) . ']';
724
725 return $name;
726 }
727
728
729 /**
730 * Adds a setting field name to the Array of Possible Selective refresh fields
731 *
732 * @since 4.2
733 *
734 * @param string $name The actual Setting name
735 *
736 * @return array The list of existing Settings, the new one included
737 */
738 public function add_setting_name( $name ) {
739 $this->settings[] = $name;
740 return $this->settings;
741 }
742
743
744 /**
745 * Using the Previously created CSS element, we not just re-create it every setting change
746 *
747 * @since 4.2
748 *
749 * @return void
750 */
751 public function maybe_selective_refresh() {
752 // Only try to apply selective refresh if it's active
753 if ( ! isset( $this->manager->selective_refresh ) ) {
754 return;
755 }
756
757 foreach ( $this->settings as $name ) {
758 $setting = $this->manager->get_setting( $name );
759
760 // Skip if we don't have that setting then skip it
761 if ( is_null( $setting ) ) {
762 continue;
763 }
764
765 // Skip if we already have that
766 if ( ! is_null( $this->manager->selective_refresh->get_partial( $name ) ) ) {
767 continue;
768 }
769
770 // Remove the Setting
771 // We need this because settings are protected on the WP_Customize_Manager
772 $this->manager->remove_setting( $name );
773
774 // Change the Transport
775 $setting->transport = 'postMessage';
776
777 // Re-add the setting
778 // We need this because settings are protected on the WP_Customize_Manager
779 $this->manager->add_setting( $setting );
780
781 // Add the Partial
782 $this->manager->selective_refresh->add_partial(
783 $name,
784 [
785 'selector' => '#' . esc_attr( $this->ID . '_css' ),
786 'render_callback' => [ $this, 'print_css_template' ],
787 ]
788 );
789 }
790 }
791
792 /**
793 * Builds and returns the Customizer CSS template contents.
794 *
795 * The method DOES NOT check if the current context is the one where the Customizer template should
796 * be printed or not; that care is left to the code calling this method.
797 *
798 * @since 4.12.6 Extracted this method from the `print_css_template` one.
799 *
800 * @return string The CSS template contents.
801 */
802 public function get_styles_scripts() {
803 /**
804 * Use this filter to add more CSS, using Underscore Template style.
805 *
806 * @since 4.4
807 *
808 * @param string $template The Customizer template.
809 *
810 * @link http://underscorejs.org/#template
811 */
812 $css_template = trim( apply_filters( 'tribe_customizer_css_template', '' ) );
813
814 // If we don't have anything on the Customizer, then don't print empty styles.
815 if ( empty( $css_template ) ) {
816 return '';
817 }
818
819 // Prepare the customizer scripts.
820 $result = '<script type="text/css" id="' . esc_attr( 'tmpl-' . $this->ID . '_css' ) . '">';
821 $result .= $css_template;
822 $result .= '</script>';
823
824 // Prepare the customizer styles.
825 $result .= '<style type="text/css" id="' . esc_attr( $this->ID . '_css' ) . '">';
826 $result .= $this->parse_css_template( $css_template );
827 $result .= '</style>';
828
829 return $result;
830 }
831 }
832