PluginProbe
Powerkit – Supercharge your WordPress Site / 2.4.4
Powerkit – Supercharge your WordPress Site v2.4.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 2.4.4, at modules/basic-elements/templates/tabs.php

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