PluginProbe
Timetics – Appointment Booking Calendar & Scheduling / 1.0.57
Timetics – Appointment Booking Calendar & Scheduling v1.0.57
1.0.61 1.0.60 1.0.59 1.0.58 1.0.57 1.0.56 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.2 1.0.20 1.0.21 1.0.22 1.0.23 1.0.24 All 62 releases
timetics / core / enqueue-inline / enqueue-inline.php

enqueue-inline.php in Timetics – Appointment Booking Calendar & Scheduling 1.0.57, at core/enqueue-inline/enqueue-inline.php

82 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Inline Enqueue class
5 *
6 * @package Timetics
7 */
8
9 namespace Timetics\Core\EnqueueInline;
10
11 defined( 'ABSPATH' ) || exit;
12
13 use Timetics\Utils\Singleton;
14
15 /**
16 * Class Enqueue_Inline
17 */
18 class Enqueue_Inline
19 {
20 use Singleton;
21
22 /**
23 * Template path for dynamic color CSS.
24 */
25 const COLOR_TEMPLATE = __DIR__ . '/templates/dynamic-colors.php';
26
27 /**
28 * Initialize the shortcode class
29 *
30 * @return void
31 */
32 public function init()
33 {
34 add_action( 'wp_enqueue_scripts', array( $this, 'custom_inline_css' ), 20 );
35 }
36
37 /**
38 * Build and attach the dynamic color CSS to the frontend stylesheet.
39 */
40 public function custom_inline_css()
41 {
42 $primary_color = timetics_get_option( 'primary_color' );
43 $secondary_color = timetics_get_option( 'secondary_color' );
44
45 if ( empty( $primary_color ) && empty( $secondary_color ) ) {
46 return;
47 }
48
49 $custom_css = $this->render_color_css( $primary_color, $secondary_color );
50
51 if ( '' === trim( $custom_css ) ) {
52 return;
53 }
54
55 wp_register_style( 'timetics-custom-css', false, array(), TIMETICS_VERSION );
56 wp_enqueue_style( 'timetics-custom-css' );
57 wp_add_inline_style( 'timetics-frontend', $custom_css );
58 }
59
60 /**
61 * Render the CSS template with the given colors.
62 *
63 * @param string $primary_color
64 * @param string $secondary_color
65 *
66 * @return string
67 */
68 protected function render_color_css( $primary_color, $secondary_color )
69 {
70 if ( ! file_exists( self::COLOR_TEMPLATE ) ) {
71 return '';
72 }
73
74 $primary_color = sanitize_hex_color( $primary_color ) ?: $primary_color;
75 $secondary_color = sanitize_hex_color( $secondary_color ) ?: $secondary_color;
76
77 ob_start();
78 include self::COLOR_TEMPLATE;
79 return ob_get_clean();
80 }
81 }
82