Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Process MailChimp Feed on Gravity Forms Update. WordPress

  • SOLVED

Hi,
I am using the Gravity Forms Mailchimp Add On to add users to a Mailchimp list. I am using Gravity View to Update the form entries. I need the Mailchimp feed to process when the admin updates the form.
Here is the relevant documentation.
You can use the hook gform_after_update_entry to run code upon the update of an entry:

https://www.gravityhelp.com/documentation/article/gform_after_update_entry/

With that hook, you could call the process_feed() function:

https://www.gravityhelp.com/documentation/article/gffeedaddon/#processing-feeds

here is what I have...
add_action( 'gform_after_update_entry', 'my_process_feed', 10, 2 );
function my_process_feed($form, $entry_id ) {
if( !is_admin() || !class_exists('GFCommon') || !class_exists( 'GFAPI' ) ) {
return;
}

$entry = GFAPI::get_entry( $entry_id );

GFCommon::process_feed( $feed, $form, $entry );
}


How can I get this to work?

Answers (2)

2016-01-29

Reigel Gallarde answers:

the doc says

public function process_feed( $feed, $entry, $form ) {}

but yours is

GFCommon::process_feed( $feed, $form, $entry );

try to change the variables position.. maybe this is the problem.. you have it in wrong position.. should be $feed, $entry, $form.

But I think that will not work too... I have looked at GFCommon class and there is no function process_feed...
The closest I can think of that you can use is GFMailChimp because you are using Mail Chimp Gravity form Addon..

try something like this:
add_action( 'gform_after_update_entry', 'my_process_feed', 10, 2 );

function my_process_feed($form, $entry_id ) {

if( !is_admin() || !class_exists('GFMailChimp') || !class_exists( 'GFAPI' ) ) {

return;

}

$entry = GFAPI::get_entry( $entry_id );
$mailchimp= GFMailChimp::get_instance();
$mailchimp->process_feed( $feed, $entry, $form );

// $feed is not known here and maybe a problem..
// try this code below too. instead of process_feed()
// $mailchimp->maybe_process_feed( $entry, $form );

}


Davis Winn comments:

Still not working... I tried this to get the feed as well.
$feed = GFAPI::get_feeds( $entry['form_id'] );


Reigel Gallarde comments:

A little debugging...

try inside that function...

$entry = GFAPI::get_entry( $entry_id );
print_r($entry);
die();


this will check if you got the entry..

if you have the entry, try this..

$mailchimp= GFMailChimp::get_instance();
print_r($mailchimp);
die();


let me know if you have mailchimp...

I have sent you a PM too...


Reigel Gallarde comments:

you can't also do GFAPI::get_feeds( $entry['form_id'] );

get_feeds is not a static function... unlike get_entry... get_entry is a static function... only static functions can be called directly without the need to initialize the it's class...


Davis Winn comments:

@Reigel - that is a big help - it appears as though it is getting the entry and here is the output from trying the Mailchimp print
GFMailChimp Object ( [_version:protected] => 3.7.1 [_min_gravityforms_version:protected] => 1.9.3 [_slug:protected] => gravityformsmailchimp [_path:protected] => gravityformsmailchimp/mailchimp.php [_full_path:protected] =>PATHREMOVEDBYME/wp-content/plugins/gravityformsmailchimp/class-gf-mailchimp.php [_url:protected] => http://www.gravityforms.com [_title:protected] => Gravity Forms MailChimp Add-On [_short_title:protected] => MailChimp [_enable_rg_autoupgrade:protected] => 1 [_capabilities:protected] => Array ( [0] => gravityforms_mailchimp [1] => gravityforms_mailchimp_uninstall ) [_capabilities_settings_page:protected] => gravityforms_mailchimp [_capabilities_form_settings:protected] => gravityforms_mailchimp [_capabilities_uninstall:protected] => gravityforms_mailchimp_uninstall [merge_var_name:protected] => [_multiple_feeds:protected] => 1 [_single_feed_submission:protected] => [_single_submission_feed:protected] => [_feed_version:GFFeedAddOn:private] => 0.11 [_feed_settings_fields:GFFeedAddOn:private] => Array ( ) [_current_feed_id:GFFeedAddOn:private] => [app_hook_suffix] => [_saved_settings:GFAddOn:private] => Array ( ) [_previous_settings:GFAddOn:private] => Array ( ) [_setting_field_errors:GFAddOn:private] => Array ( ) [_capabilities_plugin_page:protected] => Array ( ) [_capabilities_app_menu:protected] => Array ( ) [_capabilities_app_settings:protected] => Array ( ) [_no_conflict_scripts:GFAddOn:private] => Array ( ) [_no_conflict_styles:GFAddOn:private] => Array ( ) [_preview_styles:GFAddOn:private] => Array ( ) [_print_styles:GFAddOn:private] => Array ( ) [delayed_payment_integration] => Array ( [option_label] => Subscribe user to MailChimp only when payment is received. ) )


Reigel Gallarde comments:

so both of this print_r($entry); and print_r($mailchimp); has a value?


Davis Winn comments:

yes


Davis Winn comments:

I'm not sure if the Mailchimp is getting the feed id though - I believe it's 16 for that feed (form id 17)


Reigel Gallarde comments:

if you're trying to get the feed by $feed = GFAPI::get_feeds( $entry['form_id'] );... it will give you a php error... get_feeds is not a static function... have you tried this?

$entry = GFAPI::get_entry( $entry_id );
$mailchimp = GFMailChimp::get_instance();
$mailchimp->maybe_process_feed( $entry, $form );


Davis Winn comments:

OK - that will update the feed from the back end update entries page - but it doesn't seem to work when updating the entry through Gravity View... but I'm that much closer...


Reigel Gallarde comments:

frontend has different hook.

Please try this:

add_action( 'gform_pre_submission_5', 'rei_pre_submission' ); // change 5 to your form ID
function rei_pre_submission($form){

if( !class_exists('GFMailChimp') || !class_exists( 'GFAPI' ) ) {
return;
}

if (isset($_GET['entry'])) {

$entry_id = $_GET['entry'];
$entry = GFAPI::get_entry( $entry_id );

if ( !is_wp_error( $entry ) ) {
$mailchimp = GFMailChimp::get_instance();
$mailchimp->maybe_process_feed( $entry, $form );
}

}
}


Make sure to change the form ID (currently 5) in gform_pre_submission_5 above. Use your form ID.

If this will not work, we have to check it by debugging...

add_action( 'gform_pre_submission_5', 'rei_pre_submission' ); // change 5 to your form ID
function rei_pre_submission($form){

//print_r($form);
//die(); // check if we got this hook working... remove if working..

if( !class_exists('GFMailChimp') || !class_exists( 'GFAPI' ) ) {
return;
}


//print_r($_GET['entry']);
//die(); // check if we got entry id... remove if we have it...

if (isset($_GET['entry'])) {

$entry_id = $_GET['entry'];
$entry = GFAPI::get_entry( $entry_id );

if ( !is_wp_error( $entry ) ) {
$mailchimp = GFMailChimp::get_instance();
$mailchimp->maybe_process_feed( $entry, $form );
}

}
}


Davis Winn comments:

That doesn't appear to get the form or the entry...


Reigel Gallarde comments:

ok... let's try another hook... maybe this will work better.. it has the entry and the form... we don't have to get it...

add_action( 'gform_after_submission', 'my_gform_after_submission', 10, 2 );
function my_gform_after_submission( $entry, $form ) {

if( !class_exists('GFMailChimp') ) { return;}

$mailchimp = GFMailChimp::get_instance();
$mailchimp->maybe_process_feed( $entry, $form );

}


Davis Winn comments:

no - I also tried gform_post_update_entry which works for the email notifications...


Reigel Gallarde comments:

I'm not sure, but according to the docs[[LINK href="https://www.gravityhelp.com/documentation/article/gform_after_submission/"]] gform_after_submission[[/LINK]]:

<blockquote>This PHP action hook is executed at the end of the submission process (after form validation, notification, and entry creation). Use this hook to perform actions after the entry has been created (i.e. feed data to third party applications).
The Entry Object is available to this hook and contains all submitted values.</blockquote>


Reigel Gallarde comments:

maybe you need to add your form id in gform_after_submission... example if your form id is 17, add_action( 'gform_after_submission_17', 'my_gform_after_submission', 10, 2 );


Davis Winn comments:

I think gform_after_submission only fires when the entry is created the first time. gform_after_update_entry fires when the entry is updated on the entry detail page (which we got working). After more poking around in the docs I think the hook that we need is gform_post_update_entry . [[LINK href="https://www.gravityhelp.com/documentation/article/gform_post_update_entry/"]][[/LINK]] I've been messing with it - no luck


Reigel Gallarde comments:

Okay... let's try that hook..

add_action( 'gform_post_update_entry', 'my_gform_post_update_entry', 10, 2 );
function my_gform_post_update_entry( $entry, $original_entry ) {

if( !class_exists('GFMailChimp') || !class_exists('RGFormsModel') ) { return; }

$form = RGFormsModel::get_form_meta($entry['form_id']);

$mailchimp = GFMailChimp::get_instance();
$mailchimp->maybe_process_feed( $entry, $form );

}


Davis Winn comments:

I tried it - no luck ...
Here is what works for the email notifications
add_action( 'gform_post_update_entry', 'gravityview_enable_gf_notifications_after_api_update_entry', 10, 2 );

/**
* Triggers Gravity Forms notifications engine when entry is updated through Gravity Forms API (GFAPI)
* @param array $entry Updated entry object
* @param array $original_entry Original entry object
* @return void
*/
function gravityview_enable_gf_notifications_after_api_update_entry( $entry, $original_entry ) {
if( !is_admin() || !class_exists('GFCommon') || !class_exists( 'GFAPI' ) ) {
return;
}

$form = GFAPI::get_form( $entry['form_id'] );

GFCommon::send_form_submission_notifications( $form, $entry );

}



When I do the following - or what you suggested It doesn't hook in for some reason...

add_action( 'gform_post_update_entry', 'my_gform_post_update_entry', 10, 2 );

function my_gform_post_update_entry( $entry, $original_entry ) {



if( !is_admin() || !class_exists('GFCommon') || !class_exists( 'GFAPI' ) || !class_exists('GFMailChimp') ) {
return;
}

$form = GFAPI::get_form( $entry['form_id'] );




$mailchimp = GFMailChimp::get_instance();

$mailchimp->maybe_process_feed( $entry, $form );



}

2016-01-29

Bob answers:

did you put it in your theme's functions.php file?

put it in your wp-content/themes/YOUR THEME/functions.php file

and check if it works or not.


Davis Winn comments:

Yes I put it in the functions.php file - I tried several versions of that code... I also put it in a plugin file that has a very similar function for sending email notifications on update. The emails work.... Mailchimp - no dice.
Thanks for taking a look... @Bob


Bob comments:

so you want to update entry at mailchimp when it is updated at website right?


Davis Winn comments:

Yes,when the form entry is updated - not on the original submission