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

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