<?php /** * LearnDash `[ld_course_resume]` shortcode processing. * * @since 3.1.4 * @package LearnDash\Shortcodes */ use LearnDash\Core\Utilities\Cast; if ( ! defined( 'ABSPATH' ) ) { exit; } /** * Builds the `[ld_course_resume]` shortcode output. * * @global boolean $learndash_shortcode_used * * @since 3.1.4 * * @param array $atts { * An array of shortcode attributes. * * @type int $course_id Course ID. Default 0. * @type int $user_id User ID. Default current user ID. * @type string $label Resume label. Default empty. * @type string $html_class The resume CSS classes. Default 'ld-course-resume'. * @type string $html_id The value for id HTML attribute. Default empty. * @type boolean $button Whether to show button. Default true. * } * @param string $content The shortcode content. Default empty. * @param string $shortcode_slug The shortcode slug. Default 'ld_course_resume'. * * @return string The `ld_course_resume` shortcode output. */ function ld_course_resume_shortcode( $atts = array(), $content = '', $shortcode_slug = 'ld_course_resume' ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedFunctionFound global $learndash_shortcode_used; if ( ! is_array( $atts ) ) { $atts = array(); } $defaults = array( 'course_id' => 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 ( get_current_user_id() !== $atts['user_id'] || ! learndash_shortcode_can_current_user_access_post( Cast::to_int( $atts['course_id'] ) ) ) { return ''; } 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 '; } /** * Filters `ld_course_resume` shortcode attributes. * * @param array $atts An array of shortcode attributes. */ $atts = apply_filters( 'learndash_shortcode_atts_ld_course_resume', $atts ); /** * Filters shortcode attributes. * * @param array $atts An array of shortcode attributes. * @param string $shortcode_slug The current shortcode slug. */ $atts = apply_filters( 'learndash_shortcode_atts', $atts, $shortcode_slug ); if ( ( ! empty( $atts['user_id'] ) ) && ( ! empty( $atts['course_id'] ) ) ) { if ( sfwd_lms_has_access( $atts['course_id'], $atts['user_id'] ) ) { // We only output for 'in progress' courses. $course_status = learndash_course_status( $atts['course_id'], $atts['user_id'], true ); if ( 'completed' !== $course_status ) { $user_course_last_step_id = learndash_user_progress_get_first_incomplete_step( $atts['user_id'], $atts['course_id'] ); if ( ! empty( $user_course_last_step_id ) ) { $user_course_last_step_id = learndash_user_progress_get_parent_incomplete_step( $atts['user_id'], $atts['course_id'], $user_course_last_step_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 .= '<div class="learndash-wrapper">'; } $content .= '<a ' . $html_id . ' ' . $html_class . ' href="' . $course_permalink . '">' . do_shortcode( $atts['label'] ) . '</a>'; if ( true === $atts['button'] ) { $content .= '</div>'; } } } } } } return $content; } add_shortcode( 'ld_course_resume', 'ld_course_resume_shortcode', 10, 3 );
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
ld_certificate.php | File | 8.85 KB | 0644 |
|
ld_course_certificate.php | File | 2.14 KB | 0644 |
|
ld_course_complete.php | File | 2.35 KB | 0644 |
|
ld_course_content.php | File | 14.56 KB | 0644 |
|
ld_course_expire_status.php | File | 4.86 KB | 0644 |
|
ld_course_info.php | File | 1.58 KB | 0644 |
|
ld_course_inprogress.php | File | 2.36 KB | 0644 |
|
ld_course_list.php | File | 45.9 KB | 0644 |
|
ld_course_notstarted.php | File | 2.36 KB | 0644 |
|
ld_course_progress.php | File | 3.26 KB | 0644 |
|
ld_course_resume.php | File | 4.51 KB | 0644 |
|
ld_courseinfo.php | File | 17.25 KB | 0644 |
|
ld_group.php | File | 2.49 KB | 0644 |
|
ld_group_list.php | File | 1.21 KB | 0644 |
|
ld_group_user_list.php | File | 4.69 KB | 0644 |
|
ld_groupinfo.php | File | 9.34 KB | 0644 |
|
ld_infobar.php | File | 6.52 KB | 0644 |
|
ld_lesson_list.php | File | 2.07 KB | 0644 |
|
ld_materials.php | File | 2.68 KB | 0644 |
|
ld_navigation.php | File | 5.25 KB | 0644 |
|
ld_payment_buttons.php | File | 2.2 KB | 0644 |
|
ld_profile.php | File | 7.72 KB | 0644 |
|
ld_quiz.php | File | 15.78 KB | 0644 |
|
ld_quiz_complete.php | File | 2.07 KB | 0644 |
|
ld_quiz_list.php | File | 3.12 KB | 0644 |
|
ld_quizinfo.php | File | 9.4 KB | 0644 |
|
ld_registration.php | File | 1.29 KB | 0644 |
|
ld_reset_password.php | File | 1.3 KB | 0644 |
|
ld_student.php | File | 5.17 KB | 0644 |
|
ld_topic_list.php | File | 2.68 KB | 0644 |
|
ld_user_course_points.php | File | 1.86 KB | 0644 |
|
ld_user_groups.php | File | 2.17 KB | 0644 |
|
ld_usermeta.php | File | 2.97 KB | 0644 |
|
ld_visitor.php | File | 4.81 KB | 0644 |
|
learndash_user_status.php | File | 1.79 KB | 0644 |
|
shortcodes-functions.php | File | 3.12 KB | 0644 |
|
shortcodes-loader.php | File | 1.8 KB | 0644 |
|