March 2020
Beginner
660 pages
18h 28m
English
So far, we used a single conditional tag in each of the previous scenarios. Now, let's take a look at the use of multiple conditional tags at once to narrow the filtering. In this case, we will be creating a private page and redirecting the users who don't have access to that page. Consider the following code:
function wpccp_chapter2_validate_page_restrictions(){ global $wp_query; if (! isset($wp_query->post->ID) ) { return; } if(is_page('2') && ! is_user_logged_in() ){ $url = site_url(); wp_redirect($url); exit; }}add_action('template_redirect', 'wpccp_chapter2_validate_page_restrictions');
In this case, we use an action called template_redirect, instead of a filter like last time. This is a built-in action ...
Read now
Unlock full access