Skip to content

Instantly share code, notes, and snippets.

@cdmz
Last active August 29, 2015 14:25
Show Gist options
  • Save cdmz/4752c404cc595a67d07a to your computer and use it in GitHub Desktop.
Save cdmz/4752c404cc595a67d07a to your computer and use it in GitHub Desktop.
Auto change siteurl wordpress
<?php
include 'wp-load.php';
$folder = $_GET['folder'];
$results = $wpdb->get_results( "SELECT option_id,option_name,option_value FROM wp_options WHERE option_name = 'home' OR option_name = 'siteurl'");
$rows = count($results);
if($rows > 0 AND is_array($results)){
$host = $_SERVER['HTTP_HOST'];
$site_url = $results[0]->option_value;
$home = $results[1]->option_value;
if(
$host != $site_url AND
$host != $home AND
$site_url === $home
){
$host .= ($folder != '' AND strlen($folder) > 0) ? $folder : '';
$res = $wpdb->query("
UPDATE wp_options SET option_value = replace(option_value, '".$results[1]->option_value."', '".$host."') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = replace(guid, '".$results[1]->option_value."','".$host."');
UPDATE wp_posts SET post_content = replace(post_content, '".$results[1]->option_value."', '".$host."');
UPDATE wp_postmeta SET meta_value = replace(meta_value, '".$results[1]->option_value."', '".$host."');
");
}
}
exit;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment