Created
February 10, 2017 13:44
-
-
Save woogist/603de87322d1e2f1f6f7bcd9401d1b80 to your computer and use it in GitHub Desktop.
This code prevents Sensei learners from starting a course unless they've been specifically added to that course by a site administrator or a teacher.
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
<?php | |
function sensei_display_start_course_form_when_admin_or_teacher( $should_display_start, $course_id ) { | |
global $current_user; | |
if ( empty( $current_user ) ) { | |
$current_user = wp_get_current_user(); | |
} | |
if ( !( $current_user instanceof WP_User ) || 0 === $current_user->ID ) { | |
return false; | |
} | |
$allowed_roles = array( 'administrator', 'teacher' ); | |
$user_roles = $current_user->roles; | |
$is_administrator_or_teacher = count( array_intersect( $allowed_roles, $user_roles ) ) > 0; | |
return $is_administrator_or_teacher ? true : false; | |
}; | |
add_filter( 'sensei_display_start_course_form', 'sensei_display_start_course_form_when_admin_or_teacher', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment