• I created several page templates that use php code. All the access is working just fine , i cant restrict access with no problems. When i select a non default template the page can be viewed by everyone, I have no idea on how to fix this. Any ideas?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    What is the criteria for allowing access? User logged in? User has a particular role? User with NSFW avatars ??

    One way would be to add code at the top of restricted templates that does wp_die() if the criteria is not met. If users must be logged in, perhaps something like this:
    if ( ! is_user_logged_in()) wp_die('You must be logged in to view this page');

    You could add a link to the login page if you wanted to be a little friendlier.

    Add a “redirect_to” query argument to the link leading back to the current page if you really want to get fancy ??

    Thread Starter Rob19805

    (@rob19805)

    I needed it by roles. I did something similar by adding code at the top of teh template files and using capabilities. But I like yours better. May use that. Ty!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Page Access not work with non default template’ is closed to new replies.