Skip to content

Instantly share code, notes, and snippets.

@danielbachhuber
Created March 28, 2018 19:45
Show Gist options
  • Save danielbachhuber/17cbced54a8692e3eee8f2bdf4e95709 to your computer and use it in GitHub Desktop.
Save danielbachhuber/17cbced54a8692e3eee8f2bdf4e95709 to your computer and use it in GitHub Desktop.
Update a specific site from 'http://' to 'https://'.
<?php
/**
* Update a specific site from 'http://' to 'https://'.
*
* Only touches the 'home' and 'siteurl' options.
* Depending on plugins, etc., you may need to update other options too.
*
* Run on WordPress multisite with:
*
* wp site list --field=url | xargs -I % wp eval-file http-to-https.php --url=%
*/
foreach ( array( 'home', 'siteurl' ) as $option ) {
$existing = get_option( $option );
$new = str_replace( 'http://', 'https://', $existing );
if ( update_option( $option, $new ) ) {
WP_CLI::log( "Updated '{$option}' to '{$new}'" );
} else {
WP_CLI::log( "Didn't update '{$option}' to '{$new}'" );
}
}
WP_CLI::success( 'Options updated for ' . home_url() );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment