Created
February 15, 2013 22:21
-
-
Save lanche86/4964061 to your computer and use it in GitHub Desktop.
migrate-wp.php
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 | |
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