Using Gravity Forms ‘gform_site_created’ PHP filter

The gform_site_created action fires after a new site has been created. It is only applicable to Network installs with the “Create Site” option enabled.

Usage

add_action('gform_site_created', 'your_function_name', 10, 5);

Parameters

  • $site_id (integer): The ID of the created site.
  • $user_id (string): The ID of the registered user.
  • $entry (Entry Object): The entry object from which the site was created.
  • $feed (Feed Object): The Feed which is currently being processed.
  • $password (string): The password associated with the user; either submitted by the user or sent via email from WordPress.

More information

See Gravity Forms Docs: gform_site_created

Examples

Create a welcome post for the new site

This example creates a new welcome post on the newly created site.

add_action('gform_site_created', 'create_welcome_post', 10, 5);

function create_welcome_post($site_id, $user_id, $entry, $feed, $password) {
    $user = get_userdata($user_id);

    $post = array();
    $post['post_title'] = 'Welcome to your new site!';
    $post['post_content'] = "Hi {$user->first_name},nWe just wanted to personally welcome you to your new site!";

    switch_to_blog($site_id);
    wp_insert_post($post);
    restore_current_blog();
}

Add custom code here

add_action('gform_site_created', 'custom_site_created_action', 10, 5);

function custom_site_created_action($site_id, $user_id, $entry, $feed, $password) {
    // Your custom code here
}

Send a welcome email to the new site owner

add_action('gform_site_created', 'send_welcome_email', 10, 5);

function send_welcome_email($site_id, $user_id, $entry, $feed, $password) {
    $user = get_userdata($user_id);
    $user_email = $user->user_email;

    $subject = 'Welcome to Your New Site!';
    $message = "Hi {$user->first_name},nWelcome to your new site! You can now log in with your credentials.";

    wp_mail($user_email, $subject, $message);
}

Assign a default theme to the new site

add_action('gform_site_created', 'assign_default_theme', 10, 5);

function assign_default_theme($site_id, $user_id, $entry, $feed, $password) {
    $default_theme = 'twentytwenty'; // Replace with your preferred theme

    switch_to_blog($site_id);
    switch_theme($default_theme);
    restore_current_blog();
}

Add the new site owner to a specific user group

add_action('gform_site_created', 'add_site_owner_to_group', 10, 5);

function add_site_owner_to_group($site_id, $user_id, $entry, $feed, $password) {
    // Replace 'your_group_name' with the desired group name
    $group_name = 'your_group_name';

    // Assuming you have a function to add users to a group called 'add_user_to_group'
    add_user_to_group($user_id, $group_name);
}