Snippets

LearnDash Make video progression work fine with Elementor template

Created by Carlos Angeline

File custom-snippet.php Added

  • Ignore whitespace
  • Hide word diff
+add_action( 'init', function() {
+	global $shortcode_tags;
+	if ( ! isset( $shortcode_tags['ld_video'] ) ) {
+		add_shortcode( 'ld_video', function( $atts = array(), $content = '' ) {
+			if ( ( defined( 'LEARNDASH_LESSON_VIDEO' ) ) && ( true === LEARNDASH_LESSON_VIDEO ) ) {
+				$step_id   = get_the_ID();
+				$step_id   = absint( $step_id );
+				$course_id = learndash_get_course_id( $step_id );
+				$course_id = absint( $course_id );
+				$user_id   = get_current_user_id();
+				$user_id   = absint( $user_id );
+				if ( ( ! empty( $user_id ) ) && ( ! empty( $step_id ) ) ) {
+					if ( in_array( get_post_type( $step_id ), array( learndash_get_post_type_slug( 'topic' ), learndash_get_post_type_slug( 'lesson' ) ), true ) ) {
+						$settings         = learndash_get_setting( $step_id );
+						$ld_course_videos = Learndash_Course_Video::get_instance();
+						$content          = $ld_course_videos->add_video_to_content( '[ld_video]', get_post( $step_id ), $settings );
+					}
+				}
+			}
+			return $content;
+		}, 30, 2 );
+	}
+}, 100 );
HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.