• Resolved DaRo_O

    (@daro_o)


    Hello everybody!

    First of all, thank you for reading this ??

    So i’ve got this situation in my company. We have a media page where we have all of our media ressources (Logos, graphics, and so on), the main page it’s linking directly links to the child pages), it would be something like this:

    –> Main media page
    |—-> Logo
    |—-> Guidelines
    |—-> Another thing

    And like this, i’ve reached like 40 childs of the main media page.

    The thing is, i need all those childs to be password protected, and i don’t know how to manage it.

    How could i do to make those child pages inherit the parent password, or something like this? i could password protect each of them manually, but this would be slow and not really usefull when in the future we add more child pages…

    So, any of you have a idea? I’m already looking for something for the las 3 days…

    Thank you everybody if you readed til here!

    Cheers,
    Daniel

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

    (@bcworkz)

    I would base all of the child pages on a custom page template that implements some sort of security protocol. There’s many ways to manage the security. Perhaps the simplest is to have the page refuse to output content unless the user has a particular capability. Of course the user would have to be logged in for this to work.

    You could also password protect the main page and have all the links to child pages contain a nonce. The child page would check that the referer and passed nonce are correct before outputting content. Thus the only way to load a child is by following a link from the main page.

    If the main page needs to be visible to all, you could collect a password once one of the links are clicked, using JavaScript. The password is verified via AJAX and the AJAX response is the nonce to pass to the child page.

    IMO, the capability approach is the best. The password then belongs to each user and admins can easily manage access by individual users without the need to worry about who has the latest passwword. Users can manage their own passwords without admin involvement.

    Thread Starter DaRo_O

    (@daro_o)

    First of all @bcworkz thanks for your answer!

    I found a solution that does the trick for the moment:

    add_action( 'init', 'myPasswordInit' );
    function myPasswordInit() {
    	if(strpos($_SERVER["REQUEST_URI"], 'parent-page') !== false) {
    		// i check if the cookie of the password protected page is there
    		// trigger password protection
    		if(!isset($_COOKIE[ 'wp-postpass_' . COOKIEHASH ])) {
    			//if the password it's not set, i redirect to the parent page
    			wp_redirect( home_url( '/parent-page/' ) );
    		}
    	}
    }

    Not working so good because it get’s sometimes confused with the wp-admin user cookie, but for my pourpouse was more than enough!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Protect child pages with a password’ is closed to new replies.