<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="bbPress/1.0.1" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>Gravity Support Forums Topic: Else If PHP Statement</title>
		<link>https://legacy.forums.gravityhelp.com/topic/else-if-php-statement</link>
		<description>Gravity Support Forums Topic: Else If PHP Statement</description>
		<language>en-US</language>
		<pubDate>Sat, 04 Apr 2026 07:51:24 +0000</pubDate>
		<generator>http://bbpress.org/?v=1.0.1</generator>
		<textInput>
			<title><![CDATA[Search]]></title>
			<description><![CDATA[Search all topics from these forums.]]></description>
			<name>q</name>
			<link>https://legacy.forums.gravityhelp.com/search.php</link>
		</textInput>
		<atom:link href="https://legacy.forums.gravityhelp.com/rss/topic/else-if-php-statement" rel="self" type="application/rss+xml" />

		<item>
			<title>Chris Hajer on "Else If PHP Statement"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/else-if-php-statement#post-34513</link>
			<pubDate>Mon, 05 Sep 2011 23:36:39 +0000</pubDate>
			<dc:creator>Chris Hajer</dc:creator>
			<guid isPermaLink="false">34513@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Sounds like the code in your second block there should work for form 12.  You just need to find a hook to use that is fired when your requirement is satisfied.  If that's &#60;a href=&#34;http://www.gravityhelp.com/documentation/page/Gform_paypal_fulfillment&#34; rel=&#34;nofollow&#34;&#62;gform_paypal_fulfillment&#60;/a&#62; in your case, it's perfectly OK to hook your function to it.  Try it and let us know if it works for you.&#60;/p&#62;
&#60;p&#62;In your first block of code which uses gform_user_registered, can you set the custom capabilities for any user who registers?   Is that what you're asking?  If so, I think you should be able to do this:&#60;/p&#62;
&#60;p&#62;&#60;a href=&#34;http://pastebin.com/zHVhE2qC&#34; rel=&#34;nofollow&#34;&#62;http://pastebin.com/zHVhE2qC&#60;/a&#62;&#60;/p&#62;
&#60;p&#62;That code will run whenever a member is registered, so that's a good place to set your capabilities.  The capabilities are tied to the registration, not the PayPal payment (I think?)
&#60;/p&#62;</description>
		</item>
		<item>
			<title>travin on "Else If PHP Statement"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/else-if-php-statement#post-34493</link>
			<pubDate>Mon, 05 Sep 2011 17:22:01 +0000</pubDate>
			<dc:creator>travin</dc:creator>
			<guid isPermaLink="false">34493@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Thanks Chris.  I am just trying to put a little logic in the functions.php file.  I am using gravity forms for user registration to a membership site plus purchasing a software product.  Before, I only had 1 form to deal with when adding the custom capability.  Now, I have multiple forms to deal with.  Now that I think about it, my code design won't work the way I had envisioned it.  Form 11 is used for purchasing a product, registering a user, and setting a custom capability in the user meta.  Form 12 is purchasing the same product and setting the custom capability, but the user is already registered, so no registration is needed.&#60;/p&#62;
&#60;p&#62;I currently use this code to set the custom capability when a user is registered:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;add_action(&#38;quot;gform_user_registered&#38;quot;, &#38;quot;add_custom_user_meta&#38;quot;, 10, 3);  

function add_custom_user_meta($user_id, $config, $entry) {  

if($entry[&#38;#39;form_id&#38;#39;] != 11)
	return;  

wp_set_current_user( $user_id );
$user = wp_get_current_user();
$user-&#38;gt;add_cap(&#38;quot;access_s2member_ccap_creditexpertpro&#38;quot;);
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;This works perfectly as long as the user is using form 11.  So how would I fire the code when form 12 is complete?  The user will be logged in when this form is used.  It should happen after the paypal transaction is complete.  I am thinking this should work:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;add_action(&#38;quot;gform_paypal_fulfillment&#38;quot;, &#38;quot;process_order&#38;quot;, 10, 4);
function process_order($entry, $config, $transaction_id, $amount) {

if($entry[&#38;#39;form_id&#38;#39;] != 12)
	return;  

$user = wp_get_current_user();
$user-&#38;gt;add_cap(&#38;quot;access_s2member_ccap_creditexpertpro&#38;quot;);
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;Last question.  Lets say I need to add different capabilities based on the form id after a successful registration.  How would I use the else - if statement to accomplish this (which my original thought when making this post).  I tried to use the if elseif statement but obvisouly didn't format it correctly.  I was going to add the the if statement into the function to it would always check during user registration.  During registration, if one of the form numbers is use, it would set the custom capability as needed.&#60;/p&#62;
&#60;p&#62;Hope this makes sense.  Thanks for all your help.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Chris Hajer on "Else If PHP Statement"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/else-if-php-statement#post-34439</link>
			<pubDate>Sun, 04 Sep 2011 20:39:49 +0000</pubDate>
			<dc:creator>Chris Hajer</dc:creator>
			<guid isPermaLink="false">34439@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Try this:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;[php]
if ($entry[&#38;#39;form_id&#38;#39;] == 11) {
  wp_set_current_user( $user_id );
  $user = wp_get_current_user();
  $user-&#38;gt;add_cap(&#38;quot;access_s2member_ccap_creditexpertpro&#38;quot;);
}

elseif ($entry[&#38;#39;form_id&#38;#39;] == 12) {
  $user = wp_get_current_user();
  $user-&#38;gt;add_cap(&#38;quot;access_s2member_ccap_creditexpertpro&#38;quot;);
}
else
  return;&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;Just a couple things.  If you have multiple statements to execute after the &#34;if&#34;, they need be be wrapped in curly braces.  And to test for equality, you need to use == (or ===) rather than a single =, which just assigns the value on the right to the variable on the left.&#60;/p&#62;
&#60;p&#62;I have no idea if the code will work, but the syntax should be correct.  If you need help accomplishing something, please post the question and we'll help you out.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>travin on "Else If PHP Statement"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/else-if-php-statement#post-34438</link>
			<pubDate>Sun, 04 Sep 2011 19:17:22 +0000</pubDate>
			<dc:creator>travin</dc:creator>
			<guid isPermaLink="false">34438@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;I need just a little help here with some php syntax.  I am trying to add custom capabilities and need different actions based on different forms.  I tried the following but got a syntax error.  Hoping you can tell me what I did wrong.  Thanks in advance.&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;if ($entry[&#38;#39;form_id&#38;#39;] = 11)

  wp_set_current_user( $user_id );
  $user = wp_get_current_user();
  $user-&#38;gt;add_cap(&#38;quot;access_s2member_ccap_creditexpertpro&#38;quot;);

elseif ($entry[&#38;#39;form_id&#38;#39;] = 12)

  $user = wp_get_current_user();
  $user-&#38;gt;add_cap(&#38;quot;access_s2member_ccap_creditexpertpro&#38;quot;);

else

  return;&#60;/code&#62;&#60;/pre&#62;</description>
		</item>

	</channel>
</rss>
