<?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: Add custom capabilities by getting a drop down value</title>
		<link>https://legacy.forums.gravityhelp.com/topic/add-custom-capabilities-by-getting-a-drop-down-value</link>
		<description>Gravity Support Forums Topic: Add custom capabilities by getting a drop down value</description>
		<language>en-US</language>
		<pubDate>Wed, 29 Apr 2026 08:01:49 +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/add-custom-capabilities-by-getting-a-drop-down-value" rel="self" type="application/rss+xml" />

		<item>
			<title>Chris Hajer on "Add custom capabilities by getting a drop down value"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/add-custom-capabilities-by-getting-a-drop-down-value#post-149816</link>
			<pubDate>Tue, 19 Feb 2013 00:59:54 +0000</pubDate>
			<dc:creator>Chris Hajer</dc:creator>
			<guid isPermaLink="false">149816@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Your code here looks pretty simple.  If it works for you, that's the important thing.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>flatcle on "Add custom capabilities by getting a drop down value"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/add-custom-capabilities-by-getting-a-drop-down-value#post-149665</link>
			<pubDate>Mon, 18 Feb 2013 21:31:41 +0000</pubDate>
			<dc:creator>flatcle</dc:creator>
			<guid isPermaLink="false">149665@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;I have somehow managed to have it work. So blind I was unable to recognise a solution right in front of myself.&#60;/p&#62;
&#60;p&#62;Here is my code:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;[php]
add_action(&#38;#39;gform_after_submission_(your form ID)&#38;#39;, &#38;#39;add_new_capabilities&#38;#39;, 10, 2);
function add_new_capabilities($entry, $form){

$current_user = wp_get_current_user();
        $custom_cap1 = $entry[&#38;quot;(field_ID)&#38;quot;];
	$custom_cap2 = $entry[&#38;quot;(field_ID)&#38;quot;];

$current_user -&#38;gt; add_cap($custom_cap1);
$current_user -&#38;gt; add_cap($custom_cap2);
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;This code will add data to your datatable wp_usermeta - wp_capabilities without any arraying problem.&#60;/p&#62;
&#60;p&#62;As for the code I referred previously, It seems $entry returns all values contained in the dropdown as it is used in 'if phrase.' I don't know why.&#60;/p&#62;
&#60;p&#62;Any simplification and suggestion are more than welcomed.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Chris Hajer on "Add custom capabilities by getting a drop down value"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/add-custom-capabilities-by-getting-a-drop-down-value#post-149194</link>
			<pubDate>Mon, 18 Feb 2013 09:20:46 +0000</pubDate>
			<dc:creator>Chris Hajer</dc:creator>
			<guid isPermaLink="false">149194@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;What code would you use to accomplish this?  Please show us how you are going about this.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>flatcle on "Add custom capabilities by getting a drop down value"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/add-custom-capabilities-by-getting-a-drop-down-value#post-148465</link>
			<pubDate>Sun, 17 Feb 2013 10:17:52 +0000</pubDate>
			<dc:creator>flatcle</dc:creator>
			<guid isPermaLink="false">148465@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Thank you for reply!&#60;br /&#62;
I guess I need to make it simple.&#60;/p&#62;
&#60;p&#62;Let's assume that field ID 17 of Form ID 1 has dropdown values such as &#34;A&#34;, &#34;B&#34; and &#34;C&#34;&#60;br /&#62;
and we modified code on line 5 to $capabilities = $entry['17];&#60;/p&#62;
&#60;p&#62;With this $capabilities contain all dropdown values of Field ID 17 of Form ID 1, which are &#34;A&#34;, &#34;B&#34; and &#34;C&#34;, thus add custom capabilities &#34;a&#34;, &#34;b&#34; and &#34;c&#34; to the current user.&#60;/p&#62;
&#60;p&#62;What I would like to know is to add only &#34;B&#34;, if a user selected &#34;B&#34;
&#60;/p&#62;</description>
		</item>
		<item>
			<title>Chris Hajer on "Add custom capabilities by getting a drop down value"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/add-custom-capabilities-by-getting-a-drop-down-value#post-148241</link>
			<pubDate>Sun, 17 Feb 2013 03:07:52 +0000</pubDate>
			<dc:creator>Chris Hajer</dc:creator>
			<guid isPermaLink="false">148241@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;You need to debug.&#60;/p&#62;
&#60;p&#62;One line 6 in your first example, what does $capabilities contain?  We can't see your form or values to know what field ID 17, 18 and 19 contain, but you're concatenating them all, so $capabilities could look like:&#60;/p&#62;
&#60;blockquote&#62;&#60;p&#62;
1, 2, 3&#60;br /&#62;
or&#60;br /&#62;
, , 3&#60;br /&#62;
or&#60;br /&#62;
, ,&#60;br /&#62;
or even&#60;br /&#62;
1, ,&#60;br /&#62;
or&#60;br /&#62;
, 2, 3
&#60;/p&#62;&#60;/blockquote&#62;
&#60;p&#62;If you print the $capabilities variable or log it somewhere, that will go a long way to seeing why your logic on lines 7, 8 and 9 does not work properly. One thing immediately wrong with it is that your string will always contain a comma, so I'm not sure how any of that could work, because it should never be equal to 1, 2 or 3.&#60;/p&#62;
&#60;p&#62;I'm not sure how your second example is supposed to work with gform_pre_render but we should focus on getting just one of these to work.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>flatcle on "Add custom capabilities by getting a drop down value"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/add-custom-capabilities-by-getting-a-drop-down-value#post-146854</link>
			<pubDate>Thu, 14 Feb 2013 05:04:43 +0000</pubDate>
			<dc:creator>flatcle</dc:creator>
			<guid isPermaLink="false">146854@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;I am trying to add custom capabilities to user according to a value submitted from gravity form selected value.&#60;/p&#62;
&#60;p&#62;I have tried gfrom_pre_render and gform_after_submission without any success.&#60;/p&#62;
&#60;p&#62;Here is an example that I tried.&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;add_action(&#38;quot;gform_after_submission_1&#38;quot;, &#38;quot;after_submission&#38;quot;, 10, 2);

function after_submission($entry, $form){
     $user = wp_get_current_user();
     $capabilities = $entry[&#38;quot;17&#38;quot;] . &#38;#39;, &#38;#39;. $entry[&#38;quot;18&#38;quot;] .&#38;#39;, &#38;#39;. $entry[&#38;quot;19&#38;quot;];

if ($capabilities = &#38;quot;1&#38;quot;) {$user -&#38;gt; add_cap(&#38;#39;1&#38;#39;);}
if ($capabilities = &#38;quot;2&#38;quot;) {$user -&#38;gt; add_cap(&#38;#39;2&#38;#39;);}
if ($capabilities = &#38;quot;3&#38;quot;) {$user -&#38;gt; add_cap(&#38;#39;3&#38;#39;);}
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;It seems the code above add all values that field ID 17, 18, 19 has to user capabilities.&#60;/p&#62;
&#60;p&#62;So I tried another with gform_pre_render&#60;/p&#62;
&#60;p&#62;'&#60;br /&#62;
    add_filter(&#34;gform_pre_render&#34;, &#34;dropdown_custom_capabilities&#34;);&#60;br /&#62;
    add_filter(&#34;gform_admin_pre_render&#34;, &#34;dropdown_custom_capabilities&#34;);&#60;br /&#62;
    function dropdown_custom_capabilities($form){&#60;br /&#62;
            if($form[&#34;id&#34;] != 1)&#60;/p&#62;
&#60;p&#62;               return $form;&#60;/p&#62;
&#60;p&#62;    $terms = get_terms(&#34;custom-capabilities&#34;);&#60;br /&#62;
    $items = array();&#60;br /&#62;
    $items[] = array( &#34;text&#34; =&#38;gt; __('Select capabilities...', &#34;value&#34; =&#38;gt; 0 );&#60;/p&#62;
&#60;p&#62;    foreach($terms as $term)&#60;br /&#62;
        $items[] = array( &#34;text&#34; =&#38;gt; $term-&#38;gt;name, &#34;value&#34; =&#38;gt; $term-&#38;gt;slug );&#60;/p&#62;
&#60;p&#62;    foreach($form[&#34;fields&#34;] as &#38;amp;$field)&#60;/p&#62;
&#60;p&#62;                if($field[&#34;id&#34;] == 17 OR 18 OR 19){&#60;/p&#62;
&#60;p&#62;                    $field[&#34;cssClass&#34;] = 'custom-capabilities';&#60;br /&#62;
                    $field[&#34;choices&#34;] = $items;&#60;br /&#62;
}&#60;/p&#62;
&#60;p&#62;return $form&#60;/p&#62;
&#60;p&#62;if ($form = &#34;1&#34;) {$user -&#38;gt; add_cap('1');}&#60;br /&#62;
if ($form = &#34;2&#34;) {$user -&#38;gt; add_cap('2');}&#60;br /&#62;
if ($form = &#34;3&#34;) {$user -&#38;gt; add_cap('3');}&#60;/p&#62;
&#60;p&#62;}&#60;/p&#62;
&#60;p&#62;'&#60;/p&#62;
&#60;p&#62;Code above does not work.&#60;/p&#62;
&#60;p&#62;Would you possibly to point me a right direction for this matter?
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
