This started as a quick update to the CookieMonster WordPress plugin to allow default values.
It has morphed into a nearly complete re-write to add more functionality than the original.
CookieMonster-plus takes incoming parameters like http://mercs.net/cookiemonster-plus/?example=NotDefault and puts the values in a cookie so that WordPress can then replace 1 with the value passed (and cookied) within any page or post they may visit.
You can change the value of the example parameter as passed to this page and watch this page update here: (1 = 1).
CM+ will also let you specify a default value in the control panel rather than just leaving it blank if example isn't set in the URL or cookie.
This was inspired by a call for competency from Paul Myers in his Talkbiz News email newsletter. He mentioned how nicely CM would complement his new product "The Email Affiliate System" and suggested a nice twist possible for affiliates if the plugin allowed a default value. So, I wrote it into CM.
Since then, several things have changed. Because of this plugin, Paul changed "The Email Affiliate System" to "The BEAST" (Blog and Email Affiliate SysTem, in case you missed it at first).
Fall 2015, WordPress changed the way they processed shortcodes that happen to modify HTML tags. This broke one of the main ways that CM+ has been used: to pre-fill form fields based on previous interactions with the site visitor. My friend and client Phil Pustejovsky got in touch after he finally tracked down the source of his conversion rates dropping and narrowing it down to CM+ not filling in forms after the WP update to 4.2.3.
“Cookie Monster Plus has consistently increased conversions by 10% over a period of 4 years. It is incredibly helpful and solves a huge issue that no other WordPress plugin does.” – Phil Pustejovsky, Freedom Mentor
Whether you use the tool or manually update your code, you'll need to grab the whole <input type="text" /> or whatever the HTML tag happens to be and feed it to a new shortcode in the form [cmp_tag "before" cookiename "after"].
E.g. going from this:
<input name="email" type="email" class="moonray-form-input" id="mr-field-element-284" required value="[email]" placeholder/>
[cmp_tag "input name='email' type='email' class='moonray-form-input' id='mr-field-element-284' required value='" email "' placeholder"]
The things to note:
- replace the whole tag (e.g. <input type="text" />) with the shortcode,
- drop the < and /> around the tag,
- replace the angle brackets with [cmp_tag and ],
- put each half in double quotes*, and
- put just the cookie name by itself where you used to use [cookiename].
*Of course, WP doesn't do the right thing with single quotes around shortcode parameter values, which means you have to swap all the double quotes in the original tag for single quotes -- because HTML doesn't care which you use, as long as they match at the beginning and end of any given string.
Three new caveats with 1.3.13's ability to work with ampersands in the "before" or "after" portions of the [cmp_tag] shortcode:
- If you switch back to the Visual editor after making the appropriate changes in the Text editor, WordPress will be "helpful" and change them from & to & and break things again.
- Using this now turns off "smart quotes" and other things that wptexturize() does to the things we type. Most people will never notice the difference. This note is for those who do notice and may have issue with that.
- You can only put one cookie value into a given HTML tag. This becomes more of a potential issue in this use case where you might want to pass along a name and email as it passes from one site to another. Since the primary use case I'm aware of for this feature is to pass an affiliate ID, I think it is a fair solution until I process through all the potential implications of my next solution.
20150904: v.1.3.13 allow arbitrary HTML in "before" and "after" parameters, but not cookies 20150830: v.1.3.12 updated for WP 4.3 revert [cmp-hidden] in favor of more general use <"before",after/> 20150727: v.1.3.11 revert v.1.3.10 redirects added [cmp-hidden] shortcode after WP 4.2.3 changed shortcode behavior 20130901: v.1.3.10 Add redirect if unset values Possibly adding default values as CF7 placeholders 20130831: v.1.3.9 Updating for WP 3.6 / CF7 3.5.2 compatibility 20121109: v.1.3.8 Fixed the cookie duration display (was always set, only displayed immediately after saving) 20121030: v.1.3.7 Added ability to set cookies from $_POST also 20110530: v.1.3.6 Added CF7 shortcodes text+,text*+,email+,email*+ to pull values from cookies or get values [TODO: do the same with hidden fields module?] 20110310: v.1.3.5 Added cookie duration to config options 20101201: v.1.3.4 Found and squashed that pesky "Invalid argument supplied for foreach()" bug Made shortcodes show up on templated pages that didn't use get_header() 20101004: v.1.3.3 *** All parameter/cookie names will need to be re-entered if you upgrade from 1.2.X *** *** (This should be the last time that is needed barring another major re-write.) *** Added option prefix CMp_ to avoid option name space collisions 20101001: v.1.3.2 Added function name prefix CMp_ to avoid name space collisions 20100930: v.1.3.1 Unbroke cookie setting code from refactoring (Oops) 20100929: v.1.3 !! Not backward compatible with 1.2.X !! *** All parameter/cookie names will need to be re-entered if you upgrade from 1.2.X *** Changed options format to allow blank options to just disappear 20100928: v1.2.2 Verboten list -- avoid WP reserved names that may break the page (404, etc) Turn on shortcodes in widgets [and titles?] Wrap short codes in <p> tags with wpautop() 20100927: v1.2.1 Encode HTML special characters in variables before displaying (to deter malicious code injection) 20100926: v1.2 Added default values Cleaned up original CookieMonster code Now allows for more than 4 parameters Added "Settings" link to plugin admin screen
Thanks for downloading!
If you'd like to be notified of updates to
this plugin and hear about other projects
please enter your name and email and
click "Send Me Updates".