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 / selective-refresh / src / Selective_Refresh.php
kirki / customizer / packages / modules / selective-refresh / src Last commit date
Selective_Refresh.php 2 months ago
Selective_Refresh.php
106 lines
1 <?php
2 /**
3 * Handles selective refreshes for Kirki fields.
4 *
5 * @package kirki-framework/module-selective-refresh
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 /**
19 * Handle selective refreshes introduced in WordPress 4.5.
20 */
21 class Selective_Refresh {
22
23 /**
24 * The class instance.
25 *
26 * @static
27 * @access private
28 * @since 1.0.0
29 * @var object
30 */
31 private static $instance;
32
33 /**
34 * An array of fields with selective refreshes.
35 *
36 * @static
37 * @access private
38 * @since 1.0.0
39 * @var array
40 */
41 private static $fields = [];
42
43 /**
44 * Get the one, true instance of this class.
45 *
46 * @static
47 * @access public
48 * @since 1.0.0
49 * @return object
50 */
51 public static function get_instance() {
52 if ( null === self::$instance ) {
53 self::$instance = new self();
54 }
55 return self::$instance;
56 }
57
58 /**
59 * Adds any necessary actions & filters.
60 *
61 * @access public
62 */
63 public function __construct() {
64 add_filter( 'kirki_field_add_setting_args', [ $this, 'filter_setting_args' ], 10, 2 );
65 }
66
67 /**
68 * Filter setting args.
69 *
70 * @access public
71 * @since 1.0.0
72 * @param array $field The field arguments.
73 * @param WP_Customize_Manager $wp_customize The customizer instance.
74 * @return array
75 */
76 public function filter_setting_args( $field, $wp_customize ) {
77
78 // Abort if selective refresh is not available.
79 if ( ! isset( $wp_customize->selective_refresh ) ) {
80 return $field;
81 }
82
83 if ( isset( $field['partial_refresh'] ) && ! empty( $field['partial_refresh'] ) ) {
84
85 // Start going through each item in the array of partial refreshes.
86 foreach ( $field['partial_refresh'] as $partial_refresh => $partial_refresh_args ) {
87
88 // If we have all we need, create the selective refresh call.
89 if ( isset( $partial_refresh_args['render_callback'] ) && isset( $partial_refresh_args['selector'] ) ) {
90 $partial_refresh_args = wp_parse_args(
91 $partial_refresh_args,
92 [
93 'settings' => $field['settings'],
94 ]
95 );
96 $wp_customize->selective_refresh->add_partial( $partial_refresh, $partial_refresh_args );
97
98 // If partial refresh is set, change the transport to auto.
99 $field['transport'] = 'postMessage';
100 }
101 }
102 }
103
104 return $field;
105 }
106 }