ld_course_resume.php 0000666 00000006105 15214030011 0010605 0 ustar 00 0,
'user_id' => get_current_user_id(),
'label' => '',
'html_class' => 'ld-course-resume',
'html_id' => '',
'button' => true,
);
$atts = shortcode_atts( $defaults, $atts );
$atts['course_id'] = absint( $atts['course_id'] );
$atts['user_id'] = absint( $atts['user_id'] );
if ( empty( $atts['course_id'] ) ) {
$atts['course_id'] = learndash_get_course_id();
if ( ( empty( $atts['course_id'] ) ) && ( ! empty( $atts['user_id'] ) ) ) {
$atts['course_id'] = learndash_get_last_active_course( $atts['user_id'] );
}
}
if ( empty( $atts['label'] ) ) {
if ( ! empty( $content ) ) {
$atts['label'] = $content;
$content = '';
} else {
// translators: placeholder: Course.
$atts['label'] = sprintf( esc_html_x( 'Resume %s', 'placeholder: Course', 'learndash' ), LearnDash_Custom_Label::get_label( 'course' ) );
}
}
if ( ( 'false' === $atts['button'] ) || ( '0' === $atts['button'] ) ) {
$atts['button'] = false;
} else {
$atts['button'] = true;
$atts['html_class'] .= ' ld-button ';
}
/**
* Let the outside world filter the shortcode attributes.
*/
$atts = apply_filters( 'learndash_shortcode_atts_ld_course_resume', $atts );
$atts = apply_filters( 'learndash_shortcode_atts', $atts, 'ld_course_resume' );
if ( ( ! empty( $atts['user_id'] ) ) && ( ! empty( $atts['course_id'] ) ) ) {
// We only output for 'in progress' courses.
$course_status = learndash_course_status( $atts['course_id'], $atts['user_id'], true );
if ( $course_status === 'in-progress' ) {
$user_course_last_step_id = learndash_user_course_last_step( $atts['user_id'], $atts['course_id'] );
if ( ! empty( $user_course_last_step_id ) ) {
$progress = learndash_get_course_progress( null, $user_course_last_step_id, $atts['course_id'] );
if ( ( isset( $progress['next'] ) ) && ( is_a( $progress['next'], 'WP_Post' ) ) ) {
$user_course_last_step_id = $progress['next']->ID;
}
$course_permalink = learndash_get_step_permalink( $user_course_last_step_id, $atts['course_id'] );
if ( ! empty( $course_permalink ) ) {
$learndash_shortcode_used = true;
$html_class = '';
if ( ! empty( $atts['html_class'] ) ) {
$html_class = ' class="' . esc_attr( $atts['html_class'] ) . '"';
}
$html_id = '';
if ( ! empty( $atts['html_id'] ) ) {
$html_id = ' id="' . esc_attr( $atts['html_id'] ) . '"';
}
if ( true === $atts['button'] ) {
$content .= '
';
}
}
}
}
}
return $content;
}
add_shortcode( 'ld_course_resume', 'ld_course_resume_shortcode', 10, 2 );
ld_certificate.php 0000666 00000010027 15214030011 0010205 0 ustar 00 0,
'quiz_id' => 0,
'user_id' => get_current_user_id(),
'label' => esc_html__( 'Certificate', 'learndash' ),
//'id' => '',
'class' => 'button',
//'target' => '', //'_blank',
//'aria-label' => esc_html__( 'link text - new window', 'learndash' ),
'context' => '', // User defined value.
'callback' => '', // User defined value.
);
$atts = shortcode_atts( $defaults, $atts );
$atts['course_id'] = absint( $atts['course_id'] );
$atts['quiz_id'] = absint( $atts['quiz_id'] );
$atts['user_id'] = absint( $atts['user_id'] );
if ( empty( $atts['course_id'] ) ) {
$atts['course_id'] = learndash_get_course_id();
}
if ( empty( $atts['quiz_id'] ) ) {
$atts['quiz_id'] = learndash_get_quiz_id();
}
//if ( ( '_blank' === $atts['target'] ) && ( empty( $atts['aria-label'] ) ) ) {
// $atts['aria-label'] = esc_html__( 'link text - new window', 'learndash' );
//}
/**
* Allow filtering of the shortcode attributes.
*
* @since 3.2
* @param array $atts Array of shortcode attributes.
*/
$atts = apply_filters( 'ld_certificate_shortcode_values', $atts );
$atts['cert_url'] = '';
if ( ! empty( $atts['user_id'] ) ) {
if ( ( ! empty( $atts['course_id'] ) ) || ( ! empty( $atts['quiz_id'] ) ) ) {
$learndash_shortcode_used = true;
$cert_button_html = '';
if ( ! empty( $atts['quiz_id'] ) ) {
// Ensure the user passed the Quiz.
if ( learndash_is_quiz_complete( $atts['user_id'], $atts['quiz_id'], $atts['course_id'] ) ) {
$cert_details = learndash_certificate_details( $atts['quiz_id'], $atts['user_id'] );
if ( ( isset( $cert_details['certificateLink'] ) ) && ( ! empty( $cert_details['certificateLink'] ) ) ) {
$atts['cert_url'] = $cert_details['certificateLink'];
}
}
} else if ( ! empty( $atts['course_id'] ) ) {
// Ensure the user completed the Course.
if ( 'completed' === learndash_course_status( $atts['course_id'], $atts['user_id'], true ) ) {
$atts['cert_url'] = learndash_get_course_certificate_link( $atts['course_id'], $atts['user_id'] );
}
}
if ( ! empty( $atts['cert_url'] ) ) {
/**
* Allow filtering of the cert url
*
* @since 3.2
* @param URL cert_url URL for Certificate.
*/
$atts['cert_url'] = apply_filters( 'ld_certificate_shortcode_cert_url', $atts['cert_url'] );
if ( ( ! empty( $atts['callback'] ) ) && ( is_callable( $atts['callback'] ) ) ) {
$cert_button_html = call_user_func( $atts['callback'], $atts );
} else {
$cert_button_html = '';
if ( ! empty( $atts['label'] ) ) {
$cert_button_html .= do_shortcode( $atts['label'] );
}
$cert_button_html .= '';
}
}
/**
* Filter to allow override of shortcode button HTML before added to content
*
* @since 3.2
* @param html $cert_button_html HTML of generated button element.
* @param array $atts Array of shortcode attributes used to generate $cert_button_html element.
* @param string $content Shortcode additional content passed into handler function.
*/
$cert_button_html = apply_filters( 'learndash_ld_certificate_html', $cert_button_html, $atts, $content );
if ( ! empty( $cert_button_html ) ) {
$content .= $cert_button_html;
}
}
}
return $content;
}
add_shortcode( 'ld_certificate', 'ld_certificate_shortcode', 10, 2 );
ld_quiz_complete.php 0000666 00000002201 15214030011 0010576 0 ustar 00 0,
'quiz_id' => 0,
'user_id' => get_current_user_id(),
);
$atts = shortcode_atts( $defaults, $atts );
$atts['course_id'] = absint( $atts['course_id'] );
$atts['quiz_id'] = absint( $atts['quiz_id'] );
$atts['user_id'] = absint( $atts['user_id'] );
if ( empty( $atts['course_id'] ) ) {
$atts['course_id'] = learndash_get_course_id();
}
if ( empty( $atts['quiz_id'] ) ) {
$atts['quiz_id'] = learndash_get_quiz_id();
}
$learndash_shortcode_used = true;
if ( ( ! empty( $atts['quiz_id'] ) ) && ( ! empty( $atts['user_id'] ) ) ) {
if ( learndash_is_quiz_complete( $atts['user_id'], $atts['quiz_id'], $atts['course_id'] ) ) {
$content = do_shortcode( $content );
} else {
$content = '';
}
} else {
$content = '';
}
return $content;
}
add_shortcode( 'ld_quiz_complete', 'ld_quiz_complete_shortcode', 10, 2 );
shortcodes-loader.php 0000666 00000000360 15214030011 0010664 0 ustar 00