Skip to content

Instantly share code, notes, and snippets.

@mlangone
Forked from danielbachhuber/http-to-https.php
Created March 28, 2018 21:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mlangone/545b9a70f97c125b2c5cf554edd8320b to your computer and use it in GitHub Desktop.
Save mlangone/545b9a70f97c125b2c5cf554edd8320b 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