<?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: Dynamic add_action creation?</title>
		<link>https://legacy.forums.gravityhelp.com/topic/dynamic-add_action-creation</link>
		<description>Gravity Support Forums Topic: Dynamic add_action creation?</description>
		<language>en-US</language>
		<pubDate>Mon, 20 Apr 2026 09:43:02 +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/dynamic-add_action-creation" rel="self" type="application/rss+xml" />

		<item>
			<title>sascha on "Dynamic add_action creation?"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/dynamic-add_action-creation#post-46528</link>
			<pubDate>Mon, 16 Jan 2012 20:48:11 +0000</pubDate>
			<dc:creator>sascha</dc:creator>
			<guid isPermaLink="false">46528@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;In case it helps someone, I used the following code and it seems to work. But maybe one of your GF guys could look over it :)  I am not a php man....&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;//add_action(&#38;#39;gform_after_submission&#38;#39;, &#38;#39;dynamic_filtering&#38;#39;, 10, 1);

//function dynamic_filtering() {
$forms_to_filter = array(&#38;#39;1&#38;#39;, &#38;#39;2&#38;#39;, &#38;#39;3&#38;#39;, &#38;#39;4&#38;#39;, &#38;#39;5&#38;#39;, &#38;#39;6&#38;#39;); // ids of forms --- needs to be populated dynamically!
foreach ($forms_to_filter as $form_id) {
	//$after_submission = &#38;#39;gform_after_submission_&#38;#39; . $form_id;
     add_action(&#38;#39;gform_after_submission_&#38;#39; . $form_id, &#38;#39;manitu&#38;#39;, 10, 1);
}
//}

function manitu($entry) {
	do_dump ($entry);
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;As you can see I made a mistake with the array declaration in the example before! That's why it would not work. Yeah, and I forgot the brackets around the foreach argument...
&#60;/p&#62;</description>
		</item>
		<item>
			<title>sascha on "Dynamic add_action creation?"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/dynamic-add_action-creation#post-46527</link>
			<pubDate>Mon, 16 Jan 2012 20:20:49 +0000</pubDate>
			<dc:creator>sascha</dc:creator>
			<guid isPermaLink="false">46527@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Tried to above, but of course it does not work! Would I need to call a add_action('gform_after_submission', 'filter_forms_by_id') and then inside that function filter_forms_by_id do the stuff I suggested above? I cannot get my head round it. Sorry. Maybe you can...
&#60;/p&#62;</description>
		</item>
		<item>
			<title>sascha on "Dynamic add_action creation?"</title>
			<link>https://legacy.forums.gravityhelp.com/topic/dynamic-add_action-creation#post-46525</link>
			<pubDate>Mon, 16 Jan 2012 20:04:08 +0000</pubDate>
			<dc:creator>sascha</dc:creator>
			<guid isPermaLink="false">46525@https://legacy.forums.gravityhelp.com/</guid>
			<description>&#60;p&#62;Hi there,&#60;/p&#62;
&#60;p&#62;I was wondering if the below stuff could be optimised? I am sure I have seen somewhere a &#34;trick&#34; where the _1, _3, _4 etc. gform_after_submission is called dynamically, but cannot find it.&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;// select parent term automatically for the &#38;#39;project_type&#38;#39; taxonomy in form #1, 3, 4, 5, 6, 8
add_action(&#38;#39;gform_after_submission_1&#38;#39;, &#38;#39;gform_parent_category&#38;#39;);
add_action(&#38;#39;gform_after_submission_3&#38;#39;, &#38;#39;gform_parent_category&#38;#39;);
add_action(&#38;#39;gform_after_submission_4&#38;#39;, &#38;#39;gform_parent_category&#38;#39;);
add_action(&#38;#39;gform_after_submission_5&#38;#39;, &#38;#39;gform_parent_category&#38;#39;);
add_action(&#38;#39;gform_after_submission_6&#38;#39;, &#38;#39;gform_parent_category&#38;#39;);
add_action(&#38;#39;gform_after_submission_8&#38;#39;, &#38;#39;gform_parent_category&#38;#39;);

function gform_parent_category($entry) {
	$created_post = $entry[&#38;#39;post_id&#38;#39;];
	$child_ID = $entry[&#38;quot;5&#38;quot;]; // need to change this to pull dynamically
	$term_object = get_term_by(&#38;#39;id&#38;#39;, $child_ID, &#38;#39;project_type&#38;#39;); // replace project_type by chosen taxonomy
	$parent_ID = $term_object -&#38;gt; parent;
	wp_set_post_terms( $created_post, $parent_ID, &#38;#39;project_type&#38;#39;, true ); //replace project_type by chosen taxonomy
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;I would basically like to define the array of form ids first and then loop through creating the necessary add_action calls dynamically:&#60;br /&#62;
&#60;pre&#62;&#60;code&#62;$forms_to_filter = array(&#38;#39;1, 2, 3, 4, 5, 6); // ids of forms --- needs to be populated dynamically!
foreach $forms_to_filter as $form_id {
     add_action(&#38;#39;gform_after_submission_&#38;#39; . $form_id, &#38;#39;gform_parent_category&#38;#39;);
}

function gform_parent_category($entry) {
	$created_post = $entry[&#38;#39;post_id&#38;#39;];
	$child_ID = $entry[&#38;quot;5&#38;quot;]; // need to change this to pull dynamically
	$term_object = get_term_by(&#38;#39;id&#38;#39;, $child_ID, &#38;#39;project_type&#38;#39;); // replace project_type by chosen taxonomy
	$parent_ID = $term_object -&#38;gt; parent;
	wp_set_post_terms( $created_post, $parent_ID, &#38;#39;project_type&#38;#39;, true ); //replace project_type by chosen taxonomy
}&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;I am not sure at all about the right syntax for doing this though!!! Is there a way to do this? Is the above correct?
&#60;/p&#62;</description>
		</item>

	</channel>
</rss>
