PluginProbe
Kirki – Freeform Page Builder, Website Builder & Customizer / 6.3.0
Kirki – Freeform Page Builder, Website Builder & Customizer v6.3.0
6.3.0 6.2.5 6.2.4 6.2.3 6.2.2 6.2.1 6.2.0 6.1.1 6.1.0 6.0.14 6.0.13 6.0.12 6.0.11 6.0.10 6.0.9 6.0.8 6.0.7 6.0.6 6.0.5 6.0.4 6.0.3 6.0.2 6.0.1 3.1.3 3.1.4 All 56 releases
kirki / customizer / packages / modules / tooltips / src / Tooltips.php
Tooltips.php
107 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Injects tooltips to controls when the 'tooltip' argument is used.
4 *
5 * @package Kirki
6 * @category Modules
7 * @author Themeum
8 * @copyright Copyright (c) 2023, Themeum
9 * @license https://opensource.org/licenses/MIT
10 * @since 1.0
11 */
12
13 namespace Kirki\Module;
14
15 if ( ! defined( 'ABSPATH' ) ) {
16 exit;
17 }
18
19 use Kirki\URL;
20
21 /**
22 * Adds the tooltips.
23 *
24 * @since 1.0
25 */
26 class Tooltips {
27
28 /**
29 * The class instance.
30 *
31 * @static
32 * @access private
33 * @since 1.0
34 * @var object
35 */
36 private static $instance;
37
38 /**
39 * An array containing field identifieds and their tooltips.
40 *
41 * @access private
42 * @since 1.0
43 * @var array
44 */
45 private $tooltips_content = [];
46
47 /**
48 * Get the one, true instance of this class.
49 * Prevents performance issues since this is instantiated in a filter.
50 *
51 * @static
52 * @access public
53 * @since 1.0
54 * @return object
55 */
56 public static function get_instance() {
57 if ( null === self::$instance ) {
58 self::$instance = new self();
59 }
60 return self::$instance;
61 }
62
63 /**
64 * The class constructor
65 *
66 * @access public
67 * @since 1.0
68 */
69 public function __construct() {
70
71 add_action( 'customize_controls_print_footer_scripts', [ $this, 'customize_controls_print_footer_scripts' ] );
72 add_filter( 'kirki_field_add_control_args', [ $this, 'filter_control_args' ], 10, 2 );
73
74 }
75
76 /**
77 * Enqueue scripts.
78 *
79 * @access public
80 * @since 1.0
81 */
82 public function customize_controls_print_footer_scripts() {
83
84
85 wp_localize_script( 'kirki-customizer', 'kirkiTooltips', $this->tooltips_content );
86
87 }
88
89 /**
90 * Filter control args.
91 *
92 * @access public
93 * @since 1.0
94 * @param array $args The field arguments.
95 * @param WP_Customize_Manager $wp_customize The customizer instance.
96 * @return array
97 */
98 public function filter_control_args( $args, $wp_customize ) {
99 if ( isset( $args['tooltip'] ) && $args['tooltip'] ) {
100 $this->tooltips_content[ $args['settings'] ] = [
101 'id' => sanitize_key( $args['settings'] ),
102 'content' => wp_kses_post( $args['tooltip'] ),
103 ];
104 }
105 return $args;
106 }
107 }