PluginProbe ʕ •ᴥ•ʔ
Kirki – Freeform Page Builder, Website Builder & Customizer / 6.0.13
Kirki – Freeform Page Builder, Website Builder & Customizer v6.0.13
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 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 4.0.19 4.0.20 4.0.21 4.0.22 4.0.23 4.0.24 4.1 4.2.0 5.0.0 5.1.0 5.1.1 5.2.0 5.2.1 5.2.2 5.2.3 6.0.0 trunk 3.0.40 3.0.41 3.0.42 3.0.43 3.0.44 3.0.45 3.1.0 3.1.1 3.1.2
kirki / customizer / packages / modules / preset / src / Preset.php
kirki / customizer / packages / modules / preset / src Last commit date
Preset.php 2 months ago
Preset.php
95 lines
1 <?php
2 /**
3 * Automatic preset scripts calculation for Kirki controls.
4 *
5 * @package kirki-framework/module-preset
6 * @author Themeum
7 * @copyright Copyright (c) 2023, Themeum
8 * @license https://opensource.org/licenses/MIT
9 * @since 1.0.0
10 */
11
12 namespace Kirki\Module;
13
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit;
16 }
17
18 use Kirki\URL;
19
20 /**
21 * Adds styles to the customizer.
22 */
23 class Preset {
24
25 /**
26 * The class instance.
27 *
28 * @static
29 * @access private
30 * @since 1.0.0
31 * @var object
32 */
33 private static $instance;
34
35 /**
36 * An array of preset controls and their arguments.
37 *
38 * @static
39 * @access private
40 * @since 1.0.0
41 * @var array
42 */
43 private static $preset_controls = [];
44
45 /**
46 * Get the one, true instance of this class.
47 *
48 * @static
49 * @access public
50 * @since 1.0.0
51 * @return object
52 */
53 public static function get_instance() {
54 if ( null === self::$instance ) {
55 self::$instance = new self();
56 }
57 return self::$instance;
58 }
59
60 /**
61 * Constructor.
62 *
63 * @access public
64 * @since 1.0.0
65 */
66 public function __construct() {
67 add_action( 'customize_controls_print_footer_scripts', [ $this, 'customize_controls_print_footer_scripts' ] );
68 add_filter( 'kirki_field_add_control_args', [ $this, 'field_add_control_args' ] );
69 }
70
71 /**
72 * Filter control arguments.
73 *
74 * @access public
75 * @since 1.0
76 * @param array $args The field arguments.
77 * @return array
78 */
79 public function field_add_control_args( $args ) {
80 if ( isset( $args['preset'] ) && is_array( $args['preset'] ) ) {
81 self::$preset_controls[ $args['settings'] ] = $args['preset'];
82 }
83 return $args;
84 }
85
86 /**
87 * Enqueue scripts.
88 *
89 * @access public
90 * @since 1.0.0
91 */
92 public function customize_controls_print_footer_scripts() {
93 wp_localize_script( 'kirki-customizer', 'kirkiPresetControls', self::$preset_controls );
94 }
95 }