PluginProbe
Powerkit – Supercharge your WordPress Site / 3.0.4
Powerkit – Supercharge your WordPress Site v3.0.4
3.1.1 3.1.0 3.0.9 3.0.8 trunk 2.2.6 2.2.7 2.2.8 2.2.9 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.3.8 2.3.9 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 All 87 releases
powerkit / modules / basic-elements / templates / tabs.php

tabs.php in Powerkit – Supercharge your WordPress Site 3.0.4, at modules/basic-elements/templates/tabs.php

162 lines 4.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Shortcode Tabs config
4 *
5 * @package Powerkit
6 * @subpackage Templates
7 */
8
9 /**
10 * Tabs
11 */
12 add_action( 'init', function () {
13 powerkit_basic_shortcodes_register( array(
14 'name' => 'tabs',
15 'title' => esc_html__( 'Tabs', 'powerkit' ),
16 'priority' => 40,
17 'base' => 'powerkit_tabs',
18 'autoregister' => true,
19 'fields' => array(
20 array(
21 'type' => 'section',
22 'label' => esc_html__( 'Options', 'powerkit' ),
23 ),
24 array(
25 'type' => 'radio',
26 'name' => 'type',
27 'label' => esc_html__( 'Type', 'powerkit' ),
28 'style' => 'horizontal',
29 'default' => 'tabs',
30 'options' => array(
31 'tabs' => esc_html__( 'Tabs', 'powerkit' ),
32 'pills' => esc_html__( 'Pills', 'powerkit' ),
33 ),
34 ),
35 array(
36 'type' => 'radio',
37 'name' => 'nav',
38 'label' => esc_html__( 'Navigation type', 'powerkit' ),
39 'style' => 'horizontal',
40 'default' => 'horizontal',
41 'options' => array(
42 'horizontal' => esc_html__( 'Horizontal', 'powerkit' ),
43 'vertical' => esc_html__( 'Vertical', 'powerkit' ),
44 ),
45 ),
46 array(
47 'type' => 'section',
48 'label' => esc_html__( 'Content', 'powerkit' ),
49 ),
50 array(
51 'type' => 'repeater',
52 'base' => 'powerkit_tab',
53 'autoregister' => true,
54 'label' => esc_html__( 'Tabs', 'powerkit' ),
55 'fields' => array(
56 array(
57 'type' => 'input',
58 'name' => 'title',
59 'label' => esc_html__( 'Title', 'powerkit' ),
60 'default' => '',
61 'attrs' => array(
62 'class' => 'widefat',
63 ),
64 ),
65 array(
66 'type' => 'content',
67 'name' => 'content',
68 'label' => esc_html__( 'Content', 'powerkit' ),
69 'default' => '',
70 'attrs' => array(
71 'class' => 'widefat',
72 'rows' => 6,
73 ),
74 ),
75 ),
76 ),
77 ),
78 ) );
79 });
80
81 /**
82 * Tabs Wrap Shortcode
83 *
84 * @param array $output Shortcode HTML.
85 * @param array $atts User defined attributes in shortcode tag.
86 * @param string $content Shorcode tag content.
87 * @return string Shortcode result HTML.
88 */
89 function powerkit_basic_shortcodes_tabs( $output, $atts, $content ) {
90 global $powerkit_basic_shortcodes_tabs;
91 if ( ! is_array( $powerkit_basic_shortcodes_tabs ) ) {
92 $powerkit_basic_shortcodes_tabs = array();
93 }
94
95 // Output.
96 $nav_items = '';
97 $pane_items = '';
98 $num = 1;
99
100 foreach ( $powerkit_basic_shortcodes_tabs as $tab ) {
101 $data_toggle = ( 'tabs' === $atts['type'] ) ? 'tab' : 'pill';
102 $item_id = uniqid();
103 $content_id = $data_toggle . '-' . $item_id;
104
105 $nav_items .= sprintf(
106 '<li class="pk-nav-item"><a class="pk-nav-link%s pk-font-heading" data-toggle="%s" href="#%s">%s</a></li>',
107 ( 1 === $num ) ? ' pk-active' : '',
108 $data_toggle,
109 $content_id,
110 wp_kses( $tab['title'], 'post' )
111 );
112
113 $pane_items .= sprintf(
114 '<div id="%s" class="pk-tab-pane pk-fade%s" role="tabpanel">%s</div>',
115 $content_id,
116 ( 1 === $num ) ? ' pk-show pk-active' : '',
117 wp_kses( $tab['content'], 'post' )
118 );
119
120 $num++;
121 }
122
123 // Reset Tabs.
124 $powerkit_basic_shortcodes_tabs = array();
125
126 // Tabs Output.
127 $output = '';
128 $output .= '<div class="pk-tabs pk-tabs-' . $atts['nav'] . '">';
129 $output .= '<div class="pk-tabs-container">';
130 $output .= '<div class="pk-tabs-navigation"><ul class="pk-nav pk-nav-' . $atts['type'] . '" role="tablist">' . $nav_items . '</ul></div>';
131 $output .= '<div class="pk-tabs-content"><div class="pk-tab-content">' . $pane_items . '</div></div>';
132 $output .= '</div>';
133 $output .= '</div>';
134
135 return $output;
136 }
137 add_filter( 'powerkit_tabs_shortcode', 'powerkit_basic_shortcodes_tabs', 10, 3 );
138
139
140 /**
141 * Tab Item Shortcode
142 *
143 * @param array $output Shortcode HTML.
144 * @param array $atts User defined attributes in shortcode tag.
145 * @param string $content Shorcode tag content.
146 * @return string Shortcode result HTML.
147 */
148 function powerkit_basic_shortcodes_tab( $output, $atts, $content ) {
149 global $powerkit_basic_shortcodes_tabs;
150 if ( ! is_array( $powerkit_basic_shortcodes_tabs ) ) {
151 $powerkit_basic_shortcodes_tabs = array();
152 }
153
154 $powerkit_basic_shortcodes_tabs[] = array(
155 'title' => wp_kses( $atts['title'], 'post' ),
156 'content' => wp_kses( $content, 'post' ),
157 );
158
159 return false;
160 }
161 add_filter( 'powerkit_tab_shortcode', 'powerkit_basic_shortcodes_tab', 10, 3 );
162