Skip to content

Instantly share code, notes, and snippets.

@thomasplevy
Last active September 2, 2016 22:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomasplevy/7ab5f2e74906c55201260791d890d6de to your computer and use it in GitHub Desktop.
Save thomasplevy/7ab5f2e74906c55201260791d890d6de to your computer and use it in GitHub Desktop.
/**
* Redirect restrictions to a custom URL
* @param array $results array or result info
* @return void
*/
function my_llms_page_restrictions( $results ) {
// url to redirect to when user does nt have access
$redirect_url = 'http://mycustomredirect.url';
if ( $results['is_restricted'] ) {
$user_id = get_current_user_id();
// check access
$access = ( $user_id ) ? llms_is_user_enrolled( $user_id, $results['post_id'] ) : false;
// redirect if use is not logged in or does not have access
if ( ! $access ) {
wp_redirect( $redirect_url );
exit;
}
}
return $results;
}
add_filter( 'llms_page_restricted', 'my_llms_page_restrictions' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment