Skip to content

Instantly share code, notes, and snippets.

@pniaps
Created January 29, 2016 08:43
Show Gist options
  • Save pniaps/3ab8b79476ef25982d42 to your computer and use it in GitHub Desktop.
Save pniaps/3ab8b79476ef25982d42 to your computer and use it in GitHub Desktop.
Replace domain in wordpress configuration
//Insert here serialized string from wp_options table
$str = '';
function change(&$data)
{
if(is_string($data) && json_decode($data)){
$json = json_decode($data);
if(is_array($json) || is_object($json)){
foreach($json as &$jsonvalue){
change($jsonvalue);
}
$data = json_encode($json);
}
return;
}else if(is_array($data) || is_object($data)){
foreach($data as &$value){
change($value);
}
return;
}
if(is_string($data)){
//Set here old string to replace
$old = 'oldomain.tld/subdir'
//Set here new string
$new = 'newdomain.tld'
$data = str_replace($old, $new, $data);
}
}
foreach($code as &$value){
change($value);
}
header("Content-Type: text/plain");
echo serialize($code);
die();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment