masthead.php
11.4 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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
<?php
/**
* LearnDash LD30 focus mode masthead.
*
* @since 3.0.0
*
* @package LearnDash\Templates\LD30
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
global $post;
$header = array(
'logo_alt' => '',
'logo_url' => '',
'text' => '',
'text_url' => '',
);
$header['logo'] = LearnDash_Settings_Section::get_section_setting( 'LearnDash_Settings_Theme_LD30', 'login_logo' );
if ( ! empty( $header['logo'] ) ) {
$header['logo_alt'] = get_post_meta( $header['logo'], '_wp_attachment_image_alt', true );
/**
* Filters Focus mode header logo alternative text.
* This filter will be called only if there is a logo set in LearnDash plugin settings.
*
* @since 3.1.0
*
* @param string $logo_alt Header logo alternative text.
* @param int $course_id Course ID.
* @param int $user_id User ID.
*/
$header['logo_alt'] = apply_filters( 'learndash_focus_header_logo_alt', $header['logo_alt'], $course_id, $user_id );
/**
* Filters Focus mode header logo URL.
* This filter will be called only if there is a logo set in LearnDash plugin settings.
*
* @since 3.1.0
*
* @param string $logo_url Header logo URL.
* @param int $course_id Course ID.
* @param int $user_id User ID.
*/
$header['logo_url'] = apply_filters( 'learndash_focus_header_logo_url', get_home_url(), $course_id, $user_id );
} else {
/**
* Filters Focus mode header text. This text is used to display in place of the logo.
* This filter will be called only if there is no logo set in LearnDash plugin settings.
*
* @since 3.1.0
*
* @param string $header_text Focus mode header text.
* @param int $course_id Course ID.
* @param int $user_id User ID.
*/
$header['text'] = apply_filters( 'learndash_focus_header_text', '', $course_id, $user_id );
if ( ! empty( $header['text'] ) ) {
/**
* Filters Focus mode header text URL.
* This filter will be called only if there is no logo set in LearnDash plugin settings.
*
* @since 3.1.0
*
* @param string $header_text_url Header Text URL
* @param int $course_id Course ID.
* @param int $user_id User ID.
*/
$header['text_url'] = apply_filters( 'learndash_focus_header_text_url', '', $course_id, $user_id );
}
}
?>
<div class="ld-focus-header">
<?php
/**
* Fires before the header mobile nav in the focus template.
*
* @since 3.0.0
*
* @param int $course_id Course ID.
* @param int $user_id User ID.
*/
do_action( 'learndash-focus-header-mobile-nav-before', $course_id, $user_id );
?>
<div class="ld-mobile-nav">
<a href="#" class="ld-trigger-mobile-nav" aria-label="<?php esc_attr_e( 'Menu', 'learndash' ); ?>">
<span class="bar-1"></span>
<span class="bar-2"></span>
<span class="bar-3"></span>
</a>
</div>
<?php
/**
* Fires before the header logo in the focus template.
*
* @since 3.0.0
*
* @param int $course_id Course ID.
* @param int $user_id User ID.
*/
do_action( 'learndash-focus-header-logo-before', $course_id, $user_id );
?>
<div class="ld-brand-logo">
<?php
$header_element = '';
if ( ! empty( $header['logo'] ) ) {
if ( ! empty( $header['logo_url'] ) ) {
$header_element .= '<a href="' . esc_url( $header['logo_url'] ) . '">';
}
$header_element .= '<img src="' . esc_url( wp_get_attachment_url( $header['logo'] ) ) . '" alt="' . esc_html( $header['logo_alt'] ) . '" />';
if ( ! empty( $header['logo_url'] ) ) {
$header_element .= '</a>';
}
} else {
if ( ! empty( $header['text'] ) ) {
if ( ! empty( $header['text_url'] ) ) {
$header_element .= '<a href="' . esc_url( $header['text_url'] ) . '">';
}
$header_element .= esc_html( $header['text'] );
if ( ! empty( $header['text_url'] ) ) {
$header_element .= '</a>';
}
}
}
/**
* Filters Focus mode Header element markup.
*
* @since 3.1.0
*
* @param string $header_element Focus mode header element markup.
* @param array $header Array of header element details keyed logo_alt, logo_url, text, text_url.
* @param int $course_id Course ID.
* @param int $user_id User ID.
*/
$header_element = apply_filters( 'learndash_focus_header_element', $header_element, $header, $course_id, $user_id );
echo $header_element; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Outputs HTML for the header element
?>
</div>
<?php
/**
* Fires after the header logo in the focus template.
*
* @since 3.0.0
*
* @param int $course_id Course ID.
* @param int $user_id User ID.
*/
do_action( 'learndash-focus-header-logo-after', $course_id, $user_id );
if ( is_user_logged_in() ) {
learndash_get_template_part(
'modules/progress.php',
array(
'course_id' => $course_id,
'user_id' => $user_id,
'context' => 'focus',
),
true
);
}
/**
* Fires before the header nav in the focus template.
*
* @since 3.0.0
*
* @param int $course_id Course ID.
* @param int $user_id User ID.
*/
do_action( 'learndash-focus-header-nav-before', $course_id, $user_id );
$can_complete = false;
if ( ( ! learndash_lesson_progression_enabled( $course_id ) ) || ( true === learndash_can_user_bypass( $user_id, 'learndash_course_progression' ) ) ) {
if ( learndash_user_is_course_children_progress_complete( $user_id, $course_id, $post->ID ) ) {
$can_complete = true;
} else {
$can_complete = false;
}
} else {
$can_complete = learndash_can_complete_step( $user_id, $post->ID, $course_id, true );
}
learndash_get_template_part(
'modules/course-steps.php',
array(
'course_id' => $course_id,
'course_step_post' => $post,
'user_id' => $user_id,
'course_settings' => isset( $course_settings ) ? $course_settings : array(),
'can_complete' => $can_complete,
'context' => 'focus',
),
true
);
/**
* Fires after the header nav in the focus template.
*
* @since 3.0.0
*
* @param int $course_id Course ID.
* @param int $user_id User ID.
*/
do_action( 'learndash-focus-header-nav-after', $course_id, $user_id );
?>
<?php if ( is_user_logged_in() ) : ?>
<div class="ld-user-menu">
<?php
/**
* Fires before the user menu in the focus template.
*
* @since 3.0.0
*
* @param int $course_id Course ID.
* @param int $user_id User ID.
*/
do_action( 'learndash-focus-header-user-menu-before', $course_id, $user_id );
$user_data = get_userdata( $user_id );
?>
<span class="ld-text ld-user-welcome-text">
<?php
echo sprintf(
// translators: Focus mode welcome placeholder.
esc_html_x( 'Hello, %s!', 'Focus mode welcome placeholder', 'learndash' ),
/**
* Filters Focus mode user welcome name.
*
* @since 3.0.3
*
* @param string $user_nicename User nice name.
* @param \WP_User|boolean $user_data User Object or false if no user found.
*/
wp_kses_post( apply_filters( 'ld_focus_mode_welcome_name', $user_data->user_nicename, $user_data ) )
);
?>
</span>
<span class="ld-profile-avatar">
<?php
/**
* Fires before the user avatar in the focus template.
*
* @since 3.0.0
*
* @param int $course_id Course ID.
* @param int $user_id User ID.
*/
do_action( 'learndash-focus-header-avatar-before', $course_id, $user_id );
echo get_avatar( $user_id );
/**
* Fires after the user avatar in the focus template.
*
* @since 3.0.0
*
* @param int $course_id Course ID.
* @param int $user_id User ID.
*/
do_action( 'learndash-focus-header-avatar-after', $course_id, $user_id );
?>
</span> <!--/.ld-profile-avatar-->
<?php
/**
* Fires before the header user dropdown in the focus template.
*
* @since 3.0.0
*
* @param int $course_id Course ID.
* @param int $user_id User ID.
*/
do_action( 'learndash-focus-header-user-dropdown-before', $course_id, $user_id );
?>
<span class="ld-user-menu-items">
<?php
$custom_menu_items = learndash_30_get_custom_focus_menu_items();
$menu_items = array(
'course-home' => array(
'url' => get_the_permalink( $course_id ),
'label' => sprintf(
// translators: Placeholder for course home link.
esc_html_x( '%s Home', 'Placeholder for course home link', 'learndash' ),
LearnDash_Custom_Label::get_label( 'course' )
),
),
);
if ( $custom_menu_items ) :
foreach ( $custom_menu_items as $menu_item ) :
$menu_items[ $menu_item->post_name ] = array(
'url' => $menu_item->url,
'label' => $menu_item->title,
'classes' => esc_attr( 'ld-focus-menu-link ld-focus-menu-' . $menu_item->post_name ),
'target' => '',
'attr_title' => '',
'xfn' => '',
);
if ( ( property_exists( $menu_item, 'classes' ) ) && ( is_array( $menu_item->classes ) ) ) {
$classes = array_filter( $menu_item->classes, 'strlen' );
if ( ! empty( $classes ) ) {
$menu_items[ $menu_item->post_name ]['classes'] .= ' ' . implode( ' ', $classes );
}
}
if ( ( property_exists( $menu_item, 'target' ) ) && ( ! empty( $menu_item->target ) ) ) {
$menu_items[ $menu_item->post_name ]['target'] = esc_attr( $menu_item->target );
}
if ( ( property_exists( $menu_item, 'attr_title' ) ) && ( ! empty( $menu_item->attr_title ) ) ) {
$menu_items[ $menu_item->post_name ]['attr_title'] = esc_attr( $menu_item->attr_title );
}
if ( ( property_exists( $menu_item, 'xfn' ) ) && ( ! empty( $menu_item->xfn ) ) ) {
$menu_items[ $menu_item->post_name ]['xfn'] = esc_attr( $menu_item->xfn );
}
endforeach;
endif;
$menu_items['logout'] = array(
'url' => wp_logout_url( get_the_permalink( $course_id ) ),
'label' => __( 'Logout', 'learndash' ),
);
/**
* Focus Mode Header menu items.
*
* @since 3.2.3
*
* @param array $menu_items Array of menu items.
* @param int $course_id Course ID.
* @param int $user_id User ID.
*/
$menu_items = apply_filters( 'learndash_focus_header_user_dropdown_items', $menu_items, $course_id, $user_id );
if ( $menu_items && ! empty( $menu_items ) ) :
foreach ( $menu_items as $slug => $item ) :
?>
<a <?php if ( ! empty( $item['classes'] ) ) { ?>
class="<?php echo esc_attr( $item['classes'] ); ?>"
<?php } ?> <?php if ( ! empty( $item['target'] ) ) { ?>
target="<?php echo esc_attr( $item['target'] ); ?>"
<?php } ?> <?php if ( ! empty( $item['xfn'] ) ) { ?>
rel="<?php echo esc_attr( $item['xfn'] ); ?>"
<?php } ?> <?php if ( ! empty( $item['attr_title'] ) ) { ?>
title="<?php echo esc_attr( $item['attr_title'] ); ?>"
<?php } ?> href="<?php echo esc_url( $item['url'] ); ?>"><?php echo apply_filters( 'the_title', $item['label'], 0 ); ?></a>
<?php
endforeach;
endif;
?>
</span> <!--/.ld-user-menu-items-->
<?php
/**
* Fires after the header user dropdown in the focus template.
*
* @since 3.0.0
*
* @param int $course_id Course ID.
* @param int $user_id User ID.
*/
do_action( 'learndash-focus-header-user-dropdown-after', $course_id, $user_id );
?>
</div>
<?php
endif;
/**
* Fires after the header user dropdown in the focus template.
*
* @since 3.0.0
*
* @param int $course_id Course ID.
* @param int $user_id User ID.
*/
do_action( 'learndash-focus-header-usermenu-after', $course_id, $user_id );
?>
</div> <!--/.ld-focus-header-->