Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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.
<?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
You can’t perform that action at this time.