You need to wrap the first three ||
conditions in additional parentheses so they are evaluated first BEFORE the last &&
condition:
Psuedocode example:
here here
↓ ↓
if ( (condition || condtion || condition) && ! condition ) {
//do business logic...
}
This now means that:
If any ONE of is_paged()
OR is_author()
OR is_single()
IS true
THEN evaluate the second condition ! is_user_logged_in()
In your original code:
With no additional parentheses wrapping the first three conditions, IF any of those four conditions return true
then you would redirect your user whether they are logged in or not.
Final code with additional parentheses:
add_action( 'template_redirect', 'redirect_to_specific_page' );
function redirect_to_specific_page() {
if ( (is_paged() || is_author() || is_single()) && ! is_user_logged_in() ) {
wp_redirect( 'http://www.exampleblog.net/members-only/', 301 ); exit;
}
}