post_type ); /* If viewing a feed or if the user's not logged in, assume it's blocked at this point. */ if ( is_feed() || !is_user_logged_in() ) { $can_view = false; } /* If the post author, the current user can edit the post, or the current user can 'restrict_content', return true. */ elseif ( $post->post_author == $user_id || user_can( $user_id, 'restrict_content' ) || user_can( $user_id, $post_type->cap->edit_post, $post_id ) ) { $can_view = true; } /* Else, let's check the user's role against the selected roles. */ else { /* Loop through each role and set $can_view to true if the user has one of the roles. */ foreach ( $roles as $role ) { if ( user_can( $user_id, $role ) ) $can_view = true; } } } } /* Allow developers to overwrite the final return value. */ return apply_filters( 'members_can_user_view_post', $can_view, $user_id, $post_id ); } /** * Wrapper function for the members_can_user_view_post() function. This function checks if the currently * logged-in user can view the content of a specific post. * * @since 0.2.0 * @param int $post_id The ID of the post to check. * @return bool True if the user can view the post. False if the user cannot view the post. */ function members_can_current_user_view_post( $post_id = '' ) { /* Get the current user object. */ $current_user = wp_get_current_user(); /* Return the members_can_user_view_post() function, which returns true/false. */ return members_can_user_view_post( $current_user->ID, $post_id ); } ?>