// Example of restricting access to the LearnDash Certificates. In the example below
// only the admin ( users with 'manage_options' capability ) can access certificates.
add_action('template_redirect', function(){
$post_type = get_query_var( 'post_type' );
if ( $post_type == 'sfwd-certificates' ) {
// CHANGE 'manage_options' TO ANY USER CAPABILITY TO CHECK
if ( ( !is_user_logged_in() ) || ( !current_user_can( 'manage_options' ) ) ) {
// If the post_type is certiicate
// and the user is either not logged in or not admin ('manage_options')
// then redirect to home.
wp_redirect( home_url() );
exit;
}
}
});
Copy to clipboard