lifterlms_template_my_courses_loop( $student = null,  $preview = false )


Description Description


Source Source

File: includes/functions/llms.functions.templates.dashboard.php

	function lifterlms_template_my_courses_loop( $student = null, $preview = false ) {

		$student = llms_get_student( $student );
		if ( ! $student ) {
			return;
		}

		$courses = $student->get_courses( apply_filters( 'llms_my_courses_loop_courses_query_args', array(
			'limit' => 500,
		), $student ) );

		if ( ! $courses['results'] ) {

			printf( '<p>%s</p>', __( 'You are not enrolled in any courses.', 'lifterlms' ) );

		} else {

			add_action( 'lifterlms_after_loop_item_title', 'lifterlms_template_loop_enroll_status', 25 );
			add_action( 'lifterlms_after_loop_item_title', 'lifterlms_template_loop_enroll_date', 30 );

			// get sorting option
			$option = get_option( 'lifterlms_myaccount_courses_in_progress_sorting', 'date,DESC' );
			// parse to order & orderby
			$option = explode( ',', $option );
			$orderby = ! empty( $option[0] ) ? $option[0] : 'date';
			$order = ! empty( $option[1] ) ? $option[1] : 'DESC';

			// enrollment date will obey the results order
			if ( 'date' === $orderby ) {
				$orderby = 'post__in';
			} elseif ( 'order' === $orderby ) {
				$orderby = 'menu_order';
			}

			$per_page = apply_filters( 'llms_dashboard_courses_per_page', get_option( 'lifterlms_shop_courses_per_page', 9 ) );
			if ( $preview ) {
				$per_page = apply_filters( 'llms_dashboard_recent_courses_count', llms_get_loop_columns() );
			}

			$query_args = apply_filters(
				'llms_dashboard_courses_wp_query_args',
				array(
					'paged' => get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1,
					'orderby' => $orderby,
					'order' => $order,
					'post__in' => $courses['results'],
					'post_status' => 'publish',
					'post_type' => 'course',
					'posts_per_page' => $per_page,
				)
			);

			$query = new WP_Query( $query_args );

			// prevent pagination on the preview
			if ( $preview ) {
				$query->max_num_pages = 1;
			}

			add_filter( 'paginate_links', 'llms_modify_dashboard_pagination_links' );

			lifterlms_loop( $query );

			remove_filter( 'paginate_links', 'llms_modify_dashboard_pagination_links' );

			remove_action( 'lifterlms_after_loop_item_title', 'lifterlms_template_loop_enroll_status', 25 );
			remove_action( 'lifterlms_after_loop_item_title', 'lifterlms_template_loop_enroll_date', 30 );

		}// End if().

	}


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.





Permalink: