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

Gravity Forms and update_option() WordPress

  • SOLVED

Hi there. I am using Gravity Forms together with Rocket Genius's User Registration and PayPal Standard addon's to create new sites on a multisite network.

When a user completes my signup form I would like to provide options to select an industry, site theme and site language for their new site (screenshot attached).

Please can someone help me prepare a function that hooks into 'wpmu_new_blog' (???) and updates the appropriate database options with the users chosen industry, site theme and site language selections. The new function should only run after confirmation of a successful PayPal transaction.

I'm guessing the five option fields that need to be updated are: 'myplugin_industry', 'WPLANG', 'current_theme', 'template' and 'stylesheet'.

Many thanks.

Answers (1)

2015-01-12

Kyle answers:

Gravity Forms has hooks that fire after the site has been created, which contain the new site ID. So you'll simply want to jump to that site temporarily and set the options before completing the form process. Something like this:

add_action("gform_site_created", "set_new_site_opts", 10, 5);
function set_new_site_opts($site_id, $user_id, $entry, $config, $password){

switch_to_blog( $site_id );
update_option('myplugin_industry',$entry[7]);
update_option('WPLANG',$entry[9]);
update_option('current_theme',$entry[8]);
update_option('template',$entry[##]);//update entry ID #
update_option('stylesheet',$entry[##]);//update entry ID #
restore_current_blog();

}


Kyle comments:

You'll have to be careful to set the 'value' field of each dropdown option in each field to the correct option the DB wants for each one.


designbuildtest comments:

Wonderful. Cheers Kyle.

Can this function be made form specific? I have two different forms that both create new sites. My primary form creates a new user and a new site while my secondary form is accessed by logged in users who wish to create another site. The field ID's for industry, theme and language selections are different on each form.

Thanks again.


Kyle comments:

Sure, the entry object has the form id soo...

add_action("gform_site_created", "set_new_site_opts", 10, 5);
function set_new_site_opts($site_id, $user_id, $entry, $config, $password){

if( $entry["form_id"] == 1 ){ //Change this as needed or copy this whole section for each form, etc.
switch_to_blog( $site_id );
update_option('myplugin_industry',$entry[7]);
update_option('WPLANG',$entry[9]);
update_option('current_theme',$entry[8]);
update_option('template',$entry[##]);//update entry ID #
update_option('stylesheet',$entry[##]);//update entry ID #
restore_current_blog();
}

}


designbuildtest comments:

Perfect!! Thank you for your super speedy response and expert help Kyle.
Much appreciated.