Open joshdarby opened 4 years ago
Two implementation-detail questions:
Two implementation-detail questions:
- How does this work if WPE has cached the page HTML? Does WPE in production environments serve different page results with and without the cookie?
That's a great question that I'm not sure about until we put it up on a WPE environment and test it out. We may possibly need to add some cachebusting into it.
- Is it more future-proof if the form name is the ID of the post instead of the name of the post? That way, folks could rename the post without breaking the form.
I'm torn between yes and no here. Yes, the ID would be better in a lot of ways. But then we'll have users looking through x amount of forms trying to find the correct one because they don't know the actual ID of the page/post form they're looking for, and I'm not sure if it's a reasonable ask to expect them to know the ID.
But then we'll have users looking through x amount of forms trying to find the correct one because they don't know the actual ID of the page/post form they're looking for, and I'm not sure if it's a reasonable ask to expect them to know the ID.
We could add to the meta box a link to the appropriate form. In pseudocode:
$form_exists = false;
for post_id in array( this post ID, ancestor post IDs ) {
if form_exists( $post_id ) {
$form_exists = true;
"This post's visibility would be controlled by <this form>"
}
}
if ( ! $form_exists ) {
"no form exists for this post. [create one](/wp-admin/admin.php?page=gf_new_form) with the title $post_id"
}
There doesn't appear to be a way to prefill the form title in the create-new-form form, unfortunately. I was hoping &new_form_title=12345
or &title=12345
would prefill it with "12345", but the plugin contains no logic to do that:
But then we'll have users looking through x amount of forms trying to find the correct one because they don't know the actual ID of the page/post form they're looking for, and I'm not sure if it's a reasonable ask to expect them to know the ID.
We could add to the meta box a link to the appropriate form. In pseudocode:
$form_exists = false; for post_id in array( this post ID, ancestor post IDs ) { if form_exists( $post_id ) { $form_exists = true; "This post's visibility would be controlled by <this form>" } } if ( ! $form_exists ) { "no form exists for this post. [create one](/wp-admin/admin.php?page=gf_new_form) with the title $post_id" }
There doesn't appear to be a way to prefill the form title in the create-new-form form, unfortunately. I was hoping
&new_form_title=12345
or&title=12345
would prefill it with "12345", but the plugin contains no logic to do that:
@benlk I like this idea, but the inability to populate the form title with the post ID makes me weary because then we're back at the question of whether or not its a reasonable ask to expect the user to know how to find the post ID :/
Changes
This pull request makes the following changes:
set_cookie_on_form_submission
function that sets a cookie for 365 days in the users browser once they submit a form if the form contains a hidden field withaccess_ID
as its labelrestrict_access_to_pages_by_cookie
function that restricts access to a page if the aforementioned checkbox is checked. However, if the user has a cookie set namedunrestrict_POST_ID
(POST_ID will be an actual post id) and it's value is set to true, the page will show.Notes:
access_ID
Restrict access metabox:
Top level page with form:
Page with no matching form but that is restricted:
Why
For #161
Testing/Questions
Features that this PR affects:
Restrict Access
checkboxQuestions that need to be answered before merging:
Steps to test this PR:
access_ID