• Resolved Jory Hogeveen

    (@keraweb)


    Hi there!

    Thanks for the plugin. Just a simple question:
    Is there an API to clone a site with PHP instead of the interface?

    We’re trying to automate the cloning process based on external data with an endpoint that triggers the “clone”.
    Let me know and thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Jory Hogeveen

    (@keraweb)

    Just did some tests and I think I’ve found it!

    Instead of writing all that code this seems this works just as well:

    
    /**
     * Before doing anything: setup clone $_POST data.
     * [] {
     *     @type  string  'action'         => 'process',
     *     @type  string  'clone_mode'     => 'core',
     *     @type  int     'source_id'      => $blog_id,
     *     @type  string  'target_name'    => $target_name,
     *     @type  string  'target_title'   => $target_title,
     *     @type  bool    'disable_addons' => true,
     *     @type  string  'clone_nonce'    => wp_create_nonce('ns_cloner')
     * }
     */
    
    // Load WordPress.
    require( wp-load.php );
    
    // Setup clone process and run it.
    $ns_site_cloner = new ns_cloner();
    $ns_site_cloner->process();
    
    $site_id = $ns_site_cloner->target_id;
    $site_info = get_blog_details( $site_id );
    if ( $site_info ) {
    	// Clone successful!
    }
    

    Thanks!

    • This reply was modified 7 years, 4 months ago by Jory Hogeveen.
    Plugin Author Never Settle

    (@neversettle)

    Nice! Yes – there are definitely a few ways to do this. Looks like your way is using the $_POST mechanisms that we added relatively more recently to facilitate the 1-click cloning that you can do from the Sites list. Great approach, and thanks for sharing your solution!

    Thread Starter Jory Hogeveen

    (@keraweb)

    No problem!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Clone site server side’ is closed to new replies.