I would like to extend the WordPress password protection of posts by adding extra input field for user email.
So in order to see the content user will have to know the password and previously given email that is stored in custom meta field of the protected post.
I was trying to find a good hook checking that extra field but without any success. Could you give me some ideas how to make it? I don’t want to create user accounts for this kind of feature.
When you set a post as password protected, the protection happen on
get_the_content()
function. There WordPress check for a post password cookie, and if not set, not valid or expired then show the password form.This password form is submitted to
wp-login.php
, there a cookie is setted according to the password wrote in the form, then the request is redirected to the post again.The process can be described like so:
What we can do:
'the_password_form'
to edit the output of the form, adding a field for the email and a hidden field with the post id (at this point we are insideget_the_content
function so we have access to global post variable)First step:
And the second:
We are done.
Now create a post, save as password protected and set some allowed emails in custom fields using the key
'allow_email'
. There’s no limit on number of the emails you can add…Settings:
Result (TwentyThirteen with no additional styling):