Skip to content

Instantly share code, notes, and snippets.

@lanche86
Created February 15, 2013 22:21
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 lanche86/4964061 to your computer and use it in GitHub Desktop.
Save lanche86/4964061 to your computer and use it in GitHub Desktop.
migrate-wp.php
<?php
if ( $_POST ) {
$newsiteurl = $_POST['newsiteurl'];
// If last char in URL is "/" -> remove it
if ( substr( $newsiteurl, -1) == "/" ) {
$newsiteurl = substr($newsiteurl, 0, -1);
}
// Check if provided URL is valid
if ( !filter_var( $newsiteurl, FILTER_VALIDATE_URL) ) {
echo 'URL is not valid...';
} else {
include "wp-config.php";
$newsiteurl = mysql_real_escape_string( $newsiteurl );
// Get current "siteurl"
$siteurlsql = mysql_query( "SELECT option_value FROM wp_options WHERE option_name = 'siteurl'" );
while ($row = mysql_fetch_assoc($siteurlsql)) {
$siteurl = $row['option_value'];
}
mysql_query( "UPDATE wp_options SET option_value = replace( option_value, '".$siteurl."', '".$newsiteurl."' ) WHERE option_name = 'home' OR option_name = 'siteurl';" );
mysql_query( "UPDATE wp_posts SET guid = replace(guid, '".$siteurl."','".$newsiteurl."');" );
mysql_query( "UPDATE wp_posts SET post_content = replace(post_content, '".$siteurl."','".$newsiteurl."');" );
header( "Location: $newsiteurl" );
}
}
?>
<form action="" method="POST">
<input type="text" name="newsiteurl" />
<button type="submit">UPDATE</button>
</form>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment