Select Page

I had a chance to assist on a fun project for a referred customer. The desired results of the project were to create a page that contained a private video, while needing the would be viewer to fill out a form to capture some details about the individual, then allowing them to proceed. However, the customer also wanted to password protect the page. My mind was racing with ideas on how to accomplish this. I thought about a cool content blocker plugin, Restrict Content Pro by Pippin, but probably was a little overkill as this was only on one single page.

I searched the WordPress repository and found this cool little plugin, at least it looked little at first glance – Before and After. Seemingly, it looked like something that I was trying to attempt to do, and already wrapped up and shipped. So I installed and activated it. As I was rummaging through the settings, adding a new goal and thinking this was perfect… then, what about the little form? How is that supposed to work? Well, it just so happens that this plugin integrates nicely with CF7 and Gravity Forms. I really like Gravity Forms and the power it brings to forms. So, I created a form, set my new Before and After goal to be ‘successful submission’ of the Gravity Form, and I was off the races, woohoo!

Seems easy enough right? Well, don’t forget about that tiny piece of password protecting the page, which is also easy within the page settings and standard WordPress functionality. However, the wrinkle with this is that the password is valid for 10 days, and guess what, that is way too long for our customer. So, by filtering the post_password_expires and setting it for 3 minutes ( long enough to fill out the form ), I was able to satisfy the customer. The customer wanted to have the user is a must fill out the password and form everytime they visit, refresh the page, or close the browser…so, by using that filter and setting it for time() + 180 we are able to reduce the default ten minutes to just three.

Description from

https://wordpress.org/plugins/before-and-after/

Before & After is a lead capture plugin for WordPress. It allows a webmaster to require visitors to complete a goal, such as filling out a contact form, before viewing the contents of a page or downloading a file.

The plugin automatically tracks which visitors have completed your goals, and shows the appropriate content to each visitor. For example, it can show a form to visitors until they have completed the form, at which point they will be given a link to download a special file or whitepaper.

Before & After can be used with any plugin that uses shortcodes, but works especially well with Contact Form 7 and Gravity Forms.

Now, remember that we are working with the Before and After plugin, which was set with a goal to ‘successful submission’ of our Gravity Form. Well, that too sets a timed cookie, but that time is 30 days! With the 3 minutes for password protection, you basically are able to bypass the form for 30 days once you have successfully submitted that is. So, looking through the plugin for any filters or actions, I could not find any reasonable hook to adjust that 30 days… so, I looked for it on the 'wp' action ( which fires at every page load. Here is what I came up with:

On page load, unset the cookie, then reset it to 10 seconds after successful submission. But, wait for it, that is not all! The plugin also adds a successful goal post meta, based on timestamp, ip, useragent, so what I had to do, on that same hook was check to see if the users ip, matched any post_meta, then delete it…

All of this combined into one, worked like a charm, and the client is happy with it.

**I have asked permission to show the final result, but have not heard back yet…

Let me know what you think… is there a better way of doing this? maybe jQuery? or stick with the filters and actions?

There are no products

Get a FREE 15 minute consultation!

Stuck on deciding what is best for your website?  Need someone to bounce ideas off of?

Great first step! I will contact you via email soon.