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 / controls / tabs / src / Init.php
kirki / customizer / packages / controls / tabs / src Last commit date
Control 3 months ago Field 5 months ago Init.php 2 months ago
Init.php
107 lines
1 <?php
2 /**
3 * Init the Kirki tabs package.
4 *
5 * @package kirki-tabs
6 * @since 1.0.0
7 */
8
9 namespace Kirki\Tabs;
10
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit;
13 }
14
15 use Kirki\Field\Tabs;
16
17 /**
18 * Manage the tabs package.
19 */
20 class Init {
21
22 /**
23 * The class constructor.
24 */
25 public function __construct() {
26
27 add_filter( 'kirki_control_types', [ $this, 'control_type' ] );
28 add_filter( 'kirki_field_add_control_args', array( $this, 'filter_control_args' ), 10, 2 );
29 add_action( 'kirki_section_init', [ $this, 'add_tab' ], 10, 2 );
30
31 }
32
33 /**
34 * The control type.
35 *
36 * @param array $control_types The existing control types.
37 */
38 public function control_type( $control_types ) {
39
40 $control_types['kirki-tab'] = 'Kirki\Control\Tabs';
41
42 return $control_types;
43
44 }
45
46 /**
47 * Filter customizer's control arguments.
48 *
49 * @since 1.0.0
50 *
51 * @param array $args The field arguments.
52 * @param WP_Customize_Manager $wp_customize The customizer instance.
53 *
54 * @return array
55 */
56 public function filter_control_args( $args, $wp_customize ) {
57
58 if ( isset( $args['tab'] ) ) {
59 $tabs = Tabs::$tabs;
60 $section = $args['section'];
61
62 if ( isset( $tabs[ $section ] ) ) {
63 $tab_wrapper_attrs = array(
64 'data-kirki-parent-tab-id' => $section,
65 'data-kirki-parent-tab-item' => isset( $args['tab'] ) ? $args['tab'] : '',
66 );
67
68 if ( isset( $args['wrapper_attrs'] ) ) {
69 $args['wrapper_attrs'] = array_merge( $args['wrapper_attrs'], $tab_wrapper_attrs );
70 } else {
71 $args['wrapper_attrs'] = $tab_wrapper_attrs;
72 }
73 }
74 }
75
76 return $args;
77
78 }
79
80 /**
81 * Add the tab by creating custom control using Kirki API.
82 *
83 * @since 1.0.0
84 *
85 * @param string $section_id The The section id.
86 * @param array $args The section args.
87 */
88 public function add_tab( $section_id, $args ) {
89
90 if ( ! isset( $args['tabs'] ) ) {
91 return;
92 }
93
94 new \Kirki\Field\Tabs(
95 [
96 'settings' => 'kirki_tabs_' . $section_id,
97 'section' => $section_id,
98 'priority' => 0,
99 'choices' => [
100 'tabs' => $args['tabs'],
101 ],
102 ]
103 );
104
105 }
106
107 }