ld_course_complete.php
2.35 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
<?php
/**
* LearnDash `[course_complete]` shortcode processing.
*
* @since 2.1.0
* @package LearnDash\Shortcodes
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Builds the `[course_complete]` shortcode output.
*
* Shortcode that shows the content if the user has completed the course.
*
* @global boolean $learndash_shortcode_used
*
* @since 2.1.0
*
* @param array $atts {
* An array of shortcode attributes. Default empty array.
*
* @type string $content The shortcode content. Default empty.
* @type int $course_id Course ID. Default false.
* @type int $user_id User ID. Default false.
* @type boolean $autop Whether to replace line breaks with paragraph elements. Default true.
* }
* @param string $content The shortcode content. Default empty.
* @param string $shortcode_slug The shortcode slug. Default 'course_complete'.
*
* @return string The `course_complete` shortcode output.
*/
function learndash_course_complete_shortcode( $atts = array(), $content = '', $shortcode_slug = 'course_complete' ) {
global $learndash_shortcode_used;
$learndash_shortcode_used = true;
if ( ! empty( $content ) ) {
if ( ! is_array( $atts ) ) {
if ( ! empty( $atts ) ) {
$atts = array( $atts );
} else {
$atts = array();
}
}
$defaults = array(
'content' => $content,
'course_id' => false,
'user_id' => false,
'autop' => true,
);
$atts = wp_parse_args( $atts, $defaults );
if ( ( true === $atts['autop'] ) || ( 'true' === $atts['autop'] ) || ( '1' === $atts['autop'] ) ) {
$atts['autop'] = true;
} else {
$atts['autop'] = false;
}
/** This filter is documented in includes/shortcodes/ld_course_resume.php */
$atts = apply_filters( 'learndash_shortcode_atts', $atts, $shortcode_slug );
/**
* Filters `course_complete` shortcode attributes.
*
* @param array $attributes An array of course_complete shortcode attributes.
*/
$atts = apply_filters( 'learndash_course_complete_shortcode_atts', $atts );
$atts['content'] = learndash_course_status_content_shortcode( $atts, $atts['content'], esc_html__( 'Completed', 'learndash' ) );
return SFWD_LMS::get_template(
'learndash_course_complete_message',
array(
'shortcode_atts' => $atts,
),
false
);
}
return '';
}
add_shortcode( 'course_complete', 'learndash_course_complete_shortcode', 10, 3 );