• Resolved Hasaanch

    (@hasaanch)


    Hi there,
    I am developing a feature for my multisite where a user submits a gravity form and all a new is generated for them.
    Later on some changes are done on the newly duplicated site (User details are replaced there).
    But these changes are undone as the nscloner duplication function runs in background.
    Is there a way we can get the response from the function only when the Site is Completely Duplicated.
    Also we should get the newly created site ID as return.
    here’s the code i am using for reference.

                $response = ns_cloner_perform_clone( array(
    'source_id' => 9,
    'target_name' => $target_name,
    'target_title' => $target_title,
    'user_id' => $user_id
    ) );

    if($response)
    {
    print_r("<br>Site Created Successfully");
    $site_url = get_site_url(); // Get the main site URL
    $blog_url = $site_url . '/' . $target_name;

    $template_vars = array(
    'username' => $username,
    'blog_url' => $blog_url,
    'password' => $password
    );

    ob_start();
    include 'email_sitegenerated.php';
    $template = ob_get_clean();

    $to = $user_email;
    $subject = 'Your Site is Ready';
    $headers = array('Content-Type: text/html; charset=UTF-8');

    wp_mail($to, $subject, $template, $headers);

    $site_after_id = get_blog_id('/'.$target_name);


    print_r("<br>Target of Generated Site is ".$target_name);
    print_r("<br> ID of generated site is ".$site_after_id);

    clear_elementor_cache();
    switch_to_blog($site_after_id);

    // wp_cache_flush(); // Ensure no stale cache
    update_site_contact_info($contact_info);
    attach_wordpress_logo($site_logo);
    update_colors($site_after_id,$selected_demo,$main_color,$accent_color);


    restore_current_blog();

    }
Viewing 1 replies (of 1 total)
  • Plugin Author Never Settle

    (@neversettle)

    Hey @hasaanch

    There are a few ways this can be done using the plugin actions. There an action called ns_cloner_process_finish that can be used to get the target site name or id and compare it to the request from the form. Something like this

    add_action( 'ns_cloner_process_finish', function() }
    $target_id = ns_cloner_request()->get( 'target_id' ); // Created site id
    $site_target_name = ns_cloner_request()->get( 'target_name' ); // Created site name
    $target_name = strtolower( trim( $target_name ) );

    if ( $target_name === $site_target_name ) {
    // Your code here.
    }
    });

    Let me know if you need more assistance ??

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.