Last active
September 2, 2015 19:02
-
-
Save boonebgorges/c20ea5c1ef2649fc5197 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Change a site's domain. | |
* | |
* ## OPTIONS | |
* | |
* --from=<from> | |
* : The current domain of the site being changed. | |
* | |
* --to=<date> | |
* : The domain that the site is being changed to. | |
* | |
* [--dry-run] | |
* : Whether this should be a dry run. | |
*/ | |
public function change_domain( $args, $assoc_args ) { | |
global $wpdb; | |
if ( empty( $assoc_args['from'] ) || empty( $assoc_args['to'] ) ) { | |
WP_CLI::error( "The 'from' and 'to' parameters are required." ); | |
return; | |
} | |
$from_domain = $assoc_args['from']; | |
$to_domain = $assoc_args['to']; | |
$from_site = get_site_by_path( $from_domain ); | |
if ( ! $from_site ) { | |
WP_CLI::error( sprintf( 'No site with the domain %s was found. Aborting.', $from_domain ) ); | |
return; | |
} | |
$to_site = get_site_by_path( $to_domain ); | |
if ( $to_site ) { | |
WP_CLI::error( sprintf( 'An existing site was found with the domain %s. Aborting.', $to_domain ) ); | |
} | |
// Blog-specific tables first. | |
$_args = array( 'search-replace', $from_domain, $to_domain ); | |
$_assoc_args = array( 'skip-columns' => 'guid' ); | |
if ( isset( $assoc_args['dry-run'] ) ) { | |
$_assoc_args['dry-run'] = 1; | |
} | |
$_assoc_args['all-tables-with-prefix'] = 1; | |
$_assoc_args['url'] = $from_domain; | |
//\WP_CLI::set_url( $from_domain ); | |
WP_CLI::run_command( $_args, $_assoc_args ); | |
die(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment