<?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: assign user capabilities based on products purchased</title>
		<link>https://legacy.forums.gravityhelp.com/topic/assign-user-capabilities-based-on-products-purchased</link>
		<description>Gravity Support Forums Topic: assign user capabilities based on products purchased</description>
		<language>en-US</language>
		<pubDate>Sat, 04 Apr 2026 03:24:59 +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/assign-user-capabilities-based-on-products-purchased" rel="self" type="application/rss+xml" />

		<item>
			<title>gingram815 on "assign user capabilities based on products purchased"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/assign-user-capabilities-based-on-products-purchased#post-219320</link>
			<pubDate>Mon, 22 Apr 2013 12:05:52 +0000</pubDate>
			<dc:creator>gingram815</dc:creator>
			<guid isPermaLink="false">219320@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Figured it out.&#60;br /&#62;
This may not be the most elegant way, but it works:&#60;br /&#62;
The code:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;add_action(&#38;quot;gform_after_submission_3&#38;quot;, &#38;quot;assign_user_cap&#38;quot;, 10, 2);
function assign_user_cap($entry, $form){
	$user_id = get_current_user_id( );
	$user = new WP_User($user_id);
	foreach(array(67,68,69,70,71,72,73,74,75,76,77) as $field_id){
	$cap_name = $entry[$field_id]; //creates custom capability &#38;quot;adminLabel&#38;quot; for each product
	$user-&#38;gt;add_cap($cap_name); //adds capability to the user who bought the product
		}
	return $user;
	}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;I set up an admin-only single-line text field for each product with default values set to whatever I want the capability to be for that product.  Set conditional logic such that each field shows whenever the quantity for that product is not empty.  The array above in the code are the field ids of those text fields.  Hope that helps someone.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gingram815 on "assign user capabilities based on products purchased"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/assign-user-capabilities-based-on-products-purchased#post-219304</link>
			<pubDate>Mon, 22 Apr 2013 11:38:07 +0000</pubDate>
			<dc:creator>gingram815</dc:creator>
			<guid isPermaLink="false">219304@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Okay,&#60;br /&#62;
I have made some progress on this but still having some problems.  Here is my code:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;add_action(&#38;quot;gform_after_submission_3&#38;quot;, &#38;quot;assign_user_cap&#38;quot;, 10, 2);
function assign_user_cap($entry, $form){
	$user_id = get_current_user_id( );
	$user = new WP_User($user_id);
	foreach(array(16,20,17,29,32,35,38,47,51,54,62) as $field_id){
	if($entry[$field_id] &#38;gt;= 1){
	$cap_name = $form[&#38;quot;fields&#38;quot;][$field_id][&#38;quot;adminLabel&#38;quot;]; //creates custom capability &#38;quot;adminLabel&#38;quot; for each product
	$user-&#38;gt;add_cap($cap_name); //adds capability to the user who bought the product
		}}
	return $user;
	}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;It is adding capabilities but just not the correct ones.  It is adding some that it should and some that it should not.  It is also not adding some it should.  The code above is only supposed to add capabilities corresponding to classes they signed up for.  Obviously the conditional I am using is not adequate somehow.  Any help would be greatly appreciated.
&#60;/p&#62;</description>
		</item>
		<item>
			<title>gingram815 on "assign user capabilities based on products purchased"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/assign-user-capabilities-based-on-products-purchased#post-215238</link>
			<pubDate>Fri, 19 Apr 2013 03:45:51 +0000</pubDate>
			<dc:creator>gingram815</dc:creator>
			<guid isPermaLink="false">215238@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;I am designing a form for people to sign up for classes.  Each class is a single product.  I want to assign a custom capability to each product and then add the capability to the user who purchases each product.  This capability allows access to pages and/or content related to that class/product.  I just need some help assigning the capabilities to the user on submission.  &#60;/p&#62;
&#60;p&#62;Here is what I have so far:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;add_action(&#38;quot;gform_after_submission_3&#38;quot;, &#38;quot;assign__user_cap&#38;quot;, 10, 2);
function assign_user_cap($entry){
	$user_id = get_current_user_id( );
	$user = new WP_User($user_id);
	//need to get array of field ids for the products purchased
	//need to associate a capability with each product; perhaps as the admin name
	foreach($field_ids as $field_id){
	$cap_name = &#38;quot;access_&#38;quot; . $form[&#38;quot;fields&#38;quot;][$field_id][&#38;quot;adminLabel&#38;quot;]; //creates custom capability &#38;quot;access_adminLabel&#38;quot; for each product
	$user-&#38;gt;add_cap($cap_name); //adds capability to the user who bought the product
	return $user;&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;Can you help me with my syntax and the missing functions to get the field ids for purchased products?  Am I heading in the right direction here?
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
