course-steps.php
13.8 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
<?php
/**
* LearnDash LD30 Displays a Course Prev/Next navigation.
*
* Available Variables:
*
* $course_id : (int) ID of Course
* $course_step_post : (object) WP_Post instance of lesson/topic post
* $user_id : (int) ID of User
* $course_settings : (array) Settings specific to current course
* $can_complete : (bool) Can the user mark this lesson/topic complete?
* $context : (string) Context of the usage. Either 'lesson', 'topic' or 'focus' use for Focus Mode header navigation.
*
* @since 3.0.0
*
* @package LearnDash\Templates\LD30
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! isset( $can_complete ) ) {
$can_complete = false;
}
// TODO @37designs this is a bit confusing still, as you can still navigate left / right on lessons even with topics.
if ( ( isset( $course_step_post ) ) && ( is_a( $course_step_post, 'WP_Post' ) ) && ( in_array( $course_step_post->post_type, learndash_get_post_types( 'course' ), true ) ) ) {
if ( learndash_get_post_type_slug( 'lesson' ) === $course_step_post->post_type ) {
$parent_id = absint( $course_id );
} else {
$parent_id = learndash_course_get_single_parent_step( $course_id, $course_step_post->ID );
}
} else {
$parent_id = ( get_post_type() === 'sfwd-lessons' ? absint( $course_id ) : learndash_course_get_single_parent_step( $course_id, get_the_ID() ) );
}
$learndash_previous_step_id = learndash_previous_post_link( null, 'id', $course_step_post );
if ( ( empty( $learndash_previous_step_id ) ) && ( learndash_get_post_type_slug( 'topic' ) === $course_step_post->post_type ) ) {
/**
* Filters whether to show parent previous link in the course navigation.
*
* @since 3.1.0
*
* @param boolean $show_previous_link Whether to show parent previous link.
* @param int $course_step_post ID of the lesson/topic post.
* @param int $user_id User ID.
* @param int $course_id Course ID.
*/
if ( apply_filters( 'learndash_show_parent_previous_link', true, $course_step_post, $user_id, $course_id ) ) {
$learndash_previous_step_id = learndash_previous_post_link( null, 'id', get_post( $parent_id ) );
}
}
$learndash_next_step_id = '';
$button_class = 'ld-button ' . ( 'focus' === $context ? 'ld-button-transparent' : '' );
/*
* See details for filter 'learndash_show_next_link' at https://developers.learndash.com/hook/learndash_show_next_link/
*
* @since version 2.3
*/
$current_complete = false;
if ( ( empty( $course_settings ) ) && ( ! empty( $course_id ) ) ) {
$course_settings = learndash_get_setting( $course_id );
}
if ( 'sfwd-topic' === $course_step_post->post_type ) {
$current_complete = learndash_is_topic_complete( $user_id, $course_step_post->ID, $course_id );
} elseif ( 'sfwd-lessons' === $course_step_post->post_type ) {
$current_complete = learndash_is_lesson_complete( $user_id, $course_step_post->ID, $course_id );
}
if ( learndash_lesson_hasassignments( $course_step_post ) ) {
$user_assignments = learndash_get_user_assignments( $course_step_post->ID, $user_id, absint( $course_id ), 'ids' );
$approved_assignments = learndash_assignment_list_approved( $user_assignments, $course_step_post->ID, $user_id );
if ( ! $approved_assignments ) {
$current_complete = false;
}
}
$learndash_maybe_show_next_step_link = $current_complete;
//if ( ( isset( $course_settings['course_disable_lesson_progression'] ) ) && ( 'on' === $course_settings['course_disable_lesson_progression'] ) ) {
$course_lesson_progression_enabled = learndash_lesson_progression_enabled( $course_id );
if ( ! $course_lesson_progression_enabled ) {
$learndash_maybe_show_next_step_link = true;
}
if ( $learndash_maybe_show_next_step_link !== true ) {
$bypass_course_limits_admin_users = learndash_can_user_bypass( $user_id, 'learndash_course_progression' );
if ( true === $bypass_course_limits_admin_users ) {
$learndash_maybe_show_next_step_link = true;
}
}
/**
* Filters whether to show the next link in the course navigation.
*
* @since 2.3.0
*
* @param bool $show_next_link Whether to show next link.
* @param int $user_id User ID.
* @param int $step_id ID of the lesson/topic post.
*
*/
$learndash_maybe_show_next_step_link = apply_filters( 'learndash_show_next_link', $learndash_maybe_show_next_step_link, $user_id, $course_step_post->ID );
// Only complete lessons/topics.
if ( ! in_array( $course_step_post->post_type, learndash_get_post_type_slug( array( 'lesson', 'topic' ) ), true ) ) {
$can_complete = false;
$current_complete = false;
$learndash_maybe_show_next_step_link = false;
}
if ( true === (bool) $learndash_maybe_show_next_step_link ) {
$learndash_next_step_id = learndash_next_post_link( null, 'id', $course_step_post );
if ( ( empty( $learndash_next_step_id ) ) && ( learndash_get_post_type_slug( 'topic' ) === $course_step_post->post_type ) ) {
$learndash_show_parent_next_link = false;
if ( ( ! $course_lesson_progression_enabled ) || ( true === $current_complete ) || ( learndash_is_lesson_complete( $user_id, $parent_id ) ) ) {
$learndash_show_parent_next_link = true;
}
/**
* Filters whether to show parent next link in the course navigation.
*
* @since 3.1.0
*
* @param bool $learndash_show_parent_next_link Whether to show parent next link.
* @param int $course_step_post ID of the lesson/topic post.
* @param int $user_id User ID.
* @param int $course_id Course ID.
*/
if ( apply_filters( 'learndash_show_parent_next_link', $learndash_show_parent_next_link, $course_step_post, $user_id, $course_id ) ) {
$learndash_next_step_id = learndash_next_post_link( null, 'id', get_post( $parent_id ) );
}
}
} elseif ( ( ! is_user_logged_in() ) && ( empty( $learndash_next_step_id ) ) ) {
$learndash_next_step_id = learndash_next_post_link( null, 'id', $course_step_post );
if ( ( empty( $learndash_next_step_id ) ) && ( learndash_get_post_type_slug( 'topic' ) === $course_step_post->post_type ) ) {
$learndash_next_step_id = learndash_next_post_link( null, 'id', get_post( $parent_id ) );
}
if ( ! empty( $learndash_next_step_id ) ) {
if ( ! learndash_is_sample( $learndash_next_step_id ) ) {
if ( ( ! isset( $course_settings['course_price_type'] ) ) || ( 'open' !== $course_settings['course_price_type'] ) ) {
$learndash_next_step_id = '';
}
}
}
}
/**
* Filters to override next step post ID.
*
* @since 3.1.2
*
* @param int $learndash_next_step_id The next step post ID.
* @param int $course_step_post The current step WP_Post ID.
* @param int $course_id The current Course ID.
* @param int $user_id The current User ID.
*
* @return int $learndash_next_step_id
*/
$learndash_next_step_id = apply_filters( 'learndash_next_step_id', $learndash_next_step_id, $course_step_post->ID, $course_id, $user_id );
/**
* Check if we need to show the Mark Complete form. see LEARNDASH-4722
*/
$parent_lesson_id = 0;
if ( $course_step_post->post_type == 'sfwd-lessons' ) {
$parent_lesson_id = $course_step_post->ID;
} elseif ( $course_step_post->post_type == 'sfwd-topic' || $course_step_post->post_type == 'sfwd-quiz' ) {
if ( LearnDash_Settings_Section::get_section_setting( 'LearnDash_Settings_Courses_Builder', 'shared_steps' ) == 'yes' ) {
$parent_lesson_id = learndash_course_get_single_parent_step( $course_id, $course_step_post->ID );
} else {
$parent_lesson_id = learndash_get_setting( $course_step_post, 'lesson' );
}
}
if ( ! empty( $parent_lesson_id ) ) {
$lesson_access_from = ld_lesson_access_from( $parent_lesson_id, $user_id, $course_id );
if ( ( empty( $lesson_access_from ) ) || ( ! empty( $bypass_course_limits_admin_users ) ) ) {
$complete_button = learndash_mark_complete( $course_step_post );
} else {
$complete_button = '';
}
} else {
$complete_button = learndash_mark_complete( $course_step_post );
}
if ( ( true === $current_complete ) && ( is_a( $course_step_post, 'WP_Post' ) ) ){
$incomplete_button = learndash_show_mark_incomplete( $course_step_post );
} else {
$incomplete_button = '';
}
?>
<div class="ld-content-actions">
<?php
/**
* Fires before the course steps (all locations).
*
* @since 3.0.0
*
* @param string|false $post_type Post type slug.
* @param int $course_id Course ID.
* @param int $user_id User ID.
*/
do_action( 'learndash-all-course-steps-before', get_post_type(), $course_id, $user_id );
/**
* Fires before the course steps 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_type Post type slug.
* @param int $course_id Course ID.
* @param int $user_id User ID.
*/
do_action( 'learndash-' . $context . '-course-steps-before', get_post_type(), $course_id, $user_id );
//$learndash_current_post_type = get_post_type();
?>
<div class="ld-content-action <?php if ( ! $learndash_previous_step_id ) : ?>ld-empty<?php endif; ?>">
<?php if ( $learndash_previous_step_id ) : ?>
<a class="<?php echo esc_attr( $button_class ); ?>" href="<?php echo esc_url( learndash_get_step_permalink( $learndash_previous_step_id, $course_id ) ); ?>">
<?php if ( is_rtl() ) { ?>
<span class="ld-icon ld-icon-arrow-right"></span>
<?php } else { ?>
<span class="ld-icon ld-icon-arrow-left"></span>
<?php } ?>
<span class="ld-text"><?php echo esc_html( learndash_get_label_course_step_previous( get_post_type( $learndash_previous_step_id ) ) ); ?></span>
</a>
<?php endif; ?>
</div>
<?php
if ( $parent_id && 'focus' !== $context ) :
if ( $learndash_maybe_show_next_step_link ) :
?>
<div class="ld-content-action">
<?php
if ( ( true === $can_complete ) && ( true !== $current_complete ) && ( ! empty( $complete_button ) ) ) :
echo learndash_mark_complete( $course_step_post );
elseif ( ( true === $can_complete ) && ( true === $current_complete ) && ( ! empty( $incomplete_button ) ) ) :
echo $incomplete_button;
?>
<?php endif; ?>
<a href="<?php echo esc_url( learndash_get_step_permalink( $parent_id, $course_id ) ); ?>" class="ld-primary-color ld-course-step-back"><?php echo learndash_get_label_course_step_back( get_post_type( $parent_id ) ); ?></a>
</div>
<div class="ld-content-action <?php if ( ( ! $learndash_next_step_id ) ) : ?>ld-empty<?php endif; ?>">
<?php if ( $learndash_next_step_id ) : ?>
<a class="<?php echo esc_attr( $button_class ); ?>" href="<?php echo esc_url( learndash_get_step_permalink( $learndash_next_step_id, $course_id ) ); ?>">
<span class="ld-text"><?php echo learndash_get_label_course_step_next( get_post_type( $learndash_next_step_id ) ); ?></span>
<?php if ( is_rtl() ) { ?>
<span class="ld-icon ld-icon-arrow-left"></span>
<?php } else { ?>
<span class="ld-icon ld-icon-arrow-right"></span>
<?php } ?>
</a>
<?php endif; ?>
</div>
<?php else : ?>
<a href="<?php echo esc_attr( learndash_get_step_permalink( $parent_id, $course_id ) ); ?>" class="ld-primary-color"><?php echo learndash_get_label_course_step_back( get_post_type( $parent_id ) ); ?></a>
<div class="ld-content-action <?php if ( ( ! $can_complete ) && ( ! $learndash_next_step_id ) ) : ?>ld-empty<?php endif; ?>">
<?php
if ( ( true === $can_complete ) && ( true !== $current_complete ) && ( ! empty( $complete_button ) ) ) :
echo $complete_button;
elseif ( $learndash_next_step_id ) :
?>
<a class="<?php echo esc_attr( $button_class ); ?>" href="<?php echo esc_attr( learndash_get_step_permalink( $learndash_next_step_id, $course_id ) ); ?>">
<span class="ld-text"><?php echo learndash_get_label_course_step_next( get_post_type( $learndash_next_step_id ) ); ?></span>
<?php if ( is_rtl() ) { ?>
<span class="ld-icon ld-icon-arrow-left"></span>
<?php } else { ?>
<span class="ld-icon ld-icon-arrow-right"></span>
<?php } ?>
</a>
<?php endif; ?>
</div>
<?php endif; ?>
<?php elseif ( $parent_id && 'focus' === $context ) : ?>
<div class="ld-content-action <?php if ( ( ! $can_complete ) && ( ! $learndash_next_step_id ) ) : ?>ld-empty<?php endif; ?>">
<?php
if ( ( true === $can_complete ) && ( true !== $current_complete ) && ( ! empty( $complete_button ) ) ) :
echo learndash_mark_complete( $course_step_post );
elseif ( ( true === $can_complete ) && ( true === $current_complete ) && ( ! empty( $incomplete_button ) ) ) :
echo $incomplete_button;
elseif ( $learndash_next_step_id ) :
?>
<a class="<?php echo esc_attr( $button_class ); ?>" href="<?php echo esc_attr( learndash_get_step_permalink( $learndash_next_step_id, $course_id ) ); ?>">
<span class="ld-text"><?php echo learndash_get_label_course_step_next( get_post_type( $learndash_next_step_id ) ); ?></span>
<?php if ( is_rtl() ) { ?>
<span class="ld-icon ld-icon-arrow-left"></span>
<?php } else { ?>
<span class="ld-icon ld-icon-arrow-right"></span>
<?php } ?>
</a>
<?php endif; ?>
</div>
<?php endif; ?>
<?php
/**
* Fires after the course steps (all locations).
*
* @since 3.0.0
*
* @param string|false $post_type Post type slug.
* @param int $course_id Course ID.
* @param int $user_id User ID.
*/
do_action( 'learndash-all-course-steps-after', get_post_type(), $course_id, $user_id );
/**
* Fires after the course steps 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_type Post type slug.
* @param int $course_id Course ID.
* @param int $user_id User ID.
*/
do_action( 'learndash-' . $context . '-course-steps-after', get_post_type(), $course_id, $user_id );
?>
</div> <!--/.ld-topic-actions-->
<?php
//endif;