Filter for user enrolled in course functions

Hi there,

I am building a custom function to work alongside CoursePress Pro which will limit a students access to a course by a time (eg 3 months) from the date of enrollment.

What I would like to do it to hook in to the user_enrolled_in_course and enrolled_in_course functions. Unfortunately there is no ability to do so.

Would it be possible to change these functions so that a filter can be applied prior to returning the result? Similar to the below:

* Check if the user is already enrolled in the course.
* <a title="@param" href="/profile/param">param</a> $course_id
* <a title="@param" href="/profile/param">param</a> bool $user_id
* <a title="@param" href="/profile/param">param</a> string $action Obsolete parameter. No longer required.
* @return bool
function user_enrolled_in_course( $course_id, $user_id = false, $action = '' ) {
if ( empty( $user_id ) ) {
$user_id = $this->ID;
if ( get_user_option( 'enrolled_course_date_' . $course_id, $user_id ) ) {
return apply_filters( 'enrolled_in_course', true, $course_id, $user_id );
} else {
return apply_filters( 'enrolled_in_course', false, $course_id, $user_id );

// Same as above, but static
public static function enrolled_in_course( $course_id, $user_id ) {
return apply_filters( 'enrolled_in_course', get_user_option( 'enrolled_course_date_' . $course_id, $user_id ) ? true : false, $course_id, $user_id );

I have seen quite a few posts out and about where people are looking for a solution to be able to set a course time limit based on enrollment date. I am aiming to achieve this using the following:

add_filter( 'enrolled_in_course', 'my_check_enrollment_date', 10, 3 );
function my_check_enrollment_date( $value, $course_id, $user_id ) {
if ( $value !== true ) { // if already false no need for further check so bail
return $value;
$course_expires_interval = 60 * 60 * 24 * 90; // 90 days - would be held in a variable
$enrolled_date = strtotime( get_user_option( 'enrolled_course_date_' . $course_id, $user_id ) ); // convert to unix
$course_expires_date = $enrolled_date + $course_expires_interval; // gives the course expiry date
if ( time() > $course_expires_date ) {
return false;
return $value;

It goes without saying that it would be a wonderful addition to CoursePress Pro if the ability to limit a course by time based on the enrollment date was available. Possibly my solution may go some way to providing this solution.

In the meantime, if the filters could be put in place on the enrollment check functions this would be an amazing help. Thank you in advance.