-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show notice when trying to access membership-restricted course #1501
- Loading branch information
Showing
2 changed files
with
43 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,8 +14,11 @@ public static function load_wc_memberships_integration_hooks() { | |
return; | ||
} | ||
|
||
add_filter( 'sensei_is_course_content_restricted', array( __CLASS__, 'is_course_access_restricted' ), 10, 2 ); | ||
add_filter( 'sensei_couse_access_permission_message', array( __CLASS__, 'add_wc_memberships_notice' ), 10, 2 ); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
lkraav
Contributor
|
||
add_filter( 'sensei_display_start_course_form', array( __CLASS__, 'display_start_course_form_to_members_only' ), 10, 2 ); | ||
add_filter( 'sensei_user_can_register_for_course', array( __CLASS__, 'display_start_course_form_to_members_only' ), 10, 2 ); | ||
|
||
add_action( 'wc_memberships_user_membership_status_changed', array( __CLASS__, 'start_courses_associated_with_membership' ) ); | ||
add_action( 'wc_memberships_user_membership_saved', array( __CLASS__, 'on_wc_memberships_user_membership_saved' ), 10, 2 ); | ||
} | ||
|
@@ -25,12 +28,30 @@ public static function is_course_access_restricted( $access_restricted, $course_ | |
return $access_restricted; | ||
} | ||
|
||
return self::is_content_restricted( $course_id ); | ||
} | ||
|
||
private static function is_content_restricted( $object_id ) { | ||
if ( get_current_user_id() > 0 ) { | ||
$access_restricted = !current_user_can( self::WC_MEMBERSHIPS_VIEW_RESTRICTED_POST_CONTENT, $course_id ); | ||
$access_restricted = !current_user_can( self::WC_MEMBERSHIPS_VIEW_RESTRICTED_POST_CONTENT, $object_id ); | ||
return $access_restricted; | ||
} | ||
|
||
return wc_memberships_is_post_content_restricted( $course_id ); | ||
return wc_memberships_is_post_content_restricted( $object_id ); | ||
} | ||
|
||
public static function add_wc_memberships_notice( $content = '' ) { | ||
global $post; | ||
if ( false === self::is_wc_memberships_active() ) { | ||
return $content; | ||
} | ||
|
||
if ( isset( $post->ID ) && !in_array( get_post_type( $post->ID ), array( 'course', 'lesson', 'quiz' ), true ) || | ||
!self::is_content_restricted( $post->ID ) ) { | ||
return $content; | ||
} | ||
$message = wc_memberships()->get_frontend_instance()->get_content_restricted_message( $post->ID ); | ||
return $message; | ||
} | ||
|
||
/** | ||
|
@pkg please note the
couse
typo insensei_couse_access_permission_message