WordPress subscriber private pages

By default subscribers can’t see private pages.

add_cap lets us change that.

functions.php

 $subRole = get_role( 'subscriber' );
 $subRole->add_cap( 'read_private_pages' );

Also let’s not dump the WP dashboard on those subscribers 😀

function loginRedirect( $redirect_to, $request_redirect_to, $user ) {
    if ( is_a( $user, 'WP_User' ) && $user->has_cap( 'edit_posts' ) === false ) {
        return get_bloginfo( 'siteurl' );
    }
    return $redirect_to;
}
add_filter( 'login_redirect', 'loginRedirect', 10, 3 );

Thank you sltaylor.

Advertisements