Development

How to Check If a User Is Enrolled in a Course

Check Tutor LMS enrollment in PHP with tutor_utils()->is_enrolled(), including pending enrollments, a shortcode that shows content only to enrolled students, and the database fallback.

Checked against the plugin source: Tutor LMS 4.1.3, Tutor LMS Pro 4.1.3

How to Check If a User Is Enrolled in a Course

Whether you are building a members-only page, a custom dashboard or an integration, the first question is usually "is this user enrolled in this course?" In Tutor LMS 4.1.3 the answer is one function call.

The function

$enrollment = tutor_utils()->is_enrolled( $course_id, $user_id );
  • $course_id: the course ID. 0 means the current post.
  • $user_id: the user ID. 0 means the logged-in user.
  • A third argument, $is_complete, defaults to true: only completed (active) enrollments count. Pass false to include pending ones, such as unpaid orders.

It returns the enrollment record (an object with ID, post_author, post_date and more) or false. The method lives in Tutor\Models\EnrollmentModel; tutor_utils() forwards the call. The result also passes through the tutor_is_enrolled filter.

Example: a members-only shortcode

add_shortcode( 'tle_if_enrolled', 'tle_if_enrolled_shortcode' );

function tle_if_enrolled_shortcode( $atts, $content = '' ) {
	$atts = shortcode_atts( array( 'course' => 0 ), $atts );

	if ( ! function_exists( 'tutor_utils' ) || ! is_user_logged_in() ) {
		return '';
	}

	if ( tutor_utils()->is_enrolled( (int) $atts['course'] ) ) {
		return do_shortcode( $content );
	}

	return '';
}

Usage: [tle_if_enrolled course="123"]Bonus material[/tle_if_enrolled].

Checking several courses

To check many courses at once, fetch the list once:

$enrolled_ids = tutor_utils()->get_enrolled_courses_ids_by_user( $user_id );
$has_any      = (bool) array_intersect( array( 12, 34, 56 ), array_map( 'intval', $enrolled_ids ) );

What "enrolled" means in the database

Each enrollment is a post of type tutor_enrolled: post_author is the student, post_parent is the course, and post_status is the enrollment status (completed, pending or cancel). If you must query outside WordPress, for example from a reporting tool, this read-only query matches what is_enrolled() checks:

SELECT ID FROM wp_posts
WHERE post_type = 'tutor_enrolled'
  AND post_parent = 123
  AND post_author = 45
  AND post_status = 'completed'
LIMIT 1;

Use your real table prefix. Inside WordPress, always use the function so filters and caching apply.

Common mistakes

  • Checking before Tutor LMS loads: call it on or after init, not when your plugin file is first included.
  • Forgetting pending enrollments: a student who just checked out with a manual payment method is pending, not enrolled.
  • Treating admins as students: admins and course instructors can view content without an enrollment if the related setting is on. is_enrolled() still returns false for them.

Frequently asked questions

Does this work for bundles?

Yes. Pass the bundle ID; bundles are enrolled the same way (Pro).

How do I check progress, not just enrollment?

See getting a student's progress with PHP.

More helpers: useful tutor_utils() functions. Need custom access rules? Our plugin development team can help.

Save this practical guide

Add us as a preferred Google source, or ask an AI assistant to summarize this page and link back to the original guide when it is useful.

Vishavjeet
· Enterprise LMS Architect | WordPress & LMS Expert | WooCommerce | AI Automation

I’m Vishavjeet Choubey, an Enterprise LMS Architect with 10+ years of experience helping businesses, coaches, universities, and online academies build and scale powerful digital learning platforms. I specialize in enterprise LMS architecture, WordPress, WooCommerce, LifterLMS, LearnDash, Moodle, custom plugin development, and AI-driven automation. I build scalable LMS platforms, high-converting eCommerce solutions, and custom WordPress applications designed to improve user experiences, streamline operations, and drive measurable business growth. My approach combines deep WordPress and LMS engineering expertise with modern AI automation to reduce manual work, improve efficiency, and help organizations launch, scale, and grow faster.

Keep reading

Need a custom Tutor LMS solution?

Tell us what you are building or what is broken. A Tutor LMS developer reads every inquiry and replies with next steps and a free estimate.

Get a free Tutor LMS consultation

Tell us what you are building or fixing. A Tutor LMS developer replies with honest advice and next steps.

  • No obligation
  • Tutor LMS and Pro specialists
  • Your details stay private

This form is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.