course.php
19.3 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
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
<?php
/**
* LearnDash LD30 Displays the infobar in course context
*
* Will have access to same variables as course.php
*
* Available Variables:
* $course_id : (int) ID of the course
* $course : (object) Post object of the course
* $course_settings : (array) Settings specific to current course
*
* $courses_options : Options/Settings as configured on Course Options page
* $lessons_options : Options/Settings as configured on Lessons Options page
* $quizzes_options : Options/Settings as configured on Quiz Options page
*
* $user_id : Current User ID
* $logged_in : User is logged in
* $current_user : (object) Currently logged in user object
*
* $course_status : Course Status
* $has_access : User has access to course or is enrolled.
* $materials : Course Materials
* $has_course_content : Course has course content
* $lessons : Lessons Array
* $quizzes : Quizzes Array
* $lesson_progression_enabled : (true/false)
* $has_topics : (true/false)
* $lesson_topics : (array) lessons topics
*
* @since 3.0.0
*
* @package LearnDash\Templates\LD30\Modules
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
use LearnDash\Core\Models\Product;
/**
* Product object.
*
* @var Product $ld_product
*/
$ld_product = Product::find( $course_id );
$course_pricing = learndash_get_course_price( $course_id );
if ( is_user_logged_in() && isset( $has_access ) && $has_access ) :
?>
<div class="ld-course-status ld-course-status-enrolled">
<?php
/**
* Fires inside the breadcrumbs (before).
*
* @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-course-infobar-access-progress-before', get_post_type(), $course_id, $user_id );
learndash_get_template_part(
'modules/progress.php',
array(
'context' => 'course',
'user_id' => $user_id,
'course_id' => $course_id,
),
true
);
/**
* Fires inside the breadcrumbs after the progress bar.
*
* @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-course-infobar-access-progress-after', get_post_type(), $course_id, $user_id );
learndash_status_bubble( $course_status );
/**
* Fires inside the breadcrumbs after the status.
*
* @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-course-infobar-access-status-after', get_post_type(), $course_id, $user_id );
?>
</div> <!--/.ld-course-status-->
<?php elseif ( 'open' !== $course_pricing['type'] ) : ?>
<div class="ld-course-status ld-course-status-not-enrolled">
<?php
/**
* Fires inside the un-enrolled course infobox before the status.
*
* @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-course-infobar-noaccess-status-before', get_post_type(), $course_id, $user_id );
?>
<div class="ld-course-status-segment ld-course-status-seg-status">
<?php
/**
* Fires before the course infobar status cell.
*
* @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-course-infobar-status-cell-before', get_post_type(), $course_id, $user_id );
?>
<span class="ld-course-status-label"><?php echo esc_html__( 'Current Status', 'learndash' ); ?></span>
<div class="ld-course-status-content">
<?php
$ld_seats_available = $ld_product->get_seats_available();
$ld_seats_available_text = ( ! empty( $ld_seats_available )
? sprintf(
// translators: placeholder: number of places remaining.
_nx(
'(%s place remaining)',
'(%s places remaining)',
$ld_seats_available,
'placeholder: number of places remaining',
'learndash'
),
number_format_i18n( $ld_seats_available )
)
: '' );
?>
<?php if ( $ld_product->has_ended() ) : ?>
<span class="ld-status ld-status-waiting ld-tertiary-background" data-ld-tooltip="
<?php
printf(
// translators: placeholder: course.
esc_attr_x( 'This %s has ended', 'placeholder: course', 'learndash' ),
esc_html( learndash_get_custom_label_lower( 'course' ) )
);
?>
">
<?php esc_html_e( 'Ended', 'learndash' ); ?>
</span>
<?php elseif ( ! $ld_product->has_started() ) : ?>
<span class="ld-status ld-status-waiting ld-tertiary-background" data-ld-tooltip="
<?php
if ( ! $ld_product->can_be_purchased() ) :
printf(
// translators: placeholder: course, course start date.
esc_attr_x( 'This %1$s starts on %2$s', 'placeholder: course, course start date', 'learndash' ),
esc_html( learndash_get_custom_label_lower( 'course' ) ),
esc_html( learndash_adjust_date_time_display( $ld_product->get_start_date() ) )
);
else :
printf(
// translators: placeholder: course, course start date.
esc_attr_x( 'It is a pre-order. Enroll in this %1$s to get access after %2$s', 'placeholder: course, course start date', 'learndash' ),
esc_html( learndash_get_custom_label_lower( 'course' ) ),
esc_html( learndash_adjust_date_time_display( $ld_product->get_start_date() ) )
);
endif;
?>
">
<?php esc_html_e( 'Pre-order', 'learndash' ); ?>
<?php echo esc_html( $ld_seats_available_text ); ?>
</span>
<?php else : ?>
<span class="ld-status ld-status-waiting ld-tertiary-background" data-ld-tooltip="
<?php
if ( $ld_product->can_be_purchased() ) :
printf(
// translators: placeholder: course.
esc_attr_x( 'Enroll in this %s to get access', 'placeholder: course', 'learndash' ),
esc_html( learndash_get_custom_label_lower( 'course' ) )
);
else :
printf(
// translators: placeholder: course.
esc_attr_x( 'This %s is not available', 'placeholder: course', 'learndash' ),
esc_html( learndash_get_custom_label_lower( 'course' ) )
);
endif;
?>
">
<?php esc_html_e( 'Not Enrolled', 'learndash' ); ?>
<?php echo esc_html( $ld_seats_available_text ); ?>
</span>
<?php endif; ?>
</div>
<?php
/**
* Fires after the course infobar status cell.
*
* @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-course-infobar-status-cell-after', get_post_type(), $course_id, $user_id );
?>
</div> <!--/.ld-course-status-segment-->
<?php
/**
* Fires inside the un-enrolled course infobox before the price.
*
* @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-course-infobar-noaccess-price-before', get_post_type(), $course_id, $user_id );
?>
<div class="ld-course-status-segment ld-course-status-seg-price ld-course-status-mode-<?php echo esc_attr( $course_pricing['type'] ); ?>">
<?php
/**
* Fires before the course infobar price cell.
*
* @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-course-infobar-price-cell-before', get_post_type(), $course_id, $user_id );
?>
<span class="ld-course-status-label"><?php echo esc_html__( 'Price', 'learndash' ); ?></span>
<div class="ld-course-status-content">
<?php
// Some simple price settings validation logic. Not 100%.
$course_pricing = wp_parse_args(
$course_pricing,
array(
'type' => LEARNDASH_DEFAULT_COURSE_PRICE_TYPE,
'price' => '',
'interval' => '',
'frequency' => '',
'trial_price' => '',
'trial_interval' => '',
'trial_frequency' => '',
'repeats' => '',
'repeat_frequency' => '',
)
);
if ( 'subscribe' === $course_pricing['type'] ) {
if ( ( empty( $course_pricing['price'] ) ) || ( empty( $course_pricing['interval'] ) ) || ( empty( $course_pricing['frequency'] ) ) ) {
$course_pricing['type'] = LEARNDASH_DEFAULT_COURSE_PRICE_TYPE;
$course_pricing['interval'] = '';
$course_pricing['frequency'] = '';
$course_pricing['trial_price'] = '';
$course_pricing['trial_interval'] = '';
$course_pricing['trial_frequency'] = '';
$course_pricing['repeats'] = '';
$course_pricing['repeat_frequency'] = '';
} else {
if ( empty( $course_pricing['trial_price'] ) ) {
$course_pricing['trial_price'] = 0;
} elseif ( ( empty( $course_pricing['trial_interval'] ) ) || ( empty( $course_pricing['trial_frequency'] ) ) ) {
$course_pricing['trial_price'] = '';
}
}
}
if ( 'subscribe' !== $course_pricing['type'] ) {
?>
<span class="ld-course-status-price">
<?php
if ( ! empty( $course_pricing['price'] ) ) {
echo wp_kses_post( learndash_get_price_formatted( $course_pricing['price'] ) );
} elseif ( in_array( $course_pricing['type'], array( 'closed', 'free' ), true ) ) {
/**
* Filters label to be displayed when there is no price set for a course or it is closed.
*
* @since 3.0.0
*
* @param string $label The label displayed when there is no price.
*/
$label = apply_filters( 'learndash_no_price_price_label', ( 'closed' === $course_pricing['type'] ? __( 'Closed', 'learndash' ) : __( 'Free', 'learndash' ) ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Late escaped on output
echo esc_html( $label );
}
?>
</span>
<?php
} elseif ( 'subscribe' === $course_pricing['type'] ) {
if ( ! empty( $course_pricing['price'] ) ) {
if ( ! empty( $course_pricing['trial_frequency'] ) ) {
?>
<span class="ld-course-status-trial-price">
<?php
echo '<p class="ld-text ld-trial-text">';
echo wp_kses_post( learndash_get_price_formatted( $course_pricing['trial_price'] ) );
echo '</p>';
echo '<p class="ld-trial-pricing ld-pricing">';
if ( ( ! empty( $course_pricing['trial_interval'] ) ) && ( ! empty( $course_pricing['trial_frequency'] ) ) ) {
printf(
// translators: placeholders: Trial interval, Trial frequency.
esc_html_x( 'Trial price for %1$s %2$s, then', 'placeholders: Trial interval, Trial frequency', 'learndash' ),
absint( $course_pricing['trial_interval'] ),
esc_html( $course_pricing['trial_frequency'] )
);
}
echo '</p>'; // closing '<p class="ld-trial-pricing ld-pricing">'
?>
</span>
<span class="ld-course-status-course-price">
<?php
echo '<p class="ld-text ld-course-text">';
echo wp_kses_post( learndash_get_price_formatted( $course_pricing['price'] ) );
echo '</p>';
echo '<p class="ld-course-pricing ld-pricing">';
if ( ( ! empty( $course_pricing['interval'] ) ) && ( ! empty( $course_pricing['frequency'] ) ) ) {
printf(
// translators: placeholders: %1$s Interval of recurring payments (number), %2$s Frequency of recurring payments: day, week, month or year.
esc_html_x( 'Full price every %1$s %2$s afterward', 'Recurring duration message', 'learndash' ),
absint( $course_pricing['interval'] ),
esc_html( $course_pricing['frequency'] )
);
if ( ! empty( $course_pricing['repeats'] ) ) {
echo ' ';
printf(
// translators: placeholders: %1$s Number of times the recurring payment repeats, %2$s Frequency of recurring payments: day, week, month, year.
esc_html__( 'for %1$s %2$s', 'learndash' ),
// Get correct total time by multiplying interval by number of repeats
absint( $course_pricing['interval'] * $course_pricing['repeats'] ),
esc_html( $course_pricing['repeat_frequency'] )
);
}
}
echo '</p>'; // closing '<p class="ld-course-pricing ld-pricing">'.
?>
</span>
<?php
} else {
?>
<span class="ld-course-status-price">
<?php
if ( ! empty( $course_pricing['price'] ) ) {
echo wp_kses_post( learndash_get_price_formatted( $course_pricing['price'] ) );
}
?>
</span>
<span class="ld-text ld-recurring-duration">
<?php
if ( ( ! empty( $course_pricing['interval'] ) ) && ( ! empty( $course_pricing['frequency'] ) ) ) {
echo sprintf(
// translators: Recurring duration message.
esc_html_x( 'Every %1$s %2$s', 'Recurring duration message', 'learndash' ),
esc_html( $course_pricing['interval'] ),
esc_html( $course_pricing['frequency'] )
);
if ( ( ! empty( $course_pricing['repeats'] ) ) && ( ! empty( $course_pricing['repeat_frequency'] ) ) ) {
printf(
// translators: placeholders: %1$s Number of times the recurring payment repeats, %2$s Frequency of recurring payments: day, week, month, year.
esc_html__( ' for %1$s %2$s', 'learndash' ),
// Get correct total time by multiplying interval by number of repeats
absint( $course_pricing['interval'] * $course_pricing['repeats'] ),
esc_html( $course_pricing['repeat_frequency'] )
);
}
}
?>
</span>
<?php
}
}
}
?>
</div>
<?php
/**
* Fires after the infobar price cell.
*
* @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-course-infobar-price-cell-after', get_post_type(), $course_id, $user_id );
?>
</div> <!--/.ld-course-status-segment-->
<?php
/**
* Fires inside the un-enrolled course infobox before the action.
*
* @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-course-infobar-noaccess-action-before', get_post_type(), $course_id, $user_id );
/**
* Filters infobar course status segment CSS class.
*
* @since 3.0.0
*
* @param string $segment_class The List of course segment CSS class.
*/
$course_status_class = apply_filters(
'ld-course-status-segment-class',
'ld-course-status-segment ld-course-status-seg-action status-' .
( isset( $course_pricing['type'] ) ? sanitize_title( $course_pricing['type'] ) : '' )
);
?>
<div class="<?php echo esc_attr( $course_status_class ); ?>">
<span class="ld-course-status-label">
<?php
if ( $ld_product->can_be_purchased() ) {
echo esc_html_e( 'Get Started', 'learndash' );
}
?>
</span>
<div class="ld-course-status-content">
<div class="ld-course-status-action">
<?php
/**
* Fires before the course infobar action cell.
*
* @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-course-infobar-action-cell-before', get_post_type(), $course_id, $user_id );
$login_model = LearnDash_Settings_Section::get_section_setting( 'LearnDash_Settings_Theme_LD30', 'login_mode_enabled' );
/** This filter is documented in themes/ld30/includes/shortcodes.php */
$login_url = apply_filters( 'learndash_login_url', ( 'yes' === $login_model ? '#login' : wp_login_url( get_permalink() ) ) );
switch ( $course_pricing['type'] ) {
case ( 'open' ):
case ( 'free' ):
/**
* Filters whether to show login modal.
*
* @since 3.0.0
*
* @param boolean $show_login_modal Whether to show login modal.
* @param int $course_id Course ID.
* @param int $user_id User ID.
*/
if (
apply_filters( 'learndash_login_modal', true, $course_id, $user_id )
&& ! is_user_logged_in()
&& $ld_product->can_be_purchased()
) :
echo '<a class="ld-button" href="' . esc_url( $login_url ) . '">' . esc_html__( 'Login to Enroll', 'learndash' ) . '</a></span>';
else :
echo learndash_payment_buttons( $post ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Outputs Payment button HTML
endif;
break;
case ( 'paynow' ):
case ( 'subscribe' ):
$ld_payment_buttons = learndash_payment_buttons( $post );
echo $ld_payment_buttons; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Outputs Button HTML
/** This filter is documented in themes/ld30/templates/modules/infobar/course.php */
if (
apply_filters( 'learndash_login_modal', true, $course_id, $user_id )
&& ! is_user_logged_in()
&& $ld_product->can_be_purchased()
) :
echo '<span class="ld-text">';
if ( ! empty( $ld_payment_buttons ) ) {
esc_html_e( 'or', 'learndash' );
}
echo '<a class="ld-login-text" href="' . esc_url( $login_url ) . '">' . esc_html__( 'Login', 'learndash' ) . '</a></span>';
endif;
break;
case ( 'closed' ):
$button = learndash_payment_buttons( $post );
if ( empty( $button ) ) :
echo '<span class="ld-text">' . sprintf(
// translators: placeholder: course.
esc_html_x( 'This %s is currently closed', 'placeholder: course', 'learndash' ),
esc_html( learndash_get_custom_label_lower( 'course' ) )
)
. '</span>';
else :
echo $button; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Outputs Button HTML
endif;
break;
}
/**
* Fires after the course infobar action cell.
*
* @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-course-infobar-action-cell-after', get_post_type(), $course_id, $user_id );
?>
</div>
</div>
</div> <!--/.ld-course-status-action-->
<?php
/**
* Fires inside the un-enrolled course infobox after the price
*
* @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-course-infobar-noaccess-price-after', get_post_type(), $course_id, $user_id );
?>
</div> <!--/.ld-course-status-->
<?php endif; ?>