tabs.php
7.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
<?php
/**
* LearnDash LD30 Displays content tabs
*
* @since 3.0.0
*
* @package LearnDash\Templates\LD30
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Fires before the content tabs.
*
* @since 3.0.0
* @param int|false $post_id Post ID.
* @param int $course_id Course ID.
* @param int $user_id User ID.
*/
do_action( 'learndash-content-tabs-before', get_the_ID(), $course_id, $user_id );
/**
* Fires before the content tabs for any context.
*
* The dynamic portion of the hook name, `$context`, refers to the context for which the hook is fired,
* such as `course`, `lesson`, `topic`, `quiz`, etc.
*
* @since 3.0.0
*
* @param int|false $post_id Post ID.
* @param int $course_id Course ID.
* @param int $user_id User ID.
*/
do_action( 'learndash-' . $context . '-content-tabs-before', get_the_ID(), $course_id, $user_id );
$tab_count = 0;
/**
* Filters LearnDash content Tabs.
*
* @since 3.0.0
*
* @param array $tabs An array of tabs array data. The tabs array data can contain keys for id, icon, label, content.
* @param string $context The context where the tabs are shown like course, lesson, topic, quiz, etc.
* @param int $course_id Course ID.
* @param int $user_id User ID.
*/
$tabs = apply_filters(
'learndash_content_tabs',
array(
array(
'id' => 'content',
'icon' => 'ld-icon-content',
'label' => LearnDash_Custom_Label::get_label( $context ),
'content' => $content,
),
array(
'id' => 'materials',
'icon' => 'ld-icon-materials',
'label' => __( 'Materials', 'learndash' ),
'content' => $materials,
'condition' => ( isset( $materials ) && ! empty( $materials ) ),
),
),
$context,
$course_id,
$user_id
);
foreach ( $tabs as $tab ) {
if ( ! isset( $tab['condition'] ) ) {
$tab_count++;
}
if ( isset( $tab['condition'] ) && $tab['condition'] ) {
$tab_count++;
}
} ?>
<div class="ld-tabs <?php echo esc_attr( 'ld-tab-count-' . $tab_count ); ?>">
<?php
/**
* If we have more than one tab, show them
*/
if ( $tab_count > 1 ) :
$i = 0;
?>
<div role="tablist" class="ld-tabs-navigation">
<?php
foreach ( $tabs as $tab ) :
// Skip if conditionally indicated.
if ( isset( $tab['condition'] ) && ! $tab['condition'] ) {
continue;
}
$tab_class = 'ld-tab ' . ( 0 === $i ? 'ld-active' : '' );
$attrs = ( 0 === $i ? 'aria-selected="true"' : '' );
?>
<button <?php echo esc_attr( $attrs ); ?> role="tab" aria-controls="<?php echo esc_attr( $tab['id'] . '-tab' ); ?>" id="<?php echo esc_attr( 'ld-' . $tab['id'] ) . '-tab-' . get_the_ID(); ?>" class="<?php echo esc_attr( $tab_class ); ?>" data-ld-tab="<?php echo esc_attr( 'ld-tab-' . $tab['id'] . '-' . get_the_ID() ); ?>">
<span class="<?php echo esc_attr( 'ld-icon ' . $tab['icon'] ); ?>"></span>
<span class="ld-text"><?php echo esc_attr( $tab['label'] ); ?></span>
</button>
<?php
$i++;
endforeach;
?>
</div>
<?php endif; ?>
<div class="ld-tabs-content">
<?php
/**
* Fires before the content tabs.
*
* @since 3.0.0
*
* @param int|false $post_id Post ID.
* @param string $context The context for which the hook is fired such as `course`, `lesson`, `topic`, `quiz`, etc.
* @param int $course_id Course ID.
* @param int $user_id User ID.
*/
do_action( 'learndash-content-tab-listing-before', get_the_ID(), $context, $course_id, $user_id );
/**
* Fires before the content tabs for any context.
*
* The dynamic portion of the hook name, `$context`, refers to the context for which the hook is fired,
* such as `course`, `lesson`, `topic`, `quiz`, etc.
*
* @since 3.0.0
*
* @param string|false $post_id Post ID.
* @param int $course_id Course ID.
* @param int $user_id User ID.
*/
do_action( 'learndash-' . $context . '-content-tab-listing-before', get_the_ID(), $course_id, $user_id );
$i = 0;
foreach ( $tabs as $tab ) :
// Skip if conditionally indicated.
if ( isset( $tab['condition'] ) && ! $tab['condition'] ) {
continue;
}
$tab_class = 'ld-tab-content ' . ( 0 === $i ? 'ld-visible' : '' );
/**
* Fires before any tab.
*
* The dynamic portion of the hook name, `$tab['id]`, refers id of the tab.
*
* @since 3.0.0
*
* @param int|false $post_id Post ID.
* @param string $context The context for which the hook is fired such as `course`, `lesson`, `topic`, `quiz`, etc.
* @param int $course_id Course ID.
* @param int $user_id User ID.
*/
do_action( 'learndash-content-tabs-' . $tab['id'] . '-before', get_the_ID(), $context, $course_id, $user_id );
?>
<div role="tabpanel" tabindex="0" aria-labelledby="<?php echo esc_attr( $tab['id'] ); ?>" class="<?php echo esc_attr( $tab_class ); ?>" id="<?php echo esc_attr( 'ld-tab-' . $tab['id'] . '-' . get_the_ID() ); ?>">
<?php // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Might output HTML?>
<?php echo $tab['content']; ?>
</div>
<?php
/**
* Fires after any tab.
*
* The dynamic portion of the hook name, `$tab['id]`, refers to the id of the tab.
*
* @since 3.0.0
*
* @param int|false $post_id Post ID.
* @param string $context The context for which the hook is fired such as `course`, `lesson`, `topic`, `quiz`, etc.
* @param int $course_id Course ID.
* @param int $user_id User ID.
*/
do_action( 'learndash-content-tabs-' . $tab['id'] . '-after', get_the_ID(), $context, $course_id, $user_id );
$i++;
endforeach;
/**
* Fires after the content tabs.
*
* @since 3.0.0
*
* @param int|false $post_id Post ID.
* @param int $course_id Course ID.
* @param int $user_id User ID.
*/
do_action( 'learndash-content-tab-listing-after', get_the_ID(), $course_id, $user_id );
/**
* Fires after the content tabs for any context.
*
* The dynamic portion of the hook name, `$context`, refers to the context for which the hook is fired,
* such as `course`, `lesson`, `topic`, `quiz`, etc.
*
* @since 3.0.0
*
* @param string|false $post_id Post ID.
* @param int $course_id Course ID.
* @param int $user_id User ID.
*/
do_action( 'learndash-' . $context . '-content-tab-listing-after', get_the_ID(), $course_id, $user_id );
?>
</div> <!--/.ld-tabs-content-->
</div> <!--/.ld-tabs-->
<?php
/**
* Fires after the content tabs.
*
* @since 3.0.0
*
* @param int|false $post_id Post ID.
* @param int $course_id Course ID.
* @param int $user_id User ID.
*/
do_action( 'learndash-content-tabs-after', get_the_ID(), $course_id, $user_id );
/**
* Fires before the content tabs for any context.
*
* The dynamic portion of the hook name, `$context`, refers to the context for which the hook is fired,
* such as `course`, `lesson`, `topic`, `quiz`, etc.
*
* @since 3.0.0
*
* @param int|false $post_id Post ID.
* @param int $course_id Course ID.
* @param int $user_id User ID.
*/
do_action( 'learndash-' . $context . '-content-tabs-after', get_the_ID(), $course_id, $user_id );