Browse: Home / Snippets /

Enable ld_video shortcode use in Elementor template builder

Contents


Snippet #

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 );