Instantly share code, notes, and snippets.

Embed
What would you like to do?
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