<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Gravity Wiz</title>
	<atom:link href="http://gravitywiz.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://gravitywiz.com</link>
	<description>Magically enhanced tutorials, snippets and plugins for Gravity Forms!</description>
	<lastBuildDate>Tue, 21 May 2013 12:32:12 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>GP Conditional Logic Dates, First Draft</title>
		<link>http://gravitywiz.com/gp-conditional-logic-dates-first-draft/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=gp-conditional-logic-dates-first-draft</link>
		<comments>http://gravitywiz.com/gp-conditional-logic-dates-first-draft/#comments</comments>
		<pubDate>Mon, 13 May 2013 06:58:38 +0000</pubDate>
		<dc:creator>David Smith</dc:creator>
				<category><![CDATA[Perks]]></category>

		<guid isPermaLink="false">http://gravitywiz.com/?p=1861</guid>
		<description><![CDATA[<p>This new perk allows you show/hide fields based on the selected date in a Date field. It integrates with Gravity Forms&#8217; default conditional logic UI. Select the date field and then enter the date you would like the condition to be based on. All perks require Gravity Perks. If you&#8217;d like to give this perk [...]</p><p>The post <a href="http://gravitywiz.com/gp-conditional-logic-dates-first-draft/">GP Conditional Logic Dates, First Draft</a> appeared first on <a href="http://gravitywiz.com">Gravity Wiz</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>This new perk allows you show/hide fields based on the selected date in a Date field. It integrates with Gravity Forms&#8217; default conditional logic UI. Select the date field and then enter the date you would like the condition to be based on.</p>

<p>All perks require <a href="http://gravitywiz.com/gravity-perks/">Gravity Perks</a>. If you&#8217;d like to give this perk a shot, you will need a valid Gravity Perks license. Once Gravity Perks is installed, you will be able to download the GP Conditional Logic Dates v0.1 perk via the Manage Perks page.</p>

<p><strong>Please note:</strong> This perk is a first draft. Do not use on a production site. Below is a list of limitations and some general information you should be aware of if you decide to take this perk for a spin.</p>

<ul>
<li>Most importantly, this perk is possible via new hooks added in Gravity Forms 1.7.2.6. This version is not publicly available. Contact david[at]rocketgenius[dot]com with your Gravity Forms Support username to get the latest version of Gravity Forms. <strong>This perk will not work without GF v1.7.2.6 or greater.</strong></li>
<li>Only Datepicker Date fields are currently supported.</li>
<li>Date value must be entered manually using the US date format: <code>MM/DD/YYYY</code> <a href="http://grab.by/mtze">Example</a>. Will add support for jQuery Datepicker for selecting the date value in future version.</li>
<li>Supported operators: &#8220;is&#8221;, &#8220;is not&#8221;, &#8220;greater than&#8221;, &#8220;less than&#8221;. These are the only operators which are intended to be supported. All other operators do not appear to be applicable to date-based conditional logic.</li>
<li>When using the &#8220;less than&#8221; operator, if the field should not be visible until a date is actually selected, you will need to add a second condition where the selected Date field is greater than 0. <a href="http://grab.by/mtza">Example</a></li>
<li>Special conditional-logic-only merge tag supported: {today} Allows conditional logic to be applied to fields based on whether the selected date is, is not, is greater than or is less than the current date. <a href="http://grab.by/mtA4">Example</a></li>
</ul>

<h3>Upcoming Enhancements</h3>

<ol>
<li>jQuery Datepicker support will be added for selected the conditional logic date value.</li>
<li>Other Date field types (besides &#8220;Datepicker&#8221;) will be supported.</li>
<li>More special conditional-logic-only merge tags to check if the current date is a weekend, weekday, or any specific day of the week.</li>
</ol>

<p>Report any issues via the <a href="http://gravitywiz.com/support/">Support Form</a></p>
<p>The post <a href="http://gravitywiz.com/gp-conditional-logic-dates-first-draft/">GP Conditional Logic Dates, First Draft</a> appeared first on <a href="http://gravitywiz.com">Gravity Wiz</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://gravitywiz.com/gp-conditional-logic-dates-first-draft/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Subtotal Merge Tag (for Calculations)</title>
		<link>http://gravitywiz.com/subtotal-merge-tag-for-calculations/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=subtotal-merge-tag-for-calculations</link>
		<comments>http://gravitywiz.com/subtotal-merge-tag-for-calculations/#comments</comments>
		<pubDate>Thu, 18 Apr 2013 04:16:58 +0000</pubDate>
		<dc:creator>David Smith</dc:creator>
				<category><![CDATA[Snippets]]></category>

		<guid isPermaLink="false">http://gravitywiz.com/?p=1800</guid>
		<description><![CDATA[<p>Currently, there is no easy way to get the current total (let&#8217;s call it the subtotal) of the form for use in calculations. It&#8217;s possible but you&#8217;ll have to enter all of your product merge tags into a long and complicated formula to get the subtotal. This snippet helps you avoid that hassle by providing [...]</p><p>The post <a href="http://gravitywiz.com/subtotal-merge-tag-for-calculations/">Subtotal Merge Tag (for Calculations)</a> appeared first on <a href="http://gravitywiz.com">Gravity Wiz</a>.</p>]]></description>
				<content:encoded><![CDATA[<div class="introduction">A simple (but hacky) way of getting the subtotal for your Gravity Form calculations.</div>

<div class="demo-link-container"><a href="http://gravitywiz.com/demos/calculation-subtotal-merge-tag/" class="demo-link serif btn" target="_blank">view demo</a></div>

<p>Currently, there is no easy way to get the current total (let&#8217;s call it the subtotal) of the form for use in calculations. It&#8217;s possible but you&#8217;ll have to enter all of your product merge tags into a long and complicated formula to get the subtotal.</p>

<p>This snippet helps you avoid that hassle by providing a <code>{subtotal}</code> merge tag for use in your Gravity Form calculations.</p>

<div class="content-icon tip"></div><div class="callout round tip"><strong>Please note:</strong> The <code>{subtotal}</code> merge tag is only available in for fields that support calculations.</div>

<div id="gist5409587" class="gist">
      <div class="gist-file">
        <div class="gist-data gist-syntax">



  <div class="file-data">
    <table cellpadding="0" cellspacing="0" class="lines highlight">
      <tr>
        <td class="line-numbers">
          <span class="line-number" id="file-gistfile1-php-L1" rel="file-gistfile1-php-L1">1</span>
          <span class="line-number" id="file-gistfile1-php-L2" rel="file-gistfile1-php-L2">2</span>
          <span class="line-number" id="file-gistfile1-php-L3" rel="file-gistfile1-php-L3">3</span>
          <span class="line-number" id="file-gistfile1-php-L4" rel="file-gistfile1-php-L4">4</span>
          <span class="line-number" id="file-gistfile1-php-L5" rel="file-gistfile1-php-L5">5</span>
          <span class="line-number" id="file-gistfile1-php-L6" rel="file-gistfile1-php-L6">6</span>
          <span class="line-number" id="file-gistfile1-php-L7" rel="file-gistfile1-php-L7">7</span>
          <span class="line-number" id="file-gistfile1-php-L8" rel="file-gistfile1-php-L8">8</span>
          <span class="line-number" id="file-gistfile1-php-L9" rel="file-gistfile1-php-L9">9</span>
          <span class="line-number" id="file-gistfile1-php-L10" rel="file-gistfile1-php-L10">10</span>
          <span class="line-number" id="file-gistfile1-php-L11" rel="file-gistfile1-php-L11">11</span>
          <span class="line-number" id="file-gistfile1-php-L12" rel="file-gistfile1-php-L12">12</span>
          <span class="line-number" id="file-gistfile1-php-L13" rel="file-gistfile1-php-L13">13</span>
          <span class="line-number" id="file-gistfile1-php-L14" rel="file-gistfile1-php-L14">14</span>
          <span class="line-number" id="file-gistfile1-php-L15" rel="file-gistfile1-php-L15">15</span>
          <span class="line-number" id="file-gistfile1-php-L16" rel="file-gistfile1-php-L16">16</span>
          <span class="line-number" id="file-gistfile1-php-L17" rel="file-gistfile1-php-L17">17</span>
          <span class="line-number" id="file-gistfile1-php-L18" rel="file-gistfile1-php-L18">18</span>
          <span class="line-number" id="file-gistfile1-php-L19" rel="file-gistfile1-php-L19">19</span>
          <span class="line-number" id="file-gistfile1-php-L20" rel="file-gistfile1-php-L20">20</span>
          <span class="line-number" id="file-gistfile1-php-L21" rel="file-gistfile1-php-L21">21</span>
          <span class="line-number" id="file-gistfile1-php-L22" rel="file-gistfile1-php-L22">22</span>
          <span class="line-number" id="file-gistfile1-php-L23" rel="file-gistfile1-php-L23">23</span>
          <span class="line-number" id="file-gistfile1-php-L24" rel="file-gistfile1-php-L24">24</span>
          <span class="line-number" id="file-gistfile1-php-L25" rel="file-gistfile1-php-L25">25</span>
          <span class="line-number" id="file-gistfile1-php-L26" rel="file-gistfile1-php-L26">26</span>
          <span class="line-number" id="file-gistfile1-php-L27" rel="file-gistfile1-php-L27">27</span>
          <span class="line-number" id="file-gistfile1-php-L28" rel="file-gistfile1-php-L28">28</span>
          <span class="line-number" id="file-gistfile1-php-L29" rel="file-gistfile1-php-L29">29</span>
          <span class="line-number" id="file-gistfile1-php-L30" rel="file-gistfile1-php-L30">30</span>
          <span class="line-number" id="file-gistfile1-php-L31" rel="file-gistfile1-php-L31">31</span>
          <span class="line-number" id="file-gistfile1-php-L32" rel="file-gistfile1-php-L32">32</span>
          <span class="line-number" id="file-gistfile1-php-L33" rel="file-gistfile1-php-L33">33</span>
          <span class="line-number" id="file-gistfile1-php-L34" rel="file-gistfile1-php-L34">34</span>
          <span class="line-number" id="file-gistfile1-php-L35" rel="file-gistfile1-php-L35">35</span>
          <span class="line-number" id="file-gistfile1-php-L36" rel="file-gistfile1-php-L36">36</span>
          <span class="line-number" id="file-gistfile1-php-L37" rel="file-gistfile1-php-L37">37</span>
          <span class="line-number" id="file-gistfile1-php-L38" rel="file-gistfile1-php-L38">38</span>
          <span class="line-number" id="file-gistfile1-php-L39" rel="file-gistfile1-php-L39">39</span>
          <span class="line-number" id="file-gistfile1-php-L40" rel="file-gistfile1-php-L40">40</span>
          <span class="line-number" id="file-gistfile1-php-L41" rel="file-gistfile1-php-L41">41</span>
          <span class="line-number" id="file-gistfile1-php-L42" rel="file-gistfile1-php-L42">42</span>
          <span class="line-number" id="file-gistfile1-php-L43" rel="file-gistfile1-php-L43">43</span>
          <span class="line-number" id="file-gistfile1-php-L44" rel="file-gistfile1-php-L44">44</span>
          <span class="line-number" id="file-gistfile1-php-L45" rel="file-gistfile1-php-L45">45</span>
          <span class="line-number" id="file-gistfile1-php-L46" rel="file-gistfile1-php-L46">46</span>
          <span class="line-number" id="file-gistfile1-php-L47" rel="file-gistfile1-php-L47">47</span>
          <span class="line-number" id="file-gistfile1-php-L48" rel="file-gistfile1-php-L48">48</span>
          <span class="line-number" id="file-gistfile1-php-L49" rel="file-gistfile1-php-L49">49</span>
          <span class="line-number" id="file-gistfile1-php-L50" rel="file-gistfile1-php-L50">50</span>
          <span class="line-number" id="file-gistfile1-php-L51" rel="file-gistfile1-php-L51">51</span>
          <span class="line-number" id="file-gistfile1-php-L52" rel="file-gistfile1-php-L52">52</span>
          <span class="line-number" id="file-gistfile1-php-L53" rel="file-gistfile1-php-L53">53</span>
          <span class="line-number" id="file-gistfile1-php-L54" rel="file-gistfile1-php-L54">54</span>
          <span class="line-number" id="file-gistfile1-php-L55" rel="file-gistfile1-php-L55">55</span>
          <span class="line-number" id="file-gistfile1-php-L56" rel="file-gistfile1-php-L56">56</span>
          <span class="line-number" id="file-gistfile1-php-L57" rel="file-gistfile1-php-L57">57</span>
          <span class="line-number" id="file-gistfile1-php-L58" rel="file-gistfile1-php-L58">58</span>
          <span class="line-number" id="file-gistfile1-php-L59" rel="file-gistfile1-php-L59">59</span>
          <span class="line-number" id="file-gistfile1-php-L60" rel="file-gistfile1-php-L60">60</span>
          <span class="line-number" id="file-gistfile1-php-L61" rel="file-gistfile1-php-L61">61</span>
          <span class="line-number" id="file-gistfile1-php-L62" rel="file-gistfile1-php-L62">62</span>
          <span class="line-number" id="file-gistfile1-php-L63" rel="file-gistfile1-php-L63">63</span>
          <span class="line-number" id="file-gistfile1-php-L64" rel="file-gistfile1-php-L64">64</span>
          <span class="line-number" id="file-gistfile1-php-L65" rel="file-gistfile1-php-L65">65</span>
          <span class="line-number" id="file-gistfile1-php-L66" rel="file-gistfile1-php-L66">66</span>
          <span class="line-number" id="file-gistfile1-php-L67" rel="file-gistfile1-php-L67">67</span>
          <span class="line-number" id="file-gistfile1-php-L68" rel="file-gistfile1-php-L68">68</span>
          <span class="line-number" id="file-gistfile1-php-L69" rel="file-gistfile1-php-L69">69</span>
          <span class="line-number" id="file-gistfile1-php-L70" rel="file-gistfile1-php-L70">70</span>
          <span class="line-number" id="file-gistfile1-php-L71" rel="file-gistfile1-php-L71">71</span>
          <span class="line-number" id="file-gistfile1-php-L72" rel="file-gistfile1-php-L72">72</span>
          <span class="line-number" id="file-gistfile1-php-L73" rel="file-gistfile1-php-L73">73</span>
          <span class="line-number" id="file-gistfile1-php-L74" rel="file-gistfile1-php-L74">74</span>
          <span class="line-number" id="file-gistfile1-php-L75" rel="file-gistfile1-php-L75">75</span>
          <span class="line-number" id="file-gistfile1-php-L76" rel="file-gistfile1-php-L76">76</span>
          <span class="line-number" id="file-gistfile1-php-L77" rel="file-gistfile1-php-L77">77</span>
          <span class="line-number" id="file-gistfile1-php-L78" rel="file-gistfile1-php-L78">78</span>
          <span class="line-number" id="file-gistfile1-php-L79" rel="file-gistfile1-php-L79">79</span>
          <span class="line-number" id="file-gistfile1-php-L80" rel="file-gistfile1-php-L80">80</span>
          <span class="line-number" id="file-gistfile1-php-L81" rel="file-gistfile1-php-L81">81</span>
          <span class="line-number" id="file-gistfile1-php-L82" rel="file-gistfile1-php-L82">82</span>
          <span class="line-number" id="file-gistfile1-php-L83" rel="file-gistfile1-php-L83">83</span>
          <span class="line-number" id="file-gistfile1-php-L84" rel="file-gistfile1-php-L84">84</span>
          <span class="line-number" id="file-gistfile1-php-L85" rel="file-gistfile1-php-L85">85</span>
          <span class="line-number" id="file-gistfile1-php-L86" rel="file-gistfile1-php-L86">86</span>
          <span class="line-number" id="file-gistfile1-php-L87" rel="file-gistfile1-php-L87">87</span>
          <span class="line-number" id="file-gistfile1-php-L88" rel="file-gistfile1-php-L88">88</span>
          <span class="line-number" id="file-gistfile1-php-L89" rel="file-gistfile1-php-L89">89</span>
          <span class="line-number" id="file-gistfile1-php-L90" rel="file-gistfile1-php-L90">90</span>
          <span class="line-number" id="file-gistfile1-php-L91" rel="file-gistfile1-php-L91">91</span>
          <span class="line-number" id="file-gistfile1-php-L92" rel="file-gistfile1-php-L92">92</span>
          <span class="line-number" id="file-gistfile1-php-L93" rel="file-gistfile1-php-L93">93</span>
          <span class="line-number" id="file-gistfile1-php-L94" rel="file-gistfile1-php-L94">94</span>
          <span class="line-number" id="file-gistfile1-php-L95" rel="file-gistfile1-php-L95">95</span>
          <span class="line-number" id="file-gistfile1-php-L96" rel="file-gistfile1-php-L96">96</span>
          <span class="line-number" id="file-gistfile1-php-L97" rel="file-gistfile1-php-L97">97</span>
          <span class="line-number" id="file-gistfile1-php-L98" rel="file-gistfile1-php-L98">98</span>
          <span class="line-number" id="file-gistfile1-php-L99" rel="file-gistfile1-php-L99">99</span>
          <span class="line-number" id="file-gistfile1-php-L100" rel="file-gistfile1-php-L100">100</span>
          <span class="line-number" id="file-gistfile1-php-L101" rel="file-gistfile1-php-L101">101</span>
          <span class="line-number" id="file-gistfile1-php-L102" rel="file-gistfile1-php-L102">102</span>
          <span class="line-number" id="file-gistfile1-php-L103" rel="file-gistfile1-php-L103">103</span>
          <span class="line-number" id="file-gistfile1-php-L104" rel="file-gistfile1-php-L104">104</span>
          <span class="line-number" id="file-gistfile1-php-L105" rel="file-gistfile1-php-L105">105</span>
          <span class="line-number" id="file-gistfile1-php-L106" rel="file-gistfile1-php-L106">106</span>
          <span class="line-number" id="file-gistfile1-php-L107" rel="file-gistfile1-php-L107">107</span>
          <span class="line-number" id="file-gistfile1-php-L108" rel="file-gistfile1-php-L108">108</span>
          <span class="line-number" id="file-gistfile1-php-L109" rel="file-gistfile1-php-L109">109</span>
          <span class="line-number" id="file-gistfile1-php-L110" rel="file-gistfile1-php-L110">110</span>
          <span class="line-number" id="file-gistfile1-php-L111" rel="file-gistfile1-php-L111">111</span>
          <span class="line-number" id="file-gistfile1-php-L112" rel="file-gistfile1-php-L112">112</span>
          <span class="line-number" id="file-gistfile1-php-L113" rel="file-gistfile1-php-L113">113</span>
          <span class="line-number" id="file-gistfile1-php-L114" rel="file-gistfile1-php-L114">114</span>
          <span class="line-number" id="file-gistfile1-php-L115" rel="file-gistfile1-php-L115">115</span>
          <span class="line-number" id="file-gistfile1-php-L116" rel="file-gistfile1-php-L116">116</span>
          <span class="line-number" id="file-gistfile1-php-L117" rel="file-gistfile1-php-L117">117</span>
          <span class="line-number" id="file-gistfile1-php-L118" rel="file-gistfile1-php-L118">118</span>
          <span class="line-number" id="file-gistfile1-php-L119" rel="file-gistfile1-php-L119">119</span>
          <span class="line-number" id="file-gistfile1-php-L120" rel="file-gistfile1-php-L120">120</span>
          <span class="line-number" id="file-gistfile1-php-L121" rel="file-gistfile1-php-L121">121</span>
          <span class="line-number" id="file-gistfile1-php-L122" rel="file-gistfile1-php-L122">122</span>
          <span class="line-number" id="file-gistfile1-php-L123" rel="file-gistfile1-php-L123">123</span>
          <span class="line-number" id="file-gistfile1-php-L124" rel="file-gistfile1-php-L124">124</span>
          <span class="line-number" id="file-gistfile1-php-L125" rel="file-gistfile1-php-L125">125</span>
          <span class="line-number" id="file-gistfile1-php-L126" rel="file-gistfile1-php-L126">126</span>
          <span class="line-number" id="file-gistfile1-php-L127" rel="file-gistfile1-php-L127">127</span>
          <span class="line-number" id="file-gistfile1-php-L128" rel="file-gistfile1-php-L128">128</span>
          <span class="line-number" id="file-gistfile1-php-L129" rel="file-gistfile1-php-L129">129</span>
          <span class="line-number" id="file-gistfile1-php-L130" rel="file-gistfile1-php-L130">130</span>
          <span class="line-number" id="file-gistfile1-php-L131" rel="file-gistfile1-php-L131">131</span>
          <span class="line-number" id="file-gistfile1-php-L132" rel="file-gistfile1-php-L132">132</span>
          <span class="line-number" id="file-gistfile1-php-L133" rel="file-gistfile1-php-L133">133</span>
          <span class="line-number" id="file-gistfile1-php-L134" rel="file-gistfile1-php-L134">134</span>
          <span class="line-number" id="file-gistfile1-php-L135" rel="file-gistfile1-php-L135">135</span>
          <span class="line-number" id="file-gistfile1-php-L136" rel="file-gistfile1-php-L136">136</span>
          <span class="line-number" id="file-gistfile1-php-L137" rel="file-gistfile1-php-L137">137</span>
          <span class="line-number" id="file-gistfile1-php-L138" rel="file-gistfile1-php-L138">138</span>
          <span class="line-number" id="file-gistfile1-php-L139" rel="file-gistfile1-php-L139">139</span>
          <span class="line-number" id="file-gistfile1-php-L140" rel="file-gistfile1-php-L140">140</span>
          <span class="line-number" id="file-gistfile1-php-L141" rel="file-gistfile1-php-L141">141</span>
          <span class="line-number" id="file-gistfile1-php-L142" rel="file-gistfile1-php-L142">142</span>
          <span class="line-number" id="file-gistfile1-php-L143" rel="file-gistfile1-php-L143">143</span>
          <span class="line-number" id="file-gistfile1-php-L144" rel="file-gistfile1-php-L144">144</span>
          <span class="line-number" id="file-gistfile1-php-L145" rel="file-gistfile1-php-L145">145</span>
          <span class="line-number" id="file-gistfile1-php-L146" rel="file-gistfile1-php-L146">146</span>
          <span class="line-number" id="file-gistfile1-php-L147" rel="file-gistfile1-php-L147">147</span>
          <span class="line-number" id="file-gistfile1-php-L148" rel="file-gistfile1-php-L148">148</span>
          <span class="line-number" id="file-gistfile1-php-L149" rel="file-gistfile1-php-L149">149</span>
          <span class="line-number" id="file-gistfile1-php-L150" rel="file-gistfile1-php-L150">150</span>
          <span class="line-number" id="file-gistfile1-php-L151" rel="file-gistfile1-php-L151">151</span>
          <span class="line-number" id="file-gistfile1-php-L152" rel="file-gistfile1-php-L152">152</span>
          <span class="line-number" id="file-gistfile1-php-L153" rel="file-gistfile1-php-L153">153</span>
          <span class="line-number" id="file-gistfile1-php-L154" rel="file-gistfile1-php-L154">154</span>
          <span class="line-number" id="file-gistfile1-php-L155" rel="file-gistfile1-php-L155">155</span>
          <span class="line-number" id="file-gistfile1-php-L156" rel="file-gistfile1-php-L156">156</span>
          <span class="line-number" id="file-gistfile1-php-L157" rel="file-gistfile1-php-L157">157</span>
          <span class="line-number" id="file-gistfile1-php-L158" rel="file-gistfile1-php-L158">158</span>
          <span class="line-number" id="file-gistfile1-php-L159" rel="file-gistfile1-php-L159">159</span>
          <span class="line-number" id="file-gistfile1-php-L160" rel="file-gistfile1-php-L160">160</span>
          <span class="line-number" id="file-gistfile1-php-L161" rel="file-gistfile1-php-L161">161</span>
          <span class="line-number" id="file-gistfile1-php-L162" rel="file-gistfile1-php-L162">162</span>
          <span class="line-number" id="file-gistfile1-php-L163" rel="file-gistfile1-php-L163">163</span>
          <span class="line-number" id="file-gistfile1-php-L164" rel="file-gistfile1-php-L164">164</span>
          <span class="line-number" id="file-gistfile1-php-L165" rel="file-gistfile1-php-L165">165</span>
          <span class="line-number" id="file-gistfile1-php-L166" rel="file-gistfile1-php-L166">166</span>
          <span class="line-number" id="file-gistfile1-php-L167" rel="file-gistfile1-php-L167">167</span>
          <span class="line-number" id="file-gistfile1-php-L168" rel="file-gistfile1-php-L168">168</span>
          <span class="line-number" id="file-gistfile1-php-L169" rel="file-gistfile1-php-L169">169</span>
          <span class="line-number" id="file-gistfile1-php-L170" rel="file-gistfile1-php-L170">170</span>
          <span class="line-number" id="file-gistfile1-php-L171" rel="file-gistfile1-php-L171">171</span>
          <span class="line-number" id="file-gistfile1-php-L172" rel="file-gistfile1-php-L172">172</span>
          <span class="line-number" id="file-gistfile1-php-L173" rel="file-gistfile1-php-L173">173</span>
          <span class="line-number" id="file-gistfile1-php-L174" rel="file-gistfile1-php-L174">174</span>
          <span class="line-number" id="file-gistfile1-php-L175" rel="file-gistfile1-php-L175">175</span>
          <span class="line-number" id="file-gistfile1-php-L176" rel="file-gistfile1-php-L176">176</span>
          <span class="line-number" id="file-gistfile1-php-L177" rel="file-gistfile1-php-L177">177</span>
          <span class="line-number" id="file-gistfile1-php-L178" rel="file-gistfile1-php-L178">178</span>
          <span class="line-number" id="file-gistfile1-php-L179" rel="file-gistfile1-php-L179">179</span>
          <span class="line-number" id="file-gistfile1-php-L180" rel="file-gistfile1-php-L180">180</span>
          <span class="line-number" id="file-gistfile1-php-L181" rel="file-gistfile1-php-L181">181</span>
          <span class="line-number" id="file-gistfile1-php-L182" rel="file-gistfile1-php-L182">182</span>
          <span class="line-number" id="file-gistfile1-php-L183" rel="file-gistfile1-php-L183">183</span>
          <span class="line-number" id="file-gistfile1-php-L184" rel="file-gistfile1-php-L184">184</span>
          <span class="line-number" id="file-gistfile1-php-L185" rel="file-gistfile1-php-L185">185</span>
          <span class="line-number" id="file-gistfile1-php-L186" rel="file-gistfile1-php-L186">186</span>
          <span class="line-number" id="file-gistfile1-php-L187" rel="file-gistfile1-php-L187">187</span>
          <span class="line-number" id="file-gistfile1-php-L188" rel="file-gistfile1-php-L188">188</span>
          <span class="line-number" id="file-gistfile1-php-L189" rel="file-gistfile1-php-L189">189</span>
          <span class="line-number" id="file-gistfile1-php-L190" rel="file-gistfile1-php-L190">190</span>
          <span class="line-number" id="file-gistfile1-php-L191" rel="file-gistfile1-php-L191">191</span>
          <span class="line-number" id="file-gistfile1-php-L192" rel="file-gistfile1-php-L192">192</span>
          <span class="line-number" id="file-gistfile1-php-L193" rel="file-gistfile1-php-L193">193</span>
          <span class="line-number" id="file-gistfile1-php-L194" rel="file-gistfile1-php-L194">194</span>
          <span class="line-number" id="file-gistfile1-php-L195" rel="file-gistfile1-php-L195">195</span>
          <span class="line-number" id="file-gistfile1-php-L196" rel="file-gistfile1-php-L196">196</span>
          <span class="line-number" id="file-gistfile1-php-L197" rel="file-gistfile1-php-L197">197</span>
          <span class="line-number" id="file-gistfile1-php-L198" rel="file-gistfile1-php-L198">198</span>
          <span class="line-number" id="file-gistfile1-php-L199" rel="file-gistfile1-php-L199">199</span>
          <span class="line-number" id="file-gistfile1-php-L200" rel="file-gistfile1-php-L200">200</span>
          <span class="line-number" id="file-gistfile1-php-L201" rel="file-gistfile1-php-L201">201</span>
          <span class="line-number" id="file-gistfile1-php-L202" rel="file-gistfile1-php-L202">202</span>
          <span class="line-number" id="file-gistfile1-php-L203" rel="file-gistfile1-php-L203">203</span>
          <span class="line-number" id="file-gistfile1-php-L204" rel="file-gistfile1-php-L204">204</span>
          <span class="line-number" id="file-gistfile1-php-L205" rel="file-gistfile1-php-L205">205</span>
        </td>
        <td class="line-data">
          <pre class="line-pre"><div class="line" id="file-gistfile1-php-LC1"><span class="cp">&lt;?php</span></div><div class="line" id="file-gistfile1-php-LC2"><span class="sd">/**</span></div><div class="line" id="file-gistfile1-php-LC3"><span class="sd">* Calculation Subtotal Merge Tag </span></div><div class="line" id="file-gistfile1-php-LC4"><span class="sd">* http://gravitywiz.com/</span></div><div class="line" id="file-gistfile1-php-LC5"><span class="sd">*/</span></div><div class="line" id="file-gistfile1-php-LC6"><span class="k">class</span> <span class="nc">GWCalcSubtotal</span> <span class="p">{</span> </div><div class="line" id="file-gistfile1-php-LC7">    </div><div class="line" id="file-gistfile1-php-LC8">    <span class="k">public</span> <span class="k">static</span> <span class="nv">$merge_tag</span> <span class="o">=</span> <span class="s1">&#39;{subtotal}&#39;</span><span class="p">;</span> </div><div class="line" id="file-gistfile1-php-LC9">    </div><div class="line" id="file-gistfile1-php-LC10">    <span class="k">function</span> <span class="nf">__construct</span><span class="p">()</span> <span class="p">{</span></div><div class="line" id="file-gistfile1-php-LC11">        </div><div class="line" id="file-gistfile1-php-LC12">        <span class="c1">// front-end</span></div><div class="line" id="file-gistfile1-php-LC13">        <span class="nx">add_filter</span><span class="p">(</span> <span class="s1">&#39;gform_pre_render&#39;</span><span class="p">,</span> <span class="k">array</span><span class="p">(</span> <span class="nv">$this</span><span class="p">,</span> <span class="s1">&#39;maybe_replace_subtotal_merge_tag&#39;</span> <span class="p">)</span> <span class="p">);</span></div><div class="line" id="file-gistfile1-php-LC14">        <span class="nx">add_filter</span><span class="p">(</span> <span class="s1">&#39;gform_pre_submission_filter&#39;</span><span class="p">,</span> <span class="k">array</span><span class="p">(</span> <span class="nv">$this</span><span class="p">,</span> <span class="s1">&#39;maybe_replace_subtotal_merge_tag&#39;</span> <span class="p">)</span> <span class="p">);</span></div><div class="line" id="file-gistfile1-php-LC15">        </div><div class="line" id="file-gistfile1-php-LC16">        <span class="c1">// back-end</span></div><div class="line" id="file-gistfile1-php-LC17">        <span class="nx">add_filter</span><span class="p">(</span> <span class="s1">&#39;gform_admin_pre_render&#39;</span><span class="p">,</span> <span class="k">array</span><span class="p">(</span> <span class="nv">$this</span><span class="p">,</span> <span class="s1">&#39;add_merge_tags&#39;</span> <span class="p">)</span> <span class="p">);</span></div><div class="line" id="file-gistfile1-php-LC18">        </div><div class="line" id="file-gistfile1-php-LC19">    <span class="p">}</span></div><div class="line" id="file-gistfile1-php-LC20">    </div><div class="line" id="file-gistfile1-php-LC21">    <span class="sd">/**</span></div><div class="line" id="file-gistfile1-php-LC22"><span class="sd">    * Look for {subtotal} merge tag in form fields &#39;calculationFormula&#39; property. If found, replace with the</span></div><div class="line" id="file-gistfile1-php-LC23"><span class="sd">    * aggregated subtotal merge tag string.</span></div><div class="line" id="file-gistfile1-php-LC24"><span class="sd">    * </span></div><div class="line" id="file-gistfile1-php-LC25"><span class="sd">    * @param mixed $form</span></div><div class="line" id="file-gistfile1-php-LC26"><span class="sd">    */</span></div><div class="line" id="file-gistfile1-php-LC27">    <span class="k">function</span> <span class="nf">maybe_replace_subtotal_merge_tag</span><span class="p">(</span> <span class="nv">$form</span> <span class="p">)</span> <span class="p">{</span></div><div class="line" id="file-gistfile1-php-LC28">        </div><div class="line" id="file-gistfile1-php-LC29">        <span class="k">foreach</span><span class="p">(</span> <span class="nv">$form</span><span class="p">[</span><span class="s1">&#39;fields&#39;</span><span class="p">]</span> <span class="k">as</span> <span class="o">&amp;</span><span class="nv">$field</span> <span class="p">)</span> <span class="p">{</span></div><div class="line" id="file-gistfile1-php-LC30">            </div><div class="line" id="file-gistfile1-php-LC31">            <span class="k">if</span><span class="p">(</span> <span class="o">!</span><span class="nx">self</span><span class="o">::</span><span class="na">has_subtotal_merge_tag</span><span class="p">(</span> <span class="nv">$field</span> <span class="p">)</span> <span class="p">)</span></div><div class="line" id="file-gistfile1-php-LC32">                <span class="k">continue</span><span class="p">;</span></div><div class="line" id="file-gistfile1-php-LC33">            </div><div class="line" id="file-gistfile1-php-LC34">            <span class="nv">$subtotal_merge_tags</span> <span class="o">=</span> <span class="nx">self</span><span class="o">::</span><span class="na">get_subtotal_merge_tag_string</span><span class="p">(</span> <span class="nv">$form</span><span class="p">,</span> <span class="nv">$field</span> <span class="p">);</span></div><div class="line" id="file-gistfile1-php-LC35">            <span class="nv">$field</span><span class="p">[</span><span class="s1">&#39;calculationFormula&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">str_replace</span><span class="p">(</span> <span class="nx">self</span><span class="o">::</span><span class="nv">$merge_tag</span><span class="p">,</span> <span class="nv">$subtotal_merge_tags</span><span class="p">,</span> <span class="nv">$field</span><span class="p">[</span><span class="s1">&#39;calculationFormula&#39;</span><span class="p">]</span> <span class="p">);</span></div><div class="line" id="file-gistfile1-php-LC36">            </div><div class="line" id="file-gistfile1-php-LC37">        <span class="p">}</span></div><div class="line" id="file-gistfile1-php-LC38">        </div><div class="line" id="file-gistfile1-php-LC39">        <span class="k">return</span> <span class="nv">$form</span><span class="p">;</span></div><div class="line" id="file-gistfile1-php-LC40">    <span class="p">}</span></div><div class="line" id="file-gistfile1-php-LC41">    </div><div class="line" id="file-gistfile1-php-LC42">    <span class="sd">/**</span></div><div class="line" id="file-gistfile1-php-LC43"><span class="sd">    * Get all the pricing fields on the form, get their corresponding merge tags and aggregate them into a formula that</span></div><div class="line" id="file-gistfile1-php-LC44"><span class="sd">    * will yeild the form&#39;s subtotal.</span></div><div class="line" id="file-gistfile1-php-LC45"><span class="sd">    * </span></div><div class="line" id="file-gistfile1-php-LC46"><span class="sd">    * @param mixed $form</span></div><div class="line" id="file-gistfile1-php-LC47"><span class="sd">    */</span></div><div class="line" id="file-gistfile1-php-LC48">    <span class="k">static</span> <span class="k">function</span> <span class="nf">get_subtotal_merge_tag_string</span><span class="p">(</span> <span class="nv">$form</span><span class="p">,</span> <span class="nv">$current_field</span> <span class="p">)</span> <span class="p">{</span></div><div class="line" id="file-gistfile1-php-LC49">        </div><div class="line" id="file-gistfile1-php-LC50">        <span class="nv">$pricing_fields</span> <span class="o">=</span> <span class="nx">self</span><span class="o">::</span><span class="na">get_pricing_fields</span><span class="p">(</span> <span class="nv">$form</span> <span class="p">);</span></div><div class="line" id="file-gistfile1-php-LC51">        <span class="nv">$product_tag_groups</span> <span class="o">=</span> <span class="k">array</span><span class="p">();</span></div><div class="line" id="file-gistfile1-php-LC52">        </div><div class="line" id="file-gistfile1-php-LC53">        <span class="k">foreach</span><span class="p">(</span> <span class="nv">$pricing_fields</span><span class="p">[</span><span class="s1">&#39;products&#39;</span><span class="p">]</span> <span class="k">as</span> <span class="nv">$product</span> <span class="p">)</span> <span class="p">{</span></div><div class="line" id="file-gistfile1-php-LC54">            </div><div class="line" id="file-gistfile1-php-LC55">            <span class="nv">$product_field</span> <span class="o">=</span> <span class="nx">rgar</span><span class="p">(</span> <span class="nv">$product</span><span class="p">,</span> <span class="s1">&#39;product&#39;</span> <span class="p">);</span></div><div class="line" id="file-gistfile1-php-LC56">            <span class="nv">$option_fields</span> <span class="o">=</span> <span class="nx">rgar</span><span class="p">(</span> <span class="nv">$product</span><span class="p">,</span> <span class="s1">&#39;options&#39;</span> <span class="p">);</span></div><div class="line" id="file-gistfile1-php-LC57">            <span class="nv">$quantity_field</span> <span class="o">=</span> <span class="nx">rgar</span><span class="p">(</span> <span class="nv">$product</span><span class="p">,</span> <span class="s1">&#39;quantity&#39;</span> <span class="p">);</span></div><div class="line" id="file-gistfile1-php-LC58">            </div><div class="line" id="file-gistfile1-php-LC59">            <span class="c1">// do not include current field in subtotal</span></div><div class="line" id="file-gistfile1-php-LC60">            <span class="k">if</span><span class="p">(</span> <span class="nv">$product_field</span><span class="p">[</span><span class="s1">&#39;id&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="nv">$current_field</span><span class="p">[</span><span class="s1">&#39;id&#39;</span><span class="p">]</span> <span class="p">)</span></div><div class="line" id="file-gistfile1-php-LC61">                <span class="k">continue</span><span class="p">;</span></div><div class="line" id="file-gistfile1-php-LC62">            </div><div class="line" id="file-gistfile1-php-LC63">            <span class="nv">$product_tags</span> <span class="o">=</span> <span class="nx">GFCommon</span><span class="o">::</span><span class="na">get_field_merge_tags</span><span class="p">(</span> <span class="nv">$product_field</span> <span class="p">);</span></div><div class="line" id="file-gistfile1-php-LC64">            <span class="nv">$quantity_tag</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span></div><div class="line" id="file-gistfile1-php-LC65">            </div><div class="line" id="file-gistfile1-php-LC66">            <span class="c1">// if a single product type, only get the &quot;price&quot; merge tag</span></div><div class="line" id="file-gistfile1-php-LC67">            <span class="k">if</span><span class="p">(</span> <span class="nb">in_array</span><span class="p">(</span> <span class="nx">GFFormsModel</span><span class="o">::</span><span class="na">get_input_type</span><span class="p">(</span> <span class="nv">$product_field</span> <span class="p">),</span> <span class="k">array</span><span class="p">(</span> <span class="s1">&#39;singleproduct&#39;</span><span class="p">,</span> <span class="s1">&#39;calculation&#39;</span> <span class="p">)</span> <span class="p">)</span> <span class="p">)</span> <span class="p">{</span></div><div class="line" id="file-gistfile1-php-LC68">                </div><div class="line" id="file-gistfile1-php-LC69">                <span class="c1">// single products provide quantity merge tag</span></div><div class="line" id="file-gistfile1-php-LC70">                <span class="k">if</span><span class="p">(</span> <span class="k">empty</span><span class="p">(</span> <span class="nv">$quantity_field</span> <span class="p">)</span> <span class="p">)</span></div><div class="line" id="file-gistfile1-php-LC71">                    <span class="nv">$quantity_tag</span> <span class="o">=</span> <span class="nv">$product_tags</span><span class="p">[</span><span class="mi">2</span><span class="p">][</span><span class="s1">&#39;tag&#39;</span><span class="p">];</span></div><div class="line" id="file-gistfile1-php-LC72">                </div><div class="line" id="file-gistfile1-php-LC73">                <span class="nv">$product_tags</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span> <span class="nv">$product_tags</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="p">);</span></div><div class="line" id="file-gistfile1-php-LC74">            <span class="p">}</span></div><div class="line" id="file-gistfile1-php-LC75">            </div><div class="line" id="file-gistfile1-php-LC76">            <span class="c1">// if quantity field is provided for product, get merge tag</span></div><div class="line" id="file-gistfile1-php-LC77">            <span class="k">if</span><span class="p">(</span> <span class="o">!</span><span class="k">empty</span><span class="p">(</span> <span class="nv">$quantity_field</span> <span class="p">)</span> <span class="p">)</span> <span class="p">{</span></div><div class="line" id="file-gistfile1-php-LC78">                <span class="nv">$quantity_tag</span> <span class="o">=</span> <span class="nx">GFCommon</span><span class="o">::</span><span class="na">get_field_merge_tags</span><span class="p">(</span> <span class="nv">$quantity_field</span> <span class="p">);</span></div><div class="line" id="file-gistfile1-php-LC79">                <span class="nv">$quantity_tag</span> <span class="o">=</span> <span class="nv">$quantity_tag</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="s1">&#39;tag&#39;</span><span class="p">];</span></div><div class="line" id="file-gistfile1-php-LC80">            <span class="p">}</span></div><div class="line" id="file-gistfile1-php-LC81">            </div><div class="line" id="file-gistfile1-php-LC82">            <span class="nv">$product_tags</span> <span class="o">=</span> <span class="nx">wp_list_pluck</span><span class="p">(</span> <span class="nv">$product_tags</span><span class="p">,</span> <span class="s1">&#39;tag&#39;</span> <span class="p">);</span></div><div class="line" id="file-gistfile1-php-LC83">            <span class="nv">$option_tags</span> <span class="o">=</span> <span class="k">array</span><span class="p">();</span></div><div class="line" id="file-gistfile1-php-LC84">            </div><div class="line" id="file-gistfile1-php-LC85">            <span class="k">foreach</span><span class="p">(</span> <span class="nv">$option_fields</span> <span class="k">as</span> <span class="nv">$option_field</span> <span class="p">)</span> <span class="p">{</span></div><div class="line" id="file-gistfile1-php-LC86">                </div><div class="line" id="file-gistfile1-php-LC87">                <span class="nv">$new_options_tags</span> <span class="o">=</span> <span class="nx">GFCommon</span><span class="o">::</span><span class="na">get_field_merge_tags</span><span class="p">(</span> <span class="nv">$option_field</span> <span class="p">);</span></div><div class="line" id="file-gistfile1-php-LC88">                <span class="k">if</span><span class="p">(</span> <span class="o">!</span><span class="nb">is_array</span><span class="p">(</span> <span class="nv">$new_options_tags</span> <span class="p">)</span> <span class="p">)</span></div><div class="line" id="file-gistfile1-php-LC89">                    <span class="k">continue</span><span class="p">;</span></div><div class="line" id="file-gistfile1-php-LC90">                </div><div class="line" id="file-gistfile1-php-LC91">                <span class="k">if</span><span class="p">(</span> <span class="nx">GFFormsModel</span><span class="o">::</span><span class="na">get_input_type</span><span class="p">(</span> <span class="nv">$option_field</span> <span class="p">)</span> <span class="o">==</span> <span class="s1">&#39;checkbox&#39;</span> <span class="p">)</span> <span class="p">{</span></div><div class="line" id="file-gistfile1-php-LC92">                    <span class="nb">array_shift</span><span class="p">(</span> <span class="nv">$new_options_tags</span> <span class="p">);</span>    </div><div class="line" id="file-gistfile1-php-LC93">                <span class="p">}</span> <span class="k">else</span> <span class="p">{</span></div><div class="line" id="file-gistfile1-php-LC94">                    <span class="nv">$new_options_tags</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span> <span class="nb">array_shift</span><span class="p">(</span> <span class="nv">$new_options_tags</span> <span class="p">)</span> <span class="p">);</span></div><div class="line" id="file-gistfile1-php-LC95">                <span class="p">}</span></div><div class="line" id="file-gistfile1-php-LC96">                </div><div class="line" id="file-gistfile1-php-LC97">                <span class="nv">$option_tags</span> <span class="o">=</span> <span class="nb">array_merge</span><span class="p">(</span> <span class="nv">$option_tags</span><span class="p">,</span> <span class="nv">$new_options_tags</span> <span class="p">);</span></div><div class="line" id="file-gistfile1-php-LC98">            <span class="p">}</span></div><div class="line" id="file-gistfile1-php-LC99">            </div><div class="line" id="file-gistfile1-php-LC100">            <span class="nv">$option_tags</span> <span class="o">=</span> <span class="nx">wp_list_pluck</span><span class="p">(</span> <span class="nv">$option_tags</span><span class="p">,</span> <span class="s1">&#39;tag&#39;</span> <span class="p">);</span></div><div class="line" id="file-gistfile1-php-LC101">            </div><div class="line" id="file-gistfile1-php-LC102">            <span class="nv">$product_tag_groups</span><span class="p">[]</span> <span class="o">=</span> <span class="s1">&#39;( ( &#39;</span> <span class="o">.</span> <span class="nb">implode</span><span class="p">(</span> <span class="s1">&#39; + &#39;</span><span class="p">,</span> <span class="nb">array_merge</span><span class="p">(</span> <span class="nv">$product_tags</span><span class="p">,</span> <span class="nv">$option_tags</span> <span class="p">)</span> <span class="p">)</span> <span class="o">.</span> <span class="s1">&#39; ) * &#39;</span> <span class="o">.</span> <span class="nv">$quantity_tag</span> <span class="o">.</span> <span class="s1">&#39; )&#39;</span><span class="p">;</span></div><div class="line" id="file-gistfile1-php-LC103">            </div><div class="line" id="file-gistfile1-php-LC104">        <span class="p">}</span></div><div class="line" id="file-gistfile1-php-LC105">        </div><div class="line" id="file-gistfile1-php-LC106">        <span class="nv">$shipping_tag</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span></div><div class="line" id="file-gistfile1-php-LC107">        <span class="k">if</span><span class="p">(</span> <span class="nx">rgar</span><span class="p">(</span> <span class="nv">$pricing_fields</span><span class="p">,</span> <span class="s1">&#39;shipping&#39;</span> <span class="p">)</span> <span class="p">)</span> <span class="p">{</span></div><div class="line" id="file-gistfile1-php-LC108">            <span class="nv">$shipping_tag</span> <span class="o">=</span> <span class="nx">GFCommon</span><span class="o">::</span><span class="na">get_field_merge_tags</span><span class="p">(</span> <span class="nx">rgars</span><span class="p">(</span> <span class="nv">$pricing_fields</span><span class="p">,</span> <span class="s1">&#39;shipping/0&#39;</span> <span class="p">)</span> <span class="p">);</span></div><div class="line" id="file-gistfile1-php-LC109">            <span class="nv">$shipping_tag</span> <span class="o">=</span> <span class="nv">$shipping_tag</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="s1">&#39;tag&#39;</span><span class="p">];</span></div><div class="line" id="file-gistfile1-php-LC110">        <span class="p">}</span></div><div class="line" id="file-gistfile1-php-LC111">        </div><div class="line" id="file-gistfile1-php-LC112">        <span class="nv">$pricing_tag_string</span> <span class="o">=</span> <span class="s1">&#39;( ( &#39;</span> <span class="o">.</span> <span class="nb">implode</span><span class="p">(</span> <span class="s1">&#39; + &#39;</span><span class="p">,</span> <span class="nv">$product_tag_groups</span> <span class="p">)</span> <span class="o">.</span> <span class="s1">&#39; ) + &#39;</span> <span class="o">.</span> <span class="nv">$shipping_tag</span> <span class="o">.</span> <span class="s1">&#39; )&#39;</span><span class="p">;</span></div><div class="line" id="file-gistfile1-php-LC113">        </div><div class="line" id="file-gistfile1-php-LC114">        <span class="k">return</span> <span class="nv">$pricing_tag_string</span><span class="p">;</span></div><div class="line" id="file-gistfile1-php-LC115">    <span class="p">}</span></div><div class="line" id="file-gistfile1-php-LC116">    </div><div class="line" id="file-gistfile1-php-LC117">    <span class="sd">/**</span></div><div class="line" id="file-gistfile1-php-LC118"><span class="sd">    * Get all pricing fields from a given form object grouped by product and shipping with options nested under their </span></div><div class="line" id="file-gistfile1-php-LC119"><span class="sd">    * respective products.</span></div><div class="line" id="file-gistfile1-php-LC120"><span class="sd">    * </span></div><div class="line" id="file-gistfile1-php-LC121"><span class="sd">    * @param mixed $form</span></div><div class="line" id="file-gistfile1-php-LC122"><span class="sd">    */</span></div><div class="line" id="file-gistfile1-php-LC123">    <span class="k">static</span> <span class="k">function</span> <span class="nf">get_pricing_fields</span><span class="p">(</span> <span class="nv">$form</span> <span class="p">)</span> <span class="p">{</span></div><div class="line" id="file-gistfile1-php-LC124">    </div><div class="line" id="file-gistfile1-php-LC125">        <span class="nv">$product_fields</span> <span class="o">=</span> <span class="k">array</span><span class="p">();</span></div><div class="line" id="file-gistfile1-php-LC126">&nbsp;</div><div class="line" id="file-gistfile1-php-LC127">        <span class="k">foreach</span><span class="p">(</span> <span class="nv">$form</span><span class="p">[</span><span class="s2">&quot;fields&quot;</span><span class="p">]</span> <span class="k">as</span> <span class="nv">$field</span> <span class="p">)</span> <span class="p">{</span></div><div class="line" id="file-gistfile1-php-LC128">        </div><div class="line" id="file-gistfile1-php-LC129">            <span class="k">if</span><span class="p">(</span> <span class="nv">$field</span><span class="p">[</span><span class="s2">&quot;type&quot;</span><span class="p">]</span> <span class="o">!=</span> <span class="s1">&#39;product&#39;</span> <span class="p">)</span></div><div class="line" id="file-gistfile1-php-LC130">                <span class="k">continue</span><span class="p">;</span></div><div class="line" id="file-gistfile1-php-LC131">                </div><div class="line" id="file-gistfile1-php-LC132">            <span class="nv">$option_fields</span> <span class="o">=</span> <span class="nx">GFCommon</span><span class="o">::</span><span class="na">get_product_fields_by_type</span><span class="p">(</span><span class="nv">$form</span><span class="p">,</span> <span class="k">array</span><span class="p">(</span><span class="s2">&quot;option&quot;</span><span class="p">),</span> <span class="nv">$field</span><span class="p">[</span><span class="s1">&#39;id&#39;</span><span class="p">]</span> <span class="p">);</span></div><div class="line" id="file-gistfile1-php-LC133">            </div><div class="line" id="file-gistfile1-php-LC134">            <span class="c1">// can only have 1 quantity field</span></div><div class="line" id="file-gistfile1-php-LC135">            <span class="nv">$quantity_field</span> <span class="o">=</span> <span class="nx">GFCommon</span><span class="o">::</span><span class="na">get_product_fields_by_type</span><span class="p">(</span> <span class="nv">$form</span><span class="p">,</span> <span class="k">array</span><span class="p">(</span><span class="s2">&quot;quantity&quot;</span><span class="p">),</span> <span class="nv">$field</span><span class="p">[</span><span class="s1">&#39;id&#39;</span><span class="p">]</span> <span class="p">);</span></div><div class="line" id="file-gistfile1-php-LC136">            <span class="nv">$quantity_field</span> <span class="o">=</span> <span class="nx">rgar</span><span class="p">(</span> <span class="nv">$quantity_field</span><span class="p">,</span> <span class="mi">0</span> <span class="p">);</span></div><div class="line" id="file-gistfile1-php-LC137">            </div><div class="line" id="file-gistfile1-php-LC138">            <span class="nv">$product_fields</span><span class="p">[]</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span></div><div class="line" id="file-gistfile1-php-LC139">                <span class="s1">&#39;product&#39;</span> <span class="o">=&gt;</span> <span class="nv">$field</span><span class="p">,</span></div><div class="line" id="file-gistfile1-php-LC140">                <span class="s1">&#39;options&#39;</span> <span class="o">=&gt;</span> <span class="nv">$option_fields</span><span class="p">,</span></div><div class="line" id="file-gistfile1-php-LC141">                <span class="s1">&#39;quantity&#39;</span> <span class="o">=&gt;</span> <span class="nv">$quantity_field</span></div><div class="line" id="file-gistfile1-php-LC142">                <span class="p">);</span></div><div class="line" id="file-gistfile1-php-LC143">            </div><div class="line" id="file-gistfile1-php-LC144">        <span class="p">}</span></div><div class="line" id="file-gistfile1-php-LC145">&nbsp;</div><div class="line" id="file-gistfile1-php-LC146">        <span class="nv">$shipping_field</span> <span class="o">=</span> <span class="nx">GFCommon</span><span class="o">::</span><span class="na">get_fields_by_type</span><span class="p">(</span><span class="nv">$form</span><span class="p">,</span> <span class="k">array</span><span class="p">(</span><span class="s2">&quot;shipping&quot;</span><span class="p">));</span></div><div class="line" id="file-gistfile1-php-LC147">&nbsp;</div><div class="line" id="file-gistfile1-php-LC148">        <span class="k">return</span> <span class="k">array</span><span class="p">(</span> <span class="s2">&quot;products&quot;</span> <span class="o">=&gt;</span> <span class="nv">$product_fields</span><span class="p">,</span> <span class="s2">&quot;shipping&quot;</span> <span class="o">=&gt;</span> <span class="nv">$shipping_field</span> <span class="p">);</span></div><div class="line" id="file-gistfile1-php-LC149">    <span class="p">}</span></div><div class="line" id="file-gistfile1-php-LC150">    </div><div class="line" id="file-gistfile1-php-LC151">    <span class="k">function</span> <span class="nf">add_merge_tags</span><span class="p">(</span> <span class="nv">$form</span> <span class="p">)</span> <span class="p">{</span></div><div class="line" id="file-gistfile1-php-LC152">        </div><div class="line" id="file-gistfile1-php-LC153">        <span class="nv">$label</span> <span class="o">=</span> <span class="nx">__</span><span class="p">(</span><span class="s1">&#39;Subtotal&#39;</span><span class="p">,</span> <span class="s1">&#39;gravityforms&#39;</span><span class="p">);</span></div><div class="line" id="file-gistfile1-php-LC154">        </div><div class="line" id="file-gistfile1-php-LC155">        <span class="cp">?&gt;</span><span class="x"></span></div><div class="line" id="file-gistfile1-php-LC156"><span class="x">        </span></div><div class="line" id="file-gistfile1-php-LC157"><span class="x">        &lt;script type=&quot;text/javascript&quot;&gt;</span></div><div class="line" id="file-gistfile1-php-LC158"><span class="x">            </span></div><div class="line" id="file-gistfile1-php-LC159"><span class="x">            // for the future (not yet supported for calc field)</span></div><div class="line" id="file-gistfile1-php-LC160"><span class="x">            gform.addFilter(&quot;gform_merge_tags&quot;, &quot;gwcs_add_merge_tags&quot;);</span></div><div class="line" id="file-gistfile1-php-LC161"><span class="x">            function gwcs_add_merge_tags( mergeTags, elementId, hideAllFields, excludeFieldTypes, isPrepop, option ) {</span></div><div class="line" id="file-gistfile1-php-LC162"><span class="x">                console.log( elementId );</span></div><div class="line" id="file-gistfile1-php-LC163"><span class="x">                mergeTags[&quot;pricing&quot;].tags.push({ tag: &#39;</span><span class="cp">&lt;?php</span> <span class="k">echo</span> <span class="nx">self</span><span class="o">::</span><span class="nv">$merge_tag</span><span class="p">;</span> <span class="cp">?&gt;</span><span class="x">&#39;, label: &#39;</span><span class="cp">&lt;?php</span> <span class="k">echo</span> <span class="nv">$label</span><span class="p">;</span> <span class="cp">?&gt;</span><span class="x">&#39; });</span></div><div class="line" id="file-gistfile1-php-LC164"><span class="x">                return mergeTags;</span></div><div class="line" id="file-gistfile1-php-LC165"><span class="x">            }</span></div><div class="line" id="file-gistfile1-php-LC166"><span class="x">            </span></div><div class="line" id="file-gistfile1-php-LC167"><span class="x">            // hacky, but only temporary</span></div><div class="line" id="file-gistfile1-php-LC168"><span class="x">            jQuery(document).ready(function($){</span></div><div class="line" id="file-gistfile1-php-LC169"><span class="x">                </span></div><div class="line" id="file-gistfile1-php-LC170"><span class="x">                var calcMergeTagSelect = $(&#39;#field_calculation_formula_variable_select&#39;);</span></div><div class="line" id="file-gistfile1-php-LC171"><span class="x">                calcMergeTagSelect.find(&#39;optgroup&#39;).eq(0).append( &#39;&lt;option value=&quot;</span><span class="cp">&lt;?php</span> <span class="k">echo</span> <span class="nx">self</span><span class="o">::</span><span class="nv">$merge_tag</span><span class="p">;</span> <span class="cp">?&gt;</span><span class="x">&quot;&gt;</span><span class="cp">&lt;?php</span> <span class="k">echo</span> <span class="nv">$label</span><span class="p">;</span> <span class="cp">?&gt;</span><span class="x">&lt;/option&gt;&#39; );</span></div><div class="line" id="file-gistfile1-php-LC172"><span class="x">                </span></div><div class="line" id="file-gistfile1-php-LC173"><span class="x">            });</span></div><div class="line" id="file-gistfile1-php-LC174"><span class="x">            </span></div><div class="line" id="file-gistfile1-php-LC175"><span class="x">        &lt;/script&gt;</span></div><div class="line" id="file-gistfile1-php-LC176"><span class="x">        </span></div><div class="line" id="file-gistfile1-php-LC177"><span class="x">        </span><span class="cp">&lt;?php</span></div><div class="line" id="file-gistfile1-php-LC178">        <span class="c1">//return the form object from the php hook    </span></div><div class="line" id="file-gistfile1-php-LC179">        <span class="k">return</span> <span class="nv">$form</span><span class="p">;</span></div><div class="line" id="file-gistfile1-php-LC180">    <span class="p">}</span></div><div class="line" id="file-gistfile1-php-LC181">    </div><div class="line" id="file-gistfile1-php-LC182">    <span class="k">static</span> <span class="k">function</span> <span class="nf">has_subtotal_merge_tag</span><span class="p">(</span> <span class="nv">$field</span> <span class="p">)</span> <span class="p">{</span></div><div class="line" id="file-gistfile1-php-LC183">        </div><div class="line" id="file-gistfile1-php-LC184">        <span class="c1">// check if form is passed</span></div><div class="line" id="file-gistfile1-php-LC185">        <span class="k">if</span><span class="p">(</span> <span class="nb">isset</span><span class="p">(</span> <span class="nv">$field</span><span class="p">[</span><span class="s1">&#39;fields&#39;</span><span class="p">]</span> <span class="p">)</span> <span class="p">)</span> <span class="p">{</span></div><div class="line" id="file-gistfile1-php-LC186">            </div><div class="line" id="file-gistfile1-php-LC187">            <span class="nv">$form</span> <span class="o">=</span> <span class="nv">$field</span><span class="p">;</span></div><div class="line" id="file-gistfile1-php-LC188">            <span class="k">foreach</span><span class="p">(</span> <span class="nv">$form</span><span class="p">[</span><span class="s1">&#39;fields&#39;</span><span class="p">]</span> <span class="k">as</span> <span class="nv">$field</span> <span class="p">)</span> <span class="p">{</span></div><div class="line" id="file-gistfile1-php-LC189">                <span class="k">if</span><span class="p">(</span> <span class="nx">self</span><span class="o">::</span><span class="na">has_subtotal_merge_tag</span><span class="p">(</span> <span class="nv">$field</span> <span class="p">)</span> <span class="p">)</span></div><div class="line" id="file-gistfile1-php-LC190">                    <span class="k">return</span> <span class="k">true</span><span class="p">;</span></div><div class="line" id="file-gistfile1-php-LC191">            <span class="p">}</span></div><div class="line" id="file-gistfile1-php-LC192">            </div><div class="line" id="file-gistfile1-php-LC193">        <span class="p">}</span> <span class="k">else</span> <span class="p">{</span></div><div class="line" id="file-gistfile1-php-LC194">            </div><div class="line" id="file-gistfile1-php-LC195">            <span class="k">if</span><span class="p">(</span> <span class="nb">isset</span><span class="p">(</span> <span class="nv">$field</span><span class="p">[</span><span class="s1">&#39;calculationFormula&#39;</span><span class="p">]</span> <span class="p">)</span> <span class="o">&amp;&amp;</span> <span class="nb">strpos</span><span class="p">(</span> <span class="nv">$field</span><span class="p">[</span><span class="s1">&#39;calculationFormula&#39;</span><span class="p">],</span> <span class="nx">self</span><span class="o">::</span><span class="nv">$merge_tag</span> <span class="p">)</span> <span class="o">!==</span> <span class="k">false</span> <span class="p">)</span></div><div class="line" id="file-gistfile1-php-LC196">                <span class="k">return</span> <span class="k">true</span><span class="p">;</span></div><div class="line" id="file-gistfile1-php-LC197">                </div><div class="line" id="file-gistfile1-php-LC198">        <span class="p">}</span></div><div class="line" id="file-gistfile1-php-LC199">        </div><div class="line" id="file-gistfile1-php-LC200">        <span class="k">return</span> <span class="k">false</span><span class="p">;</span></div><div class="line" id="file-gistfile1-php-LC201">    <span class="p">}</span></div><div class="line" id="file-gistfile1-php-LC202">    </div><div class="line" id="file-gistfile1-php-LC203"><span class="p">}</span></div><div class="line" id="file-gistfile1-php-LC204">&nbsp;</div><div class="line" id="file-gistfile1-php-LC205"><span class="k">new</span> <span class="nx">GWCalcSubtotal</span><span class="p">();</span></div></pre>
        </td>
      </tr>
    </table>
  </div>

        </div>

        <div class="gist-meta">
          <a href="https://gist.github.com/spivurno/5409587/raw/253bd3b0666a6787c91ae7e72edbf585f3812dfc/gistfile1.php" style="float:right">view raw</a>
          <a href="https://gist.github.com/spivurno/5409587#file-gistfile1-php" style="float:right; margin-right:10px; color:#666;">gistfile1.php</a>
          <a href="https://gist.github.com/spivurno/5409587">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
        </div>
      </div>
</div>


<h3>How do I install this snippet?</h3><p>Easy peasy. Just copy and paste the code above into your theme's <em>functions.php</em> file.</p>

<h3>How do I use this functionality?</h3>

<p>This snippet will add a new &#8220;Subtotal&#8221; merge tag to the merge tag select available for the &#8220;Formula&#8221; setting on Calculation fields. Selecting this option will insert the <code>{subtotal}</code> merge tag into your &#8220;Formula&#8221; setting. You can then use all available mathematical operations available to this field to manipulate this subtotal as needed.</p>

<div class="inline-image full"><img src="http://gravitywiz.com/wp-content/uploads/2013/04/formula-subtotal-merge-tag.png" alt="formula-subtotal-merge-tag" width="502" height="280" class="alignnone size-full wp-image-1801" /><span class="caption">Formula Setting: Subtotal Merge Tag</span></div>

<div class="inline-image full"><img src="http://gravitywiz.com/wp-content/uploads/2013/04/formula-subtotal-tax.png" alt="formula-subtotal-tax" width="502" height="280" class="alignnone size-full wp-image-1802" /><span class="caption">Formula Setting: Subtotal Used to Calculate Tax</span></div>
<p>The post <a href="http://gravitywiz.com/subtotal-merge-tag-for-calculations/">Subtotal Merge Tag (for Calculations)</a> appeared first on <a href="http://gravitywiz.com">Gravity Wiz</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://gravitywiz.com/subtotal-merge-tag-for-calculations/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Use Gravity Forms Conditional Logic with Dates</title>
		<link>http://gravitywiz.com/use-gravity-forms-conditional-logic-with-dates/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=use-gravity-forms-conditional-logic-with-dates</link>
		<comments>http://gravitywiz.com/use-gravity-forms-conditional-logic-with-dates/#comments</comments>
		<pubDate>Fri, 01 Mar 2013 16:52:31 +0000</pubDate>
		<dc:creator>David Smith</dc:creator>
				<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://gravitywiz.com/?p=1466</guid>
		<description><![CDATA[<p>You&#8217;re probably familiar with Gravity Forms conditional logic. That awesome feature that allows you to show or hide fields depending a set of custom conditions. One feature that isn&#8217;t yet support is date-based conditions. Or is it? This method will allow you to show or hide any field based on a date. You can configure [...]</p><p>The post <a href="http://gravitywiz.com/use-gravity-forms-conditional-logic-with-dates/">Use Gravity Forms Conditional Logic with Dates</a> appeared first on <a href="http://gravitywiz.com">Gravity Wiz</a>.</p>]]></description>
				<content:encoded><![CDATA[<div class="introduction">A simple method for showing and hiding Gravity Form fields based on the current date.</div>

<p>You&#8217;re probably familiar with Gravity Forms conditional logic. That awesome feature that allows you to show or hide fields depending a set of custom conditions. One feature that isn&#8217;t yet support is date-based conditions. Or is it?</p>

<p>This method will allow you to show or hide any field based on a date. You can configure it to show/hide if that date has passed, has not passed or if you are currently on that date.</p>

<p>This tutorial is based on the following example. You are selling tickets to a conference. Tickets sold a week <em>before</em> the conference are $10. Tickets sold <em>within</em> a week of the conference are $15. Let&#8217;s dig in!</p>

<ol>
<li><a href="#the-code">The Code</a></li>
<li><a href="#timestamp-field">Setting Up Timestamp Field</a></li>
<li><a href="#conditional-field">Setting Up Conditional Field</a></li>
</ol>

<p><a name="the-code"></a></p>

<h3>1. The Code</h3>

<div id="gist5065194" class="gist">
      <div class="gist-file">
        <div class="gist-data gist-syntax">



  <div class="file-data">
    <table cellpadding="0" cellspacing="0" class="lines highlight">
      <tr>
        <td class="line-numbers">
          <span class="line-number" id="file-gistfile1-php-L1" rel="file-gistfile1-php-L1">1</span>
          <span class="line-number" id="file-gistfile1-php-L2" rel="file-gistfile1-php-L2">2</span>
          <span class="line-number" id="file-gistfile1-php-L3" rel="file-gistfile1-php-L3">3</span>
          <span class="line-number" id="file-gistfile1-php-L4" rel="file-gistfile1-php-L4">4</span>
          <span class="line-number" id="file-gistfile1-php-L5" rel="file-gistfile1-php-L5">5</span>
          <span class="line-number" id="file-gistfile1-php-L6" rel="file-gistfile1-php-L6">6</span>
          <span class="line-number" id="file-gistfile1-php-L7" rel="file-gistfile1-php-L7">7</span>
          <span class="line-number" id="file-gistfile1-php-L8" rel="file-gistfile1-php-L8">8</span>
          <span class="line-number" id="file-gistfile1-php-L9" rel="file-gistfile1-php-L9">9</span>
        </td>
        <td class="line-data">
          <pre class="line-pre"><div class="line" id="file-gistfile1-php-LC1"><span class="cp">&lt;?php</span></div><div class="line" id="file-gistfile1-php-LC2"><span class="sd">/**</span></div><div class="line" id="file-gistfile1-php-LC3"><span class="sd"> * Use Gravity Forms Conditional Logic with Dates</span></div><div class="line" id="file-gistfile1-php-LC4"><span class="sd"> * http://gravitywiz.com/use-gravity-forms-conditional-logic-with-dates/</span></div><div class="line" id="file-gistfile1-php-LC5"><span class="sd"> */</span></div><div class="line" id="file-gistfile1-php-LC6"><span class="nx">add_filter</span><span class="p">(</span><span class="s2">&quot;gform_field_value_timestamp&quot;</span><span class="p">,</span> <span class="s2">&quot;gwiz_populate_timestamp&quot;</span><span class="p">);</span></div><div class="line" id="file-gistfile1-php-LC7"><span class="k">function</span> <span class="nf">gwiz_populate_timestamp</span><span class="p">(</span> <span class="nv">$value</span> <span class="p">){</span></div><div class="line" id="file-gistfile1-php-LC8">    <span class="k">return</span> <span class="nb">time</span><span class="p">();</span></div><div class="line" id="file-gistfile1-php-LC9"><span class="p">}</span></div></pre>
        </td>
      </tr>
    </table>
  </div>

        </div>

        <div class="gist-meta">
          <a href="https://gist.github.com/spivurno/5065194/raw/9782c72d93039f030cfd7b44b4bb44f5a7fe3858/gistfile1.php" style="float:right">view raw</a>
          <a href="https://gist.github.com/spivurno/5065194#file-gistfile1-php" style="float:right; margin-right:10px; color:#666;">gistfile1.php</a>
          <a href="https://gist.github.com/spivurno/5065194">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
        </div>
      </div>
</div>


<p>Copy and paste the above snippet into your theme&#8217;s functions.php file. This code enables you to populate a field on your form with the current date and time in the form of a UNIX timestamp.</p>

<p>It isn&#8217;t super important that you know what a UNIX timestamp is (the number of seconds since January 1, 1970) but it is important to understand that a timestamp is an integer. No weird date formatting just a really big number. For example, this post was published on March 1, 2013. The time stamp for this date is 1362117600.</p>

<p>Gravity Forms conditional logic can&#8217;t work with formatted dates but by converting the date into a number we can let Gravity Forms handle the rest.</p>

<p><a name="timestamp-field"></a></p>

<h3>2. Setting Up Time Stamp Field</h3>

<p>Our timestamp snippet doesn&#8217;t do much on it&#8217;s own. We need to tell it which field to populate with the timestamp. Go ahead and open any form to which you would like to add this functionality and follow these steps:</p>

<ol>
<li>Add a new Hidden field and label it &#8220;Timestamp&#8221;</li>
<li>Click on the &#8220;Advanced&#8221; tab to view the field&#8217;s advanced settings.</li>
<li>Check the checkbox labeled &#8220;Allow Field to be Populated Dynamically&#8221;.</li>
<li>Enabling the &#8220;Allow Field to be Populated Dynamically&#8221; option will reveal the &#8220;Parameter Name&#8221; input. Add this value <code>timestamp</code>.</li>
</ol>

<p>Awesome! Now this field is configured to be dynamically populated with the current timestamp any time the form is viewed.</p>

<div class="inline-image full"><img src="http://gravitywiz.com/wp-content/uploads/2013/03/timestamp.png" alt="timestamp" width="500" height="302" class="alignnone size-full wp-image-1471" /><span class="caption">Timestamp Field</span></div>

<p><a name="conditional-field"></a></p>

<h3>3. Setting Up Conditional Field</h3>

<p>Now it&#8217;s time for the fun part!</p>

<ol>
<li>Create another field that you would like to which you would like to apply the date-based conditional logic. </li>
<li>Click on the &#8220;Advanced&#8221; tab to access the field&#8217;s advanced settings.</li>
<li>Check the &#8220;Enable Conditional Logic&#8221; checkbox.</li>
<li>Select the &#8220;Timestamp&#8221; field from the first drop down.</li>
<li>Select &#8220;less than&#8221; or &#8220;greater than&#8221; from the operator drop down depending on your intent (more details below).</li>
<li>Enter the <strong>timestamp</strong> for the date this condition is based on (more details below).</li>
</ol>

<p>For our working example, we will have two product fields. One with the early bird pricing (any time a week before the event) and another for regular pricing (any time within a week of the event).</p>

<p>The event is on March 18, 2013. We want the pricing to be dependent on a date one week before the event, so March 8, 2013 is our &#8220;conditional date&#8221;. The timestamp for this date (set to midnight) is <strong>1362700800</strong>. Based on that conditional date, here is how each field&#8217;s conditional logic would be configured:</p>

<div class="inline-image full"><img src="http://gravitywiz.com/wp-content/uploads/2013/03/early-bird-settings.png" alt="early-bird-settings" width="500" height="506" class="alignnone size-full wp-image-1473" /><span class="caption">Early Bird Product Field</span></div>

<div class="inline-image full"><img src="http://gravitywiz.com/wp-content/uploads/2013/03/regular-settings.png" alt="regular-settings" width="500" height="535" class="alignnone size-full wp-image-1474" /><span class="caption">Regular Pricing Field</span></div>

<h4>Should I use &#8220;less than&#8221;, &#8220;greater than&#8221;, or &#8220;is&#8221;?</h4>

<p>If the field should show/hide if the current date is <em>before</em> the conditional date, you will want to use the &#8220;less than&#8221; operator.</p>

<p>If the field should show/hide if the current date is <em>after</em> the conditional date, you will want to use the &#8220;greater than&#8221; operator. You&#8217;ll note in the example, the regular pricing has an extra &#8220;is&#8221; clause. Without this, there would be one second at midnight on the conditional date that neither pricing field would display.</p>

<p>If the field should show/hide between two dates, you will need to create two conditions and use the &#8220;greater than&#8221; for the starting date condition and &#8220;less than&#8221; for the ending date condition.</p>

<h4>How do I get a timestamp for my conditional date?</h4>

<p>The conditional date will also need to be in the UNIX timestamp format. Use this <a href="http://www.epochconverter.com/">online UNIX timestamp converter</a> to convert the date you want to base your show/hide condition on to a timestamp. Once you have your timestamp, enter it into the last input on the condition row.</p>
<p>The post <a href="http://gravitywiz.com/use-gravity-forms-conditional-logic-with-dates/">Use Gravity Forms Conditional Logic with Dates</a> appeared first on <a href="http://gravitywiz.com">Gravity Wiz</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://gravitywiz.com/use-gravity-forms-conditional-logic-with-dates/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Calculate Number of Days Between Two Dates</title>
		<link>http://gravitywiz.com/calculate-number-of-days-between-two-dates/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=calculate-number-of-days-between-two-dates</link>
		<comments>http://gravitywiz.com/calculate-number-of-days-between-two-dates/#comments</comments>
		<pubDate>Sat, 23 Feb 2013 03:11:30 +0000</pubDate>
		<dc:creator>David Smith</dc:creator>
				<category><![CDATA[Snippets]]></category>

		<guid isPermaLink="false">http://gravitywiz.com/?p=1285</guid>
		<description><![CDATA[<p>Have you ever needed to calculate the number of days between two given date fields? Here&#8217;s a scenario for consideration. Let&#8217;s say you have a Gravity Form set up to register users for a multi-day event. The user is able to select a start date and end date that they will be attending the event. [...]</p><p>The post <a href="http://gravitywiz.com/calculate-number-of-days-between-two-dates/">Calculate Number of Days Between Two Dates</a> appeared first on <a href="http://gravitywiz.com">Gravity Wiz</a>.</p>]]></description>
				<content:encoded><![CDATA[<div class="introduction">Calculate the number of days between two given date fields and populate this number into a field on the form.</div>

<div class="demo-link-container"><a href="http://gravitywiz.com/demos/calculate-number-of-days-between-two-dates/" class="demo-link serif btn" target="_blank">view demo</a></div>

<ul class="gw-post-updates"><li><p><strong>March 3, 2013:</strong> Updated to fix issue where "include_end_date" option was not working and added better support for different date formats.</p>
</li><li><p><strong>March 2, 2013:</strong> Updated to support applying to multiple sets of date fields on the same form. Also updated to fix issue where functionality did not run when form was returned due to validation error.</p>
</li><li><p><strong>March 15, 2013:</strong> Updated to fix issue when conditional logic was used on the form.</p>
</li></ul>

<p>Have you ever needed to calculate the number of days between two given date fields? Here&#8217;s a scenario for consideration.</p>

<p>Let&#8217;s say you have a Gravity Form set up to register users for a multi-day event. The user is able to select a start date and end date that they will be attending the event. For each day of attendance they must pay an attendance fee of $10. How can we calculate the total price they should pay for registration?</p>

<p>This snippet will allow to calculate the number of days between two date fields and then populate the calculated number of days into another field. This is beneficial because with this calculated number of days now available as a field value, we can use Gravity Forms&#8217; Calculation Product to correctly calculate the registration fee based on the selected dates.</p>

<div id="gist4996579" class="gist">
      <div class="gist-file">
        <div class="gist-data gist-syntax">



  <div class="file-data">
    <table cellpadding="0" cellspacing="0" class="lines highlight">
      <tr>
        <td class="line-numbers">
          <span class="line-number" id="file-gistfile1-php-L1" rel="file-gistfile1-php-L1">1</span>
          <span class="line-number" id="file-gistfile1-php-L2" rel="file-gistfile1-php-L2">2</span>
          <span class="line-number" id="file-gistfile1-php-L3" rel="file-gistfile1-php-L3">3</span>
          <span class="line-number" id="file-gistfile1-php-L4" rel="file-gistfile1-php-L4">4</span>
          <span class="line-number" id="file-gistfile1-php-L5" rel="file-gistfile1-php-L5">5</span>
          <span class="line-number" id="file-gistfile1-php-L6" rel="file-gistfile1-php-L6">6</span>
          <span class="line-number" id="file-gistfile1-php-L7" rel="file-gistfile1-php-L7">7</span>
          <span class="line-number" id="file-gistfile1-php-L8" rel="file-gistfile1-php-L8">8</span>
          <span class="line-number" id="file-gistfile1-php-L9" rel="file-gistfile1-php-L9">9</span>
          <span class="line-number" id="file-gistfile1-php-L10" rel="file-gistfile1-php-L10">10</span>
          <span class="line-number" id="file-gistfile1-php-L11" rel="file-gistfile1-php-L11">11</span>
          <span class="line-number" id="file-gistfile1-php-L12" rel="file-gistfile1-php-L12">12</span>
          <span class="line-number" id="file-gistfile1-php-L13" rel="file-gistfile1-php-L13">13</span>
          <span class="line-number" id="file-gistfile1-php-L14" rel="file-gistfile1-php-L14">14</span>
          <span class="line-number" id="file-gistfile1-php-L15" rel="file-gistfile1-php-L15">15</span>
          <span class="line-number" id="file-gistfile1-php-L16" rel="file-gistfile1-php-L16">16</span>
          <span class="line-number" id="file-gistfile1-php-L17" rel="file-gistfile1-php-L17">17</span>
          <span class="line-number" id="file-gistfile1-php-L18" rel="file-gistfile1-php-L18">18</span>
          <span class="line-number" id="file-gistfile1-php-L19" rel="file-gistfile1-php-L19">19</span>
          <span class="line-number" id="file-gistfile1-php-L20" rel="file-gistfile1-php-L20">20</span>
          <span class="line-number" id="file-gistfile1-php-L21" rel="file-gistfile1-php-L21">21</span>
          <span class="line-number" id="file-gistfile1-php-L22" rel="file-gistfile1-php-L22">22</span>
          <span class="line-number" id="file-gistfile1-php-L23" rel="file-gistfile1-php-L23">23</span>
          <span class="line-number" id="file-gistfile1-php-L24" rel="file-gistfile1-php-L24">24</span>
          <span class="line-number" id="file-gistfile1-php-L25" rel="file-gistfile1-php-L25">25</span>
          <span class="line-number" id="file-gistfile1-php-L26" rel="file-gistfile1-php-L26">26</span>
          <span class="line-number" id="file-gistfile1-php-L27" rel="file-gistfile1-php-L27">27</span>
          <span class="line-number" id="file-gistfile1-php-L28" rel="file-gistfile1-php-L28">28</span>
          <span class="line-number" id="file-gistfile1-php-L29" rel="file-gistfile1-php-L29">29</span>
          <span class="line-number" id="file-gistfile1-php-L30" rel="file-gistfile1-php-L30">30</span>
          <span class="line-number" id="file-gistfile1-php-L31" rel="file-gistfile1-php-L31">31</span>
          <span class="line-number" id="file-gistfile1-php-L32" rel="file-gistfile1-php-L32">32</span>
          <span class="line-number" id="file-gistfile1-php-L33" rel="file-gistfile1-php-L33">33</span>
          <span class="line-number" id="file-gistfile1-php-L34" rel="file-gistfile1-php-L34">34</span>
          <span class="line-number" id="file-gistfile1-php-L35" rel="file-gistfile1-php-L35">35</span>
          <span class="line-number" id="file-gistfile1-php-L36" rel="file-gistfile1-php-L36">36</span>
          <span class="line-number" id="file-gistfile1-php-L37" rel="file-gistfile1-php-L37">37</span>
          <span class="line-number" id="file-gistfile1-php-L38" rel="file-gistfile1-php-L38">38</span>
          <span class="line-number" id="file-gistfile1-php-L39" rel="file-gistfile1-php-L39">39</span>
          <span class="line-number" id="file-gistfile1-php-L40" rel="file-gistfile1-php-L40">40</span>
          <span class="line-number" id="file-gistfile1-php-L41" rel="file-gistfile1-php-L41">41</span>
          <span class="line-number" id="file-gistfile1-php-L42" rel="file-gistfile1-php-L42">42</span>
          <span class="line-number" id="file-gistfile1-php-L43" rel="file-gistfile1-php-L43">43</span>
          <span class="line-number" id="file-gistfile1-php-L44" rel="file-gistfile1-php-L44">44</span>
          <span class="line-number" id="file-gistfile1-php-L45" rel="file-gistfile1-php-L45">45</span>
          <span class="line-number" id="file-gistfile1-php-L46" rel="file-gistfile1-php-L46">46</span>
          <span class="line-number" id="file-gistfile1-php-L47" rel="file-gistfile1-php-L47">47</span>
          <span class="line-number" id="file-gistfile1-php-L48" rel="file-gistfile1-php-L48">48</span>
          <span class="line-number" id="file-gistfile1-php-L49" rel="file-gistfile1-php-L49">49</span>
          <span class="line-number" id="file-gistfile1-php-L50" rel="file-gistfile1-php-L50">50</span>
          <span class="line-number" id="file-gistfile1-php-L51" rel="file-gistfile1-php-L51">51</span>
          <span class="line-number" id="file-gistfile1-php-L52" rel="file-gistfile1-php-L52">52</span>
          <span class="line-number" id="file-gistfile1-php-L53" rel="file-gistfile1-php-L53">53</span>
          <span class="line-number" id="file-gistfile1-php-L54" rel="file-gistfile1-php-L54">54</span>
          <span class="line-number" id="file-gistfile1-php-L55" rel="file-gistfile1-php-L55">55</span>
          <span class="line-number" id="file-gistfile1-php-L56" rel="file-gistfile1-php-L56">56</span>
          <span class="line-number" id="file-gistfile1-php-L57" rel="file-gistfile1-php-L57">57</span>
          <span class="line-number" id="file-gistfile1-php-L58" rel="file-gistfile1-php-L58">58</span>
          <span class="line-number" id="file-gistfile1-php-L59" rel="file-gistfile1-php-L59">59</span>
          <span class="line-number" id="file-gistfile1-php-L60" rel="file-gistfile1-php-L60">60</span>
          <span class="line-number" id="file-gistfile1-php-L61" rel="file-gistfile1-php-L61">61</span>
          <span class="line-number" id="file-gistfile1-php-L62" rel="file-gistfile1-php-L62">62</span>
          <span class="line-number" id="file-gistfile1-php-L63" rel="file-gistfile1-php-L63">63</span>
          <span class="line-number" id="file-gistfile1-php-L64" rel="file-gistfile1-php-L64">64</span>
          <span class="line-number" id="file-gistfile1-php-L65" rel="file-gistfile1-php-L65">65</span>
          <span class="line-number" id="file-gistfile1-php-L66" rel="file-gistfile1-php-L66">66</span>
          <span class="line-number" id="file-gistfile1-php-L67" rel="file-gistfile1-php-L67">67</span>
          <span class="line-number" id="file-gistfile1-php-L68" rel="file-gistfile1-php-L68">68</span>
          <span class="line-number" id="file-gistfile1-php-L69" rel="file-gistfile1-php-L69">69</span>
          <span class="line-number" id="file-gistfile1-php-L70" rel="file-gistfile1-php-L70">70</span>
          <span class="line-number" id="file-gistfile1-php-L71" rel="file-gistfile1-php-L71">71</span>
          <span class="line-number" id="file-gistfile1-php-L72" rel="file-gistfile1-php-L72">72</span>
          <span class="line-number" id="file-gistfile1-php-L73" rel="file-gistfile1-php-L73">73</span>
          <span class="line-number" id="file-gistfile1-php-L74" rel="file-gistfile1-php-L74">74</span>
          <span class="line-number" id="file-gistfile1-php-L75" rel="file-gistfile1-php-L75">75</span>
          <span class="line-number" id="file-gistfile1-php-L76" rel="file-gistfile1-php-L76">76</span>
          <span class="line-number" id="file-gistfile1-php-L77" rel="file-gistfile1-php-L77">77</span>
          <span class="line-number" id="file-gistfile1-php-L78" rel="file-gistfile1-php-L78">78</span>
          <span class="line-number" id="file-gistfile1-php-L79" rel="file-gistfile1-php-L79">79</span>
          <span class="line-number" id="file-gistfile1-php-L80" rel="file-gistfile1-php-L80">80</span>
          <span class="line-number" id="file-gistfile1-php-L81" rel="file-gistfile1-php-L81">81</span>
          <span class="line-number" id="file-gistfile1-php-L82" rel="file-gistfile1-php-L82">82</span>
          <span class="line-number" id="file-gistfile1-php-L83" rel="file-gistfile1-php-L83">83</span>
          <span class="line-number" id="file-gistfile1-php-L84" rel="file-gistfile1-php-L84">84</span>
          <span class="line-number" id="file-gistfile1-php-L85" rel="file-gistfile1-php-L85">85</span>
          <span class="line-number" id="file-gistfile1-php-L86" rel="file-gistfile1-php-L86">86</span>
          <span class="line-number" id="file-gistfile1-php-L87" rel="file-gistfile1-php-L87">87</span>
          <span class="line-number" id="file-gistfile1-php-L88" rel="file-gistfile1-php-L88">88</span>
          <span class="line-number" id="file-gistfile1-php-L89" rel="file-gistfile1-php-L89">89</span>
          <span class="line-number" id="file-gistfile1-php-L90" rel="file-gistfile1-php-L90">90</span>
          <span class="line-number" id="file-gistfile1-php-L91" rel="file-gistfile1-php-L91">91</span>
          <span class="line-number" id="file-gistfile1-php-L92" rel="file-gistfile1-php-L92">92</span>
          <span class="line-number" id="file-gistfile1-php-L93" rel="file-gistfile1-php-L93">93</span>
          <span class="line-number" id="file-gistfile1-php-L94" rel="file-gistfile1-php-L94">94</span>
          <span class="line-number" id="file-gistfile1-php-L95" rel="file-gistfile1-php-L95">95</span>
          <span class="line-number" id="file-gistfile1-php-L96" rel="file-gistfile1-php-L96">96</span>
          <span class="line-number" id="file-gistfile1-php-L97" rel="file-gistfile1-php-L97">97</span>
          <span class="line-number" id="file-gistfile1-php-L98" rel="file-gistfile1-php-L98">98</span>
          <span class="line-number" id="file-gistfile1-php-L99" rel="file-gistfile1-php-L99">99</span>
          <span class="line-number" id="file-gistfile1-php-L100" rel="file-gistfile1-php-L100">100</span>
          <span class="line-number" id="file-gistfile1-php-L101" rel="file-gistfile1-php-L101">101</span>
          <span class="line-number" id="file-gistfile1-php-L102" rel="file-gistfile1-php-L102">102</span>
          <span class="line-number" id="file-gistfile1-php-L103" rel="file-gistfile1-php-L103">103</span>
          <span class="line-number" id="file-gistfile1-php-L104" rel="file-gistfile1-php-L104">104</span>
          <span class="line-number" id="file-gistfile1-php-L105" rel="file-gistfile1-php-L105">105</span>
          <span class="line-number" id="file-gistfile1-php-L106" rel="file-gistfile1-php-L106">106</span>
          <span class="line-number" id="file-gistfile1-php-L107" rel="file-gistfile1-php-L107">107</span>
          <span class="line-number" id="file-gistfile1-php-L108" rel="file-gistfile1-php-L108">108</span>
          <span class="line-number" id="file-gistfile1-php-L109" rel="file-gistfile1-php-L109">109</span>
          <span class="line-number" id="file-gistfile1-php-L110" rel="file-gistfile1-php-L110">110</span>
          <span class="line-number" id="file-gistfile1-php-L111" rel="file-gistfile1-php-L111">111</span>
          <span class="line-number" id="file-gistfile1-php-L112" rel="file-gistfile1-php-L112">112</span>
          <span class="line-number" id="file-gistfile1-php-L113" rel="file-gistfile1-php-L113">113</span>
          <span class="line-number" id="file-gistfile1-php-L114" rel="file-gistfile1-php-L114">114</span>
          <span class="line-number" id="file-gistfile1-php-L115" rel="file-gistfile1-php-L115">115</span>
          <span class="line-number" id="file-gistfile1-php-L116" rel="file-gistfile1-php-L116">116</span>
          <span class="line-number" id="file-gistfile1-php-L117" rel="file-gistfile1-php-L117">117</span>
          <span class="line-number" id="file-gistfile1-php-L118" rel="file-gistfile1-php-L118">118</span>
          <span class="line-number" id="file-gistfile1-php-L119" rel="file-gistfile1-php-L119">119</span>
          <span class="line-number" id="file-gistfile1-php-L120" rel="file-gistfile1-php-L120">120</span>
          <span class="line-number" id="file-gistfile1-php-L121" rel="file-gistfile1-php-L121">121</span>
          <span class="line-number" id="file-gistfile1-php-L122" rel="file-gistfile1-php-L122">122</span>
          <span class="line-number" id="file-gistfile1-php-L123" rel="file-gistfile1-php-L123">123</span>
          <span class="line-number" id="file-gistfile1-php-L124" rel="file-gistfile1-php-L124">124</span>
          <span class="line-number" id="file-gistfile1-php-L125" rel="file-gistfile1-php-L125">125</span>
          <span class="line-number" id="file-gistfile1-php-L126" rel="file-gistfile1-php-L126">126</span>
          <span class="line-number" id="file-gistfile1-php-L127" rel="file-gistfile1-php-L127">127</span>
          <span class="line-number" id="file-gistfile1-php-L128" rel="file-gistfile1-php-L128">128</span>
          <span class="line-number" id="file-gistfile1-php-L129" rel="file-gistfile1-php-L129">129</span>
          <span class="line-number" id="file-gistfile1-php-L130" rel="file-gistfile1-php-L130">130</span>
          <span class="line-number" id="file-gistfile1-php-L131" rel="file-gistfile1-php-L131">131</span>
          <span class="line-number" id="file-gistfile1-php-L132" rel="file-gistfile1-php-L132">132</span>
          <span class="line-number" id="file-gistfile1-php-L133" rel="file-gistfile1-php-L133">133</span>
          <span class="line-number" id="file-gistfile1-php-L134" rel="file-gistfile1-php-L134">134</span>
          <span class="line-number" id="file-gistfile1-php-L135" rel="file-gistfile1-php-L135">135</span>
          <span class="line-number" id="file-gistfile1-php-L136" rel="file-gistfile1-php-L136">136</span>
          <span class="line-number" id="file-gistfile1-php-L137" rel="file-gistfile1-php-L137">137</span>
          <span class="line-number" id="file-gistfile1-php-L138" rel="file-gistfile1-php-L138">138</span>
          <span class="line-number" id="file-gistfile1-php-L139" rel="file-gistfile1-php-L139">139</span>
          <span class="line-number" id="file-gistfile1-php-L140" rel="file-gistfile1-php-L140">140</span>
          <span class="line-number" id="file-gistfile1-php-L141" rel="file-gistfile1-php-L141">141</span>
          <span class="line-number" id="file-gistfile1-php-L142" rel="file-gistfile1-php-L142">142</span>
          <span class="line-number" id="file-gistfile1-php-L143" rel="file-gistfile1-php-L143">143</span>
          <span class="line-number" id="file-gistfile1-php-L144" rel="file-gistfile1-php-L144">144</span>
          <span class="line-number" id="file-gistfile1-php-L145" rel="file-gistfile1-php-L145">145</span>
          <span class="line-number" id="file-gistfile1-php-L146" rel="file-gistfile1-php-L146">146</span>
          <span class="line-number" id="file-gistfile1-php-L147" rel="file-gistfile1-php-L147">147</span>
          <span class="line-number" id="file-gistfile1-php-L148" rel="file-gistfile1-php-L148">148</span>
          <span class="line-number" id="file-gistfile1-php-L149" rel="file-gistfile1-php-L149">149</span>
          <span class="line-number" id="file-gistfile1-php-L150" rel="file-gistfile1-php-L150">150</span>
          <span class="line-number" id="file-gistfile1-php-L151" rel="file-gistfile1-php-L151">151</span>
          <span class="line-number" id="file-gistfile1-php-L152" rel="file-gistfile1-php-L152">152</span>
          <span class="line-number" id="file-gistfile1-php-L153" rel="file-gistfile1-php-L153">153</span>
          <span class="line-number" id="file-gistfile1-php-L154" rel="file-gistfile1-php-L154">154</span>
          <span class="line-number" id="file-gistfile1-php-L155" rel="file-gistfile1-php-L155">155</span>
          <span class="line-number" id="file-gistfile1-php-L156" rel="file-gistfile1-php-L156">156</span>
          <span class="line-number" id="file-gistfile1-php-L157" rel="file-gistfile1-php-L157">157</span>
          <span class="line-number" id="file-gistfile1-php-L158" rel="file-gistfile1-php-L158">158</span>
          <span class="line-number" id="file-gistfile1-php-L159" rel="file-gistfile1-php-L159">159</span>
          <span class="line-number" id="file-gistfile1-php-L160" rel="file-gistfile1-php-L160">160</span>
          <span class="line-number" id="file-gistfile1-php-L161" rel="file-gistfile1-php-L161">161</span>
          <span class="line-number" id="file-gistfile1-php-L162" rel="file-gistfile1-php-L162">162</span>
          <span class="line-number" id="file-gistfile1-php-L163" rel="file-gistfile1-php-L163">163</span>
          <span class="line-number" id="file-gistfile1-php-L164" rel="file-gistfile1-php-L164">164</span>
          <span class="line-number" id="file-gistfile1-php-L165" rel="file-gistfile1-php-L165">165</span>
          <span class="line-number" id="file-gistfile1-php-L166" rel="file-gistfile1-php-L166">166</span>
          <span class="line-number" id="file-gistfile1-php-L167" rel="file-gistfile1-php-L167">167</span>
          <span class="line-number" id="file-gistfile1-php-L168" rel="file-gistfile1-php-L168">168</span>
          <span class="line-number" id="file-gistfile1-php-L169" rel="file-gistfile1-php-L169">169</span>
          <span class="line-number" id="file-gistfile1-php-L170" rel="file-gistfile1-php-L170">170</span>
          <span class="line-number" id="file-gistfile1-php-L171" rel="file-gistfile1-php-L171">171</span>
          <span class="line-number" id="file-gistfile1-php-L172" rel="file-gistfile1-php-L172">172</span>
          <span class="line-number" id="file-gistfile1-php-L173" rel="file-gistfile1-php-L173">173</span>
          <span class="line-number" id="file-gistfile1-php-L174" rel="file-gistfile1-php-L174">174</span>
          <span class="line-number" id="file-gistfile1-php-L175" rel="file-gistfile1-php-L175">175</span>
          <span class="line-number" id="file-gistfile1-php-L176" rel="file-gistfile1-php-L176">176</span>
          <span class="line-number" id="file-gistfile1-php-L177" rel="file-gistfile1-php-L177">177</span>
          <span class="line-number" id="file-gistfile1-php-L178" rel="file-gistfile1-php-L178">178</span>
          <span class="line-number" id="file-gistfile1-php-L179" rel="file-gistfile1-php-L179">179</span>
          <span class="line-number" id="file-gistfile1-php-L180" rel="file-gistfile1-php-L180">180</span>
          <span class="line-number" id="file-gistfile1-php-L181" rel="file-gistfile1-php-L181">181</span>
          <span class="line-number" id="file-gistfile1-php-L182" rel="file-gistfile1-php-L182">182</span>
          <span class="line-number" id="file-gistfile1-php-L183" rel="file-gistfile1-php-L183">183</span>
          <span class="line-number" id="file-gistfile1-php-L184" rel="file-gistfile1-php-L184">184</span>
          <span class="line-number" id="file-gistfile1-php-L185" rel="file-gistfile1-php-L185">185</span>
          <span class="line-number" id="file-gistfile1-php-L186" rel="file-gistfile1-php-L186">186</span>
          <span class="line-number" id="file-gistfile1-php-L187" rel="file-gistfile1-php-L187">187</span>
          <span class="line-number" id="file-gistfile1-php-L188" rel="file-gistfile1-php-L188">188</span>
          <span class="line-number" id="file-gistfile1-php-L189" rel="file-gistfile1-php-L189">189</span>
          <span class="line-number" id="file-gistfile1-php-L190" rel="file-gistfile1-php-L190">190</span>
          <span class="line-number" id="file-gistfile1-php-L191" rel="file-gistfile1-php-L191">191</span>
          <span class="line-number" id="file-gistfile1-php-L192" rel="file-gistfile1-php-L192">192</span>
          <span class="line-number" id="file-gistfile1-php-L193" rel="file-gistfile1-php-L193">193</span>
          <span class="line-number" id="file-gistfile1-php-L194" rel="file-gistfile1-php-L194">194</span>
          <span class="line-number" id="file-gistfile1-php-L195" rel="file-gistfile1-php-L195">195</span>
          <span class="line-number" id="file-gistfile1-php-L196" rel="file-gistfile1-php-L196">196</span>
          <span class="line-number" id="file-gistfile1-php-L197" rel="file-gistfile1-php-L197">197</span>
          <span class="line-number" id="file-gistfile1-php-L198" rel="file-gistfile1-php-L198">198</span>
          <span class="line-number" id="file-gistfile1-php-L199" rel="file-gistfile1-php-L199">199</span>
          <span class="line-number" id="file-gistfile1-php-L200" rel="file-gistfile1-php-L200">200</span>
          <span class="line-number" id="file-gistfile1-php-L201" rel="file-gistfile1-php-L201">201</span>
          <span class="line-number" id="file-gistfile1-php-L202" rel="file-gistfile1-php-L202">202</span>
          <span class="line-number" id="file-gistfile1-php-L203" rel="file-gistfile1-php-L203">203</span>
          <span class="line-number" id="file-gistfile1-php-L204" rel="file-gistfile1-php-L204">204</span>
          <span class="line-number" id="file-gistfile1-php-L205" rel="file-gistfile1-php-L205">205</span>
          <span class="line-number" id="file-gistfile1-php-L206" rel="file-gistfile1-php-L206">206</span>
          <span class="line-number" id="file-gistfile1-php-L207" rel="file-gistfile1-php-L207">207</span>
          <span class="line-number" id="file-gistfile1-php-L208" rel="file-gistfile1-php-L208">208</span>
          <span class="line-number" id="file-gistfile1-php-L209" rel="file-gistfile1-php-L209">209</span>
          <span class="line-number" id="file-gistfile1-php-L210" rel="file-gistfile1-php-L210">210</span>
          <span class="line-number" id="file-gistfile1-php-L211" rel="file-gistfile1-php-L211">211</span>
          <span class="line-number" id="file-gistfile1-php-L212" rel="file-gistfile1-php-L212">212</span>
          <span class="line-number" id="file-gistfile1-php-L213" rel="file-gistfile1-php-L213">213</span>
          <span class="line-number" id="file-gistfile1-php-L214" rel="file-gistfile1-php-L214">214</span>
          <span class="line-number" id="file-gistfile1-php-L215" rel="file-gistfile1-php-L215">215</span>
        </td>
        <td class="line-data">
          <pre class="line-pre"><div class="line" id="file-gistfile1-php-LC1"><span class="cp">&lt;?php</span></div><div class="line" id="file-gistfile1-php-LC2"><span class="sd">/**</span></div><div class="line" id="file-gistfile1-php-LC3"><span class="sd"> * Calculate Number of Days via Two Date Fields</span></div><div class="line" id="file-gistfile1-php-LC4"><span class="sd"> * http://gravitywiz.com/calculate-number-of-days-between-two-dates/</span></div><div class="line" id="file-gistfile1-php-LC5"><span class="sd"> */</span></div><div class="line" id="file-gistfile1-php-LC6"><span class="k">class</span> <span class="nc">GWDayCount</span> <span class="p">{</span></div><div class="line" id="file-gistfile1-php-LC7">&nbsp;</div><div class="line" id="file-gistfile1-php-LC8">    <span class="k">private</span> <span class="k">static</span> <span class="nv">$script_output</span><span class="p">;</span></div><div class="line" id="file-gistfile1-php-LC9">&nbsp;</div><div class="line" id="file-gistfile1-php-LC10">    <span class="k">function</span> <span class="nf">__construct</span><span class="p">(</span> <span class="nv">$args</span> <span class="p">)</span> <span class="p">{</span></div><div class="line" id="file-gistfile1-php-LC11">&nbsp;</div><div class="line" id="file-gistfile1-php-LC12">        <span class="nb">extract</span><span class="p">(</span> <span class="nx">wp_parse_args</span><span class="p">(</span> <span class="nv">$args</span><span class="p">,</span> <span class="k">array</span><span class="p">(</span></div><div class="line" id="file-gistfile1-php-LC13">            <span class="s1">&#39;form_id&#39;</span>          <span class="o">=&gt;</span> <span class="k">false</span><span class="p">,</span></div><div class="line" id="file-gistfile1-php-LC14">            <span class="s1">&#39;start_field_id&#39;</span>   <span class="o">=&gt;</span> <span class="k">false</span><span class="p">,</span></div><div class="line" id="file-gistfile1-php-LC15">            <span class="s1">&#39;end_field_id&#39;</span>     <span class="o">=&gt;</span> <span class="k">false</span><span class="p">,</span></div><div class="line" id="file-gistfile1-php-LC16">            <span class="s1">&#39;count_field_id&#39;</span>   <span class="o">=&gt;</span> <span class="k">false</span><span class="p">,</span></div><div class="line" id="file-gistfile1-php-LC17">            <span class="s1">&#39;include_end_date&#39;</span> <span class="o">=&gt;</span> <span class="k">true</span><span class="p">,</span></div><div class="line" id="file-gistfile1-php-LC18">            <span class="p">)</span> <span class="p">)</span> <span class="p">);</span></div><div class="line" id="file-gistfile1-php-LC19">&nbsp;</div><div class="line" id="file-gistfile1-php-LC20">        <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">form_id</span>        <span class="o">=</span> <span class="nv">$form_id</span><span class="p">;</span></div><div class="line" id="file-gistfile1-php-LC21">        <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">start_field_id</span> <span class="o">=</span> <span class="nv">$start_field_id</span><span class="p">;</span></div><div class="line" id="file-gistfile1-php-LC22">        <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">end_field_id</span>   <span class="o">=</span> <span class="nv">$end_field_id</span><span class="p">;</span></div><div class="line" id="file-gistfile1-php-LC23">        <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">count_field_id</span> <span class="o">=</span> <span class="nv">$count_field_id</span><span class="p">;</span></div><div class="line" id="file-gistfile1-php-LC24">        <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">count_adjust</span>   <span class="o">=</span> <span class="nv">$include_end_date</span> <span class="o">?</span> <span class="mi">1</span> <span class="o">:</span> <span class="mi">0</span><span class="p">;</span></div><div class="line" id="file-gistfile1-php-LC25">&nbsp;</div><div class="line" id="file-gistfile1-php-LC26">        <span class="nx">add_filter</span><span class="p">(</span> <span class="s2">&quot;gform_pre_render_</span><span class="si">{</span><span class="nv">$form_id</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">,</span> <span class="k">array</span><span class="p">(</span> <span class="o">&amp;</span><span class="nv">$this</span><span class="p">,</span> <span class="s1">&#39;load_form_script&#39;</span><span class="p">)</span> <span class="p">);</span></div><div class="line" id="file-gistfile1-php-LC27">        <span class="nx">add_action</span><span class="p">(</span> <span class="s2">&quot;gform_pre_submission_</span><span class="si">{</span><span class="nv">$form_id</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">,</span> <span class="k">array</span><span class="p">(</span> <span class="o">&amp;</span><span class="nv">$this</span><span class="p">,</span> <span class="s1">&#39;override_submitted_value&#39;</span><span class="p">)</span> <span class="p">);</span></div><div class="line" id="file-gistfile1-php-LC28">&nbsp;</div><div class="line" id="file-gistfile1-php-LC29">    <span class="p">}</span></div><div class="line" id="file-gistfile1-php-LC30">&nbsp;</div><div class="line" id="file-gistfile1-php-LC31">    <span class="k">function</span> <span class="nf">load_form_script</span><span class="p">(</span> <span class="nv">$form</span> <span class="p">)</span> <span class="p">{</span></div><div class="line" id="file-gistfile1-php-LC32">        </div><div class="line" id="file-gistfile1-php-LC33">        <span class="c1">// workaround to make this work for &lt; 1.7</span></div><div class="line" id="file-gistfile1-php-LC34">        <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">form</span> <span class="o">=</span> <span class="nv">$form</span><span class="p">;</span></div><div class="line" id="file-gistfile1-php-LC35">        <span class="nx">add_filter</span><span class="p">(</span> <span class="s1">&#39;gform_init_scripts_footer&#39;</span><span class="p">,</span> <span class="k">array</span><span class="p">(</span> <span class="o">&amp;</span><span class="nv">$this</span><span class="p">,</span> <span class="s1">&#39;add_init_script&#39;</span> <span class="p">)</span> <span class="p">);</span></div><div class="line" id="file-gistfile1-php-LC36">        </div><div class="line" id="file-gistfile1-php-LC37">        <span class="k">if</span><span class="p">(</span> <span class="nx">self</span><span class="o">::</span><span class="nv">$script_output</span> <span class="p">)</span></div><div class="line" id="file-gistfile1-php-LC38">            <span class="k">return</span> <span class="nv">$form</span><span class="p">;</span></div><div class="line" id="file-gistfile1-php-LC39">&nbsp;</div><div class="line" id="file-gistfile1-php-LC40">        <span class="cp">?&gt;</span><span class="x"></span></div><div class="line" id="file-gistfile1-php-LC41">&nbsp;</div><div class="line" id="file-gistfile1-php-LC42"><span class="x">        &lt;script type=&quot;text/javascript&quot;&gt;</span></div><div class="line" id="file-gistfile1-php-LC43">&nbsp;</div><div class="line" id="file-gistfile1-php-LC44"><span class="x">        (function($){</span></div><div class="line" id="file-gistfile1-php-LC45">&nbsp;</div><div class="line" id="file-gistfile1-php-LC46"><span class="x">            window.gwdc = function( options ) {</span></div><div class="line" id="file-gistfile1-php-LC47">&nbsp;</div><div class="line" id="file-gistfile1-php-LC48"><span class="x">                this.options = options;</span></div><div class="line" id="file-gistfile1-php-LC49"><span class="x">                this.startDateInput = $( &#39;#input_&#39; + this.options.formId + &#39;_&#39; + this.options.startFieldId );</span></div><div class="line" id="file-gistfile1-php-LC50"><span class="x">                this.endDateInput = $( &#39;#input_&#39; + this.options.formId + &#39;_&#39; + this.options.endFieldId );</span></div><div class="line" id="file-gistfile1-php-LC51"><span class="x">                this.countInput = $( &#39;#input_&#39; + this.options.formId + &#39;_&#39; + this.options.countFieldId );</span></div><div class="line" id="file-gistfile1-php-LC52">&nbsp;</div><div class="line" id="file-gistfile1-php-LC53"><span class="x">                this.init = function() {</span></div><div class="line" id="file-gistfile1-php-LC54">&nbsp;</div><div class="line" id="file-gistfile1-php-LC55"><span class="x">                    var gwdc = this;</span></div><div class="line" id="file-gistfile1-php-LC56">&nbsp;</div><div class="line" id="file-gistfile1-php-LC57"><span class="x">                    // add data for &quot;format&quot; for parsing date</span></div><div class="line" id="file-gistfile1-php-LC58"><span class="x">                    gwdc.startDateInput.data( &#39;format&#39;, this.options.startDateFormat );</span></div><div class="line" id="file-gistfile1-php-LC59"><span class="x">                    gwdc.endDateInput.data( &#39;format&#39;, this.options.endDateFormat );</span></div><div class="line" id="file-gistfile1-php-LC60">&nbsp;</div><div class="line" id="file-gistfile1-php-LC61"><span class="x">                    gwdc.populateDayCount();</span></div><div class="line" id="file-gistfile1-php-LC62">&nbsp;</div><div class="line" id="file-gistfile1-php-LC63"><span class="x">                    $(document).on( &#39;change&#39;, &#39;#&#39; + this.startDateInput.attr(&#39;id&#39;) + &#39;, #&#39; + this.endDateInput.attr(&#39;id&#39;), function(){</span></div><div class="line" id="file-gistfile1-php-LC64"><span class="x">                        gwdc.populateDayCount();</span></div><div class="line" id="file-gistfile1-php-LC65"><span class="x">                    });</span></div><div class="line" id="file-gistfile1-php-LC66">&nbsp;</div><div class="line" id="file-gistfile1-php-LC67"><span class="x">                }</span></div><div class="line" id="file-gistfile1-php-LC68">&nbsp;</div><div class="line" id="file-gistfile1-php-LC69"><span class="x">                this.getDayCount = function() {</span></div><div class="line" id="file-gistfile1-php-LC70">&nbsp;</div><div class="line" id="file-gistfile1-php-LC71"><span class="x">                    var startDate = this.parseDate( this.startDateInput.val(), this.startDateInput.data(&#39;format&#39;) )</span></div><div class="line" id="file-gistfile1-php-LC72"><span class="x">                    var endDate = this.parseDate( this.endDateInput.val(), this.endDateInput.data(&#39;format&#39;) );</span></div><div class="line" id="file-gistfile1-php-LC73"><span class="x">                    var dayCount = 0;</span></div><div class="line" id="file-gistfile1-php-LC74">&nbsp;</div><div class="line" id="file-gistfile1-php-LC75"><span class="x">                    if( !this.isValidDate( startDate ) || !this.isValidDate( endDate ) )</span></div><div class="line" id="file-gistfile1-php-LC76"><span class="x">                        return &#39;&#39;;</span></div><div class="line" id="file-gistfile1-php-LC77">&nbsp;</div><div class="line" id="file-gistfile1-php-LC78"><span class="x">                    if( startDate &gt; endDate ) {</span></div><div class="line" id="file-gistfile1-php-LC79"><span class="x">                        return 0;</span></div><div class="line" id="file-gistfile1-php-LC80"><span class="x">                    } else {</span></div><div class="line" id="file-gistfile1-php-LC81">&nbsp;</div><div class="line" id="file-gistfile1-php-LC82"><span class="x">                        var diff = endDate - startDate;</span></div><div class="line" id="file-gistfile1-php-LC83"><span class="x">                        dayCount = diff / ( 60 * 60 * 24 * 1000 ); // secs * mins * hours * milliseconds</span></div><div class="line" id="file-gistfile1-php-LC84"><span class="x">                        dayCount = Math.round( dayCount ) + this.options.countAdjust;</span></div><div class="line" id="file-gistfile1-php-LC85">&nbsp;</div><div class="line" id="file-gistfile1-php-LC86"><span class="x">                        return dayCount;</span></div><div class="line" id="file-gistfile1-php-LC87"><span class="x">                    }</span></div><div class="line" id="file-gistfile1-php-LC88">&nbsp;</div><div class="line" id="file-gistfile1-php-LC89"><span class="x">                }</span></div><div class="line" id="file-gistfile1-php-LC90">&nbsp;</div><div class="line" id="file-gistfile1-php-LC91"><span class="x">                this.parseDate = function( value, format ) {</span></div><div class="line" id="file-gistfile1-php-LC92">&nbsp;</div><div class="line" id="file-gistfile1-php-LC93"><span class="x">                    if( !value )</span></div><div class="line" id="file-gistfile1-php-LC94"><span class="x">                        return false;</span></div><div class="line" id="file-gistfile1-php-LC95">&nbsp;</div><div class="line" id="file-gistfile1-php-LC96"><span class="x">                    format = format.split(&#39;_&#39;);</span></div><div class="line" id="file-gistfile1-php-LC97"><span class="x">                    var dateFormat = format[0];</span></div><div class="line" id="file-gistfile1-php-LC98"><span class="x">                    var separators = { slash: &#39;/&#39;, dash: &#39;-&#39;, dot: &#39;.&#39; };</span></div><div class="line" id="file-gistfile1-php-LC99"><span class="x">                    var separator = format.length &gt; 1 ? separators[format[1]] : separators.slash;</span></div><div class="line" id="file-gistfile1-php-LC100"><span class="x">                    var dateArr = value.split(separator);</span></div><div class="line" id="file-gistfile1-php-LC101">&nbsp;</div><div class="line" id="file-gistfile1-php-LC102"><span class="x">                    switch( dateFormat ) {</span></div><div class="line" id="file-gistfile1-php-LC103"><span class="x">                    case &#39;mdy&#39;:</span></div><div class="line" id="file-gistfile1-php-LC104"><span class="x">                        return new Date( dateArr[2], dateArr[0] - 1, dateArr[1] );</span></div><div class="line" id="file-gistfile1-php-LC105"><span class="x">                    case &#39;dmy&#39;:</span></div><div class="line" id="file-gistfile1-php-LC106"><span class="x">                        return new Date( dateArr[2], dateArr[1] - 1, dateArr[0] );</span></div><div class="line" id="file-gistfile1-php-LC107"><span class="x">                    case &#39;ymd&#39;:</span></div><div class="line" id="file-gistfile1-php-LC108"><span class="x">                        return new Date( dateArr[0], dateArr[1] - 1, dateArr[2] );</span></div><div class="line" id="file-gistfile1-php-LC109"><span class="x">                    }</span></div><div class="line" id="file-gistfile1-php-LC110">&nbsp;</div><div class="line" id="file-gistfile1-php-LC111"><span class="x">                    return false;</span></div><div class="line" id="file-gistfile1-php-LC112"><span class="x">                }</span></div><div class="line" id="file-gistfile1-php-LC113">&nbsp;</div><div class="line" id="file-gistfile1-php-LC114"><span class="x">                this.populateDayCount = function() {</span></div><div class="line" id="file-gistfile1-php-LC115"><span class="x">                    this.countInput.val( this.getDayCount() ).change();</span></div><div class="line" id="file-gistfile1-php-LC116"><span class="x">                }</span></div><div class="line" id="file-gistfile1-php-LC117">&nbsp;</div><div class="line" id="file-gistfile1-php-LC118"><span class="x">                this.isValidDate = function( date ) {</span></div><div class="line" id="file-gistfile1-php-LC119"><span class="x">                    return !isNaN( Date.parse( date ) );</span></div><div class="line" id="file-gistfile1-php-LC120"><span class="x">                }</span></div><div class="line" id="file-gistfile1-php-LC121">&nbsp;</div><div class="line" id="file-gistfile1-php-LC122"><span class="x">                this.init();</span></div><div class="line" id="file-gistfile1-php-LC123">&nbsp;</div><div class="line" id="file-gistfile1-php-LC124"><span class="x">            }</span></div><div class="line" id="file-gistfile1-php-LC125">&nbsp;</div><div class="line" id="file-gistfile1-php-LC126"><span class="x">        })(jQuery);</span></div><div class="line" id="file-gistfile1-php-LC127">&nbsp;</div><div class="line" id="file-gistfile1-php-LC128"><span class="x">        &lt;/script&gt;</span></div><div class="line" id="file-gistfile1-php-LC129">&nbsp;</div><div class="line" id="file-gistfile1-php-LC130"><span class="x">        </span><span class="cp">&lt;?php</span></div><div class="line" id="file-gistfile1-php-LC131">        <span class="nx">self</span><span class="o">::</span><span class="nv">$script_output</span> <span class="o">=</span> <span class="k">true</span><span class="p">;</span></div><div class="line" id="file-gistfile1-php-LC132">        <span class="k">return</span> <span class="nv">$form</span><span class="p">;</span></div><div class="line" id="file-gistfile1-php-LC133">    <span class="p">}</span></div><div class="line" id="file-gistfile1-php-LC134">    </div><div class="line" id="file-gistfile1-php-LC135">    <span class="k">function</span> <span class="nf">add_init_script</span><span class="p">(</span> <span class="nv">$return</span> <span class="p">)</span> <span class="p">{</span></div><div class="line" id="file-gistfile1-php-LC136">        </div><div class="line" id="file-gistfile1-php-LC137">        <span class="nv">$start_field_format</span> <span class="o">=</span> <span class="k">false</span><span class="p">;</span></div><div class="line" id="file-gistfile1-php-LC138">        <span class="nv">$end_field_format</span> <span class="o">=</span> <span class="k">false</span><span class="p">;</span></div><div class="line" id="file-gistfile1-php-LC139">&nbsp;</div><div class="line" id="file-gistfile1-php-LC140">        <span class="k">foreach</span><span class="p">(</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">form</span><span class="p">[</span><span class="s1">&#39;fields&#39;</span><span class="p">]</span> <span class="k">as</span> <span class="o">&amp;</span><span class="nv">$field</span> <span class="p">)</span> <span class="p">{</span></div><div class="line" id="file-gistfile1-php-LC141">&nbsp;</div><div class="line" id="file-gistfile1-php-LC142">            <span class="k">if</span><span class="p">(</span> <span class="nv">$field</span><span class="p">[</span><span class="s1">&#39;id&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">start_field_id</span> <span class="p">)</span></div><div class="line" id="file-gistfile1-php-LC143">                <span class="nv">$start_field_format</span> <span class="o">=</span> <span class="nv">$field</span><span class="p">[</span><span class="s1">&#39;dateFormat&#39;</span><span class="p">]</span> <span class="o">?</span> <span class="nv">$field</span><span class="p">[</span><span class="s1">&#39;dateFormat&#39;</span><span class="p">]</span> <span class="o">:</span> <span class="s1">&#39;mdy&#39;</span><span class="p">;</span></div><div class="line" id="file-gistfile1-php-LC144">&nbsp;</div><div class="line" id="file-gistfile1-php-LC145">            <span class="k">if</span><span class="p">(</span> <span class="nv">$field</span><span class="p">[</span><span class="s1">&#39;id&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">end_field_id</span> <span class="p">)</span></div><div class="line" id="file-gistfile1-php-LC146">                <span class="nv">$end_field_format</span> <span class="o">=</span> <span class="nv">$field</span><span class="p">[</span><span class="s1">&#39;dateFormat&#39;</span><span class="p">]</span> <span class="o">?</span> <span class="nv">$field</span><span class="p">[</span><span class="s1">&#39;dateFormat&#39;</span><span class="p">]</span> <span class="o">:</span> <span class="s1">&#39;mdy&#39;</span><span class="p">;</span></div><div class="line" id="file-gistfile1-php-LC147">&nbsp;</div><div class="line" id="file-gistfile1-php-LC148">        <span class="p">}</span></div><div class="line" id="file-gistfile1-php-LC149">        </div><div class="line" id="file-gistfile1-php-LC150">        <span class="nv">$script</span> <span class="o">=</span> <span class="s2">&quot;new gwdc({</span></div><div class="line" id="file-gistfile1-php-LC151"><span class="s2">                formId:             </span><span class="si">{</span><span class="nv">$this</span><span class="o">-&gt;</span><span class="na">form</span><span class="p">[</span><span class="s1">&#39;id&#39;</span><span class="p">]</span><span class="si">}</span><span class="s2">,</span></div><div class="line" id="file-gistfile1-php-LC152"><span class="s2">                startFieldId:       </span><span class="si">{</span><span class="nv">$this</span><span class="o">-&gt;</span><span class="na">start_field_id</span><span class="si">}</span><span class="s2">,</span></div><div class="line" id="file-gistfile1-php-LC153"><span class="s2">                startDateFormat:    &#39;</span><span class="si">$start_field_format</span><span class="s2">&#39;,</span></div><div class="line" id="file-gistfile1-php-LC154"><span class="s2">                endFieldId:         </span><span class="si">{</span><span class="nv">$this</span><span class="o">-&gt;</span><span class="na">end_field_id</span><span class="si">}</span><span class="s2">,</span></div><div class="line" id="file-gistfile1-php-LC155"><span class="s2">                endDateFormat:      &#39;</span><span class="si">$end_field_format</span><span class="s2">&#39;,</span></div><div class="line" id="file-gistfile1-php-LC156"><span class="s2">                countFieldId:       </span><span class="si">{</span><span class="nv">$this</span><span class="o">-&gt;</span><span class="na">count_field_id</span><span class="si">}</span><span class="s2">,</span></div><div class="line" id="file-gistfile1-php-LC157"><span class="s2">                countAdjust:        </span><span class="si">{</span><span class="nv">$this</span><span class="o">-&gt;</span><span class="na">count_adjust</span><span class="si">}</span><span class="s2"></span></div><div class="line" id="file-gistfile1-php-LC158"><span class="s2">            });&quot;</span><span class="p">;</span></div><div class="line" id="file-gistfile1-php-LC159">        </div><div class="line" id="file-gistfile1-php-LC160">        <span class="nx">GFFormDisplay</span><span class="o">::</span><span class="na">add_init_script</span><span class="p">(</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">form</span><span class="p">[</span><span class="s1">&#39;id&#39;</span><span class="p">],</span> <span class="s1">&#39;gw_display_count_&#39;</span> <span class="o">.</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">count_field_id</span><span class="p">,</span> <span class="nx">GFFormDisplay</span><span class="o">::</span><span class="na">ON_PAGE_RENDER</span><span class="p">,</span> <span class="nv">$script</span> <span class="p">);</span></div><div class="line" id="file-gistfile1-php-LC161">        </div><div class="line" id="file-gistfile1-php-LC162">        <span class="c1">// remove filter so init script is not output on subsequent forms</span></div><div class="line" id="file-gistfile1-php-LC163">        <span class="nx">remove_filter</span><span class="p">(</span> <span class="s1">&#39;gform_init_scripts_footer&#39;</span><span class="p">,</span> <span class="k">array</span><span class="p">(</span> <span class="o">&amp;</span><span class="nv">$this</span><span class="p">,</span> <span class="s1">&#39;add_init_script&#39;</span> <span class="p">)</span> <span class="p">);</span></div><div class="line" id="file-gistfile1-php-LC164">        </div><div class="line" id="file-gistfile1-php-LC165">        <span class="k">return</span> <span class="nv">$return</span><span class="p">;</span></div><div class="line" id="file-gistfile1-php-LC166">    <span class="p">}</span></div><div class="line" id="file-gistfile1-php-LC167">&nbsp;</div><div class="line" id="file-gistfile1-php-LC168">    <span class="k">function</span> <span class="nf">override_submitted_value</span><span class="p">(</span> <span class="nv">$form</span> <span class="p">)</span> <span class="p">{</span></div><div class="line" id="file-gistfile1-php-LC169">&nbsp;</div><div class="line" id="file-gistfile1-php-LC170">        <span class="nv">$start_date</span> <span class="o">=</span> <span class="k">false</span><span class="p">;</span></div><div class="line" id="file-gistfile1-php-LC171">        <span class="nv">$end_date</span> <span class="o">=</span> <span class="k">false</span><span class="p">;</span></div><div class="line" id="file-gistfile1-php-LC172">&nbsp;</div><div class="line" id="file-gistfile1-php-LC173">        <span class="k">foreach</span><span class="p">(</span> <span class="nv">$form</span><span class="p">[</span><span class="s1">&#39;fields&#39;</span><span class="p">]</span> <span class="k">as</span> <span class="o">&amp;</span><span class="nv">$field</span> <span class="p">)</span> <span class="p">{</span></div><div class="line" id="file-gistfile1-php-LC174">&nbsp;</div><div class="line" id="file-gistfile1-php-LC175">            <span class="k">if</span><span class="p">(</span> <span class="nv">$field</span><span class="p">[</span><span class="s1">&#39;id&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">start_field_id</span> <span class="p">)</span></div><div class="line" id="file-gistfile1-php-LC176">                <span class="nv">$start_date</span> <span class="o">=</span> <span class="nx">self</span><span class="o">::</span><span class="na">parse_field_date</span><span class="p">(</span> <span class="nv">$field</span> <span class="p">);</span></div><div class="line" id="file-gistfile1-php-LC177">&nbsp;</div><div class="line" id="file-gistfile1-php-LC178">            <span class="k">if</span><span class="p">(</span> <span class="nv">$field</span><span class="p">[</span><span class="s1">&#39;id&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">end_field_id</span> <span class="p">)</span></div><div class="line" id="file-gistfile1-php-LC179">                <span class="nv">$end_date</span> <span class="o">=</span> <span class="nx">self</span><span class="o">::</span><span class="na">parse_field_date</span><span class="p">(</span> <span class="nv">$field</span> <span class="p">);</span></div><div class="line" id="file-gistfile1-php-LC180">&nbsp;</div><div class="line" id="file-gistfile1-php-LC181">        <span class="p">}</span></div><div class="line" id="file-gistfile1-php-LC182">&nbsp;</div><div class="line" id="file-gistfile1-php-LC183">        <span class="k">if</span><span class="p">(</span> <span class="nv">$start_date</span> <span class="o">&gt;</span> <span class="nv">$end_date</span> <span class="p">)</span> <span class="p">{</span></div><div class="line" id="file-gistfile1-php-LC184">&nbsp;</div><div class="line" id="file-gistfile1-php-LC185">            <span class="nv">$day_count</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span></div><div class="line" id="file-gistfile1-php-LC186">&nbsp;</div><div class="line" id="file-gistfile1-php-LC187">        <span class="p">}</span> <span class="k">else</span> <span class="p">{</span></div><div class="line" id="file-gistfile1-php-LC188">&nbsp;</div><div class="line" id="file-gistfile1-php-LC189">            <span class="nv">$diff</span> <span class="o">=</span> <span class="nv">$end_date</span> <span class="o">-</span> <span class="nv">$start_date</span><span class="p">;</span></div><div class="line" id="file-gistfile1-php-LC190">            <span class="nv">$day_count</span> <span class="o">=</span> <span class="nv">$diff</span> <span class="o">/</span> <span class="p">(</span> <span class="mi">60</span> <span class="o">*</span> <span class="mi">60</span> <span class="o">*</span> <span class="mi">24</span> <span class="p">);</span> <span class="c1">// secs * mins * hours</span></div><div class="line" id="file-gistfile1-php-LC191">            <span class="nv">$day_count</span> <span class="o">=</span> <span class="nx">round</span><span class="p">(</span> <span class="nv">$day_count</span> <span class="p">)</span> <span class="o">+</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">count_adjust</span><span class="p">;</span></div><div class="line" id="file-gistfile1-php-LC192">&nbsp;</div><div class="line" id="file-gistfile1-php-LC193">        <span class="p">}</span></div><div class="line" id="file-gistfile1-php-LC194">&nbsp;</div><div class="line" id="file-gistfile1-php-LC195">        <span class="nv">$_POST</span><span class="p">[</span><span class="s2">&quot;input_</span><span class="si">{</span><span class="nv">$this</span><span class="o">-&gt;</span><span class="na">count_field_id</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="nv">$day_count</span><span class="p">;</span></div><div class="line" id="file-gistfile1-php-LC196">&nbsp;</div><div class="line" id="file-gistfile1-php-LC197">    <span class="p">}</span></div><div class="line" id="file-gistfile1-php-LC198">&nbsp;</div><div class="line" id="file-gistfile1-php-LC199">    <span class="k">static</span> <span class="k">function</span> <span class="nf">parse_field_date</span><span class="p">(</span> <span class="nv">$field</span> <span class="p">)</span> <span class="p">{</span></div><div class="line" id="file-gistfile1-php-LC200">&nbsp;</div><div class="line" id="file-gistfile1-php-LC201">        <span class="nv">$date_value</span> <span class="o">=</span> <span class="nx">rgpost</span><span class="p">(</span><span class="s2">&quot;input_</span><span class="si">{</span><span class="nv">$field</span><span class="p">[</span><span class="s1">&#39;id&#39;</span><span class="p">]</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">);</span></div><div class="line" id="file-gistfile1-php-LC202">        <span class="nv">$date_format</span> <span class="o">=</span> <span class="k">empty</span><span class="p">(</span> <span class="nv">$field</span><span class="p">[</span><span class="s1">&#39;dateFormat&#39;</span><span class="p">]</span> <span class="p">)</span> <span class="o">?</span> <span class="s1">&#39;mdy&#39;</span> <span class="o">:</span> <span class="nx">esc_attr</span><span class="p">(</span> <span class="nv">$field</span><span class="p">[</span><span class="s1">&#39;dateFormat&#39;</span><span class="p">]</span> <span class="p">);</span></div><div class="line" id="file-gistfile1-php-LC203">        <span class="nv">$date_info</span> <span class="o">=</span> <span class="nx">GFCommon</span><span class="o">::</span><span class="na">parse_date</span><span class="p">(</span> <span class="nv">$date_value</span><span class="p">,</span> <span class="nv">$date_format</span> <span class="p">);</span></div><div class="line" id="file-gistfile1-php-LC204">&nbsp;</div><div class="line" id="file-gistfile1-php-LC205">        <span class="k">return</span> <span class="nb">strtotime</span><span class="p">(</span> <span class="s2">&quot;</span><span class="si">{</span><span class="nv">$date_info</span><span class="p">[</span><span class="s1">&#39;year&#39;</span><span class="p">]</span><span class="si">}</span><span class="s2">-</span><span class="si">{</span><span class="nv">$date_info</span><span class="p">[</span><span class="s1">&#39;month&#39;</span><span class="p">]</span><span class="si">}</span><span class="s2">-</span><span class="si">{</span><span class="nv">$date_info</span><span class="p">[</span><span class="s1">&#39;day&#39;</span><span class="p">]</span><span class="si">}</span><span class="s2">&quot;</span> <span class="p">);</span></div><div class="line" id="file-gistfile1-php-LC206">    <span class="p">}</span></div><div class="line" id="file-gistfile1-php-LC207">&nbsp;</div><div class="line" id="file-gistfile1-php-LC208"><span class="p">}</span></div><div class="line" id="file-gistfile1-php-LC209">&nbsp;</div><div class="line" id="file-gistfile1-php-LC210"><span class="k">new</span> <span class="nx">GWDayCount</span><span class="p">(</span> <span class="k">array</span><span class="p">(</span></div><div class="line" id="file-gistfile1-php-LC211">    <span class="s1">&#39;form_id&#39;</span>        <span class="o">=&gt;</span> <span class="mi">16</span><span class="p">,</span></div><div class="line" id="file-gistfile1-php-LC212">    <span class="s1">&#39;start_field_id&#39;</span> <span class="o">=&gt;</span> <span class="mi">1</span><span class="p">,</span></div><div class="line" id="file-gistfile1-php-LC213">    <span class="s1">&#39;end_field_id&#39;</span>   <span class="o">=&gt;</span> <span class="mi">2</span><span class="p">,</span></div><div class="line" id="file-gistfile1-php-LC214">    <span class="s1">&#39;count_field_id&#39;</span> <span class="o">=&gt;</span> <span class="mi">4</span></div><div class="line" id="file-gistfile1-php-LC215">    <span class="p">)</span> <span class="p">);</span></div></pre>
        </td>
      </tr>
    </table>
  </div>

        </div>

        <div class="gist-meta">
          <a href="https://gist.github.com/spivurno/4996579/raw/91480474b8f228b93bbf102db6ce09c4868e77a8/gistfile1.php" style="float:right">view raw</a>
          <a href="https://gist.github.com/spivurno/4996579#file-gistfile1-php" style="float:right; margin-right:10px; color:#666;">gistfile1.php</a>
          <a href="https://gist.github.com/spivurno/4996579">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
        </div>
      </div>
</div>


<h3>How do I install this snippet?</h3><p>Easy peasy. Just copy and paste the code above into your theme's <em>functions.php</em> file.</p>

<h3>How do I use this functionality?</h3>

<p>To use this snippet&#8217;s functionality just go directly below the snippet and instantiate the <code>GWDayCount()</code> class. Instantiate is a big word but all it means is that you&#8217;ll be creating a new &#8220;instance&#8221; of the <code>GWDayCount()</code> class with a set of parameters (aka options) for that specific instance.</p>

<p><strong>Standard Usage</strong>
<div id="gist5013643" class="gist">       <div class="gist-file">         <div class="gist-data gist-syntax">      <div class="file-data">     <table cellpadding="0" cellspacing="0" class="lines highlight">       <tr>         <td class="line-numbers">                                                                             <span class="line-number" id="file-gistfile1-php-L7" rel="file-gistfile1-php-L7">7</span>           <span class="line-number" id="file-gistfile1-php-L8" rel="file-gistfile1-php-L8">8</span>           <span class="line-number" id="file-gistfile1-php-L9" rel="file-gistfile1-php-L9">9</span>           <span class="line-number" id="file-gistfile1-php-L10" rel="file-gistfile1-php-L10">10</span>           <span class="line-number" id="file-gistfile1-php-L11" rel="file-gistfile1-php-L11">11</span>           <span class="line-number" id="file-gistfile1-php-L12" rel="file-gistfile1-php-L12">12</span>                                                                                                 </td>         <td class="line-data">           <pre class="line-pre"><div class="line" id="file-gistfile1-php-LC7"><span class="k">new</span> <span class="nx">GWDayCount</span><span class="p">(</span> <span class="k">array</span><span class="p">(</span></div><div class="line" id="file-gistfile1-php-LC8">	<span class="s1">&#39;form_id&#39;</span>        <span class="o">=&gt;</span> <span class="mi">9</span><span class="p">,</span></div><div class="line" id="file-gistfile1-php-LC9">	<span class="s1">&#39;start_field_id&#39;</span> <span class="o">=&gt;</span> <span class="mi">1</span><span class="p">,</span></div><div class="line" id="file-gistfile1-php-LC10">	<span class="s1">&#39;end_field_id&#39;</span>   <span class="o">=&gt;</span> <span class="mi">2</span><span class="p">,</span></div><div class="line" id="file-gistfile1-php-LC11">	<span class="s1">&#39;count_field_id&#39;</span> <span class="o">=&gt;</span> <span class="mi">3</span></div><div class="line" id="file-gistfile1-php-LC12">	<span class="p">)</span> <span class="p">);</span></div></pre>         </td>       </tr>     </table>   </div>          </div>          <div class="gist-meta">           <a href="https://gist.github.com/spivurno/5013643/raw/8d10364529e7ca3dbe74aac75b9bc3f496ee534a/gistfile1.php" style="float:right">view raw</a>           <a href="https://gist.github.com/spivurno/5013643#file-gistfile1-php" style="float:right; margin-right:10px; color:#666;">gistfile1.php</a>           <a href="https://gist.github.com/spivurno/5013643">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.         </div>       </div> </div> </p>

<p><strong>Count &#8220;Nights&#8221; Only</strong><br />End date is not included in the day count so you are essentially counting the number of &#8220;nights&#8221; between the two dates.
<div id="gist5013643" class="gist">       <div class="gist-file">         <div class="gist-data gist-syntax">      <div class="file-data">     <table cellpadding="0" cellspacing="0" class="lines highlight">       <tr>         <td class="line-numbers">                                                                                                                                                          <span class="line-number" id="file-gistfile1-php-L14" rel="file-gistfile1-php-L14">14</span>           <span class="line-number" id="file-gistfile1-php-L15" rel="file-gistfile1-php-L15">15</span>           <span class="line-number" id="file-gistfile1-php-L16" rel="file-gistfile1-php-L16">16</span>           <span class="line-number" id="file-gistfile1-php-L17" rel="file-gistfile1-php-L17">17</span>           <span class="line-number" id="file-gistfile1-php-L18" rel="file-gistfile1-php-L18">18</span>           <span class="line-number" id="file-gistfile1-php-L19" rel="file-gistfile1-php-L19">19</span>           <span class="line-number" id="file-gistfile1-php-L20" rel="file-gistfile1-php-L20">20</span>         </td>         <td class="line-data">           <pre class="line-pre"><div class="line" id="file-gistfile1-php-LC14"><span class="k">new</span> <span class="nx">GWDayCount</span><span class="p">(</span> <span class="k">array</span><span class="p">(</span></div><div class="line" id="file-gistfile1-php-LC15">	<span class="s1">&#39;form_id&#39;</span>          <span class="o">=&gt;</span> <span class="mi">9</span><span class="p">,</span></div><div class="line" id="file-gistfile1-php-LC16">	<span class="s1">&#39;start_field_id&#39;</span>   <span class="o">=&gt;</span> <span class="mi">1</span><span class="p">,</span></div><div class="line" id="file-gistfile1-php-LC17">	<span class="s1">&#39;end_field_id&#39;</span>     <span class="o">=&gt;</span> <span class="mi">2</span><span class="p">,</span></div><div class="line" id="file-gistfile1-php-LC18">	<span class="s1">&#39;count_field_id&#39;</span>   <span class="o">=&gt;</span> <span class="mi">3</span><span class="p">,</span></div><div class="line" id="file-gistfile1-php-LC19">	<span class="s1">&#39;include_end_date&#39;</span> <span class="o">=&gt;</span> <span class="k">false</span></div><div class="line" id="file-gistfile1-php-LC20">	<span class="p">)</span> <span class="p">);</span></div></pre>         </td>       </tr>     </table>   </div>          </div>          <div class="gist-meta">           <a href="https://gist.github.com/spivurno/5013643/raw/8d10364529e7ca3dbe74aac75b9bc3f496ee534a/gistfile1.php" style="float:right">view raw</a>           <a href="https://gist.github.com/spivurno/5013643#file-gistfile1-php" style="float:right; margin-right:10px; color:#666;">gistfile1.php</a>           <a href="https://gist.github.com/spivurno/5013643">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.         </div>       </div> </div> </p>

<p>Once you instantiated the class you are finished! If you would like to have this functionality on multiple forms then just create a new instance of the class and fill in the parameters for the new form. That&#8217;s it!</p>

<h4>Parameter Details</h4>

<ul>
<li><code>form_id</code>: The form ID of the form you would like to apply this functionality to.</li>
<li><code>start_field_id</code>: The ID of the date field that will contain the start date. This field must be a date field and the parameter only holds a single field.</li>
<li><code>end_field_id</code>: This parameter holds the ID of the date field that will contain the forms end date. This field, like the start_field_id field, must be a date field and only holds a single field ID.</li>
<li><code>count_field_id</code>: This parameter holds the ID of the field that will be populated with the calculated number of days between the start date and end date.</li>
<li><code>include_end_date</code>: Defaults to true. Set to this false if you would like to count only &#8220;nights&#8221; where the start date would be the check-in date and the end date would be the check-out date.</li>
</ul>

<h3>Points of Note</h3>

<ul>
<li>This is currently only setup to work with &#8220;Date Picker&#8221; date fields. Let me know if you need this with other types of date fields in the comments.</li>
</ul>
<p>The post <a href="http://gravitywiz.com/calculate-number-of-days-between-two-dates/">Calculate Number of Days Between Two Dates</a> appeared first on <a href="http://gravitywiz.com">Gravity Wiz</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://gravitywiz.com/calculate-number-of-days-between-two-dates/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>Customizing Gravity Forms User Registration Activation Page</title>
		<link>http://gravitywiz.com/customizing-gravity-forms-user-registration-activation-page/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=customizing-gravity-forms-user-registration-activation-page</link>
		<comments>http://gravitywiz.com/customizing-gravity-forms-user-registration-activation-page/#comments</comments>
		<pubDate>Tue, 19 Feb 2013 15:00:21 +0000</pubDate>
		<dc:creator>David Smith</dc:creator>
				<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://gravitywiz.com/?p=1154</guid>
		<description><![CDATA[<p>If you&#8217;ve checked out the latest beta for the Gravity Forms User Registration add-on, you might have noticed one of the awesome new features is &#8220;Pending Activations&#8221;. Here&#8217;s how they work. When the user signs up, instead of automatically being registered as a user on your WordPress site, an activation email is sent to the [...]</p><p>The post <a href="http://gravitywiz.com/customizing-gravity-forms-user-registration-activation-page/">Customizing Gravity Forms User Registration Activation Page</a> appeared first on <a href="http://gravitywiz.com">Gravity Wiz</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>If you&#8217;ve checked out the <a href="http://www.gravityhelp.com/downloads/add-ons/">latest beta</a> for the <a href="http://www.gravityforms.com/add-ons/user-registration/">Gravity Forms User Registration add-on</a>, you might have noticed one of the awesome new features is &#8220;Pending Activations&#8221;. Here&#8217;s how they work.</p>

<p>When the user signs up, instead of automatically being registered as a user on your WordPress site, an activation email is sent to the email address they signed up with. The activation email contains an activation link. When the user clicks this link and visits the activation page, they are &#8220;activated&#8221; and their user account is registered.</p>

<p>One of the first things you&#8217;re probably going to want to do with this new feature is customize the activation page. This is the page where users land after clicking the activation link in the activation email. This walk-through aims to demonstrate how this activation page can be completely customized.</p>

<p>This process can be broken down into two simple steps:</p>

<ol>
<li><a href="#create_custom_template">Create a custom activate.php template</a></li>
<li><a href="#override_default_template">Override default activate.php template</a></li>
</ol>

<p><a name="create_custom_template"></a></p>

<h3>1. Create a Custom <strong>activate.php</strong> Template</h3>

<p>At the most basic level, all you need to do here is find the <strong>activate.php</strong> file in the GF User Registration plugin folder and place a copy of this file in your theme folder.</p>

<ul>
<li><strong>Path to GF User Registration activate.php file</strong><br /><code>&lt;root&gt;/wp-content/plugins/gravityformsuserregistration/includes/activate.php</code></li>
<li><strong>Sample path to your theme folder</strong><br /><code>&lt;root&gt;/wp-content/themes/<strong>&lt;your_theme&gt;</strong>/</code></li>
</ul>

<p>The issue with this is that the <strong>activate.php</strong> template really isn&#8217;t easy to customize. There are a lot of nested conditionals and special variables that you probably won&#8217;t understand without really digging in.</p>

<h4>GW Activate Template</h4>

<p>To alleviate some of this burden, I&#8217;ve created a special version of the <strong>activate.php</strong> which you can download and include in your theme which is much simpler to customize. The primary benefit is that it takes 99% of the HTML output that lives in the activate.php template and moves it out to easy-to-edit template parts.</p>

<p><a href="https://github.com/spivurno/gfur-activate-template">GW Activate Template on GitHub</a></p>

<p>Just click the &#8220;zip&#8221; button to download all the template files. Once downloaded, unzip the <strong>gfur-activate-template-master.zip</strong> file. Inside you will find a <em>gfur-activate-template-master</em> folder. Rename this to &#8220;gfur-activate-template&#8221; and move this folder into your theme folder.</p>

<div class="inline-image full"><img src="http://gravitywiz.com/wp-content/uploads/2013/02/github-download-zip.png" alt="github-download-zip" width="500" height="300" class="alignnone size-full wp-image-1174" /><span class="caption">Download GW Activate Template Files</span></div>

<h4>The Different Views of Activation</h4>

<p>There are several different &#8220;views&#8221; or &#8220;parts&#8221; of the activation page.</p>

<table class="gfur-activate-template-table">
<tr>
<td><a href="http://gravitywiz.com/wp-content/uploads/2013/02/activate-success.png"><img src="http://gravitywiz.com/wp-content/uploads/2013/02/activate-success-300x180.png" alt="activate-success" width="300" height="180" class="alignnone size-medium wp-image-1170" /></a></td>
<td>
<h5>Success</h5>
This is the default view that a user will see after clicking the activation link in the activation email. This view is handled by the <b>activate-success.php</b> template part.</td>
</tr>
<tr>
<td><a href="http://gravitywiz.com/wp-content/uploads/2013/02/activate-error-already-active.png"><img src="http://gravitywiz.com/wp-content/uploads/2013/02/activate-error-already-active-300x180.png" alt="activate-error-already-active" width="300" height="180" class="alignnone size-medium wp-image-1171" /></a></td>
<td>
<h5>Error: Already Active</h5>
Occurs when a user attempts to activate an activation key which has already been activated. This view is handled by the <b>activate-error.php</b> template part.</td>
</tr>
<tr>
<td><a href="http://gravitywiz.com/wp-content/uploads/2013/02/activate-error.png"><img src="http://gravitywiz.com/wp-content/uploads/2013/02/activate-error-300x180.png" alt="activate-error" width="300" height="180" class="alignnone size-medium wp-image-1172" /></a></td>
<td>
<h5>Error</h5>
If anything goes wrong during the activation (i.e. bad activation key, username already registered, etc), this view will handling displaying the error. This view is handled by the <b>activate-error.php</b> template part.</td>
</tr>
<tr>
<td><a href="http://gravitywiz.com/wp-content/uploads/2013/02/activate-no-key.png"><img src="http://gravitywiz.com/wp-content/uploads/2013/02/activate-no-key-300x180.png" alt="activate-no-key" width="300" height="180" class="alignnone size-medium wp-image-1173" /></a></td>
<td>
<h5>No Key</h5>
It&#8217;s quite unlikely that users will see this view since the activation key is passed in the activation link; however, for the sake of completeness, this view is what the user will see if no activation key is passed in the activation link. This view is handled in the <b>activate-no-key.php</b> template part.</td>
</tr>
</table>

<p><a name="override_default_template"></a></p>

<h3>2. Overriding the Default Activation Template</h3>

<p>With the template files in place, you&#8217;re ready to override the default activate template files to point to your custom files. Doing this is actually pretty simple. Just add this code to your theme&#8217;s functions.php file:</p>

<div id="gist4950600" class="gist">
      <div class="gist-file">
        <div class="gist-data gist-syntax">



  <div class="file-data">
    <table cellpadding="0" cellspacing="0" class="lines highlight">
      <tr>
        <td class="line-numbers">
          <span class="line-number" id="file-gistfile1-php-L1" rel="file-gistfile1-php-L1">1</span>
          <span class="line-number" id="file-gistfile1-php-L2" rel="file-gistfile1-php-L2">2</span>
          <span class="line-number" id="file-gistfile1-php-L3" rel="file-gistfile1-php-L3">3</span>
          <span class="line-number" id="file-gistfile1-php-L4" rel="file-gistfile1-php-L4">4</span>
          <span class="line-number" id="file-gistfile1-php-L5" rel="file-gistfile1-php-L5">5</span>
          <span class="line-number" id="file-gistfile1-php-L6" rel="file-gistfile1-php-L6">6</span>
          <span class="line-number" id="file-gistfile1-php-L7" rel="file-gistfile1-php-L7">7</span>
          <span class="line-number" id="file-gistfile1-php-L8" rel="file-gistfile1-php-L8">8</span>
          <span class="line-number" id="file-gistfile1-php-L9" rel="file-gistfile1-php-L9">9</span>
          <span class="line-number" id="file-gistfile1-php-L10" rel="file-gistfile1-php-L10">10</span>
          <span class="line-number" id="file-gistfile1-php-L11" rel="file-gistfile1-php-L11">11</span>
          <span class="line-number" id="file-gistfile1-php-L12" rel="file-gistfile1-php-L12">12</span>
          <span class="line-number" id="file-gistfile1-php-L13" rel="file-gistfile1-php-L13">13</span>
          <span class="line-number" id="file-gistfile1-php-L14" rel="file-gistfile1-php-L14">14</span>
          <span class="line-number" id="file-gistfile1-php-L15" rel="file-gistfile1-php-L15">15</span>
          <span class="line-number" id="file-gistfile1-php-L16" rel="file-gistfile1-php-L16">16</span>
          <span class="line-number" id="file-gistfile1-php-L17" rel="file-gistfile1-php-L17">17</span>
          <span class="line-number" id="file-gistfile1-php-L18" rel="file-gistfile1-php-L18">18</span>
        </td>
        <td class="line-data">
          <pre class="line-pre"><div class="line" id="file-gistfile1-php-LC1"><span class="cp">&lt;?php</span></div><div class="line" id="file-gistfile1-php-LC2">&nbsp;</div><div class="line" id="file-gistfile1-php-LC3"><span class="sd">/**</span></div><div class="line" id="file-gistfile1-php-LC4"><span class="sd">* Custom Activation Template</span></div><div class="line" id="file-gistfile1-php-LC5"><span class="sd">* http://gravitywiz.com/2013/02/13/customizing-gravity-forms-user-registration-activation-page</span></div><div class="line" id="file-gistfile1-php-LC6"><span class="sd">*/</span></div><div class="line" id="file-gistfile1-php-LC7"><span class="nx">add_action</span><span class="p">(</span><span class="s1">&#39;wp&#39;</span><span class="p">,</span> <span class="s1">&#39;custom_maybe_activate_user&#39;</span><span class="p">,</span> <span class="mi">9</span><span class="p">);</span></div><div class="line" id="file-gistfile1-php-LC8"><span class="k">function</span> <span class="nf">custom_maybe_activate_user</span><span class="p">()</span> <span class="p">{</span></div><div class="line" id="file-gistfile1-php-LC9">&nbsp;</div><div class="line" id="file-gistfile1-php-LC10">    <span class="nv">$template_path</span> <span class="o">=</span> <span class="nx">STYLESHEETPATH</span> <span class="o">.</span> <span class="s1">&#39;/gfur-activate-template/activate.php&#39;</span><span class="p">;</span></div><div class="line" id="file-gistfile1-php-LC11">    </div><div class="line" id="file-gistfile1-php-LC12">    <span class="k">if</span><span class="p">(</span> <span class="o">!</span><span class="nb">file_exists</span><span class="p">(</span><span class="nv">$template_path</span><span class="p">)</span> <span class="o">||</span> <span class="nx">rgget</span><span class="p">(</span><span class="s1">&#39;page&#39;</span><span class="p">)</span> <span class="o">!=</span> <span class="s1">&#39;gf_activation&#39;</span> <span class="p">)</span></div><div class="line" id="file-gistfile1-php-LC13">        <span class="k">return</span><span class="p">;</span></div><div class="line" id="file-gistfile1-php-LC14">    </div><div class="line" id="file-gistfile1-php-LC15">    <span class="k">require_once</span><span class="p">(</span> <span class="nv">$template_path</span> <span class="p">);</span></div><div class="line" id="file-gistfile1-php-LC16">    </div><div class="line" id="file-gistfile1-php-LC17">    <span class="k">exit</span><span class="p">();</span></div><div class="line" id="file-gistfile1-php-LC18"><span class="p">}</span></div></pre>
        </td>
      </tr>
    </table>
  </div>

        </div>

        <div class="gist-meta">
          <a href="https://gist.github.com/spivurno/4950600/raw/f0179b22c4d264ea10330b9fbe26c3d88f0a207e/gistfile1.php" style="float:right">view raw</a>
          <a href="https://gist.github.com/spivurno/4950600#file-gistfile1-php" style="float:right; margin-right:10px; color:#666;">gistfile1.php</a>
          <a href="https://gist.github.com/spivurno/4950600">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
        </div>
      </div>
</div>


<p>In plain speak, this code says: &#8220;Here is a path to the template file I&#8217;d like to use for my activation page. If this file exists and we&#8217;re on the GF User Registration activation page, go ahead and load my custom activation page file.&#8221;</p>

<p>If you&#8217;re using the GW Activate Template files and followed the instructions above, you won&#8217;t need to change this snippet at all. It&#8217;ll just work. Otherwise, you will need to change the <code>$template_path</code> variable to point to the location of your own custom activate.php file.</p>

<h2>Anything else?</h2>

<p>That&#8217;s it for now. Give it a go and let me know how it works out of you. I&#8217;m eager for any feedback you have!</p>
<p>The post <a href="http://gravitywiz.com/customizing-gravity-forms-user-registration-activation-page/">Customizing Gravity Forms User Registration Activation Page</a> appeared first on <a href="http://gravitywiz.com">Gravity Wiz</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://gravitywiz.com/customizing-gravity-forms-user-registration-activation-page/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Multi-page Form Navigation</title>
		<link>http://gravitywiz.com/multi-page-navigation/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=multi-page-navigation</link>
		<comments>http://gravitywiz.com/multi-page-navigation/#comments</comments>
		<pubDate>Sat, 02 Feb 2013 17:10:47 +0000</pubDate>
		<dc:creator>David Smith</dc:creator>
				<category><![CDATA[Snippets]]></category>

		<guid isPermaLink="false">http://gravitywiz.com/?p=1083</guid>
		<description><![CDATA[<p>This snippet can add the multi-page form navigation functionality to any form with multiple pages. Only forms using the &#8220;Steps&#8221; progress indicator will have the page steps converted into page links. For forms using the &#8220;Progess Bar&#8221; or no progress indicator at all can still make use of this functionality by creating custom links using [...]</p><p>The post <a href="http://gravitywiz.com/multi-page-navigation/">Multi-page Form Navigation</a> appeared first on <a href="http://gravitywiz.com">Gravity Wiz</a>.</p>]]></description>
				<content:encoded><![CDATA[<div class="introduction">Adds support for navigating between form pages by converting the page steps into page links or creating your own custom page links.</div>

<div class="demo-link-container"><a href="http://gravitywiz.com/demos/multi-page-navigation/" class="demo-link serif btn" target="_blank">view demo</a></div>

<p>This snippet can add the multi-page form navigation functionality to any form with multiple pages. Only forms using the <a href="#setting_progress_indicator">&#8220;Steps&#8221; progress indicator</a> will have the page steps converted into page links. For forms using the &#8220;Progess Bar&#8221; or no progress indicator at all can still make use of this functionality by creating custom links using the <a href="#custom_page_links">custom page link</a> formatting instructions below.</p>

<p>Currently, this functionality is setup so that the page links are not activated until the user reaches the final page of the form. Users can then navigate freely to any page using the page step links (displayed above the form).</p>

<p>After reaching the last page, navigating back to any form page will display a link: &#8220;Back to Last Page&#8221;. Clicking this link will (you guessed it!) take the user back to the last page.</p>

<div id="gist4697549" class="gist">
      <div class="gist-file">
        <div class="gist-data gist-syntax">



  <div class="file-data">
    <table cellpadding="0" cellspacing="0" class="lines highlight">
      <tr>
        <td class="line-numbers">
          <span class="line-number" id="file-gistfile1-php-L1" rel="file-gistfile1-php-L1">1</span>
          <span class="line-number" id="file-gistfile1-php-L2" rel="file-gistfile1-php-L2">2</span>
          <span class="line-number" id="file-gistfile1-php-L3" rel="file-gistfile1-php-L3">3</span>
          <span class="line-number" id="file-gistfile1-php-L4" rel="file-gistfile1-php-L4">4</span>
          <span class="line-number" id="file-gistfile1-php-L5" rel="file-gistfile1-php-L5">5</span>
          <span class="line-number" id="file-gistfile1-php-L6" rel="file-gistfile1-php-L6">6</span>
          <span class="line-number" id="file-gistfile1-php-L7" rel="file-gistfile1-php-L7">7</span>
          <span class="line-number" id="file-gistfile1-php-L8" rel="file-gistfile1-php-L8">8</span>
          <span class="line-number" id="file-gistfile1-php-L9" rel="file-gistfile1-php-L9">9</span>
          <span class="line-number" id="file-gistfile1-php-L10" rel="file-gistfile1-php-L10">10</span>
          <span class="line-number" id="file-gistfile1-php-L11" rel="file-gistfile1-php-L11">11</span>
          <span class="line-number" id="file-gistfile1-php-L12" rel="file-gistfile1-php-L12">12</span>
          <span class="line-number" id="file-gistfile1-php-L13" rel="file-gistfile1-php-L13">13</span>
          <span class="line-number" id="file-gistfile1-php-L14" rel="file-gistfile1-php-L14">14</span>
          <span class="line-number" id="file-gistfile1-php-L15" rel="file-gistfile1-php-L15">15</span>
          <span class="line-number" id="file-gistfile1-php-L16" rel="file-gistfile1-php-L16">16</span>
          <span class="line-number" id="file-gistfile1-php-L17" rel="file-gistfile1-php-L17">17</span>
          <span class="line-number" id="file-gistfile1-php-L18" rel="file-gistfile1-php-L18">18</span>
          <span class="line-number" id="file-gistfile1-php-L19" rel="file-gistfile1-php-L19">19</span>
          <span class="line-number" id="file-gistfile1-php-L20" rel="file-gistfile1-php-L20">20</span>
          <span class="line-number" id="file-gistfile1-php-L21" rel="file-gistfile1-php-L21">21</span>
          <span class="line-number" id="file-gistfile1-php-L22" rel="file-gistfile1-php-L22">22</span>
          <span class="line-number" id="file-gistfile1-php-L23" rel="file-gistfile1-php-L23">23</span>
          <span class="line-number" id="file-gistfile1-php-L24" rel="file-gistfile1-php-L24">24</span>
          <span class="line-number" id="file-gistfile1-php-L25" rel="file-gistfile1-php-L25">25</span>
          <span class="line-number" id="file-gistfile1-php-L26" rel="file-gistfile1-php-L26">26</span>
          <span class="line-number" id="file-gistfile1-php-L27" rel="file-gistfile1-php-L27">27</span>
          <span class="line-number" id="file-gistfile1-php-L28" rel="file-gistfile1-php-L28">28</span>
          <span class="line-number" id="file-gistfile1-php-L29" rel="file-gistfile1-php-L29">29</span>
          <span class="line-number" id="file-gistfile1-php-L30" rel="file-gistfile1-php-L30">30</span>
          <span class="line-number" id="file-gistfile1-php-L31" rel="file-gistfile1-php-L31">31</span>
          <span class="line-number" id="file-gistfile1-php-L32" rel="file-gistfile1-php-L32">32</span>
          <span class="line-number" id="file-gistfile1-php-L33" rel="file-gistfile1-php-L33">33</span>
          <span class="line-number" id="file-gistfile1-php-L34" rel="file-gistfile1-php-L34">34</span>
          <span class="line-number" id="file-gistfile1-php-L35" rel="file-gistfile1-php-L35">35</span>
          <span class="line-number" id="file-gistfile1-php-L36" rel="file-gistfile1-php-L36">36</span>
          <span class="line-number" id="file-gistfile1-php-L37" rel="file-gistfile1-php-L37">37</span>
          <span class="line-number" id="file-gistfile1-php-L38" rel="file-gistfile1-php-L38">38</span>
          <span class="line-number" id="file-gistfile1-php-L39" rel="file-gistfile1-php-L39">39</span>
          <span class="line-number" id="file-gistfile1-php-L40" rel="file-gistfile1-php-L40">40</span>
          <span class="line-number" id="file-gistfile1-php-L41" rel="file-gistfile1-php-L41">41</span>
          <span class="line-number" id="file-gistfile1-php-L42" rel="file-gistfile1-php-L42">42</span>
          <span class="line-number" id="file-gistfile1-php-L43" rel="file-gistfile1-php-L43">43</span>
          <span class="line-number" id="file-gistfile1-php-L44" rel="file-gistfile1-php-L44">44</span>
          <span class="line-number" id="file-gistfile1-php-L45" rel="file-gistfile1-php-L45">45</span>
          <span class="line-number" id="file-gistfile1-php-L46" rel="file-gistfile1-php-L46">46</span>
          <span class="line-number" id="file-gistfile1-php-L47" rel="file-gistfile1-php-L47">47</span>
          <span class="line-number" id="file-gistfile1-php-L48" rel="file-gistfile1-php-L48">48</span>
          <span class="line-number" id="file-gistfile1-php-L49" rel="file-gistfile1-php-L49">49</span>
          <span class="line-number" id="file-gistfile1-php-L50" rel="file-gistfile1-php-L50">50</span>
          <span class="line-number" id="file-gistfile1-php-L51" rel="file-gistfile1-php-L51">51</span>
          <span class="line-number" id="file-gistfile1-php-L52" rel="file-gistfile1-php-L52">52</span>
          <span class="line-number" id="file-gistfile1-php-L53" rel="file-gistfile1-php-L53">53</span>
          <span class="line-number" id="file-gistfile1-php-L54" rel="file-gistfile1-php-L54">54</span>
          <span class="line-number" id="file-gistfile1-php-L55" rel="file-gistfile1-php-L55">55</span>
          <span class="line-number" id="file-gistfile1-php-L56" rel="file-gistfile1-php-L56">56</span>
          <span class="line-number" id="file-gistfile1-php-L57" rel="file-gistfile1-php-L57">57</span>
          <span class="line-number" id="file-gistfile1-php-L58" rel="file-gistfile1-php-L58">58</span>
          <span class="line-number" id="file-gistfile1-php-L59" rel="file-gistfile1-php-L59">59</span>
          <span class="line-number" id="file-gistfile1-php-L60" rel="file-gistfile1-php-L60">60</span>
          <span class="line-number" id="file-gistfile1-php-L61" rel="file-gistfile1-php-L61">61</span>
          <span class="line-number" id="file-gistfile1-php-L62" rel="file-gistfile1-php-L62">62</span>
          <span class="line-number" id="file-gistfile1-php-L63" rel="file-gistfile1-php-L63">63</span>
          <span class="line-number" id="file-gistfile1-php-L64" rel="file-gistfile1-php-L64">64</span>
          <span class="line-number" id="file-gistfile1-php-L65" rel="file-gistfile1-php-L65">65</span>
          <span class="line-number" id="file-gistfile1-php-L66" rel="file-gistfile1-php-L66">66</span>
          <span class="line-number" id="file-gistfile1-php-L67" rel="file-gistfile1-php-L67">67</span>
          <span class="line-number" id="file-gistfile1-php-L68" rel="file-gistfile1-php-L68">68</span>
          <span class="line-number" id="file-gistfile1-php-L69" rel="file-gistfile1-php-L69">69</span>
          <span class="line-number" id="file-gistfile1-php-L70" rel="file-gistfile1-php-L70">70</span>
          <span class="line-number" id="file-gistfile1-php-L71" rel="file-gistfile1-php-L71">71</span>
          <span class="line-number" id="file-gistfile1-php-L72" rel="file-gistfile1-php-L72">72</span>
          <span class="line-number" id="file-gistfile1-php-L73" rel="file-gistfile1-php-L73">73</span>
          <span class="line-number" id="file-gistfile1-php-L74" rel="file-gistfile1-php-L74">74</span>
          <span class="line-number" id="file-gistfile1-php-L75" rel="file-gistfile1-php-L75">75</span>
          <span class="line-number" id="file-gistfile1-php-L76" rel="file-gistfile1-php-L76">76</span>
          <span class="line-number" id="file-gistfile1-php-L77" rel="file-gistfile1-php-L77">77</span>
          <span class="line-number" id="file-gistfile1-php-L78" rel="file-gistfile1-php-L78">78</span>
          <span class="line-number" id="file-gistfile1-php-L79" rel="file-gistfile1-php-L79">79</span>
          <span class="line-number" id="file-gistfile1-php-L80" rel="file-gistfile1-php-L80">80</span>
          <span class="line-number" id="file-gistfile1-php-L81" rel="file-gistfile1-php-L81">81</span>
          <span class="line-number" id="file-gistfile1-php-L82" rel="file-gistfile1-php-L82">82</span>
          <span class="line-number" id="file-gistfile1-php-L83" rel="file-gistfile1-php-L83">83</span>
          <span class="line-number" id="file-gistfile1-php-L84" rel="file-gistfile1-php-L84">84</span>
          <span class="line-number" id="file-gistfile1-php-L85" rel="file-gistfile1-php-L85">85</span>
          <span class="line-number" id="file-gistfile1-php-L86" rel="file-gistfile1-php-L86">86</span>
          <span class="line-number" id="file-gistfile1-php-L87" rel="file-gistfile1-php-L87">87</span>
          <span class="line-number" id="file-gistfile1-php-L88" rel="file-gistfile1-php-L88">88</span>
          <span class="line-number" id="file-gistfile1-php-L89" rel="file-gistfile1-php-L89">89</span>
          <span class="line-number" id="file-gistfile1-php-L90" rel="file-gistfile1-php-L90">90</span>
          <span class="line-number" id="file-gistfile1-php-L91" rel="file-gistfile1-php-L91">91</span>
          <span class="line-number" id="file-gistfile1-php-L92" rel="file-gistfile1-php-L92">92</span>
          <span class="line-number" id="file-gistfile1-php-L93" rel="file-gistfile1-php-L93">93</span>
          <span class="line-number" id="file-gistfile1-php-L94" rel="file-gistfile1-php-L94">94</span>
          <span class="line-number" id="file-gistfile1-php-L95" rel="file-gistfile1-php-L95">95</span>
          <span class="line-number" id="file-gistfile1-php-L96" rel="file-gistfile1-php-L96">96</span>
          <span class="line-number" id="file-gistfile1-php-L97" rel="file-gistfile1-php-L97">97</span>
          <span class="line-number" id="file-gistfile1-php-L98" rel="file-gistfile1-php-L98">98</span>
          <span class="line-number" id="file-gistfile1-php-L99" rel="file-gistfile1-php-L99">99</span>
          <span class="line-number" id="file-gistfile1-php-L100" rel="file-gistfile1-php-L100">100</span>
          <span class="line-number" id="file-gistfile1-php-L101" rel="file-gistfile1-php-L101">101</span>
          <span class="line-number" id="file-gistfile1-php-L102" rel="file-gistfile1-php-L102">102</span>
          <span class="line-number" id="file-gistfile1-php-L103" rel="file-gistfile1-php-L103">103</span>
          <span class="line-number" id="file-gistfile1-php-L104" rel="file-gistfile1-php-L104">104</span>
          <span class="line-number" id="file-gistfile1-php-L105" rel="file-gistfile1-php-L105">105</span>
          <span class="line-number" id="file-gistfile1-php-L106" rel="file-gistfile1-php-L106">106</span>
          <span class="line-number" id="file-gistfile1-php-L107" rel="file-gistfile1-php-L107">107</span>
          <span class="line-number" id="file-gistfile1-php-L108" rel="file-gistfile1-php-L108">108</span>
          <span class="line-number" id="file-gistfile1-php-L109" rel="file-gistfile1-php-L109">109</span>
          <span class="line-number" id="file-gistfile1-php-L110" rel="file-gistfile1-php-L110">110</span>
          <span class="line-number" id="file-gistfile1-php-L111" rel="file-gistfile1-php-L111">111</span>
          <span class="line-number" id="file-gistfile1-php-L112" rel="file-gistfile1-php-L112">112</span>
          <span class="line-number" id="file-gistfile1-php-L113" rel="file-gistfile1-php-L113">113</span>
          <span class="line-number" id="file-gistfile1-php-L114" rel="file-gistfile1-php-L114">114</span>
          <span class="line-number" id="file-gistfile1-php-L115" rel="file-gistfile1-php-L115">115</span>
          <span class="line-number" id="file-gistfile1-php-L116" rel="file-gistfile1-php-L116">116</span>
          <span class="line-number" id="file-gistfile1-php-L117" rel="file-gistfile1-php-L117">117</span>
          <span class="line-number" id="file-gistfile1-php-L118" rel="file-gistfile1-php-L118">118</span>
          <span class="line-number" id="file-gistfile1-php-L119" rel="file-gistfile1-php-L119">119</span>
          <span class="line-number" id="file-gistfile1-php-L120" rel="file-gistfile1-php-L120">120</span>
          <span class="line-number" id="file-gistfile1-php-L121" rel="file-gistfile1-php-L121">121</span>
          <span class="line-number" id="file-gistfile1-php-L122" rel="file-gistfile1-php-L122">122</span>
          <span class="line-number" id="file-gistfile1-php-L123" rel="file-gistfile1-php-L123">123</span>
          <span class="line-number" id="file-gistfile1-php-L124" rel="file-gistfile1-php-L124">124</span>
          <span class="line-number" id="file-gistfile1-php-L125" rel="file-gistfile1-php-L125">125</span>
          <span class="line-number" id="file-gistfile1-php-L126" rel="file-gistfile1-php-L126">126</span>
          <span class="line-number" id="file-gistfile1-php-L127" rel="file-gistfile1-php-L127">127</span>
          <span class="line-number" id="file-gistfile1-php-L128" rel="file-gistfile1-php-L128">128</span>
          <span class="line-number" id="file-gistfile1-php-L129" rel="file-gistfile1-php-L129">129</span>
          <span class="line-number" id="file-gistfile1-php-L130" rel="file-gistfile1-php-L130">130</span>
          <span class="line-number" id="file-gistfile1-php-L131" rel="file-gistfile1-php-L131">131</span>
          <span class="line-number" id="file-gistfile1-php-L132" rel="file-gistfile1-php-L132">132</span>
          <span class="line-number" id="file-gistfile1-php-L133" rel="file-gistfile1-php-L133">133</span>
          <span class="line-number" id="file-gistfile1-php-L134" rel="file-gistfile1-php-L134">134</span>
          <span class="line-number" id="file-gistfile1-php-L135" rel="file-gistfile1-php-L135">135</span>
          <span class="line-number" id="file-gistfile1-php-L136" rel="file-gistfile1-php-L136">136</span>
          <span class="line-number" id="file-gistfile1-php-L137" rel="file-gistfile1-php-L137">137</span>
          <span class="line-number" id="file-gistfile1-php-L138" rel="file-gistfile1-php-L138">138</span>
          <span class="line-number" id="file-gistfile1-php-L139" rel="file-gistfile1-php-L139">139</span>
          <span class="line-number" id="file-gistfile1-php-L140" rel="file-gistfile1-php-L140">140</span>
          <span class="line-number" id="file-gistfile1-php-L141" rel="file-gistfile1-php-L141">141</span>
          <span class="line-number" id="file-gistfile1-php-L142" rel="file-gistfile1-php-L142">142</span>
          <span class="line-number" id="file-gistfile1-php-L143" rel="file-gistfile1-php-L143">143</span>
          <span class="line-number" id="file-gistfile1-php-L144" rel="file-gistfile1-php-L144">144</span>
          <span class="line-number" id="file-gistfile1-php-L145" rel="file-gistfile1-php-L145">145</span>
          <span class="line-number" id="file-gistfile1-php-L146" rel="file-gistfile1-php-L146">146</span>
          <span class="line-number" id="file-gistfile1-php-L147" rel="file-gistfile1-php-L147">147</span>
          <span class="line-number" id="file-gistfile1-php-L148" rel="file-gistfile1-php-L148">148</span>
          <span class="line-number" id="file-gistfile1-php-L149" rel="file-gistfile1-php-L149">149</span>
          <span class="line-number" id="file-gistfile1-php-L150" rel="file-gistfile1-php-L150">150</span>
          <span class="line-number" id="file-gistfile1-php-L151" rel="file-gistfile1-php-L151">151</span>
          <span class="line-number" id="file-gistfile1-php-L152" rel="file-gistfile1-php-L152">152</span>
          <span class="line-number" id="file-gistfile1-php-L153" rel="file-gistfile1-php-L153">153</span>
          <span class="line-number" id="file-gistfile1-php-L154" rel="file-gistfile1-php-L154">154</span>
          <span class="line-number" id="file-gistfile1-php-L155" rel="file-gistfile1-php-L155">155</span>
          <span class="line-number" id="file-gistfile1-php-L156" rel="file-gistfile1-php-L156">156</span>
          <span class="line-number" id="file-gistfile1-php-L157" rel="file-gistfile1-php-L157">157</span>
          <span class="line-number" id="file-gistfile1-php-L158" rel="file-gistfile1-php-L158">158</span>
          <span class="line-number" id="file-gistfile1-php-L159" rel="file-gistfile1-php-L159">159</span>
          <span class="line-number" id="file-gistfile1-php-L160" rel="file-gistfile1-php-L160">160</span>
          <span class="line-number" id="file-gistfile1-php-L161" rel="file-gistfile1-php-L161">161</span>
          <span class="line-number" id="file-gistfile1-php-L162" rel="file-gistfile1-php-L162">162</span>
          <span class="line-number" id="file-gistfile1-php-L163" rel="file-gistfile1-php-L163">163</span>
          <span class="line-number" id="file-gistfile1-php-L164" rel="file-gistfile1-php-L164">164</span>
          <span class="line-number" id="file-gistfile1-php-L165" rel="file-gistfile1-php-L165">165</span>
          <span class="line-number" id="file-gistfile1-php-L166" rel="file-gistfile1-php-L166">166</span>
          <span class="line-number" id="file-gistfile1-php-L167" rel="file-gistfile1-php-L167">167</span>
          <span class="line-number" id="file-gistfile1-php-L168" rel="file-gistfile1-php-L168">168</span>
          <span class="line-number" id="file-gistfile1-php-L169" rel="file-gistfile1-php-L169">169</span>
          <span class="line-number" id="file-gistfile1-php-L170" rel="file-gistfile1-php-L170">170</span>
          <span class="line-number" id="file-gistfile1-php-L171" rel="file-gistfile1-php-L171">171</span>
          <span class="line-number" id="file-gistfile1-php-L172" rel="file-gistfile1-php-L172">172</span>
          <span class="line-number" id="file-gistfile1-php-L173" rel="file-gistfile1-php-L173">173</span>
          <span class="line-number" id="file-gistfile1-php-L174" rel="file-gistfile1-php-L174">174</span>
          <span class="line-number" id="file-gistfile1-php-L175" rel="file-gistfile1-php-L175">175</span>
          <span class="line-number" id="file-gistfile1-php-L176" rel="file-gistfile1-php-L176">176</span>
          <span class="line-number" id="file-gistfile1-php-L177" rel="file-gistfile1-php-L177">177</span>
          <span class="line-number" id="file-gistfile1-php-L178" rel="file-gistfile1-php-L178">178</span>
          <span class="line-number" id="file-gistfile1-php-L179" rel="file-gistfile1-php-L179">179</span>
        </td>
        <td class="line-data">
          <pre class="line-pre"><div class="line" id="file-gistfile1-php-LC1"><span class="cp">&lt;?php</span></div><div class="line" id="file-gistfile1-php-LC2"><span class="sd">/**</span></div><div class="line" id="file-gistfile1-php-LC3"><span class="sd"> * Multi-page Navigation</span></div><div class="line" id="file-gistfile1-php-LC4"><span class="sd"> * http://gravitywiz.com/</span></div><div class="line" id="file-gistfile1-php-LC5"><span class="sd"> */</span></div><div class="line" id="file-gistfile1-php-LC6">&nbsp;</div><div class="line" id="file-gistfile1-php-LC7"><span class="k">class</span> <span class="nc">GWMultipageNavigation</span> <span class="p">{</span></div><div class="line" id="file-gistfile1-php-LC8">&nbsp;</div><div class="line" id="file-gistfile1-php-LC9">    <span class="k">private</span> <span class="nv">$script_displayed</span><span class="p">;</span></div><div class="line" id="file-gistfile1-php-LC10">&nbsp;</div><div class="line" id="file-gistfile1-php-LC11">    <span class="k">function</span> <span class="nf">__construct</span><span class="p">(</span> <span class="nv">$args</span> <span class="o">=</span> <span class="k">array</span><span class="p">()</span> <span class="p">)</span> <span class="p">{</span></div><div class="line" id="file-gistfile1-php-LC12">&nbsp;</div><div class="line" id="file-gistfile1-php-LC13">        <span class="nv">$form_ids</span> <span class="o">=</span> <span class="k">false</span><span class="p">;</span></div><div class="line" id="file-gistfile1-php-LC14">        <span class="k">if</span><span class="p">(</span> <span class="nb">isset</span><span class="p">(</span> <span class="nv">$args</span><span class="p">[</span><span class="s1">&#39;form_id&#39;</span><span class="p">]</span> <span class="p">)</span> <span class="p">)</span> <span class="p">{</span></div><div class="line" id="file-gistfile1-php-LC15">            <span class="nv">$form_ids</span> <span class="o">=</span> <span class="nb">is_array</span><span class="p">(</span> <span class="nv">$args</span><span class="p">[</span><span class="s1">&#39;form_id&#39;</span><span class="p">]</span> <span class="p">)</span> <span class="o">?</span> <span class="nv">$args</span><span class="p">[</span><span class="s1">&#39;form_id&#39;</span><span class="p">]</span> <span class="o">:</span> <span class="k">array</span><span class="p">(</span> <span class="nv">$args</span><span class="p">[</span><span class="s1">&#39;form_id&#39;</span><span class="p">]</span> <span class="p">);</span></div><div class="line" id="file-gistfile1-php-LC16">        <span class="p">}</span></div><div class="line" id="file-gistfile1-php-LC17">&nbsp;</div><div class="line" id="file-gistfile1-php-LC18">        <span class="k">if</span><span class="p">(</span> <span class="o">!</span><span class="k">empty</span><span class="p">(</span><span class="nv">$form_ids</span><span class="p">)</span> <span class="p">)</span> <span class="p">{</span></div><div class="line" id="file-gistfile1-php-LC19">            <span class="k">foreach</span><span class="p">(</span> <span class="nv">$form_ids</span> <span class="k">as</span> <span class="nv">$form_id</span> <span class="p">)</span> <span class="p">{</span></div><div class="line" id="file-gistfile1-php-LC20">                <span class="nx">add_filter</span><span class="p">(</span><span class="s2">&quot;gform_pre_render_</span><span class="si">{</span><span class="nv">$form_id</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">,</span> <span class="k">array</span><span class="p">(</span> <span class="o">&amp;</span><span class="nv">$this</span><span class="p">,</span> <span class="s1">&#39;output_navigation_script&#39;</span> <span class="p">),</span> <span class="mi">10</span><span class="p">,</span> <span class="mi">2</span> <span class="p">);</span></div><div class="line" id="file-gistfile1-php-LC21">                <span class="c1">//add_filter(&#39;gform_register_init_scripts&#39;, array( &amp;$this, &#39;register_script&#39;) );</span></div><div class="line" id="file-gistfile1-php-LC22">            <span class="p">}</span></div><div class="line" id="file-gistfile1-php-LC23">        <span class="p">}</span> <span class="k">else</span> <span class="p">{</span></div><div class="line" id="file-gistfile1-php-LC24">            <span class="nx">add_filter</span><span class="p">(</span><span class="s1">&#39;gform_pre_render&#39;</span><span class="p">,</span> <span class="k">array</span><span class="p">(</span> <span class="o">&amp;</span><span class="nv">$this</span><span class="p">,</span> <span class="s1">&#39;output_navigation_script&#39;</span> <span class="p">),</span> <span class="mi">10</span><span class="p">,</span> <span class="mi">2</span> <span class="p">);</span></div><div class="line" id="file-gistfile1-php-LC25">        <span class="p">}</span></div><div class="line" id="file-gistfile1-php-LC26">&nbsp;</div><div class="line" id="file-gistfile1-php-LC27">    <span class="p">}</span></div><div class="line" id="file-gistfile1-php-LC28">&nbsp;</div><div class="line" id="file-gistfile1-php-LC29">    <span class="k">function</span> <span class="nf">output_navigation_script</span><span class="p">(</span> <span class="nv">$form</span><span class="p">,</span> <span class="nv">$is_ajax</span> <span class="p">)</span> <span class="p">{</span></div><div class="line" id="file-gistfile1-php-LC30">&nbsp;</div><div class="line" id="file-gistfile1-php-LC31">        <span class="c1">// only apply this to multi-page forms</span></div><div class="line" id="file-gistfile1-php-LC32">        <span class="k">if</span><span class="p">(</span> <span class="nb">count</span><span class="p">(</span><span class="nv">$form</span><span class="p">[</span><span class="s1">&#39;pagination&#39;</span><span class="p">][</span><span class="s1">&#39;pages&#39;</span><span class="p">])</span> <span class="o">&lt;=</span> <span class="mi">1</span> <span class="p">)</span></div><div class="line" id="file-gistfile1-php-LC33">            <span class="k">return</span> <span class="nv">$form</span><span class="p">;</span></div><div class="line" id="file-gistfile1-php-LC34">&nbsp;</div><div class="line" id="file-gistfile1-php-LC35">        <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">register_script</span><span class="p">(</span> <span class="nv">$form</span> <span class="p">);</span></div><div class="line" id="file-gistfile1-php-LC36">&nbsp;</div><div class="line" id="file-gistfile1-php-LC37">        <span class="k">if</span><span class="p">(</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">is_last_page</span><span class="p">(</span> <span class="nv">$form</span> <span class="p">)</span> <span class="o">||</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">is_last_page_reached</span><span class="p">()</span> <span class="p">)</span> <span class="p">{</span></div><div class="line" id="file-gistfile1-php-LC38">            <span class="nv">$input</span> <span class="o">=</span> <span class="s1">&#39;&lt;input id=&quot;gw_last_page_reached&quot; name=&quot;gw_last_page_reached&quot; value=&quot;1&quot; type=&quot;hidden&quot; /&gt;&#39;</span><span class="p">;</span></div><div class="line" id="file-gistfile1-php-LC39">            <span class="nx">add_filter</span><span class="p">(</span> <span class="s2">&quot;gform_form_tag_</span><span class="si">{</span><span class="nv">$form</span><span class="p">[</span><span class="s1">&#39;id&#39;</span><span class="p">]</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">,</span> <span class="nb">create_function</span><span class="p">(</span><span class="s1">&#39;$a&#39;</span><span class="p">,</span> <span class="s1">&#39;return $a . &#39;&#39;</span> <span class="o">.</span> <span class="nv">$input</span> <span class="o">.</span> <span class="s1">&#39;&#39;;&#39;</span> <span class="p">)</span> <span class="p">);</span></div><div class="line" id="file-gistfile1-php-LC40">        <span class="p">}</span></div><div class="line" id="file-gistfile1-php-LC41">&nbsp;</div><div class="line" id="file-gistfile1-php-LC42">        <span class="c1">// only output the gwmpn object once regardless of how many forms are being displayed</span></div><div class="line" id="file-gistfile1-php-LC43">        <span class="c1">// also do not output again on ajax submissions</span></div><div class="line" id="file-gistfile1-php-LC44">        <span class="k">if</span><span class="p">(</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">script_displayed</span> <span class="o">||</span> <span class="p">(</span> <span class="nv">$is_ajax</span> <span class="o">&amp;&amp;</span> <span class="nx">rgpost</span><span class="p">(</span><span class="s1">&#39;gform_submit&#39;</span><span class="p">)</span> <span class="p">))</span></div><div class="line" id="file-gistfile1-php-LC45">            <span class="k">return</span> <span class="nv">$form</span><span class="p">;</span></div><div class="line" id="file-gistfile1-php-LC46">&nbsp;</div><div class="line" id="file-gistfile1-php-LC47">        <span class="cp">?&gt;</span><span class="x"></span></div><div class="line" id="file-gistfile1-php-LC48">&nbsp;</div><div class="line" id="file-gistfile1-php-LC49"><span class="x">        &lt;script type=&quot;text/javascript&quot;&gt;</span></div><div class="line" id="file-gistfile1-php-LC50">&nbsp;</div><div class="line" id="file-gistfile1-php-LC51"><span class="x">            (function($){</span></div><div class="line" id="file-gistfile1-php-LC52">&nbsp;</div><div class="line" id="file-gistfile1-php-LC53"><span class="x">                window.gwmpnObj = function( args ) {</span></div><div class="line" id="file-gistfile1-php-LC54">&nbsp;</div><div class="line" id="file-gistfile1-php-LC55"><span class="x">                    this.formId = args.formId;</span></div><div class="line" id="file-gistfile1-php-LC56"><span class="x">                    this.formElem = jQuery(&#39;form#gform_&#39; + this.formId);</span></div><div class="line" id="file-gistfile1-php-LC57"><span class="x">                    this.currentPage = args.currentPage;</span></div><div class="line" id="file-gistfile1-php-LC58"><span class="x">                    this.lastPage = args.lastPage;</span></div><div class="line" id="file-gistfile1-php-LC59"><span class="x">                    this.labels = args.labels;</span></div><div class="line" id="file-gistfile1-php-LC60">&nbsp;</div><div class="line" id="file-gistfile1-php-LC61"><span class="x">                    this.init = function() {</span></div><div class="line" id="file-gistfile1-php-LC62">&nbsp;</div><div class="line" id="file-gistfile1-php-LC63"><span class="x">                        // if this form is ajax-enabled, we&#39;ll need to get the current page via JS</span></div><div class="line" id="file-gistfile1-php-LC64"><span class="x">                        if( this.isAjax() )</span></div><div class="line" id="file-gistfile1-php-LC65"><span class="x">                            this.currentPage = this.getCurrentPage();</span></div><div class="line" id="file-gistfile1-php-LC66">&nbsp;</div><div class="line" id="file-gistfile1-php-LC67"><span class="x">                        if( !this.isLastPage() &amp;&amp; !this.isLastPageReached() )</span></div><div class="line" id="file-gistfile1-php-LC68"><span class="x">                            return;</span></div><div class="line" id="file-gistfile1-php-LC69">&nbsp;</div><div class="line" id="file-gistfile1-php-LC70"><span class="x">                        var gwmpn = this;</span></div><div class="line" id="file-gistfile1-php-LC71"><span class="x">                        var steps = $(&#39;form#gform_&#39; + this.formId + &#39; .gf_step&#39;);</span></div><div class="line" id="file-gistfile1-php-LC72">&nbsp;</div><div class="line" id="file-gistfile1-php-LC73"><span class="x">                        steps.each(function(){</span></div><div class="line" id="file-gistfile1-php-LC74">&nbsp;</div><div class="line" id="file-gistfile1-php-LC75"><span class="x">                            var stepNumber = parseInt( $(this).find(&#39;span.gf_step_number&#39;).text() );</span></div><div class="line" id="file-gistfile1-php-LC76">&nbsp;</div><div class="line" id="file-gistfile1-php-LC77"><span class="x">                            if( stepNumber != gwmpn.currentPage ) {</span></div><div class="line" id="file-gistfile1-php-LC78"><span class="x">                                $(this).html( gwmpn.createPageLink( stepNumber, $(this).html() ) )</span></div><div class="line" id="file-gistfile1-php-LC79"><span class="x">                                    .addClass(&#39;gw-step-linked&#39;);</span></div><div class="line" id="file-gistfile1-php-LC80"><span class="x">                            } else {</span></div><div class="line" id="file-gistfile1-php-LC81"><span class="x">                                $(this).addClass(&#39;gw-step-current&#39;);</span></div><div class="line" id="file-gistfile1-php-LC82"><span class="x">                            }</span></div><div class="line" id="file-gistfile1-php-LC83">&nbsp;</div><div class="line" id="file-gistfile1-php-LC84"><span class="x">                        });</span></div><div class="line" id="file-gistfile1-php-LC85">&nbsp;</div><div class="line" id="file-gistfile1-php-LC86"><span class="x">                        if( !this.isLastPage() )</span></div><div class="line" id="file-gistfile1-php-LC87"><span class="x">                            this.addBackToLastPageButton();</span></div><div class="line" id="file-gistfile1-php-LC88">&nbsp;</div><div class="line" id="file-gistfile1-php-LC89"><span class="x">                        $(document).on(&#39;click&#39;, &#39;#gform_&#39; + this.formId + &#39; a.gwmpn-page-link&#39;, function(event){</span></div><div class="line" id="file-gistfile1-php-LC90"><span class="x">                            event.preventDefault();</span></div><div class="line" id="file-gistfile1-php-LC91">&nbsp;</div><div class="line" id="file-gistfile1-php-LC92"><span class="x">                            var hrefArray = $(this).attr(&#39;href&#39;).split(&#39;#&#39;);</span></div><div class="line" id="file-gistfile1-php-LC93"><span class="x">                            if( hrefArray.length &gt;= 2 ) {</span></div><div class="line" id="file-gistfile1-php-LC94"><span class="x">                                var pageNumber = hrefArray.pop();</span></div><div class="line" id="file-gistfile1-php-LC95"><span class="x">                                gwmpn.postToPage( pageNumber );</span></div><div class="line" id="file-gistfile1-php-LC96"><span class="x">                            }</span></div><div class="line" id="file-gistfile1-php-LC97">&nbsp;</div><div class="line" id="file-gistfile1-php-LC98"><span class="x">                        });</span></div><div class="line" id="file-gistfile1-php-LC99">&nbsp;</div><div class="line" id="file-gistfile1-php-LC100"><span class="x">                    }</span></div><div class="line" id="file-gistfile1-php-LC101">&nbsp;</div><div class="line" id="file-gistfile1-php-LC102"><span class="x">                    this.createPageLink = function( stepNumber, HTML ) {</span></div><div class="line" id="file-gistfile1-php-LC103"><span class="x">                        return &#39;&lt;a href=&quot;#&#39; + stepNumber + &#39;&quot; class=&quot;gwmpn-page-link&quot;&gt;&#39; + HTML + &#39;&lt;/a&gt;&#39;;</span></div><div class="line" id="file-gistfile1-php-LC104"><span class="x">                    }</span></div><div class="line" id="file-gistfile1-php-LC105">&nbsp;</div><div class="line" id="file-gistfile1-php-LC106"><span class="x">                    this.postToPage = function(page) {</span></div><div class="line" id="file-gistfile1-php-LC107"><span class="x">                        this.formElem.append(&#39;&lt;input type=&quot;hidden&quot; name=&quot;gw_page_change&quot; value=&quot;1&quot; /&gt;&#39;);</span></div><div class="line" id="file-gistfile1-php-LC108"><span class="x">                        this.formElem.find(&#39;input[name=&quot;gform_target_page_number_&#39; + this.formId + &#39;&quot;]&#39;).val(page);</span></div><div class="line" id="file-gistfile1-php-LC109"><span class="x">                        this.formElem.submit();</span></div><div class="line" id="file-gistfile1-php-LC110"><span class="x">                    }</span></div><div class="line" id="file-gistfile1-php-LC111">&nbsp;</div><div class="line" id="file-gistfile1-php-LC112"><span class="x">                    this.addBackToLastPageButton = function() {</span></div><div class="line" id="file-gistfile1-php-LC113"><span class="x">                        this.formElem.find(&#39;#gform_page_&#39; + this.formId + &#39;_&#39; + this.currentPage + &#39; .gform_page_footer&#39;)</span></div><div class="line" id="file-gistfile1-php-LC114"><span class="x">                            .append(&#39;&lt;input type=&quot;button&quot; onclick=&quot;gwmpn.postToPage(&#39; + this.lastPage + &#39;)&quot; value=&quot;&#39; + this.labels.lastPageButton + &#39;&quot; class=&quot;button gform_last_page_button&quot;&gt;&#39;);</span></div><div class="line" id="file-gistfile1-php-LC115"><span class="x">                    }</span></div><div class="line" id="file-gistfile1-php-LC116">&nbsp;</div><div class="line" id="file-gistfile1-php-LC117"><span class="x">                    this.getCurrentPage = function() {</span></div><div class="line" id="file-gistfile1-php-LC118"><span class="x">                        return this.formElem.find( &#39;input#gform_source_page_number_&#39; + this.formId ).val();</span></div><div class="line" id="file-gistfile1-php-LC119"><span class="x">                    }</span></div><div class="line" id="file-gistfile1-php-LC120">&nbsp;</div><div class="line" id="file-gistfile1-php-LC121"><span class="x">                    this.isLastPage = function() {</span></div><div class="line" id="file-gistfile1-php-LC122"><span class="x">                        return this.currentPage &gt;= this.lastPage;</span></div><div class="line" id="file-gistfile1-php-LC123"><span class="x">                    }</span></div><div class="line" id="file-gistfile1-php-LC124">&nbsp;</div><div class="line" id="file-gistfile1-php-LC125"><span class="x">                    this.isLastPageReached = function() {</span></div><div class="line" id="file-gistfile1-php-LC126"><span class="x">                        return this.formElem.find(&#39;input[name=&quot;gw_last_page_reached&quot;]&#39;).val() == true;</span></div><div class="line" id="file-gistfile1-php-LC127"><span class="x">                    }</span></div><div class="line" id="file-gistfile1-php-LC128">&nbsp;</div><div class="line" id="file-gistfile1-php-LC129"><span class="x">                    this.isAjax = function() {</span></div><div class="line" id="file-gistfile1-php-LC130"><span class="x">                        return this.formElem.attr(&#39;target&#39;) == &#39;gform_ajax_frame_&#39; + this.formId;</span></div><div class="line" id="file-gistfile1-php-LC131"><span class="x">                    }</span></div><div class="line" id="file-gistfile1-php-LC132">&nbsp;</div><div class="line" id="file-gistfile1-php-LC133"><span class="x">                    this.init();</span></div><div class="line" id="file-gistfile1-php-LC134">&nbsp;</div><div class="line" id="file-gistfile1-php-LC135"><span class="x">                }</span></div><div class="line" id="file-gistfile1-php-LC136">&nbsp;</div><div class="line" id="file-gistfile1-php-LC137"><span class="x">            })(jQuery);</span></div><div class="line" id="file-gistfile1-php-LC138">&nbsp;</div><div class="line" id="file-gistfile1-php-LC139"><span class="x">        &lt;/script&gt;</span></div><div class="line" id="file-gistfile1-php-LC140">&nbsp;</div><div class="line" id="file-gistfile1-php-LC141"><span class="x">        </span><span class="cp">&lt;?php</span></div><div class="line" id="file-gistfile1-php-LC142">        <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">script_displayed</span> <span class="o">=</span> <span class="k">true</span><span class="p">;</span></div><div class="line" id="file-gistfile1-php-LC143">        <span class="k">return</span> <span class="nv">$form</span><span class="p">;</span></div><div class="line" id="file-gistfile1-php-LC144">    <span class="p">}</span></div><div class="line" id="file-gistfile1-php-LC145">&nbsp;</div><div class="line" id="file-gistfile1-php-LC146">    <span class="k">function</span> <span class="nf">register_script</span><span class="p">(</span> <span class="nv">$form</span> <span class="p">)</span> <span class="p">{</span></div><div class="line" id="file-gistfile1-php-LC147">&nbsp;</div><div class="line" id="file-gistfile1-php-LC148">        <span class="nv">$page_number</span> <span class="o">=</span> <span class="nx">GFFormDisplay</span><span class="o">::</span><span class="na">get_current_page</span><span class="p">(</span><span class="nv">$form</span><span class="p">[</span><span class="s1">&#39;id&#39;</span><span class="p">]);</span></div><div class="line" id="file-gistfile1-php-LC149">        <span class="nv">$last_page</span> <span class="o">=</span> <span class="nb">count</span><span class="p">(</span><span class="nv">$form</span><span class="p">[</span><span class="s1">&#39;pagination&#39;</span><span class="p">][</span><span class="s1">&#39;pages&#39;</span><span class="p">]);</span></div><div class="line" id="file-gistfile1-php-LC150">&nbsp;</div><div class="line" id="file-gistfile1-php-LC151">        <span class="nv">$args</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span></div><div class="line" id="file-gistfile1-php-LC152">            <span class="s1">&#39;formId&#39;</span> <span class="o">=&gt;</span> <span class="nv">$form</span><span class="p">[</span><span class="s1">&#39;id&#39;</span><span class="p">],</span></div><div class="line" id="file-gistfile1-php-LC153">            <span class="s1">&#39;currentPage&#39;</span> <span class="o">=&gt;</span> <span class="nv">$page_number</span><span class="p">,</span></div><div class="line" id="file-gistfile1-php-LC154">            <span class="s1">&#39;lastPage&#39;</span> <span class="o">=&gt;</span> <span class="nv">$last_page</span><span class="p">,</span></div><div class="line" id="file-gistfile1-php-LC155">            <span class="s1">&#39;labels&#39;</span> <span class="o">=&gt;</span> <span class="k">array</span><span class="p">(</span></div><div class="line" id="file-gistfile1-php-LC156">                <span class="s1">&#39;lastPageButton&#39;</span> <span class="o">=&gt;</span> <span class="nx">__</span><span class="p">(</span><span class="s1">&#39;Back to Last Page&#39;</span><span class="p">)</span></div><div class="line" id="file-gistfile1-php-LC157">                <span class="p">)</span></div><div class="line" id="file-gistfile1-php-LC158">            <span class="p">);</span></div><div class="line" id="file-gistfile1-php-LC159">&nbsp;</div><div class="line" id="file-gistfile1-php-LC160">        <span class="nv">$script</span> <span class="o">=</span> <span class="s2">&quot;window.gwmpn = new gwmpnObj(&quot;</span> <span class="o">.</span> <span class="nb">json_encode</span><span class="p">(</span> <span class="nv">$args</span> <span class="p">)</span> <span class="o">.</span> <span class="s2">&quot;);&quot;</span><span class="p">;</span></div><div class="line" id="file-gistfile1-php-LC161">        <span class="nx">GFFormDisplay</span><span class="o">::</span><span class="na">add_init_script</span><span class="p">(</span> <span class="nv">$form</span><span class="p">[</span><span class="s1">&#39;id&#39;</span><span class="p">],</span> <span class="s1">&#39;gwmpn&#39;</span><span class="p">,</span> <span class="nx">GFFormDisplay</span><span class="o">::</span><span class="na">ON_PAGE_RENDER</span><span class="p">,</span> <span class="nv">$script</span> <span class="p">);</span></div><div class="line" id="file-gistfile1-php-LC162">&nbsp;</div><div class="line" id="file-gistfile1-php-LC163">    <span class="p">}</span></div><div class="line" id="file-gistfile1-php-LC164">&nbsp;</div><div class="line" id="file-gistfile1-php-LC165">    <span class="k">function</span> <span class="nf">is_last_page</span><span class="p">(</span> <span class="nv">$form</span> <span class="p">)</span> <span class="p">{</span></div><div class="line" id="file-gistfile1-php-LC166">&nbsp;</div><div class="line" id="file-gistfile1-php-LC167">        <span class="nv">$page_number</span> <span class="o">=</span> <span class="nx">GFFormDisplay</span><span class="o">::</span><span class="na">get_current_page</span><span class="p">(</span><span class="nv">$form</span><span class="p">[</span><span class="s1">&#39;id&#39;</span><span class="p">]);</span></div><div class="line" id="file-gistfile1-php-LC168">        <span class="nv">$last_page</span> <span class="o">=</span> <span class="nb">count</span><span class="p">(</span><span class="nv">$form</span><span class="p">[</span><span class="s1">&#39;pagination&#39;</span><span class="p">][</span><span class="s1">&#39;pages&#39;</span><span class="p">]);</span></div><div class="line" id="file-gistfile1-php-LC169">&nbsp;</div><div class="line" id="file-gistfile1-php-LC170">        <span class="k">return</span> <span class="nv">$page_number</span> <span class="o">&gt;=</span> <span class="nv">$last_page</span><span class="p">;</span></div><div class="line" id="file-gistfile1-php-LC171">    <span class="p">}</span></div><div class="line" id="file-gistfile1-php-LC172">&nbsp;</div><div class="line" id="file-gistfile1-php-LC173">    <span class="k">function</span> <span class="nf">is_last_page_reached</span><span class="p">()</span> <span class="p">{</span></div><div class="line" id="file-gistfile1-php-LC174">        <span class="k">return</span> <span class="nx">rgpost</span><span class="p">(</span><span class="s1">&#39;gw_last_page_reached&#39;</span><span class="p">);</span></div><div class="line" id="file-gistfile1-php-LC175">    <span class="p">}</span></div><div class="line" id="file-gistfile1-php-LC176">&nbsp;</div><div class="line" id="file-gistfile1-php-LC177"><span class="p">}</span></div><div class="line" id="file-gistfile1-php-LC178">&nbsp;</div><div class="line" id="file-gistfile1-php-LC179"><span class="nv">$gw_multipage_navigation</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">GWMultipageNavigation</span><span class="p">();</span></div></pre>
        </td>
      </tr>
    </table>
  </div>

        </div>

        <div class="gist-meta">
          <a href="https://gist.github.com%2Fspivurno%2F4697549%2Fraw%2F93e62d9bea9a7844d71b666a4c8618103991314f%2Fgistfile1.php" style="float:right">view raw</a>
          <a href="https://gist.github.com/spivurno/4697549#file-gistfile1-php" style="float:right; margin-right:10px; color:#666;">gistfile1.php</a>
          <a href="https://gist.github.com/spivurno/4697549">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
        </div>
      </div>
</div>


<h3>How do I install this snippet?</h3><p>Easy peasy. Just copy and paste the code above into your theme's <em>functions.php</em> file.</p>

<h3>How do I use this functionality?</h3>

<p>If you want to apply this functionality to all forms and you are already using the &#8220;Steps&#8221; progress indicator for your forms, installing the snippet is all you&#8217;ll need to do. If you&#8217;re interested in limiting this functionality to a few specific forms, need some help setting your form&#8217;s progress indicator, or want to learn how to create your own custom page links, read on!</p>

<ul>
<li><a href="#limit_to_form">Limiting to a Specific Form(s)</a></li>
<li><a href="#set_progress_indicator">Setting Progress Indicator</a></li>
<li><a href="#custom_page_links">Creating Custom Page Links</a></li>
</ul>

<p><a name="limit_to_form"></a></p>

<h4>Limiting to a Specific Form</h4>

<p><strong>Limit to a Single Form</strong>
<div id="gist4697895" class="gist">       <div class="gist-file">         <div class="gist-data gist-syntax">      <div class="file-data">     <table cellpadding="0" cellspacing="0" class="lines highlight">       <tr>         <td class="line-numbers">                                            <span class="line-number" id="file-gistfile1-php-L4" rel="file-gistfile1-php-L4">4</span>                                                                           </td>         <td class="line-data">           <pre class="line-pre"><div class="line" id="file-gistfile1-php-LC4"><span class="nv">$gw_multipage_navigation</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">GWMultipageNavigation</span><span class="p">();</span></div></pre>         </td>       </tr>     </table>   </div>          </div>          <div class="gist-meta">           <a href="https://gist.github.com%2Fspivurno%2F4697895%2Fraw%2Fff5095c293257c45651b904cd3ae268a3425c814%2Fgistfile1.php" style="float:right">view raw</a>           <a href="https://gist.github.com/spivurno/4697895#file-gistfile1-php" style="float:right; margin-right:10px; color:#666;">gistfile1.php</a>           <a href="https://gist.github.com/spivurno/4697895">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.         </div>       </div> </div> </p>

<p><strong>Limit to Multiple Forms</strong>
<div id="gist4697895" class="gist">       <div class="gist-file">         <div class="gist-data gist-syntax">      <div class="file-data">     <table cellpadding="0" cellspacing="0" class="lines highlight">       <tr>         <td class="line-numbers">                                                                                                              <span class="line-number" id="file-gistfile1-php-L10" rel="file-gistfile1-php-L10">10</span>         </td>         <td class="line-data">           <pre class="line-pre"><div class="line" id="file-gistfile1-php-LC10"><span class="nv">$gw_multipage_navigation</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">GWMultipageNavigation</span><span class="p">(</span> <span class="k">array</span><span class="p">(</span> <span class="s1">&#39;form_id&#39;</span> <span class="o">=&gt;</span> <span class="k">array</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">11</span><span class="p">)</span> <span class="p">)</span> <span class="p">);</span></div></pre>         </td>       </tr>     </table>   </div>          </div>          <div class="gist-meta">           <a href="https://gist.github.com%2Fspivurno%2F4697895%2Fraw%2Fff5095c293257c45651b904cd3ae268a3425c814%2Fgistfile1.php" style="float:right">view raw</a>           <a href="https://gist.github.com/spivurno/4697895#file-gistfile1-php" style="float:right; margin-right:10px; color:#666;">gistfile1.php</a>           <a href="https://gist.github.com/spivurno/4697895">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.         </div>       </div> </div> </p>

<p><a name="set_progress_indicator"></a></p>

<h4>Setting Progress Indicator</h4>

<p>If you&#8217;d like your form&#8217;s page steps (which display above the form), you&#8217;ll need to set your paging progress indicator to &#8220;Steps&#8221;. To do so, find the &#8220;Start Paging&#8221; field and open its settings. Under the &#8220;Properties&#8221; tab, find the &#8220;Progress Indicator&#8221; setting and select the &#8220;Steps&#8221; option. If you&#8217;d like to specify a name for each step, you can do so here.</p>

<div class="inline-image full"><img src="http://gravitywiz.com/wp-content/uploads/2013/02/paging-progress-indicator.png" alt="paging-progress-indicator" width="502" height="472" class="alignnone size-full wp-image-1098" /><span class="caption">Paging Progress Indicator: Steps</span></div>

<p><a name="custom_page_links"></a></p>

<h4>Creating Custom Page Links</h4>

<p>If you&#8217;d like to create your own custom page links, you can do so using the following link format:</p>

<div class="gist"><div class="gist-snippet"><div class="gist-data gist-syntax"><div class="highlight"><pre><span class="nt">&lt;a</span> <span class="na">href=</span><span class="s">"#{pageNumber}"</span> <span class="na">class=</span><span class="s">"gwmpn-page-link"</span><span class="nt">&gt;</span>My Link Text<span class="nt">&lt;/a&gt;</span>
</pre></div></div></div></div>

<p>Just update <code>{pageNumber}</code> to the page number you would like to link to and update <code>My Link Text</code> to whatever text (or other HTML) you would like to display for your link. <strong>Note:</strong> The link must be output somewhere within the opening and closing GF &lt;form&gt; tags.</p>

<h3>Small Disclaimer</h3>

<p>One not-so-awesome thing about this snippet is that we&#8217;re outputting a decent bit of Javascript to the page. Ideally, this Javascript would be included in a separate file. For the sake of users new to WordPress and/or web development, I chose to go the simpler, less efficient route for ease of installation.</p>

<p>If you&#8217;d like to move the JS portion to a separate file, please do! The entire <code>gwmpnObj</code> JS object can be moved to any JS file; just make sure you include it on any page you display a form configured to use it.</p>

<h2>Closing Notes</h2>

<p><a href="http://gravitywiz.com/what-is-a-perk/">Gravity Perks</a> is almost ready to launch and this snippet will be available as a <a href="http://gravitywiz.com/what-is-a-perk/">perk</a>. What does that mean for you? Have a centralized location to manage all your Gravity Forms functionality and an awesome repository of useful Gravity Form enhancements. <a href="http://gravitywiz.com/what-is-a-perk/">Sign-up</a> to be notified when Gravity Perks is released or view the currently <a href="http://gravitywiz.com/available-perks/">available perks</a> in beta and help test!</p>
<p>The post <a href="http://gravitywiz.com/multi-page-navigation/">Multi-page Form Navigation</a> appeared first on <a href="http://gravitywiz.com">Gravity Wiz</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://gravitywiz.com/multi-page-navigation/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Fix Gravity Form Tabindex Conflicts</title>
		<link>http://gravitywiz.com/fix-gravity-form-tabindex-conflicts/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=fix-gravity-form-tabindex-conflicts</link>
		<comments>http://gravitywiz.com/fix-gravity-form-tabindex-conflicts/#comments</comments>
		<pubDate>Tue, 29 Jan 2013 03:16:18 +0000</pubDate>
		<dc:creator>David Smith</dc:creator>
				<category><![CDATA[Snippets]]></category>

		<guid isPermaLink="false">http://gravitywiz.com/?p=1071</guid>
		<description><![CDATA[<p>This is most common when loading a Gravity Form on a page which is loading a non-GF form (like the WordPress comment form). You&#8217;re typing away on your Gravity Form and tab to the next field. Awesome. Except the next field is a completely different form. This snippet sets the starting index of your Gravity [...]</p><p>The post <a href="http://gravitywiz.com/fix-gravity-form-tabindex-conflicts/">Fix Gravity Form Tabindex Conflicts</a> appeared first on <a href="http://gravitywiz.com">Gravity Wiz</a>.</p>]]></description>
				<content:encoded><![CDATA[<div class="introduction">Avoid the annoying issue where tabbing from a field in one form tabs you to a field in another form. This is caused by conflicting tab indexes.</div>

<p>This is most common when loading a Gravity Form on a page which is loading a non-GF form (like the WordPress comment form). You&#8217;re typing away on your Gravity Form and tab to the next field. Awesome. Except the next field is a completely different form. This snippet sets the starting index of your Gravity Form inputs ridiculously high so such conflicts never happen again.</p>

<div id="gist4661036" class="gist">
      <div class="gist-file">
        <div class="gist-data gist-syntax">



  <div class="file-data">
    <table cellpadding="0" cellspacing="0" class="lines highlight">
      <tr>
        <td class="line-numbers">
          <span class="line-number" id="file-gistfile1-php-L1" rel="file-gistfile1-php-L1">1</span>
          <span class="line-number" id="file-gistfile1-php-L2" rel="file-gistfile1-php-L2">2</span>
          <span class="line-number" id="file-gistfile1-php-L3" rel="file-gistfile1-php-L3">3</span>
          <span class="line-number" id="file-gistfile1-php-L4" rel="file-gistfile1-php-L4">4</span>
          <span class="line-number" id="file-gistfile1-php-L5" rel="file-gistfile1-php-L5">5</span>
          <span class="line-number" id="file-gistfile1-php-L6" rel="file-gistfile1-php-L6">6</span>
          <span class="line-number" id="file-gistfile1-php-L7" rel="file-gistfile1-php-L7">7</span>
          <span class="line-number" id="file-gistfile1-php-L8" rel="file-gistfile1-php-L8">8</span>
          <span class="line-number" id="file-gistfile1-php-L9" rel="file-gistfile1-php-L9">9</span>
          <span class="line-number" id="file-gistfile1-php-L10" rel="file-gistfile1-php-L10">10</span>
        </td>
        <td class="line-data">
          <pre class="line-pre"><div class="line" id="file-gistfile1-php-LC1"><span class="cp">&lt;?php</span></div><div class="line" id="file-gistfile1-php-LC2"><span class="sd">/**</span></div><div class="line" id="file-gistfile1-php-LC3"><span class="sd"> * Fix Gravity Form Tabindex Conflicts</span></div><div class="line" id="file-gistfile1-php-LC4"><span class="sd"> * http://gravitywiz.com</span></div><div class="line" id="file-gistfile1-php-LC5"><span class="sd"> */</span></div><div class="line" id="file-gistfile1-php-LC6"><span class="nx">add_filter</span><span class="p">(</span><span class="s2">&quot;gform_tabindex&quot;</span><span class="p">,</span> <span class="s2">&quot;gform_tabindexer&quot;</span><span class="p">);</span></div><div class="line" id="file-gistfile1-php-LC7"><span class="k">function</span> <span class="nf">gform_tabindexer</span><span class="p">()</span> <span class="p">{</span></div><div class="line" id="file-gistfile1-php-LC8">    <span class="nv">$starting_index</span> <span class="o">=</span> <span class="mi">1000</span><span class="p">;</span> <span class="c1">// if you need a higher tabindex, update this number</span></div><div class="line" id="file-gistfile1-php-LC9">    <span class="k">return</span> <span class="nx">GFCommon</span><span class="o">::</span><span class="nv">$tab_index</span> <span class="o">&gt;=</span> <span class="nv">$starting_index</span> <span class="o">?</span> <span class="nx">GFCommon</span><span class="o">::</span><span class="nv">$tab_index</span> <span class="o">:</span> <span class="nv">$starting_index</span><span class="p">;</span></div><div class="line" id="file-gistfile1-php-LC10"><span class="p">}</span></div></pre>
        </td>
      </tr>
    </table>
  </div>

        </div>

        <div class="gist-meta">
          <a href="https://gist.github.com/raw/4661036/31bbbe9f165f9cf71e9ae2cb7f2650de670fec77/gistfile1.php" style="float:right">view raw</a>
          <a href="https://gist.github.com/4661036#file-gistfile1-php" style="float:right; margin-right:10px; color:#666;">gistfile1.php</a>
          <a href="https://gist.github.com/4661036">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
        </div>
      </div>
</div>


<h3>How do I install this snippet?</h3><p>Easy peasy. Just copy and paste the code above into your theme's <em>functions.php</em> file.</p>

<h3>How to I use this functionality?</h3>

<p>This snippet is plug-n-play. No changes needed (unless you&#8217;re still seeing tabindex conflicts which is highly unlikely). If you are, just update the <code>1000</code> in the snippet to a higher number until the conflict disappears.</p>
<p>The post <a href="http://gravitywiz.com/fix-gravity-form-tabindex-conflicts/">Fix Gravity Form Tabindex Conflicts</a> appeared first on <a href="http://gravitywiz.com">Gravity Wiz</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://gravitywiz.com/fix-gravity-form-tabindex-conflicts/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Basic WordPress membership site with protected content using Gravity Forms</title>
		<link>http://gravitywiz.com/basic-wordpress-membership-site-with-protected-content-using-gravity-forms/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=basic-wordpress-membership-site-with-protected-content-using-gravity-forms</link>
		<comments>http://gravitywiz.com/basic-wordpress-membership-site-with-protected-content-using-gravity-forms/#comments</comments>
		<pubDate>Wed, 14 Nov 2012 17:00:26 +0000</pubDate>
		<dc:creator>stevehenty</dc:creator>
				<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://gravitywiz.com/?p=939</guid>
		<description><![CDATA[<p>Level of difficulty: easy, really easy What you’ll need: Gravity Forms (Developer License) Gravity Forms User Registration Add-On Justin Tadlock’s Members Plugin About 15 minutes Introduction WordPress already has quite a lot of the functionality you need to create a basic membership site. The trouble is, you quickly realise that some parts of the functionality [...]</p><p>The post <a href="http://gravitywiz.com/basic-wordpress-membership-site-with-protected-content-using-gravity-forms/">Basic WordPress membership site with protected content using Gravity Forms</a> appeared first on <a href="http://gravitywiz.com">Gravity Wiz</a>.</p>]]></description>
				<content:encoded><![CDATA[<p><strong>Level of difficulty:</strong> easy, really easy</p>

<p><strong>What you’ll need:</strong></p>

<ul>
<li>Gravity Forms (Developer License)</li>
<li>Gravity Forms User Registration Add-On</li>
<li>Justin Tadlock’s <a href="http://wordpress.org/extend/plugins/members/">Members Plugin</a></li>
<li>About 15 minutes</li>
</ul>

<h2>Introduction</h2>

<p>WordPress already has quite a lot of the functionality you need to create a basic membership site. The trouble is, you quickly realise that some parts of the functionality can be improved. The nice thing about WordPress though is that you can nearly always find a plugin that will help you as your site grows.</p>

<p>In this tutorial, we’ll be using Gravity Forms and Justin Tadlock’s Members plugin to turn WordPress into a basic membership site and require visitors to register to be able to see protect posts and pages. Non-members will only see the titles of the posts.</p>

<p>Once you’ve got the plugins installed, the configuration only takes a few simple steps.</p>

<p>Step 1: <a href="#step-1">Set up the registration form in Gravity Forms</a><br />
Step 2: <a href="#step-2">Configure the form to create user accounts</a><br />
Step 3: <a href="#step-3">Configure some members-only content</a><br />
Step 4: <a href="#step-4">Add a login box to a sidebar</a><br /></p>

<p><a name="step-1"></a></p>

<h3>Step 1: Setting up the registration form</h3>

<p>WordPress, out of the box, is limited to a rather sparse registration form with just username and password fields in the middle of a virtually blank page. It’s all very zen but not much use if we need to collect more information about the users, sign them up to a mailing list or require that they accept terms and conditions. By using Gravity Forms to create the registration form we get the features you might expect for a membership site; we can put the registration form on any page or widget area, include any additional fields, make sure that users get signed up to an email list, require email verification and keep the account on hold until the administrator’s approval.</p>

<p>To create our basic registration form we need to create a new Gravity Form following the directions <a href="http://www.gravityhelp.com/documentation/page/User_Registration_Add-On">here</a>. You’ll end up with a form that looks something like this:</p>

<div class="inline-image full"><img class="alignnone size-full wp-image-951" src="http://gravitywiz.com/wp-content/uploads/2012/11/setup-registration-form.png" alt="" width="470" height="543" /><span class="caption"></span></div>

<div class="content-icon tip"></div><div class="callout round tip">The user won&#8217;t be logged in automatically so you may want to change the form&#8217;s confirmation message to display a link to the login page.</div>

<p>Now we’ve got the form set up we need to tell Gravity Forms that this form will be used for new user registrations.</p>

<p><a name="step-2"></a></p>

<h3>Step 2: Configure the form to create user accounts</h3>

<p>Once you’ve installed the User Registration Add-On you’ll need to set up a simple user registration feed. This will map each field on the registration form to a field in the WordPress user settings and will make sure that Gravity Forms creates the user account with the right information.</p>

<div class="inline-image full"><img class="alignnone size-full wp-image-952" src="http://gravitywiz.com/wp-content/uploads/2012/11/setup-user-registration-feed.png" alt="" width="620" /><span class="caption"></span></div>

<p>Don&#8217;t worry about the User Meta and Additional Options sections for the moment &#8211; you can add those options later if you like.</p>

<p>The registration form now knows it has to check the username field to make sure it’s not already taken. If there’s another account with that username then form will fail the validation and ask the user to choose a different username.</p>

<p>Now we have a Gravity Form configured to create user accounts for our members we need to protect some content.</p>

<p><a name="step-3"></a></p>

<h3>Step 3: Protecting content</h3>

<p>WordPress has a couple of options for protecting content but neither are particularly helpful for a membership site. The first requires the post author to assign a password to each post and the second requires the user to be an editor of the blog. We’ll need to make sure that all registered users can see our protected content so we’ll need finer control over who can see what.</p>

<p>There are lots of plugins that will do this for you to varying levels of complexity but our basic membership site just needs a simple plugin that will allow us to hide certain content from non-members. Justin Tadlock’s Members plugin has been around for a long time and continues to be developed and supported and it gives us plenty of control.</p>

<p>Once you’ve installed and activated the Members plugin you’ll find this box on the edit page below the content of each post and page:</p>

<div class="inline-image full"><img class="alignnone size-full wp-image-953" src="http://gravitywiz.com/wp-content/uploads/2012/11/protecting-content.png" alt="" width="506" height="292" /><span class="caption"></span></div>

<p>The only thing we need to configure here is the role which will have access. Select the “subscriber” role for each of the posts and pages you’d like to protect. This will ensure that all registered users will have access to content and anonymous users will see something like this for protected posts and pages:</p>

<div class="inline-image full"><img class="alignnone size-full wp-image-956" src="http://gravitywiz.com/wp-content/uploads/2012/11/protected-post.png" alt="" width="403" height="165" /><span class="caption"></span></div>

<div class="content-icon tip"></div><div class="callout round tip">If you want to hide posts completely then you may want to try the <a href="http://wordpress.org/extend/plugins/wordpress-access-control/">WordPress Access Control</a> plugin.</div>

<p><a name="step-4"></a></p>

<h3>Step 4: Add a login form</h3>

<p>The standard login form on WordPress is like the registration form. It works perfectly but it doesn’t give us any control over what the login page looks like. If we want to integrate the login form into one or all of the pages we’ll need to use a plugin. The Members plugin, in addition to controlling access, also has a login widget that you can activate in the settings and then add to a sidebar. By default it will look like this:</p>

<div class="inline-image full"><img class="alignnone size-full wp-image-954" src="http://gravitywiz.com/wp-content/uploads/2012/11/login-form.png" alt="" width="192" height="269" /><span class="caption"></span></div>

<p>And once the user has logged it, it’ll look like this:</p>

<div class="inline-image full"><img class="alignnone size-full wp-image-955" src="http://gravitywiz.com/wp-content/uploads/2012/11/login-form-logged-in.png" alt="" width="172" height="46" /><span class="caption"></span></div>

<div class="content-icon tip"></div><div class="callout round tip">For further control over the login form, and the logged in content, try the <a href="http://wordpress.org/extend/plugins/sidebar-login/">Sidebar Login</a> plugin.</div>

<p>That’s all there is to it &#8211; your WordPress site is now set up to provide protected content for members only.</p>

<h2>Next Steps</h2>

<p>As your membership site grows you’ll find you want to refine the set up further.</p>

<h4>Remove the admin bar</h4>

<p>One of the first things you’ll probably want to do is hide the admin bar that appears at the top for logged in users. Again, lots of plugins will do this for you for instance <a href="http://wordpress.org/extend/plugins/admin-bar-disabler/">Admin Bar Disabler</a> and <a href="http://wordpress.org/extend/plugins/wordpress-admin-bar/">Admin bar</a>.</p>

<h4>Auto-login after register</h4>

<p>If you’d like to save your newly registered members the additional step of having to log in immediately after registering there’s a little snippet of code <a href="http://premium.wpmudev.org/forums/topic/gravity-forms-and-membership-signup#post-232538">here</a> that you can add to your theme’s functions.php file that do this for you. New members will be automatically logged in so you can send them directly to your member content.</p>

<div class="content-icon tip"></div><div class="callout round tip">The new <a href="http://gravitywiz.com/gravity-perks/">Gravity Perks</a> add-on provides this functionality as a perk: <strong>GP Auto Login</strong>. No need to get messy editing your functions.php. Just click, install, and activate.</div>

<h4>Charge for access</h4>

<p>You can easily add a paywall to your membership site by using the Gravity Forms PayPal Add-On to require payment before the account is created. Both one-off payments and recurring subscriptions with automatic account cancellations are supported.</p>

<h4>Add more membership levels</h4>

<p>The Members looks very simple on the surface but it’s actually a very flexible and deceptively powerful plugin. With a bit of planning and care it can be used to create multiple membership levels which you can then assign to users, post and pages.</p>

<h4>Protect downloads</h4>

<p>If you have a special download like a pdf report or a product that only your members should have access to then that link needs to be protected to reduce the risk of unauthorised sharing. The <a href="http://wordpress.org/extend/plugins/pluginbuddy-s3-urls/">PluginBuddy S3 URLs</a> plugin will generate a link to your download that expires automatically after a specified number of seconds.</p>

<h4>Configure admin approval for new accounts</h4>

<p>By activating the &#8220;user activation&#8221; option in the current version of the Gravity Forms User Registration Add-On (1.5 beta1.2) the user will receive a mail with an activation link which will create the account immediately. If you’d like to make sure that only the administrator can approve the account you’ll need to add the following bit of code to the functions.php file in the current theme.</p>

<div id="gist4049312" class="gist">
      <div class="gist-file">
        <div class="gist-data gist-syntax">



  <div class="file-data">
    <table cellpadding="0" cellspacing="0" class="lines highlight">
      <tr>
        <td class="line-numbers">
          <span class="line-number" id="file-gistfile1-php-L1" rel="file-gistfile1-php-L1">1</span>
          <span class="line-number" id="file-gistfile1-php-L2" rel="file-gistfile1-php-L2">2</span>
          <span class="line-number" id="file-gistfile1-php-L3" rel="file-gistfile1-php-L3">3</span>
          <span class="line-number" id="file-gistfile1-php-L4" rel="file-gistfile1-php-L4">4</span>
          <span class="line-number" id="file-gistfile1-php-L5" rel="file-gistfile1-php-L5">5</span>
          <span class="line-number" id="file-gistfile1-php-L6" rel="file-gistfile1-php-L6">6</span>
          <span class="line-number" id="file-gistfile1-php-L7" rel="file-gistfile1-php-L7">7</span>
          <span class="line-number" id="file-gistfile1-php-L8" rel="file-gistfile1-php-L8">8</span>
          <span class="line-number" id="file-gistfile1-php-L9" rel="file-gistfile1-php-L9">9</span>
          <span class="line-number" id="file-gistfile1-php-L10" rel="file-gistfile1-php-L10">10</span>
          <span class="line-number" id="file-gistfile1-php-L11" rel="file-gistfile1-php-L11">11</span>
          <span class="line-number" id="file-gistfile1-php-L12" rel="file-gistfile1-php-L12">12</span>
          <span class="line-number" id="file-gistfile1-php-L13" rel="file-gistfile1-php-L13">13</span>
          <span class="line-number" id="file-gistfile1-php-L14" rel="file-gistfile1-php-L14">14</span>
          <span class="line-number" id="file-gistfile1-php-L15" rel="file-gistfile1-php-L15">15</span>
          <span class="line-number" id="file-gistfile1-php-L16" rel="file-gistfile1-php-L16">16</span>
          <span class="line-number" id="file-gistfile1-php-L17" rel="file-gistfile1-php-L17">17</span>
          <span class="line-number" id="file-gistfile1-php-L18" rel="file-gistfile1-php-L18">18</span>
          <span class="line-number" id="file-gistfile1-php-L19" rel="file-gistfile1-php-L19">19</span>
          <span class="line-number" id="file-gistfile1-php-L20" rel="file-gistfile1-php-L20">20</span>
          <span class="line-number" id="file-gistfile1-php-L21" rel="file-gistfile1-php-L21">21</span>
          <span class="line-number" id="file-gistfile1-php-L22" rel="file-gistfile1-php-L22">22</span>
          <span class="line-number" id="file-gistfile1-php-L23" rel="file-gistfile1-php-L23">23</span>
          <span class="line-number" id="file-gistfile1-php-L24" rel="file-gistfile1-php-L24">24</span>
          <span class="line-number" id="file-gistfile1-php-L25" rel="file-gistfile1-php-L25">25</span>
          <span class="line-number" id="file-gistfile1-php-L26" rel="file-gistfile1-php-L26">26</span>
          <span class="line-number" id="file-gistfile1-php-L27" rel="file-gistfile1-php-L27">27</span>
        </td>
        <td class="line-data">
          <pre class="line-pre"><div class="line" id="file-gistfile1-php-LC1"><span class="x">/**</span></div><div class="line" id="file-gistfile1-php-LC2"><span class="x">* Configure Admin Approval for New Accounts</span></div><div class="line" id="file-gistfile1-php-LC3"><span class="x">* http://gravitywiz.com/</span></div><div class="line" id="file-gistfile1-php-LC4"><span class="x">*/</span></div><div class="line" id="file-gistfile1-php-LC5"><span class="x">remove_filter(&#39;wpmu_signup_user_notification_email&#39;, array(&#39;GFUserSignups&#39;, &#39;modify_signup_user_notification_message&#39;));</span></div><div class="line" id="file-gistfile1-php-LC6"><span class="x">add_filter(&#39;wpmu_signup_user_notification_email&#39;, &#39;my_modify_signup_user_notification_message&#39;);</span></div><div class="line" id="file-gistfile1-php-LC7">&nbsp;</div><div class="line" id="file-gistfile1-php-LC8"><span class="x">function my_modify_signup_user_notification_message() {        </span></div><div class="line" id="file-gistfile1-php-LC9"><span class="x">    return false;</span></div><div class="line" id="file-gistfile1-php-LC10"><span class="x">}</span></div><div class="line" id="file-gistfile1-php-LC11"><span class="x">    </span></div><div class="line" id="file-gistfile1-php-LC12"><span class="x">add_action(&#39;gform_user_registered&#39;, &#39;my_new_user_notification&#39;, 10, 4);</span></div><div class="line" id="file-gistfile1-php-LC13"><span class="x">function my_new_user_notification($user_id, $config, $lead, $password) {</span></div><div class="line" id="file-gistfile1-php-LC14"><span class="x">    $user = new WP_User($user_id);</span></div><div class="line" id="file-gistfile1-php-LC15">&nbsp;</div><div class="line" id="file-gistfile1-php-LC16"><span class="x">    $user_login = stripslashes($user-&gt;user_login);</span></div><div class="line" id="file-gistfile1-php-LC17"><span class="x">    $user_email = stripslashes($user-&gt;user_email);</span></div><div class="line" id="file-gistfile1-php-LC18">&nbsp;</div><div class="line" id="file-gistfile1-php-LC19"><span class="x">    $blogname = wp_specialchars_decode(get_option(&#39;blogname&#39;), ENT_QUOTES);</span></div><div class="line" id="file-gistfile1-php-LC20">&nbsp;</div><div class="line" id="file-gistfile1-php-LC21"><span class="x">    $message = &quot;Thanks for signing up. Your account has been approved and you can now log in.rn&quot;;</span></div><div class="line" id="file-gistfile1-php-LC22"><span class="x">    $message .= sprintf(__(&#39;Username: %s&#39;), $user_login) . &quot;rn&quot;;</span></div><div class="line" id="file-gistfile1-php-LC23"><span class="x">    $message .= &quot;Password: the one you entered in the registration formrn&quot;;</span></div><div class="line" id="file-gistfile1-php-LC24"><span class="x">    $message .= wp_login_url() . &quot;rn&quot;;</span></div><div class="line" id="file-gistfile1-php-LC25">&nbsp;</div><div class="line" id="file-gistfile1-php-LC26"><span class="x">    wp_mail($user_email, sprintf(__(&#39;[%s] Your account has been been approved&#39;), $blogname), $message);</span></div><div class="line" id="file-gistfile1-php-LC27"><span class="x">}</span></div></pre>
        </td>
      </tr>
    </table>
  </div>

        </div>

        <div class="gist-meta">
          <a href="https://gist.github.com/spivurno/4049312/raw/9f979e467554216b247741e3ee2cf38519eec70f/gistfile1.php" style="float:right">view raw</a>
          <a href="https://gist.github.com/spivurno/4049312#file-gistfile1-php" style="float:right; margin-right:10px; color:#666;">gistfile1.php</a>
          <a href="https://gist.github.com/spivurno/4049312">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
        </div>
      </div>
</div>


<p>&nbsp;</p>

<p><a href="http://stevenhenty.com" target="_blank">Steve Henty</a> is a developer at <a href="http://rocketgenius.com" target="_blank">rocketgenius</a>.</p>
<p>The post <a href="http://gravitywiz.com/basic-wordpress-membership-site-with-protected-content-using-gravity-forms/">Basic WordPress membership site with protected content using Gravity Forms</a> appeared first on <a href="http://gravitywiz.com">Gravity Wiz</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://gravitywiz.com/basic-wordpress-membership-site-with-protected-content-using-gravity-forms/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>Ban/Limit Email Domains for Gravity Form Email Fields</title>
		<link>http://gravitywiz.com/banlimit-email-domains-for-gravity-form-email-fields/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=banlimit-email-domains-for-gravity-form-email-fields</link>
		<comments>http://gravitywiz.com/banlimit-email-domains-for-gravity-form-email-fields/#comments</comments>
		<pubDate>Sun, 11 Nov 2012 15:31:59 +0000</pubDate>
		<dc:creator>David Smith</dc:creator>
				<category><![CDATA[Snippets]]></category>

		<guid isPermaLink="false">http://gravitywiz.com/?p=961</guid>
		<description><![CDATA[<p>Want to ban users from entering test@test.com and spamming your registration form? Want to only allow users with your companies email address to signup (i.e. jane@yourcompany.com). This snippet will let you do both! How do I use this functionality? All you need to do is create a new instance of the GWEmailDomainControl() class, populated with [...]</p><p>The post <a href="http://gravitywiz.com/banlimit-email-domains-for-gravity-form-email-fields/">Ban/Limit Email Domains for Gravity Form Email Fields</a> appeared first on <a href="http://gravitywiz.com">Gravity Wiz</a>.</p>]]></description>
				<content:encoded><![CDATA[<div class="introduction">This snippet allows you to ban or limit any email domain(s) for your Gravity Form email fields.</div>

<p>Want to ban users from entering <em>test@test.com</em> and spamming your registration form? Want to only allow users with your companies email address to signup (i.e. jane@yourcompany.com). This snippet will let you do both!</p>

<div id="gist4055158" class="gist">
      <div class="gist-file">
        <div class="gist-data gist-syntax">



  <div class="file-data">
    <table cellpadding="0" cellspacing="0" class="lines highlight">
      <tr>
        <td class="line-numbers">
          <span class="line-number" id="file-gistfile1-php-L1" rel="file-gistfile1-php-L1">1</span>
          <span class="line-number" id="file-gistfile1-php-L2" rel="file-gistfile1-php-L2">2</span>
          <span class="line-number" id="file-gistfile1-php-L3" rel="file-gistfile1-php-L3">3</span>
          <span class="line-number" id="file-gistfile1-php-L4" rel="file-gistfile1-php-L4">4</span>
          <span class="line-number" id="file-gistfile1-php-L5" rel="file-gistfile1-php-L5">5</span>
          <span class="line-number" id="file-gistfile1-php-L6" rel="file-gistfile1-php-L6">6</span>
          <span class="line-number" id="file-gistfile1-php-L7" rel="file-gistfile1-php-L7">7</span>
          <span class="line-number" id="file-gistfile1-php-L8" rel="file-gistfile1-php-L8">8</span>
          <span class="line-number" id="file-gistfile1-php-L9" rel="file-gistfile1-php-L9">9</span>
          <span class="line-number" id="file-gistfile1-php-L10" rel="file-gistfile1-php-L10">10</span>
          <span class="line-number" id="file-gistfile1-php-L11" rel="file-gistfile1-php-L11">11</span>
          <span class="line-number" id="file-gistfile1-php-L12" rel="file-gistfile1-php-L12">12</span>
          <span class="line-number" id="file-gistfile1-php-L13" rel="file-gistfile1-php-L13">13</span>
          <span class="line-number" id="file-gistfile1-php-L14" rel="file-gistfile1-php-L14">14</span>
          <span class="line-number" id="file-gistfile1-php-L15" rel="file-gistfile1-php-L15">15</span>
          <span class="line-number" id="file-gistfile1-php-L16" rel="file-gistfile1-php-L16">16</span>
          <span class="line-number" id="file-gistfile1-php-L17" rel="file-gistfile1-php-L17">17</span>
          <span class="line-number" id="file-gistfile1-php-L18" rel="file-gistfile1-php-L18">18</span>
          <span class="line-number" id="file-gistfile1-php-L19" rel="file-gistfile1-php-L19">19</span>
          <span class="line-number" id="file-gistfile1-php-L20" rel="file-gistfile1-php-L20">20</span>
          <span class="line-number" id="file-gistfile1-php-L21" rel="file-gistfile1-php-L21">21</span>
          <span class="line-number" id="file-gistfile1-php-L22" rel="file-gistfile1-php-L22">22</span>
          <span class="line-number" id="file-gistfile1-php-L23" rel="file-gistfile1-php-L23">23</span>
          <span class="line-number" id="file-gistfile1-php-L24" rel="file-gistfile1-php-L24">24</span>
          <span class="line-number" id="file-gistfile1-php-L25" rel="file-gistfile1-php-L25">25</span>
          <span class="line-number" id="file-gistfile1-php-L26" rel="file-gistfile1-php-L26">26</span>
          <span class="line-number" id="file-gistfile1-php-L27" rel="file-gistfile1-php-L27">27</span>
          <span class="line-number" id="file-gistfile1-php-L28" rel="file-gistfile1-php-L28">28</span>
          <span class="line-number" id="file-gistfile1-php-L29" rel="file-gistfile1-php-L29">29</span>
          <span class="line-number" id="file-gistfile1-php-L30" rel="file-gistfile1-php-L30">30</span>
          <span class="line-number" id="file-gistfile1-php-L31" rel="file-gistfile1-php-L31">31</span>
          <span class="line-number" id="file-gistfile1-php-L32" rel="file-gistfile1-php-L32">32</span>
          <span class="line-number" id="file-gistfile1-php-L33" rel="file-gistfile1-php-L33">33</span>
          <span class="line-number" id="file-gistfile1-php-L34" rel="file-gistfile1-php-L34">34</span>
          <span class="line-number" id="file-gistfile1-php-L35" rel="file-gistfile1-php-L35">35</span>
          <span class="line-number" id="file-gistfile1-php-L36" rel="file-gistfile1-php-L36">36</span>
          <span class="line-number" id="file-gistfile1-php-L37" rel="file-gistfile1-php-L37">37</span>
          <span class="line-number" id="file-gistfile1-php-L38" rel="file-gistfile1-php-L38">38</span>
          <span class="line-number" id="file-gistfile1-php-L39" rel="file-gistfile1-php-L39">39</span>
          <span class="line-number" id="file-gistfile1-php-L40" rel="file-gistfile1-php-L40">40</span>
          <span class="line-number" id="file-gistfile1-php-L41" rel="file-gistfile1-php-L41">41</span>
          <span class="line-number" id="file-gistfile1-php-L42" rel="file-gistfile1-php-L42">42</span>
          <span class="line-number" id="file-gistfile1-php-L43" rel="file-gistfile1-php-L43">43</span>
          <span class="line-number" id="file-gistfile1-php-L44" rel="file-gistfile1-php-L44">44</span>
          <span class="line-number" id="file-gistfile1-php-L45" rel="file-gistfile1-php-L45">45</span>
          <span class="line-number" id="file-gistfile1-php-L46" rel="file-gistfile1-php-L46">46</span>
          <span class="line-number" id="file-gistfile1-php-L47" rel="file-gistfile1-php-L47">47</span>
          <span class="line-number" id="file-gistfile1-php-L48" rel="file-gistfile1-php-L48">48</span>
          <span class="line-number" id="file-gistfile1-php-L49" rel="file-gistfile1-php-L49">49</span>
          <span class="line-number" id="file-gistfile1-php-L50" rel="file-gistfile1-php-L50">50</span>
          <span class="line-number" id="file-gistfile1-php-L51" rel="file-gistfile1-php-L51">51</span>
          <span class="line-number" id="file-gistfile1-php-L52" rel="file-gistfile1-php-L52">52</span>
          <span class="line-number" id="file-gistfile1-php-L53" rel="file-gistfile1-php-L53">53</span>
          <span class="line-number" id="file-gistfile1-php-L54" rel="file-gistfile1-php-L54">54</span>
          <span class="line-number" id="file-gistfile1-php-L55" rel="file-gistfile1-php-L55">55</span>
          <span class="line-number" id="file-gistfile1-php-L56" rel="file-gistfile1-php-L56">56</span>
          <span class="line-number" id="file-gistfile1-php-L57" rel="file-gistfile1-php-L57">57</span>
          <span class="line-number" id="file-gistfile1-php-L58" rel="file-gistfile1-php-L58">58</span>
          <span class="line-number" id="file-gistfile1-php-L59" rel="file-gistfile1-php-L59">59</span>
          <span class="line-number" id="file-gistfile1-php-L60" rel="file-gistfile1-php-L60">60</span>
          <span class="line-number" id="file-gistfile1-php-L61" rel="file-gistfile1-php-L61">61</span>
          <span class="line-number" id="file-gistfile1-php-L62" rel="file-gistfile1-php-L62">62</span>
          <span class="line-number" id="file-gistfile1-php-L63" rel="file-gistfile1-php-L63">63</span>
          <span class="line-number" id="file-gistfile1-php-L64" rel="file-gistfile1-php-L64">64</span>
          <span class="line-number" id="file-gistfile1-php-L65" rel="file-gistfile1-php-L65">65</span>
          <span class="line-number" id="file-gistfile1-php-L66" rel="file-gistfile1-php-L66">66</span>
          <span class="line-number" id="file-gistfile1-php-L67" rel="file-gistfile1-php-L67">67</span>
          <span class="line-number" id="file-gistfile1-php-L68" rel="file-gistfile1-php-L68">68</span>
          <span class="line-number" id="file-gistfile1-php-L69" rel="file-gistfile1-php-L69">69</span>
          <span class="line-number" id="file-gistfile1-php-L70" rel="file-gistfile1-php-L70">70</span>
          <span class="line-number" id="file-gistfile1-php-L71" rel="file-gistfile1-php-L71">71</span>
          <span class="line-number" id="file-gistfile1-php-L72" rel="file-gistfile1-php-L72">72</span>
          <span class="line-number" id="file-gistfile1-php-L73" rel="file-gistfile1-php-L73">73</span>
          <span class="line-number" id="file-gistfile1-php-L74" rel="file-gistfile1-php-L74">74</span>
          <span class="line-number" id="file-gistfile1-php-L75" rel="file-gistfile1-php-L75">75</span>
          <span class="line-number" id="file-gistfile1-php-L76" rel="file-gistfile1-php-L76">76</span>
          <span class="line-number" id="file-gistfile1-php-L77" rel="file-gistfile1-php-L77">77</span>
          <span class="line-number" id="file-gistfile1-php-L78" rel="file-gistfile1-php-L78">78</span>
          <span class="line-number" id="file-gistfile1-php-L79" rel="file-gistfile1-php-L79">79</span>
          <span class="line-number" id="file-gistfile1-php-L80" rel="file-gistfile1-php-L80">80</span>
          <span class="line-number" id="file-gistfile1-php-L81" rel="file-gistfile1-php-L81">81</span>
          <span class="line-number" id="file-gistfile1-php-L82" rel="file-gistfile1-php-L82">82</span>
        </td>
        <td class="line-data">
          <pre class="line-pre"><div class="line" id="file-gistfile1-php-LC1"><span class="cp">&lt;?php</span></div><div class="line" id="file-gistfile1-php-LC2"><span class="sd">/**</span></div><div class="line" id="file-gistfile1-php-LC3"><span class="sd">* Ban/Limit Email Domains for Gravity Form Email Fields</span></div><div class="line" id="file-gistfile1-php-LC4"><span class="sd">* http://gravitywiz.com/2012/11/11/banlimit-email-domains-for-gravity-form-email-fields/</span></div><div class="line" id="file-gistfile1-php-LC5"><span class="sd">*/</span></div><div class="line" id="file-gistfile1-php-LC6"><span class="k">class</span> <span class="nc">GWEmailDomainControl</span> <span class="p">{</span></div><div class="line" id="file-gistfile1-php-LC7">    </div><div class="line" id="file-gistfile1-php-LC8">    <span class="k">private</span> <span class="nv">$_args</span><span class="p">;</span></div><div class="line" id="file-gistfile1-php-LC9">    </div><div class="line" id="file-gistfile1-php-LC10">    <span class="k">function</span> <span class="nf">__construct</span><span class="p">(</span><span class="nv">$args</span><span class="p">)</span> <span class="p">{</span></div><div class="line" id="file-gistfile1-php-LC11">        </div><div class="line" id="file-gistfile1-php-LC12">        <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">_args</span> <span class="o">=</span> <span class="nx">wp_parse_args</span><span class="p">(</span><span class="nv">$args</span><span class="p">,</span> <span class="k">array</span><span class="p">(</span></div><div class="line" id="file-gistfile1-php-LC13">            <span class="s1">&#39;form_id&#39;</span> <span class="o">=&gt;</span> <span class="k">false</span><span class="p">,</span></div><div class="line" id="file-gistfile1-php-LC14">            <span class="s1">&#39;field_id&#39;</span> <span class="o">=&gt;</span> <span class="k">false</span><span class="p">,</span></div><div class="line" id="file-gistfile1-php-LC15">            <span class="s1">&#39;domains&#39;</span> <span class="o">=&gt;</span> <span class="k">false</span><span class="p">,</span></div><div class="line" id="file-gistfile1-php-LC16">            <span class="s1">&#39;validation_message&#39;</span> <span class="o">=&gt;</span> <span class="nx">__</span><span class="p">(</span><span class="s1">&#39;Sorry, &lt;strong&gt;%s&lt;/strong&gt; email accounts are not eligible for this form.&#39;</span><span class="p">),</span></div><div class="line" id="file-gistfile1-php-LC17">            <span class="s1">&#39;mode&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;ban&#39;</span> <span class="c1">// also accepts &quot;limit&quot;</span></div><div class="line" id="file-gistfile1-php-LC18">            <span class="p">));</span></div><div class="line" id="file-gistfile1-php-LC19">        </div><div class="line" id="file-gistfile1-php-LC20">        <span class="c1">// convert field ID to an array for consistency, it can be passed as an array or a single ID</span></div><div class="line" id="file-gistfile1-php-LC21">        <span class="k">if</span><span class="p">(</span><span class="nv">$this</span><span class="o">-&gt;</span><span class="na">_args</span><span class="p">[</span><span class="s1">&#39;field_id&#39;</span><span class="p">]</span> <span class="o">&amp;&amp;</span> <span class="o">!</span><span class="nb">is_array</span><span class="p">(</span><span class="nv">$this</span><span class="o">-&gt;</span><span class="na">_args</span><span class="p">[</span><span class="s1">&#39;field_id&#39;</span><span class="p">]))</span></div><div class="line" id="file-gistfile1-php-LC22">            <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">_args</span><span class="p">[</span><span class="s1">&#39;field_id&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="k">array</span><span class="p">(</span><span class="nv">$this</span><span class="o">-&gt;</span><span class="na">_args</span><span class="p">[</span><span class="s1">&#39;field_id&#39;</span><span class="p">]);</span></div><div class="line" id="file-gistfile1-php-LC23">        </div><div class="line" id="file-gistfile1-php-LC24">        <span class="nv">$form_filter</span> <span class="o">=</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">_args</span><span class="p">[</span><span class="s1">&#39;form_id&#39;</span><span class="p">]</span> <span class="o">?</span> <span class="s2">&quot;_</span><span class="si">{</span><span class="nv">$this</span><span class="o">-&gt;</span><span class="na">_args</span><span class="p">[</span><span class="s1">&#39;form_id&#39;</span><span class="p">]</span><span class="si">}</span><span class="s2">&quot;</span> <span class="o">:</span> <span class="s1">&#39;&#39;</span><span class="p">;</span></div><div class="line" id="file-gistfile1-php-LC25">        </div><div class="line" id="file-gistfile1-php-LC26">        <span class="nx">add_filter</span><span class="p">(</span><span class="s2">&quot;gform_validation</span><span class="si">{</span><span class="nv">$form_filter</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">,</span> <span class="k">array</span><span class="p">(</span><span class="nv">$this</span><span class="p">,</span> <span class="s1">&#39;validate&#39;</span><span class="p">));</span></div><div class="line" id="file-gistfile1-php-LC27">        </div><div class="line" id="file-gistfile1-php-LC28">    <span class="p">}</span></div><div class="line" id="file-gistfile1-php-LC29">    </div><div class="line" id="file-gistfile1-php-LC30">    <span class="k">function</span> <span class="nf">validate</span><span class="p">(</span><span class="nv">$validation_result</span><span class="p">)</span> <span class="p">{</span></div><div class="line" id="file-gistfile1-php-LC31">        </div><div class="line" id="file-gistfile1-php-LC32">        <span class="nv">$form</span> <span class="o">=</span> <span class="nv">$validation_result</span><span class="p">[</span><span class="s1">&#39;form&#39;</span><span class="p">];</span></div><div class="line" id="file-gistfile1-php-LC33">        </div><div class="line" id="file-gistfile1-php-LC34">        <span class="k">foreach</span><span class="p">(</span><span class="nv">$form</span><span class="p">[</span><span class="s1">&#39;fields&#39;</span><span class="p">]</span> <span class="k">as</span> <span class="o">&amp;</span><span class="nv">$field</span><span class="p">)</span> <span class="p">{</span></div><div class="line" id="file-gistfile1-php-LC35">            </div><div class="line" id="file-gistfile1-php-LC36">            <span class="c1">// if this is not an email field, skip</span></div><div class="line" id="file-gistfile1-php-LC37">            <span class="k">if</span><span class="p">(</span><span class="nx">RGFormsModel</span><span class="o">::</span><span class="na">get_input_type</span><span class="p">(</span><span class="nv">$field</span><span class="p">)</span> <span class="o">!=</span> <span class="s1">&#39;email&#39;</span><span class="p">)</span></div><div class="line" id="file-gistfile1-php-LC38">                <span class="k">continue</span><span class="p">;</span></div><div class="line" id="file-gistfile1-php-LC39">                </div><div class="line" id="file-gistfile1-php-LC40">            <span class="c1">// if field ID was passed and current field is not in that array, skip</span></div><div class="line" id="file-gistfile1-php-LC41">            <span class="k">if</span><span class="p">(</span><span class="nv">$this</span><span class="o">-&gt;</span><span class="na">_args</span><span class="p">[</span><span class="s1">&#39;field_id&#39;</span><span class="p">]</span> <span class="o">&amp;&amp;</span> <span class="o">!</span><span class="nb">in_array</span><span class="p">(</span><span class="nv">$field</span><span class="p">[</span><span class="s1">&#39;id&#39;</span><span class="p">],</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">_args</span><span class="p">[</span><span class="s1">&#39;field_id&#39;</span><span class="p">]))</span></div><div class="line" id="file-gistfile1-php-LC42">                <span class="k">continue</span><span class="p">;</span></div><div class="line" id="file-gistfile1-php-LC43">            </div><div class="line" id="file-gistfile1-php-LC44">            <span class="nv">$domain</span> <span class="o">=</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">get_email_domain</span><span class="p">(</span><span class="nv">$field</span><span class="p">);</span></div><div class="line" id="file-gistfile1-php-LC45">            </div><div class="line" id="file-gistfile1-php-LC46">            <span class="c1">// if domain is valid OR if the email field is empty, skip</span></div><div class="line" id="file-gistfile1-php-LC47">            <span class="k">if</span><span class="p">(</span><span class="nv">$this</span><span class="o">-&gt;</span><span class="na">is_domain_valid</span><span class="p">(</span><span class="nv">$domain</span><span class="p">)</span> <span class="o">||</span> <span class="k">empty</span><span class="p">(</span><span class="nv">$domain</span><span class="p">))</span></div><div class="line" id="file-gistfile1-php-LC48">                <span class="k">continue</span><span class="p">;</span></div><div class="line" id="file-gistfile1-php-LC49">            </div><div class="line" id="file-gistfile1-php-LC50">            <span class="nv">$validation_result</span><span class="p">[</span><span class="s1">&#39;is_valid&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="k">false</span><span class="p">;</span></div><div class="line" id="file-gistfile1-php-LC51">            <span class="nv">$field</span><span class="p">[</span><span class="s1">&#39;failed_validation&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="k">true</span><span class="p">;</span></div><div class="line" id="file-gistfile1-php-LC52">            <span class="nv">$field</span><span class="p">[</span><span class="s1">&#39;validation_message&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="nb">sprintf</span><span class="p">(</span><span class="nv">$this</span><span class="o">-&gt;</span><span class="na">_args</span><span class="p">[</span><span class="s1">&#39;validation_message&#39;</span><span class="p">],</span> <span class="nv">$domain</span><span class="p">);</span></div><div class="line" id="file-gistfile1-php-LC53">            </div><div class="line" id="file-gistfile1-php-LC54">        <span class="p">}</span></div><div class="line" id="file-gistfile1-php-LC55">        </div><div class="line" id="file-gistfile1-php-LC56">        <span class="nv">$validation_result</span><span class="p">[</span><span class="s1">&#39;form&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="nv">$form</span><span class="p">;</span></div><div class="line" id="file-gistfile1-php-LC57">        <span class="k">return</span> <span class="nv">$validation_result</span><span class="p">;</span></div><div class="line" id="file-gistfile1-php-LC58">    <span class="p">}</span></div><div class="line" id="file-gistfile1-php-LC59">        </div><div class="line" id="file-gistfile1-php-LC60">    <span class="k">function</span> <span class="nf">get_email_domain</span><span class="p">(</span><span class="nv">$field</span><span class="p">){</span></div><div class="line" id="file-gistfile1-php-LC61">        <span class="nv">$email</span> <span class="o">=</span> <span class="nb">explode</span><span class="p">(</span><span class="s1">&#39;@&#39;</span><span class="p">,</span> <span class="nx">rgpost</span><span class="p">(</span><span class="s2">&quot;input_</span><span class="si">{</span><span class="nv">$field</span><span class="p">[</span><span class="s1">&#39;id&#39;</span><span class="p">]</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">));</span></div><div class="line" id="file-gistfile1-php-LC62">        <span class="k">return</span> <span class="nx">rgar</span><span class="p">(</span><span class="nv">$email</span><span class="p">,</span> <span class="mi">1</span><span class="p">);</span></div><div class="line" id="file-gistfile1-php-LC63">    <span class="p">}</span></div><div class="line" id="file-gistfile1-php-LC64">    </div><div class="line" id="file-gistfile1-php-LC65">    <span class="k">function</span> <span class="nf">is_domain_valid</span><span class="p">(</span><span class="nv">$domain</span><span class="p">)</span> <span class="p">{</span></div><div class="line" id="file-gistfile1-php-LC66">        <span class="k">if</span><span class="p">(</span><span class="nv">$this</span><span class="o">-&gt;</span><span class="na">_args</span><span class="p">[</span><span class="s1">&#39;mode&#39;</span><span class="p">]</span> <span class="o">==</span> <span class="s1">&#39;ban&#39;</span><span class="p">)</span> <span class="p">{</span></div><div class="line" id="file-gistfile1-php-LC67">            <span class="k">return</span> <span class="o">!</span><span class="nb">in_array</span><span class="p">(</span><span class="nv">$domain</span><span class="p">,</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">_args</span><span class="p">[</span><span class="s1">&#39;domains&#39;</span><span class="p">]);</span></div><div class="line" id="file-gistfile1-php-LC68">        <span class="p">}</span> </div><div class="line" id="file-gistfile1-php-LC69">        <span class="k">else</span> <span class="p">{</span></div><div class="line" id="file-gistfile1-php-LC70">            <span class="k">return</span> <span class="nb">in_array</span><span class="p">(</span><span class="nv">$domain</span><span class="p">,</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">_args</span><span class="p">[</span><span class="s1">&#39;domains&#39;</span><span class="p">]);</span></div><div class="line" id="file-gistfile1-php-LC71">        <span class="p">}</span></div><div class="line" id="file-gistfile1-php-LC72">    <span class="p">}</span></div><div class="line" id="file-gistfile1-php-LC73">    </div><div class="line" id="file-gistfile1-php-LC74"><span class="p">}</span></div><div class="line" id="file-gistfile1-php-LC75">&nbsp;</div><div class="line" id="file-gistfile1-php-LC76"><span class="k">new</span> <span class="nx">GWEmailDomainControl</span><span class="p">(</span><span class="k">array</span><span class="p">(</span></div><div class="line" id="file-gistfile1-php-LC77">    <span class="s1">&#39;form_id&#39;</span> <span class="o">=&gt;</span> <span class="mi">152</span><span class="p">,</span></div><div class="line" id="file-gistfile1-php-LC78">    <span class="s1">&#39;field_id&#39;</span> <span class="o">=&gt;</span> <span class="mi">9</span><span class="p">,</span></div><div class="line" id="file-gistfile1-php-LC79">    <span class="s1">&#39;domains&#39;</span> <span class="o">=&gt;</span> <span class="k">array</span><span class="p">(</span><span class="s1">&#39;gmail.com&#39;</span><span class="p">,</span> <span class="s1">&#39;hotmail.com&#39;</span><span class="p">,</span> <span class="s1">&#39;test.com&#39;</span><span class="p">),</span></div><div class="line" id="file-gistfile1-php-LC80">    <span class="s1">&#39;validation_message&#39;</span> <span class="o">=&gt;</span> <span class="nx">__</span><span class="p">(</span><span class="s1">&#39;Oh no! &lt;strong&gt;%s&lt;/strong&gt; email accounts are not eligible for this form.&#39;</span><span class="p">),</span></div><div class="line" id="file-gistfile1-php-LC81">    <span class="s1">&#39;mode&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;ban&#39;</span></div><div class="line" id="file-gistfile1-php-LC82">    <span class="p">));</span></div></pre>
        </td>
      </tr>
    </table>
  </div>

        </div>

        <div class="gist-meta">
          <a href="https://gist.github.com/raw/4055158/01ce4b942d53868ae8eebb7b9e6899112539b6f1/gistfile1.php" style="float:right">view raw</a>
          <a href="https://gist.github.com/4055158#file-gistfile1-php" style="float:right; margin-right:10px; color:#666;">gistfile1.php</a>
          <a href="https://gist.github.com/4055158">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
        </div>
      </div>
</div>


<h3>How do I install this snippet?</h3><p>Easy peasy. Just copy and paste the code above into your theme's <em>functions.php</em> file.</p>

<h3>How do I use this functionality?</h3>

<p>All you need to do is create a new instance of the <code>GWEmailDomainControl()</code> class, populated with your specific details, like so:</p>

<div id="gist4055175" class="gist">       <div class="gist-file">         <div class="gist-data gist-syntax">      <div class="file-data">     <table cellpadding="0" cellspacing="0" class="lines highlight">       <tr>         <td class="line-numbers">                                            <span class="line-number" id="file-gistfile1-php-L4" rel="file-gistfile1-php-L4">4</span>           <span class="line-number" id="file-gistfile1-php-L5" rel="file-gistfile1-php-L5">5</span>           <span class="line-number" id="file-gistfile1-php-L6" rel="file-gistfile1-php-L6">6</span>           <span class="line-number" id="file-gistfile1-php-L7" rel="file-gistfile1-php-L7">7</span>           <span class="line-number" id="file-gistfile1-php-L8" rel="file-gistfile1-php-L8">8</span>                                                                                                                                                                                                                                                                      </td>         <td class="line-data">           <pre class="line-pre"><div class="line" id="file-gistfile1-php-LC4"><span class="k">new</span> <span class="nx">GWEmailDomainControl</span><span class="p">(</span><span class="k">array</span><span class="p">(</span></div><div class="line" id="file-gistfile1-php-LC5">    <span class="s1">&#39;form_id&#39;</span> <span class="o">=&gt;</span> <span class="mi">152</span><span class="p">,</span></div><div class="line" id="file-gistfile1-php-LC6">    <span class="s1">&#39;field_id&#39;</span> <span class="o">=&gt;</span> <span class="mi">9</span><span class="p">,</span></div><div class="line" id="file-gistfile1-php-LC7">    <span class="s1">&#39;domains&#39;</span> <span class="o">=&gt;</span> <span class="k">array</span><span class="p">(</span><span class="s1">&#39;gmail.com&#39;</span><span class="p">,</span> <span class="s1">&#39;hotmail.com&#39;</span><span class="p">,</span> <span class="s1">&#39;test.com&#39;</span><span class="p">)</span></div><div class="line" id="file-gistfile1-php-LC8">    <span class="p">));</span></div></pre>         </td>       </tr>     </table>   </div>          </div>          <div class="gist-meta">           <a href="https://gist.github.com/raw/4055175/3f84f0ece1997f30eaa2c717eafcad7923ee7034/gistfile1.php" style="float:right">view raw</a>           <a href="https://gist.github.com/4055175#file-gistfile1-php" style="float:right; margin-right:10px; color:#666;">gistfile1.php</a>           <a href="https://gist.github.com/4055175">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.         </div>       </div> </div> 

<p>By default, the form will &#8220;ban&#8221; the specified email domains; however, you can also limit by the specified domains by passing <code>limit</code> for the <code>mode</code> argument. The example below demonstrates this as well as how to apply the email domain control to two specific fields by passing an array of field IDs for the <code>field_id</code> argument:</p>

<div id="gist4055175" class="gist">       <div class="gist-file">         <div class="gist-data gist-syntax">      <div class="file-data">     <table cellpadding="0" cellspacing="0" class="lines highlight">       <tr>         <td class="line-numbers">                                                                                                                                                                                                                            <span class="line-number" id="file-gistfile1-php-L20" rel="file-gistfile1-php-L20">20</span>           <span class="line-number" id="file-gistfile1-php-L21" rel="file-gistfile1-php-L21">21</span>           <span class="line-number" id="file-gistfile1-php-L22" rel="file-gistfile1-php-L22">22</span>           <span class="line-number" id="file-gistfile1-php-L23" rel="file-gistfile1-php-L23">23</span>           <span class="line-number" id="file-gistfile1-php-L24" rel="file-gistfile1-php-L24">24</span>           <span class="line-number" id="file-gistfile1-php-L25" rel="file-gistfile1-php-L25">25</span>                                                                           </td>         <td class="line-data">           <pre class="line-pre"><div class="line" id="file-gistfile1-php-LC20"><span class="k">new</span> <span class="nx">GWEmailDomainControl</span><span class="p">(</span><span class="k">array</span><span class="p">(</span></div><div class="line" id="file-gistfile1-php-LC21">    <span class="s1">&#39;form_id&#39;</span> <span class="o">=&gt;</span> <span class="mi">152</span><span class="p">,</span></div><div class="line" id="file-gistfile1-php-LC22">    <span class="s1">&#39;field_id&#39;</span> <span class="o">=&gt;</span> <span class="mi">9</span><span class="p">,</span></div><div class="line" id="file-gistfile1-php-LC23">    <span class="s1">&#39;domains&#39;</span> <span class="o">=&gt;</span> <span class="k">array</span><span class="p">(</span><span class="s1">&#39;gmail.com&#39;</span><span class="p">,</span> <span class="s1">&#39;hotmail.com&#39;</span><span class="p">,</span> <span class="s1">&#39;test.com&#39;</span><span class="p">),</span></div><div class="line" id="file-gistfile1-php-LC24">    <span class="s1">&#39;mode&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;limit&#39;</span></div><div class="line" id="file-gistfile1-php-LC25">    <span class="p">));</span></div></pre>         </td>       </tr>     </table>   </div>          </div>          <div class="gist-meta">           <a href="https://gist.github.com/raw/4055175/3f84f0ece1997f30eaa2c717eafcad7923ee7034/gistfile1.php" style="float:right">view raw</a>           <a href="https://gist.github.com/4055175#file-gistfile1-php" style="float:right; margin-right:10px; color:#666;">gistfile1.php</a>           <a href="https://gist.github.com/4055175">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.         </div>       </div> </div> 

<p>To apply this functionality to ALL fields on a form, do not pass the <code>field_id</code> argument at all.</p>

<div id="gist4055175" class="gist">       <div class="gist-file">         <div class="gist-data gist-syntax">      <div class="file-data">     <table cellpadding="0" cellspacing="0" class="lines highlight">       <tr>         <td class="line-numbers">                                                                                                                                                                                                                                                                                                         <span class="line-number" id="file-gistfile1-php-L27" rel="file-gistfile1-php-L27">27</span>           <span class="line-number" id="file-gistfile1-php-L28" rel="file-gistfile1-php-L28">28</span>           <span class="line-number" id="file-gistfile1-php-L29" rel="file-gistfile1-php-L29">29</span>           <span class="line-number" id="file-gistfile1-php-L30" rel="file-gistfile1-php-L30">30</span>           <span class="line-number" id="file-gistfile1-php-L31" rel="file-gistfile1-php-L31">31</span>         </td>         <td class="line-data">           <pre class="line-pre"><div class="line" id="file-gistfile1-php-LC27"><span class="c1">// apply to all email fields on a form</span></div><div class="line" id="file-gistfile1-php-LC28"><span class="k">new</span> <span class="nx">GWEmailDomainControl</span><span class="p">(</span><span class="k">array</span><span class="p">(</span></div><div class="line" id="file-gistfile1-php-LC29">    <span class="s1">&#39;form_id&#39;</span> <span class="o">=&gt;</span> <span class="mi">152</span><span class="p">,</span></div><div class="line" id="file-gistfile1-php-LC30">    <span class="s1">&#39;domains&#39;</span> <span class="o">=&gt;</span> <span class="k">array</span><span class="p">(</span><span class="s1">&#39;gmail.com&#39;</span><span class="p">,</span> <span class="s1">&#39;hotmail.com&#39;</span><span class="p">,</span> <span class="s1">&#39;test.com&#39;</span><span class="p">)</span></div><div class="line" id="file-gistfile1-php-LC31">    <span class="p">));</span></div></pre>         </td>       </tr>     </table>   </div>          </div>          <div class="gist-meta">           <a href="https://gist.github.com/raw/4055175/3f84f0ece1997f30eaa2c717eafcad7923ee7034/gistfile1.php" style="float:right">view raw</a>           <a href="https://gist.github.com/4055175#file-gistfile1-php" style="float:right; margin-right:10px; color:#666;">gistfile1.php</a>           <a href="https://gist.github.com/4055175">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.         </div>       </div> </div> 

<p>Here is a full list of available options:</p>

<div id="gist4055175" class="gist">       <div class="gist-file">         <div class="gist-data gist-syntax">      <div class="file-data">     <table cellpadding="0" cellspacing="0" class="lines highlight">       <tr>         <td class="line-numbers">                                                                                                                         <span class="line-number" id="file-gistfile1-php-L11" rel="file-gistfile1-php-L11">11</span>           <span class="line-number" id="file-gistfile1-php-L12" rel="file-gistfile1-php-L12">12</span>           <span class="line-number" id="file-gistfile1-php-L13" rel="file-gistfile1-php-L13">13</span>           <span class="line-number" id="file-gistfile1-php-L14" rel="file-gistfile1-php-L14">14</span>           <span class="line-number" id="file-gistfile1-php-L15" rel="file-gistfile1-php-L15">15</span>           <span class="line-number" id="file-gistfile1-php-L16" rel="file-gistfile1-php-L16">16</span>           <span class="line-number" id="file-gistfile1-php-L17" rel="file-gistfile1-php-L17">17</span>                                                                                                                                                                   </td>         <td class="line-data">           <pre class="line-pre"><div class="line" id="file-gistfile1-php-LC11"><span class="k">new</span> <span class="nx">GWEmailDomainControl</span><span class="p">(</span><span class="k">array</span><span class="p">(</span></div><div class="line" id="file-gistfile1-php-LC12">    <span class="s1">&#39;form_id&#39;</span> <span class="o">=&gt;</span> <span class="mi">152</span><span class="p">,</span></div><div class="line" id="file-gistfile1-php-LC13">    <span class="s1">&#39;field_id&#39;</span> <span class="o">=&gt;</span> <span class="mi">9</span><span class="p">,</span> <span class="c1">// multiple field IDs can be passed as an array: array(8,9)</span></div><div class="line" id="file-gistfile1-php-LC14">    <span class="s1">&#39;domains&#39;</span> <span class="o">=&gt;</span> <span class="k">array</span><span class="p">(</span><span class="s1">&#39;gmail.com&#39;</span><span class="p">,</span> <span class="s1">&#39;hotmail.com&#39;</span><span class="p">,</span> <span class="s1">&#39;test.com&#39;</span><span class="p">),</span></div><div class="line" id="file-gistfile1-php-LC15">    <span class="s1">&#39;validation_message&#39;</span> <span class="o">=&gt;</span> <span class="nx">__</span><span class="p">(</span><span class="s1">&#39;Oh no! &lt;strong&gt;%s&lt;/strong&gt; email accounts are not eligible for this form.&#39;</span><span class="p">),</span></div><div class="line" id="file-gistfile1-php-LC16">    <span class="s1">&#39;mode&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;ban&#39;</span> <span class="c1">// also accepts &quot;limit&quot;</span></div><div class="line" id="file-gistfile1-php-LC17">    <span class="p">));</span></div></pre>         </td>       </tr>     </table>   </div>          </div>          <div class="gist-meta">           <a href="https://gist.github.com/raw/4055175/3f84f0ece1997f30eaa2c717eafcad7923ee7034/gistfile1.php" style="float:right">view raw</a>           <a href="https://gist.github.com/4055175#file-gistfile1-php" style="float:right; margin-right:10px; color:#666;">gistfile1.php</a>           <a href="https://gist.github.com/4055175">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.         </div>       </div> </div> 

<ul>
<li><code>form_id</code> The form ID of the form you would like to apply this functionality to. If you want to apply the the same email domain control to all forms, simply do not pass the <code>form_id</code> argument at all.</li>
<li><code>field_id</code> The field ID for which this email domain control should be applied. If you would like to apply the same control to multiple fields you can pass an array of field IDs: <code>'field_id' => array(8,12,15)</code>. If you want this to apply to all fields on a form, simply do not pass the <code>field_id</code> argument at all.</li>
<li><code>domains</code> An array of email domains that should be banned or limited to depending on what <code>mode</code> you have set.</li>
<li><code>validation_message</code> The message which will be displayed below the email field if the submitted email contains an invalid domain. You can use <code>%s</code> anywhere in the message to output the invalid domain.</li>
<li><code>mode</code> By default, this is set to <code>ban</code> which will mark any of the specified domains as invalid if they are submitted in the email field. You can also pass a <code>limit</code> mode. In this mode, the specified domains are the only valid domains. All other domains will be marked as invalid.</li>
</ul>
<p>The post <a href="http://gravitywiz.com/banlimit-email-domains-for-gravity-form-email-fields/">Ban/Limit Email Domains for Gravity Form Email Fields</a> appeared first on <a href="http://gravitywiz.com">Gravity Wiz</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://gravitywiz.com/banlimit-email-domains-for-gravity-form-email-fields/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Better Limit Submission Per Time Period by User or IP</title>
		<link>http://gravitywiz.com/better-limit-submission-per-time-period-by-user-or-ip/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=better-limit-submission-per-time-period-by-user-or-ip</link>
		<comments>http://gravitywiz.com/better-limit-submission-per-time-period-by-user-or-ip/#comments</comments>
		<pubDate>Tue, 06 Nov 2012 13:19:38 +0000</pubDate>
		<dc:creator>David Smith</dc:creator>
				<category><![CDATA[Snippets]]></category>

		<guid isPermaLink="false">http://gravitywiz.com/?p=928</guid>
		<description><![CDATA[<p>This snippet replaces both the and the snippets. How to I use this functionality? All you need to do is create a new instance of the GWSubmissionLimit() class, populated with your specific details, like so: Want to apply the same submission limit to all forms? Want to apply multiple limitations? This example allows you to [...]</p><p>The post <a href="http://gravitywiz.com/better-limit-submission-per-time-period-by-user-or-ip/">Better Limit Submission Per Time Period by User or IP</a> appeared first on <a href="http://gravitywiz.com">Gravity Wiz</a>.</p>]]></description>
				<content:encoded><![CDATA[<div class="introduction">This snippet allows you to limit submissions to any (or all) Gravity Forms per a time period (i.e. 30 minutes, 24 hours, 2 days, etc) by a WP User ID, by the submitting users IP adddress, or from a specific embed URL.</div>

<p>This snippet replaces both the <a href="http://gravitywiz.com/limit-user-to-one-submission-per-time-period/">Limit User to One Submission Per Time Period</a> and the <a href="http://gravitywiz.com/limit-ip-to-one-submission-per-time-period/">Limit IP to One Submission Per Time Period</a> snippets.</p>

<div class="content-icon tip"></div><div class="callout round tip">This snippet was updated on <strong>January 15th, 2012</strong> to provide support for limiting by the embed URL of the form and also specifying multiple &#8220;limit_by&#8221; parameters. Big thanks to <strong>Lee</strong> for funding this enhancement!</div>

<div id="gist4024361" class="gist">
      <div class="gist-file">
        <div class="gist-data gist-syntax">



  <div class="file-data">
    <table cellpadding="0" cellspacing="0" class="lines highlight">
      <tr>
        <td class="line-numbers">
          <span class="line-number" id="file-gistfile1-php-L1" rel="file-gistfile1-php-L1">1</span>
          <span class="line-number" id="file-gistfile1-php-L2" rel="file-gistfile1-php-L2">2</span>
          <span class="line-number" id="file-gistfile1-php-L3" rel="file-gistfile1-php-L3">3</span>
          <span class="line-number" id="file-gistfile1-php-L4" rel="file-gistfile1-php-L4">4</span>
          <span class="line-number" id="file-gistfile1-php-L5" rel="file-gistfile1-php-L5">5</span>
          <span class="line-number" id="file-gistfile1-php-L6" rel="file-gistfile1-php-L6">6</span>
          <span class="line-number" id="file-gistfile1-php-L7" rel="file-gistfile1-php-L7">7</span>
          <span class="line-number" id="file-gistfile1-php-L8" rel="file-gistfile1-php-L8">8</span>
          <span class="line-number" id="file-gistfile1-php-L9" rel="file-gistfile1-php-L9">9</span>
          <span class="line-number" id="file-gistfile1-php-L10" rel="file-gistfile1-php-L10">10</span>
          <span class="line-number" id="file-gistfile1-php-L11" rel="file-gistfile1-php-L11">11</span>
          <span class="line-number" id="file-gistfile1-php-L12" rel="file-gistfile1-php-L12">12</span>
          <span class="line-number" id="file-gistfile1-php-L13" rel="file-gistfile1-php-L13">13</span>
          <span class="line-number" id="file-gistfile1-php-L14" rel="file-gistfile1-php-L14">14</span>
          <span class="line-number" id="file-gistfile1-php-L15" rel="file-gistfile1-php-L15">15</span>
          <span class="line-number" id="file-gistfile1-php-L16" rel="file-gistfile1-php-L16">16</span>
          <span class="line-number" id="file-gistfile1-php-L17" rel="file-gistfile1-php-L17">17</span>
          <span class="line-number" id="file-gistfile1-php-L18" rel="file-gistfile1-php-L18">18</span>
          <span class="line-number" id="file-gistfile1-php-L19" rel="file-gistfile1-php-L19">19</span>
          <span class="line-number" id="file-gistfile1-php-L20" rel="file-gistfile1-php-L20">20</span>
          <span class="line-number" id="file-gistfile1-php-L21" rel="file-gistfile1-php-L21">21</span>
          <span class="line-number" id="file-gistfile1-php-L22" rel="file-gistfile1-php-L22">22</span>
          <span class="line-number" id="file-gistfile1-php-L23" rel="file-gistfile1-php-L23">23</span>
          <span class="line-number" id="file-gistfile1-php-L24" rel="file-gistfile1-php-L24">24</span>
          <span class="line-number" id="file-gistfile1-php-L25" rel="file-gistfile1-php-L25">25</span>
          <span class="line-number" id="file-gistfile1-php-L26" rel="file-gistfile1-php-L26">26</span>
          <span class="line-number" id="file-gistfile1-php-L27" rel="file-gistfile1-php-L27">27</span>
          <span class="line-number" id="file-gistfile1-php-L28" rel="file-gistfile1-php-L28">28</span>
          <span class="line-number" id="file-gistfile1-php-L29" rel="file-gistfile1-php-L29">29</span>
          <span class="line-number" id="file-gistfile1-php-L30" rel="file-gistfile1-php-L30">30</span>
          <span class="line-number" id="file-gistfile1-php-L31" rel="file-gistfile1-php-L31">31</span>
          <span class="line-number" id="file-gistfile1-php-L32" rel="file-gistfile1-php-L32">32</span>
          <span class="line-number" id="file-gistfile1-php-L33" rel="file-gistfile1-php-L33">33</span>
          <span class="line-number" id="file-gistfile1-php-L34" rel="file-gistfile1-php-L34">34</span>
          <span class="line-number" id="file-gistfile1-php-L35" rel="file-gistfile1-php-L35">35</span>
          <span class="line-number" id="file-gistfile1-php-L36" rel="file-gistfile1-php-L36">36</span>
          <span class="line-number" id="file-gistfile1-php-L37" rel="file-gistfile1-php-L37">37</span>
          <span class="line-number" id="file-gistfile1-php-L38" rel="file-gistfile1-php-L38">38</span>
          <span class="line-number" id="file-gistfile1-php-L39" rel="file-gistfile1-php-L39">39</span>
          <span class="line-number" id="file-gistfile1-php-L40" rel="file-gistfile1-php-L40">40</span>
          <span class="line-number" id="file-gistfile1-php-L41" rel="file-gistfile1-php-L41">41</span>
          <span class="line-number" id="file-gistfile1-php-L42" rel="file-gistfile1-php-L42">42</span>
          <span class="line-number" id="file-gistfile1-php-L43" rel="file-gistfile1-php-L43">43</span>
          <span class="line-number" id="file-gistfile1-php-L44" rel="file-gistfile1-php-L44">44</span>
          <span class="line-number" id="file-gistfile1-php-L45" rel="file-gistfile1-php-L45">45</span>
          <span class="line-number" id="file-gistfile1-php-L46" rel="file-gistfile1-php-L46">46</span>
          <span class="line-number" id="file-gistfile1-php-L47" rel="file-gistfile1-php-L47">47</span>
          <span class="line-number" id="file-gistfile1-php-L48" rel="file-gistfile1-php-L48">48</span>
          <span class="line-number" id="file-gistfile1-php-L49" rel="file-gistfile1-php-L49">49</span>
          <span class="line-number" id="file-gistfile1-php-L50" rel="file-gistfile1-php-L50">50</span>
          <span class="line-number" id="file-gistfile1-php-L51" rel="file-gistfile1-php-L51">51</span>
          <span class="line-number" id="file-gistfile1-php-L52" rel="file-gistfile1-php-L52">52</span>
          <span class="line-number" id="file-gistfile1-php-L53" rel="file-gistfile1-php-L53">53</span>
          <span class="line-number" id="file-gistfile1-php-L54" rel="file-gistfile1-php-L54">54</span>
          <span class="line-number" id="file-gistfile1-php-L55" rel="file-gistfile1-php-L55">55</span>
          <span class="line-number" id="file-gistfile1-php-L56" rel="file-gistfile1-php-L56">56</span>
          <span class="line-number" id="file-gistfile1-php-L57" rel="file-gistfile1-php-L57">57</span>
          <span class="line-number" id="file-gistfile1-php-L58" rel="file-gistfile1-php-L58">58</span>
          <span class="line-number" id="file-gistfile1-php-L59" rel="file-gistfile1-php-L59">59</span>
          <span class="line-number" id="file-gistfile1-php-L60" rel="file-gistfile1-php-L60">60</span>
          <span class="line-number" id="file-gistfile1-php-L61" rel="file-gistfile1-php-L61">61</span>
          <span class="line-number" id="file-gistfile1-php-L62" rel="file-gistfile1-php-L62">62</span>
          <span class="line-number" id="file-gistfile1-php-L63" rel="file-gistfile1-php-L63">63</span>
          <span class="line-number" id="file-gistfile1-php-L64" rel="file-gistfile1-php-L64">64</span>
          <span class="line-number" id="file-gistfile1-php-L65" rel="file-gistfile1-php-L65">65</span>
          <span class="line-number" id="file-gistfile1-php-L66" rel="file-gistfile1-php-L66">66</span>
          <span class="line-number" id="file-gistfile1-php-L67" rel="file-gistfile1-php-L67">67</span>
          <span class="line-number" id="file-gistfile1-php-L68" rel="file-gistfile1-php-L68">68</span>
          <span class="line-number" id="file-gistfile1-php-L69" rel="file-gistfile1-php-L69">69</span>
          <span class="line-number" id="file-gistfile1-php-L70" rel="file-gistfile1-php-L70">70</span>
          <span class="line-number" id="file-gistfile1-php-L71" rel="file-gistfile1-php-L71">71</span>
          <span class="line-number" id="file-gistfile1-php-L72" rel="file-gistfile1-php-L72">72</span>
          <span class="line-number" id="file-gistfile1-php-L73" rel="file-gistfile1-php-L73">73</span>
          <span class="line-number" id="file-gistfile1-php-L74" rel="file-gistfile1-php-L74">74</span>
          <span class="line-number" id="file-gistfile1-php-L75" rel="file-gistfile1-php-L75">75</span>
          <span class="line-number" id="file-gistfile1-php-L76" rel="file-gistfile1-php-L76">76</span>
          <span class="line-number" id="file-gistfile1-php-L77" rel="file-gistfile1-php-L77">77</span>
          <span class="line-number" id="file-gistfile1-php-L78" rel="file-gistfile1-php-L78">78</span>
          <span class="line-number" id="file-gistfile1-php-L79" rel="file-gistfile1-php-L79">79</span>
          <span class="line-number" id="file-gistfile1-php-L80" rel="file-gistfile1-php-L80">80</span>
          <span class="line-number" id="file-gistfile1-php-L81" rel="file-gistfile1-php-L81">81</span>
          <span class="line-number" id="file-gistfile1-php-L82" rel="file-gistfile1-php-L82">82</span>
          <span class="line-number" id="file-gistfile1-php-L83" rel="file-gistfile1-php-L83">83</span>
          <span class="line-number" id="file-gistfile1-php-L84" rel="file-gistfile1-php-L84">84</span>
          <span class="line-number" id="file-gistfile1-php-L85" rel="file-gistfile1-php-L85">85</span>
          <span class="line-number" id="file-gistfile1-php-L86" rel="file-gistfile1-php-L86">86</span>
          <span class="line-number" id="file-gistfile1-php-L87" rel="file-gistfile1-php-L87">87</span>
          <span class="line-number" id="file-gistfile1-php-L88" rel="file-gistfile1-php-L88">88</span>
          <span class="line-number" id="file-gistfile1-php-L89" rel="file-gistfile1-php-L89">89</span>
          <span class="line-number" id="file-gistfile1-php-L90" rel="file-gistfile1-php-L90">90</span>
          <span class="line-number" id="file-gistfile1-php-L91" rel="file-gistfile1-php-L91">91</span>
          <span class="line-number" id="file-gistfile1-php-L92" rel="file-gistfile1-php-L92">92</span>
          <span class="line-number" id="file-gistfile1-php-L93" rel="file-gistfile1-php-L93">93</span>
          <span class="line-number" id="file-gistfile1-php-L94" rel="file-gistfile1-php-L94">94</span>
        </td>
        <td class="line-data">
          <pre class="line-pre"><div class="line" id="file-gistfile1-php-LC1"><span class="cp">&lt;?php</span></div><div class="line" id="file-gistfile1-php-LC2">&nbsp;</div><div class="line" id="file-gistfile1-php-LC3"><span class="sd">/**</span></div><div class="line" id="file-gistfile1-php-LC4"><span class="sd">* Better Limit Submissions Per Time Period by User or IP</span></div><div class="line" id="file-gistfile1-php-LC5"><span class="sd">* http://gravitywiz.com/2012/05/12/limit-ip-to-one-submission-per-time-period</span></div><div class="line" id="file-gistfile1-php-LC6"><span class="sd">*/</span></div><div class="line" id="file-gistfile1-php-LC7">&nbsp;</div><div class="line" id="file-gistfile1-php-LC8"><span class="k">class</span> <span class="nc">GWSubmissionLimit</span> <span class="p">{</span></div><div class="line" id="file-gistfile1-php-LC9">    </div><div class="line" id="file-gistfile1-php-LC10">    <span class="k">private</span> <span class="nv">$_args</span><span class="p">;</span></div><div class="line" id="file-gistfile1-php-LC11">    </div><div class="line" id="file-gistfile1-php-LC12">    <span class="k">function</span> <span class="nf">__construct</span><span class="p">(</span><span class="nv">$args</span><span class="p">)</span> <span class="p">{</span></div><div class="line" id="file-gistfile1-php-LC13">        </div><div class="line" id="file-gistfile1-php-LC14">        <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">_args</span> <span class="o">=</span> <span class="nx">wp_parse_args</span><span class="p">(</span><span class="nv">$args</span><span class="p">,</span> <span class="k">array</span><span class="p">(</span></div><div class="line" id="file-gistfile1-php-LC15">            <span class="s1">&#39;form_id&#39;</span> <span class="o">=&gt;</span> <span class="k">false</span><span class="p">,</span></div><div class="line" id="file-gistfile1-php-LC16">            <span class="s1">&#39;limit&#39;</span> <span class="o">=&gt;</span> <span class="mi">1</span><span class="p">,</span></div><div class="line" id="file-gistfile1-php-LC17">            <span class="s1">&#39;time_period&#39;</span> <span class="o">=&gt;</span> <span class="mi">60</span> <span class="o">*</span> <span class="mi">60</span> <span class="o">*</span> <span class="mi">24</span><span class="p">,</span> <span class="c1">// must be provided in seconds: 60 seconds in a minute, 60 minutes in an hour, 24 hours in a day</span></div><div class="line" id="file-gistfile1-php-LC18">            <span class="s1">&#39;limit_message&#39;</span> <span class="o">=&gt;</span> <span class="nx">__</span><span class="p">(</span><span class="s1">&#39;Sorry, you have reached the submission limit for this form.&#39;</span><span class="p">),</span></div><div class="line" id="file-gistfile1-php-LC19">            <span class="s1">&#39;limit_by&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;ip&#39;</span> <span class="c1">// also accepts &quot;user_id&quot;</span></div><div class="line" id="file-gistfile1-php-LC20">            <span class="p">));</span></div><div class="line" id="file-gistfile1-php-LC21">        </div><div class="line" id="file-gistfile1-php-LC22">        <span class="nv">$form_filter</span> <span class="o">=</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">_args</span><span class="p">[</span><span class="s1">&#39;form_id&#39;</span><span class="p">]</span> <span class="o">?</span> <span class="s2">&quot;_</span><span class="si">{</span><span class="nv">$this</span><span class="o">-&gt;</span><span class="na">_args</span><span class="p">[</span><span class="s1">&#39;form_id&#39;</span><span class="p">]</span><span class="si">}</span><span class="s2">&quot;</span> <span class="o">:</span> <span class="s1">&#39;&#39;</span><span class="p">;</span></div><div class="line" id="file-gistfile1-php-LC23">        </div><div class="line" id="file-gistfile1-php-LC24">        <span class="nx">add_filter</span><span class="p">(</span><span class="s2">&quot;gform_pre_render</span><span class="si">{</span><span class="nv">$form_filter</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">,</span> <span class="k">array</span><span class="p">(</span><span class="nv">$this</span><span class="p">,</span> <span class="s1">&#39;pre_render&#39;</span><span class="p">));</span></div><div class="line" id="file-gistfile1-php-LC25">        <span class="nx">add_filter</span><span class="p">(</span><span class="s2">&quot;gform_validation</span><span class="si">{</span><span class="nv">$form_filter</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">,</span> <span class="k">array</span><span class="p">(</span><span class="nv">$this</span><span class="p">,</span> <span class="s1">&#39;validate&#39;</span><span class="p">));</span></div><div class="line" id="file-gistfile1-php-LC26">        </div><div class="line" id="file-gistfile1-php-LC27">    <span class="p">}</span></div><div class="line" id="file-gistfile1-php-LC28">    </div><div class="line" id="file-gistfile1-php-LC29">    <span class="k">function</span> <span class="nf">pre_render</span><span class="p">(</span><span class="nv">$form</span><span class="p">)</span> <span class="p">{</span></div><div class="line" id="file-gistfile1-php-LC30">        </div><div class="line" id="file-gistfile1-php-LC31">        <span class="k">if</span><span class="p">(</span> <span class="o">!</span><span class="nv">$this</span><span class="o">-&gt;</span><span class="na">is_limit_reached</span><span class="p">(</span><span class="nv">$form</span><span class="p">[</span><span class="s1">&#39;id&#39;</span><span class="p">])</span> <span class="p">)</span></div><div class="line" id="file-gistfile1-php-LC32">            <span class="k">return</span> <span class="nv">$form</span><span class="p">;</span></div><div class="line" id="file-gistfile1-php-LC33">    </div><div class="line" id="file-gistfile1-php-LC34">        <span class="nv">$submission_info</span> <span class="o">=</span> <span class="nx">rgar</span><span class="p">(</span><span class="nx">GFFormDisplay</span><span class="o">::</span><span class="nv">$submission</span><span class="p">,</span> <span class="nv">$form</span><span class="p">[</span><span class="s1">&#39;id&#39;</span><span class="p">]);</span></div><div class="line" id="file-gistfile1-php-LC35">    </div><div class="line" id="file-gistfile1-php-LC36">        <span class="c1">// if no submission, hide form</span></div><div class="line" id="file-gistfile1-php-LC37">        <span class="c1">// if submission and not valid, hide form</span></div><div class="line" id="file-gistfile1-php-LC38">        <span class="k">if</span><span class="p">(</span><span class="o">!</span><span class="nv">$submission_info</span> <span class="o">||</span> <span class="o">!</span><span class="nx">rgar</span><span class="p">(</span><span class="nv">$submission_info</span><span class="p">,</span> <span class="s1">&#39;is_valid&#39;</span><span class="p">))</span> <span class="p">{</span></div><div class="line" id="file-gistfile1-php-LC39">            <span class="nx">add_filter</span><span class="p">(</span><span class="s1">&#39;gform_get_form_filter&#39;</span><span class="p">,</span> <span class="nb">create_function</span><span class="p">(</span><span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="s2">&quot;return &#39;&lt;div class=</span><span class="se">&quot;</span><span class="s2">limit-message</span><span class="se">&quot;</span><span class="s2">&gt;</span><span class="si">{</span><span class="nv">$this</span><span class="o">-&gt;</span><span class="na">_args</span><span class="p">[</span><span class="s1">&#39;limit_message&#39;</span><span class="p">]</span><span class="si">}</span><span class="s2">&lt;/div&gt;&#39;;&quot;</span><span class="p">)</span> <span class="p">);</span></div><div class="line" id="file-gistfile1-php-LC40">            <span class="c1">//add_filter(&#39;gform_get_form_filter&#39;, create_function(&#39;$form_string, $form&#39;, &#39;return $form[&quot;id&quot;] == &#39; . $form[&#39;id&#39;] . &#39; ? &#39;&lt;div class=&quot;limit-message&quot;&gt;&#39; . $this-&gt;_args[&#39;limit_message&#39;] . &#39;&lt;/div&gt;&#39; : $form_string;&#39;), 10, 2 );</span></div><div class="line" id="file-gistfile1-php-LC41">        <span class="p">}</span></div><div class="line" id="file-gistfile1-php-LC42">         </div><div class="line" id="file-gistfile1-php-LC43">        <span class="k">return</span> <span class="nv">$form</span><span class="p">;</span></div><div class="line" id="file-gistfile1-php-LC44">        </div><div class="line" id="file-gistfile1-php-LC45">    <span class="p">}</span></div><div class="line" id="file-gistfile1-php-LC46">    </div><div class="line" id="file-gistfile1-php-LC47">    <span class="k">function</span> <span class="nf">validate</span><span class="p">(</span><span class="nv">$validation_result</span><span class="p">)</span> <span class="p">{</span></div><div class="line" id="file-gistfile1-php-LC48">    </div><div class="line" id="file-gistfile1-php-LC49">        <span class="k">if</span><span class="p">(</span><span class="nv">$this</span><span class="o">-&gt;</span><span class="na">is_limit_reached</span><span class="p">(</span><span class="nv">$validation_result</span><span class="p">[</span><span class="s1">&#39;form&#39;</span><span class="p">][</span><span class="s1">&#39;id&#39;</span><span class="p">]))</span></div><div class="line" id="file-gistfile1-php-LC50">            <span class="nv">$validation_result</span><span class="p">[</span><span class="s1">&#39;is_valid&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="k">false</span><span class="p">;</span></div><div class="line" id="file-gistfile1-php-LC51">        </div><div class="line" id="file-gistfile1-php-LC52">        <span class="k">return</span> <span class="nv">$validation_result</span><span class="p">;</span></div><div class="line" id="file-gistfile1-php-LC53">    <span class="p">}</span></div><div class="line" id="file-gistfile1-php-LC54">    </div><div class="line" id="file-gistfile1-php-LC55">    <span class="k">public</span> <span class="k">function</span> <span class="nf">is_limit_reached</span><span class="p">(</span><span class="nv">$form_id</span><span class="p">)</span> <span class="p">{</span></div><div class="line" id="file-gistfile1-php-LC56">        <span class="k">global</span> <span class="nv">$wpdb</span><span class="p">;</span></div><div class="line" id="file-gistfile1-php-LC57">        </div><div class="line" id="file-gistfile1-php-LC58">        <span class="nv">$limit_by</span> <span class="o">=</span> <span class="nb">is_array</span><span class="p">(</span><span class="nv">$this</span><span class="o">-&gt;</span><span class="na">_args</span><span class="p">[</span><span class="s1">&#39;limit_by&#39;</span><span class="p">])</span> <span class="o">?</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">_args</span><span class="p">[</span><span class="s1">&#39;limit_by&#39;</span><span class="p">]</span> <span class="o">:</span> <span class="k">array</span><span class="p">(</span><span class="nv">$this</span><span class="o">-&gt;</span><span class="na">_args</span><span class="p">[</span><span class="s1">&#39;limit_by&#39;</span><span class="p">]);</span></div><div class="line" id="file-gistfile1-php-LC59">        <span class="nv">$where</span> <span class="o">=</span> <span class="k">array</span><span class="p">();</span></div><div class="line" id="file-gistfile1-php-LC60">        </div><div class="line" id="file-gistfile1-php-LC61">        <span class="k">foreach</span><span class="p">(</span><span class="nv">$limit_by</span> <span class="k">as</span> <span class="nv">$limiter</span><span class="p">)</span> <span class="p">{</span></div><div class="line" id="file-gistfile1-php-LC62">            <span class="k">switch</span><span class="p">(</span><span class="nv">$limiter</span><span class="p">)</span> <span class="p">{</span></div><div class="line" id="file-gistfile1-php-LC63">            <span class="k">case</span> <span class="s1">&#39;user_id&#39;</span><span class="o">:</span></div><div class="line" id="file-gistfile1-php-LC64">                <span class="nv">$where</span><span class="p">[]</span> <span class="o">=</span> <span class="nv">$wpdb</span><span class="o">-&gt;</span><span class="na">prepare</span><span class="p">(</span><span class="s1">&#39;created_by = %s&#39;</span><span class="p">,</span> <span class="nx">get_current_user_id</span><span class="p">());</span></div><div class="line" id="file-gistfile1-php-LC65">                <span class="k">break</span><span class="p">;</span></div><div class="line" id="file-gistfile1-php-LC66">            <span class="k">case</span> <span class="s1">&#39;embed_url&#39;</span><span class="o">:</span></div><div class="line" id="file-gistfile1-php-LC67">                <span class="nv">$where</span><span class="p">[]</span> <span class="o">=</span> <span class="nv">$wpdb</span><span class="o">-&gt;</span><span class="na">prepare</span><span class="p">(</span><span class="s1">&#39;source_url = %s&#39;</span><span class="p">,</span> <span class="nx">RGFormsModel</span><span class="o">::</span><span class="na">get_current_page_url</span><span class="p">());</span></div><div class="line" id="file-gistfile1-php-LC68">                <span class="k">break</span><span class="p">;</span></div><div class="line" id="file-gistfile1-php-LC69">            <span class="k">default</span><span class="o">:</span></div><div class="line" id="file-gistfile1-php-LC70">                <span class="nv">$where</span><span class="p">[]</span> <span class="o">=</span> <span class="nv">$wpdb</span><span class="o">-&gt;</span><span class="na">prepare</span><span class="p">(</span><span class="s1">&#39;ip = %s&#39;</span><span class="p">,</span> <span class="nx">RGFormsModel</span><span class="o">::</span><span class="na">get_ip</span><span class="p">());</span></div><div class="line" id="file-gistfile1-php-LC71">            <span class="p">}</span></div><div class="line" id="file-gistfile1-php-LC72">        <span class="p">}</span></div><div class="line" id="file-gistfile1-php-LC73">        </div><div class="line" id="file-gistfile1-php-LC74">        <span class="nv">$where</span><span class="p">[]</span> <span class="o">=</span> <span class="nv">$wpdb</span><span class="o">-&gt;</span><span class="na">prepare</span><span class="p">(</span><span class="s1">&#39;form_id = %d&#39;</span><span class="p">,</span> <span class="nv">$form_id</span><span class="p">);</span></div><div class="line" id="file-gistfile1-php-LC75">        <span class="nv">$where</span><span class="p">[]</span> <span class="o">=</span> <span class="nv">$wpdb</span><span class="o">-&gt;</span><span class="na">prepare</span><span class="p">(</span><span class="s1">&#39;date_created BETWEEN DATE_SUB(utc_timestamp(), INTERVAL %d SECOND) AND utc_timestamp()&#39;</span><span class="p">,</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">_args</span><span class="p">[</span><span class="s1">&#39;time_period&#39;</span><span class="p">]);</span></div><div class="line" id="file-gistfile1-php-LC76">        <span class="nv">$where</span> <span class="o">=</span> <span class="nb">implode</span><span class="p">(</span><span class="s1">&#39; AND &#39;</span><span class="p">,</span> <span class="nv">$where</span><span class="p">);</span></div><div class="line" id="file-gistfile1-php-LC77">        </div><div class="line" id="file-gistfile1-php-LC78">        <span class="nv">$sql</span> <span class="o">=</span> <span class="s2">&quot;SELECT count(id)</span></div><div class="line" id="file-gistfile1-php-LC79"><span class="s2">                FROM </span><span class="si">{</span><span class="nv">$wpdb</span><span class="o">-&gt;</span><span class="na">prefix</span><span class="si">}</span><span class="s2">rg_lead</span></div><div class="line" id="file-gistfile1-php-LC80"><span class="s2">                WHERE </span><span class="si">$where</span><span class="s2">&quot;</span><span class="p">;</span></div><div class="line" id="file-gistfile1-php-LC81">        </div><div class="line" id="file-gistfile1-php-LC82">        <span class="nv">$entry_count</span> <span class="o">=</span> <span class="nv">$wpdb</span><span class="o">-&gt;</span><span class="na">get_var</span><span class="p">(</span><span class="nv">$sql</span><span class="p">);</span></div><div class="line" id="file-gistfile1-php-LC83">        </div><div class="line" id="file-gistfile1-php-LC84">        <span class="k">return</span> <span class="nv">$entry_count</span> <span class="o">&gt;=</span> <span class="nv">$this</span><span class="o">-&gt;</span><span class="na">_args</span><span class="p">[</span><span class="s1">&#39;limit&#39;</span><span class="p">];</span></div><div class="line" id="file-gistfile1-php-LC85">    <span class="p">}</span></div><div class="line" id="file-gistfile1-php-LC86">    </div><div class="line" id="file-gistfile1-php-LC87"><span class="p">}</span></div><div class="line" id="file-gistfile1-php-LC88">&nbsp;</div><div class="line" id="file-gistfile1-php-LC89"><span class="c1">// standard usage</span></div><div class="line" id="file-gistfile1-php-LC90"><span class="k">new</span> <span class="nx">GWSubmissionLimit</span><span class="p">(</span><span class="k">array</span><span class="p">(</span></div><div class="line" id="file-gistfile1-php-LC91">    <span class="s1">&#39;form_id&#39;</span> <span class="o">=&gt;</span> <span class="mi">86</span><span class="p">,</span></div><div class="line" id="file-gistfile1-php-LC92">    <span class="s1">&#39;limit&#39;</span> <span class="o">=&gt;</span> <span class="mi">2</span><span class="p">,</span></div><div class="line" id="file-gistfile1-php-LC93">    <span class="s1">&#39;limit_message&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;Aha! You have been limited.&#39;</span></div><div class="line" id="file-gistfile1-php-LC94">    <span class="p">));</span></div></pre>
        </td>
      </tr>
    </table>
  </div>

        </div>

        <div class="gist-meta">
          <a href="https://gist.github.com/spivurno/4024361/raw/37b8af881fc0f01e86189ec49941d781004da1ac/gistfile1.php" style="float:right">view raw</a>
          <a href="https://gist.github.com/spivurno/4024361#file-gistfile1-php" style="float:right; margin-right:10px; color:#666;">gistfile1.php</a>
          <a href="https://gist.github.com/spivurno/4024361">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.
        </div>
      </div>
</div>


<h3>How do I install this snippet?</h3><p>Easy peasy. Just copy and paste the code above into your theme's <em>functions.php</em> file.</p>

<h3>How to I use this functionality?</h3>

<p>All you need to do is create a new instance of the <code>GWSubmissionLimit()</code> class, populated with your specific details, like so:</p>

<div id="gist4024503" class="gist">       <div class="gist-file">         <div class="gist-data gist-syntax">      <div class="file-data">     <table cellpadding="0" cellspacing="0" class="lines highlight">       <tr>         <td class="line-numbers">                                            <span class="line-number" id="file-gistfile1-php-L4" rel="file-gistfile1-php-L4">4</span>           <span class="line-number" id="file-gistfile1-php-L5" rel="file-gistfile1-php-L5">5</span>           <span class="line-number" id="file-gistfile1-php-L6" rel="file-gistfile1-php-L6">6</span>           <span class="line-number" id="file-gistfile1-php-L7" rel="file-gistfile1-php-L7">7</span>                                                                                                                                                                                                                                                           </td>         <td class="line-data">           <pre class="line-pre"><div class="line" id="file-gistfile1-php-LC4"><span class="k">new</span> <span class="nx">GWSubmissionLimit</span><span class="p">(</span><span class="k">array</span><span class="p">(</span></div><div class="line" id="file-gistfile1-php-LC5">    <span class="s1">&#39;form_id&#39;</span> <span class="o">=&gt;</span> <span class="mi">86</span><span class="p">,</span></div><div class="line" id="file-gistfile1-php-LC6">    <span class="s1">&#39;limit&#39;</span> <span class="o">=&gt;</span> <span class="mi">2</span><span class="p">,</span></div><div class="line" id="file-gistfile1-php-LC7">    <span class="p">));</span></div></pre>         </td>       </tr>     </table>   </div>          </div>          <div class="gist-meta">           <a href="https://gist.github.com/spivurno/4024503/raw/82c729c650917cf135fb422b6f59565aa237dc85/gistfile1.php" style="float:right">view raw</a>           <a href="https://gist.github.com/spivurno/4024503#file-gistfile1-php" style="float:right; margin-right:10px; color:#666;">gistfile1.php</a>           <a href="https://gist.github.com/spivurno/4024503">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.         </div>       </div> </div> 

<p>Want to apply the same submission limit to all forms?</p>

<div id="gist4024503" class="gist">       <div class="gist-file">         <div class="gist-data gist-syntax">      <div class="file-data">     <table cellpadding="0" cellspacing="0" class="lines highlight">       <tr>         <td class="line-numbers">                                                                                                                                                                                                                 <span class="line-number" id="file-gistfile1-php-L19" rel="file-gistfile1-php-L19">19</span>           <span class="line-number" id="file-gistfile1-php-L20" rel="file-gistfile1-php-L20">20</span>           <span class="line-number" id="file-gistfile1-php-L21" rel="file-gistfile1-php-L21">21</span>                                                                                                 </td>         <td class="line-data">           <pre class="line-pre"><div class="line" id="file-gistfile1-php-LC19"><span class="k">new</span> <span class="nx">GWSubmissionLimit</span><span class="p">(</span><span class="k">array</span><span class="p">(</span></div><div class="line" id="file-gistfile1-php-LC20">    <span class="s1">&#39;limit&#39;</span> <span class="o">=&gt;</span> <span class="mi">5</span></div><div class="line" id="file-gistfile1-php-LC21">    <span class="p">));</span></div></pre>         </td>       </tr>     </table>   </div>          </div>          <div class="gist-meta">           <a href="https://gist.github.com/spivurno/4024503/raw/82c729c650917cf135fb422b6f59565aa237dc85/gistfile1.php" style="float:right">view raw</a>           <a href="https://gist.github.com/spivurno/4024503#file-gistfile1-php" style="float:right; margin-right:10px; color:#666;">gistfile1.php</a>           <a href="https://gist.github.com/spivurno/4024503">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.         </div>       </div> </div> 

<p>Want to apply multiple limitations? This example allows you to limit the number of a submissions a logged in user can make to specific form from the same embed URL. This would allow you embed the same form on multiple pages and allow users to submit that form up to the submission limit on each page.</p>

<div id="gist4024503" class="gist">       <div class="gist-file">         <div class="gist-data gist-syntax">      <div class="file-data">     <table cellpadding="0" cellspacing="0" class="lines highlight">       <tr>         <td class="line-numbers">                                                                                                                                                                                                                                                                        <span class="line-number" id="file-gistfile1-php-L24" rel="file-gistfile1-php-L24">24</span>           <span class="line-number" id="file-gistfile1-php-L25" rel="file-gistfile1-php-L25">25</span>           <span class="line-number" id="file-gistfile1-php-L26" rel="file-gistfile1-php-L26">26</span>           <span class="line-number" id="file-gistfile1-php-L27" rel="file-gistfile1-php-L27">27</span>           <span class="line-number" id="file-gistfile1-php-L28" rel="file-gistfile1-php-L28">28</span>           <span class="line-number" id="file-gistfile1-php-L29" rel="file-gistfile1-php-L29">29</span>         </td>         <td class="line-data">           <pre class="line-pre"><div class="line" id="file-gistfile1-php-LC24"><span class="k">new</span> <span class="nx">GWSubmissionLimit</span><span class="p">(</span><span class="k">array</span><span class="p">(</span></div><div class="line" id="file-gistfile1-php-LC25">    <span class="s1">&#39;form_id&#39;</span> <span class="o">=&gt;</span> <span class="mi">2</span><span class="p">,</span></div><div class="line" id="file-gistfile1-php-LC26">    <span class="s1">&#39;limit&#39;</span> <span class="o">=&gt;</span> <span class="mi">1</span><span class="p">,</span></div><div class="line" id="file-gistfile1-php-LC27">    <span class="s1">&#39;limit_message&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;Aha! You have been limited.&#39;</span><span class="p">,</span></div><div class="line" id="file-gistfile1-php-LC28">    <span class="s1">&#39;limit_by&#39;</span> <span class="o">=&gt;</span> <span class="k">array</span><span class="p">(</span><span class="s1">&#39;embed_url&#39;</span><span class="p">,</span> <span class="s1">&#39;user_id&#39;</span><span class="p">)</span></div><div class="line" id="file-gistfile1-php-LC29">    <span class="p">));</span></div></pre>         </td>       </tr>     </table>   </div>          </div>          <div class="gist-meta">           <a href="https://gist.github.com/spivurno/4024503/raw/82c729c650917cf135fb422b6f59565aa237dc85/gistfile1.php" style="float:right">view raw</a>           <a href="https://gist.github.com/spivurno/4024503#file-gistfile1-php" style="float:right; margin-right:10px; color:#666;">gistfile1.php</a>           <a href="https://gist.github.com/spivurno/4024503">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.         </div>       </div> </div> 

<p>Here is a full list of available options:</p>

<div id="gist4024503" class="gist">       <div class="gist-file">         <div class="gist-data gist-syntax">      <div class="file-data">     <table cellpadding="0" cellspacing="0" class="lines highlight">       <tr>         <td class="line-numbers">                                                                                                              <span class="line-number" id="file-gistfile1-php-L10" rel="file-gistfile1-php-L10">10</span>           <span class="line-number" id="file-gistfile1-php-L11" rel="file-gistfile1-php-L11">11</span>           <span class="line-number" id="file-gistfile1-php-L12" rel="file-gistfile1-php-L12">12</span>           <span class="line-number" id="file-gistfile1-php-L13" rel="file-gistfile1-php-L13">13</span>           <span class="line-number" id="file-gistfile1-php-L14" rel="file-gistfile1-php-L14">14</span>           <span class="line-number" id="file-gistfile1-php-L15" rel="file-gistfile1-php-L15">15</span>           <span class="line-number" id="file-gistfile1-php-L16" rel="file-gistfile1-php-L16">16</span>                                                                                                                                                        </td>         <td class="line-data">           <pre class="line-pre"><div class="line" id="file-gistfile1-php-LC10"><span class="k">new</span> <span class="nx">GWSubmissionLimit</span><span class="p">(</span><span class="k">array</span><span class="p">(</span></div><div class="line" id="file-gistfile1-php-LC11">    <span class="s1">&#39;form_id&#39;</span> <span class="o">=&gt;</span> <span class="mi">2</span><span class="p">,</span></div><div class="line" id="file-gistfile1-php-LC12">    <span class="s1">&#39;limit&#39;</span> <span class="o">=&gt;</span> <span class="mi">5</span><span class="p">,</span></div><div class="line" id="file-gistfile1-php-LC13">    <span class="s1">&#39;time_period&#39;</span> <span class="o">=&gt;</span> <span class="mi">60</span> <span class="o">*</span> <span class="mi">60</span> <span class="o">*</span> <span class="mi">24</span> <span class="o">*</span> <span class="mi">2</span><span class="p">,</span> <span class="c1">// two days in seconds</span></div><div class="line" id="file-gistfile1-php-LC14">    <span class="s1">&#39;limit_message&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;You are all maxed out! Try again in a couple days.&#39;</span><span class="p">,</span></div><div class="line" id="file-gistfile1-php-LC15">    <span class="s1">&#39;limit_by&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;ip&#39;</span><span class="p">,</span> <span class="c1">// default is &#39;ip&#39;, also supports &#39;user_id&#39; and &#39;embed_url&#39;; can alternately provide an array of limitations: array(&#39;ip&#39;, &#39;embed_url&#39;)</span></div><div class="line" id="file-gistfile1-php-LC16">    <span class="p">));</span></div></pre>         </td>       </tr>     </table>   </div>          </div>          <div class="gist-meta">           <a href="https://gist.github.com/spivurno/4024503/raw/82c729c650917cf135fb422b6f59565aa237dc85/gistfile1.php" style="float:right">view raw</a>           <a href="https://gist.github.com/spivurno/4024503#file-gistfile1-php" style="float:right; margin-right:10px; color:#666;">gistfile1.php</a>           <a href="https://gist.github.com/spivurno/4024503">This Gist</a> brought to you by <a href="http://github.com">GitHub</a>.         </div>       </div> </div> 

<ul>
<li><code>form_id</code> The form ID of the form you would like to limit. If you want to apply the the same submission limit to all forms, set the <code>form_id</code> as <code>false</code> or do not provide it at all.</li>
<li><code>limit</code> The number of submissions allowed before the user will no longer be able to make additional submission.</li>
<li><code>time_period</code> The period of time to which the <code>limit</code> applies. The default time period is one day. In any 24 hour period, if the user reaches the <code>limit</code> they will no longer be able to make new submissions.</li>
<li><code>limit_message</code> The message which should be displayed to the user once they have reached the specified submission limit.</li>
<li><code>limit_by</code> Specify which identifying data the user should be limited by. The default is <code>ip</code>. <code>user_id</code> is also supported which allows you to limit logged in WP users. <code>embed_url</code> is now supported to limit submissions of a form from a specific embed URL.</li>
</ul>
<p>The post <a href="http://gravitywiz.com/better-limit-submission-per-time-period-by-user-or-ip/">Better Limit Submission Per Time Period by User or IP</a> appeared first on <a href="http://gravitywiz.com">Gravity Wiz</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://gravitywiz.com/better-limit-submission-per-time-period-by-user-or-ip/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
	</channel>
</rss>
