Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for LearnDash #2

Open
JiveDig opened this issue May 17, 2019 · 1 comment
Open

Add support for LearnDash #2

JiveDig opened this issue May 17, 2019 · 1 comment

Comments

@JiveDig
Copy link
Member

JiveDig commented May 17, 2019

This would be really simple. The code is already there, we just need to add a setting to choose LD Courses, then this code to add the user.

// If not enrolled already.
if ( ! $this->is_user_enrolled_to_course( $user_id, $course_id ) {
	// Enroll.
	ld_update_course_access( $user_id, $course_id, $remove = false );
}

/**
 * Check if a user is already enrolled to a course
 * 
 * @param   int   $user_id    User ID
 * @param   int   $course_id  Course ID
 * 
 * @return  bool  True if enrolled|false otherwise
 */
function is_user_enrolled_to_course( $user_id = 0, $course_id = 0 ) {
	$enrolled_courses = learndash_user_get_enrolled_courses( $user_id );
	return ( is_array( $enrolled_courses ) && in_array( $course_id, $enrolled_courses ) );
}
@JiveDig
Copy link
Member Author

JiveDig commented May 21, 2019

Added via fc9cc46

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant