Created
September 13, 2019 16:54
-
-
Save zetrider/35bd94060a606ce5ca742457aed8081e to your computer and use it in GitHub Desktop.
old domain to new domain
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
<? | |
global $wpdb; | |
define('MY_OLD_DOMAIN', 'http://olddomain.ru'); | |
define('MY_NEW_DOMAIN', 'http://newdomain.ru'); | |
function myWalkCallback(&$item, $key) | |
{ | |
$item = str_replace(MY_OLD_DOMAIN, MY_NEW_DOMAIN, $item); | |
} | |
$rows = $wpdb->get_results("SELECT * FROM wp_options WHERE option_value LIKE '%" . MY_OLD_DOMAIN . "%'"); | |
foreach($rows as $row) | |
{ | |
$value = @unserialize($row->option_value); | |
if(!$value) | |
{ | |
continue; | |
} | |
array_walk_recursive($value, 'myWalkCallback'); | |
$wpdb->update('wp_options', ['option_value' => serialize($value)], ['option_id' => $row->option_id]); | |
if ($wpdb->last_error) | |
{ | |
echo $wpdb->last_error . '<br>'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment