PluginProbe
Booking Calendar / 11.8.4
Booking Calendar v11.8.4
11.8.4 11.8.3 11.8.2 11.8.1 11.8 11.7 11.6.1 11.6 11.5 11.4.3 11.4.2 11.4.1 11.4 11.3 11.2.1 11.2 11.1 11.0 10.15.7 10.15.6 10.1.3 10.10 10.10.1 10.10.2 10.11 All 204 releases
booking / includes / booking-resource-selector / booking-resource-selector__theme.php

booking-resource-selector__theme.php in Booking Calendar 11.8.4, at includes/booking-resource-selector/booking-resource-selector__theme.php

119 lines 4.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Scoped Booking Form Style integration for the Booking Resource selector.
4 *
5 * @package Booking Calendar
6 */
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit;
10 }
11
12 /**
13 * Return Form Style variables consumed by the resource selection interface.
14 *
15 * @return string[] CSS custom-property names.
16 */
17 function wpbc_booking_resource_selector_get_theme_css_var_names() {
18 return array(
19 '--wpbc-bfb-form-background',
20 '--wpbc-bfb-form-border-color',
21 '--wpbc-bfb-form-border-width',
22 '--wpbc-bfb-form-border-radius',
23 '--wpbc-bfb-form-padding',
24 '--wpbc-bfb-form-box-shadow',
25 '--wpbc_form-label-color',
26 '--wpbc_form-label-sublabel-color',
27 '--wpbc_form-label-error-color',
28 '--wpbc_form-field-background-color',
29 '--wpbc_form-field-text-color',
30 '--wpbc_form-field-border-color',
31 '--wpbc_form-field-border-radius',
32 '--wpbc_form-field-focus-border-color',
33 '--wpbc_form-field-focus-shadow-color',
34 '--wpbc_form-choice-checked-border-color',
35 '--wpbc_form-choice-focus-color',
36 '--wpbc_form-button-border-radius',
37 '--wpbc_form-button-border-style',
38 '--wpbc_form-button-border-size',
39 '--wpbc_form-button-background-color',
40 '--wpbc_form-button-background-color-alt',
41 '--wpbc_form-button-border-color',
42 '--wpbc_form-button-primary-border-style',
43 '--wpbc_form-button-text-color',
44 '--wpbc_form-button-hover-background-color',
45 '--wpbc_form-button-hover-border-color',
46 '--wpbc_form-button-hover-text-color',
47 '--wpbc_form-button-light-background-color',
48 '--wpbc_form-button-light-border-color',
49 '--wpbc_form-button-light-border-style',
50 '--wpbc_form-button-light-border-size',
51 '--wpbc_form-button-light-text-color',
52 '--wpbc_form-button-light-box-shadow',
53 '--wpbc_form-button-light-hover-background-color',
54 '--wpbc_form-button-light-hover-border-color',
55 '--wpbc_form-button-light-hover-text-color',
56 '--wpbc_form-button-light-hover-box-shadow',
57 '--wpbc_form-button-primary-hover-border-color',
58 '--wpbc_form-accent-contrast-color',
59 );
60 }
61
62 /**
63 * Resolve whitelisted selector variables from the active Booking Form Style.
64 *
65 * @return array<string,string> Theme values sanitized during serialization.
66 */
67 function wpbc_booking_resource_selector_get_theme_css_vars() {
68 if ( ! function_exists( 'wpbc_bfb_settings__get_current_form_style' ) || ! function_exists( 'wpbc_bfb_settings__get_form_style_css_vars' ) ) {
69 return array();
70 }
71
72 $form_style = wpbc_bfb_settings__get_current_form_style();
73 $form_vars = wpbc_bfb_settings__get_form_style_css_vars( $form_style );
74 $allowed = array_fill_keys( wpbc_booking_resource_selector_get_theme_css_var_names(), true );
75 $theme_vars = array_intersect_key( is_array( $form_vars ) ? $form_vars : array(), $allowed );
76 $theme_vars = apply_filters( 'wpbc_booking_resource_selector_theme_css_vars', $theme_vars, $form_style );
77
78 return array_intersect_key( is_array( $theme_vars ) ? $theme_vars : array(), $allowed );
79 }
80
81 /**
82 * Sanitize one CSS custom-property value for generated inline CSS.
83 *
84 * @param mixed $css_value Candidate CSS value.
85 *
86 * @return string Safe CSS value or an empty string.
87 */
88 function wpbc_booking_resource_selector_sanitize_theme_css_value( $css_value ) {
89 $css_value = is_scalar( $css_value ) ? trim( (string) $css_value ) : '';
90 if ( '' === $css_value ) {
91 return '';
92 }
93
94 $css_value = str_replace( array( ';', '{', '}', '"', "'", '<', '>', "\n", "\r", "\0" ), '', $css_value );
95
96 return trim( $css_value );
97 }
98
99 /**
100 * Build one page-level CSS rule for selector theme scopes.
101 *
102 * @return string Safe scoped CSS, or an empty string when unavailable.
103 */
104 function wpbc_booking_resource_selector_build_theme_css() {
105 $declarations = '';
106 foreach ( wpbc_booking_resource_selector_get_theme_css_vars() as $property_name => $property_value ) {
107 $property_value = wpbc_booking_resource_selector_sanitize_theme_css_value( $property_value );
108 if ( '' !== $property_value ) {
109 $declarations .= $property_name . ':' . $property_value . ';';
110 }
111 }
112
113 if ( '' === $declarations ) {
114 return '';
115 }
116
117 return '.wpbc_booking_resource_selector .wpbc_booking_ui_theme_scope,.wpbc_booking_resource_selector__loading{' . $declarations . '}';
118 }
119