├── .editorconfig
├── .gitignore
├── README.md
└── script
└── migrate.php
/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | [*]
4 | charset = utf-8
5 | indent_style = space
6 | indent_size = 2
7 | end_of_line = lf
8 | insert_final_newline = true
9 | trim_trailing_whitespace = true
10 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # ignore idea project files
2 | .idea
3 |
4 | # ignore OS stuff
5 | Thumbs.db
6 | *~
7 | .DS_Store
8 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
Note: This WP script has been unloved for a couple of years. I'm not even sure if it still works / is useful, but if anyone would like to help maintain it please drop me an email :)
4 |
5 | Migrate helps to move WordPress installations between URLs, for example between a development and production URL, or between domain names.
6 |
7 | At this time, the Migrate is only a script, rather than a plugin so that it can be run to correct database problems after a site has been moved.
8 |
9 | Download
10 |
11 | Download a zip file from GitHub. Direct link: https://github.com/ErisDS/Migrate/zipball/master
12 |
13 |
14 | Usage
15 |
16 |
17 | - After moving your WordPress install (files and database) to a new url
18 | - Place the script
migrate.php
in the root folder of your WordPress installation (at it's new location) at the same level as wp-config.php.
19 | - Navigate to yournewurl.com/migrate.php
20 | - Fill out the "Your current URL" field with the orignal URL at which you installed WordPress
21 | - Fill out the "Your replacement URL" field with the new URL that you want WordPress to sit under
22 | - Press "Continue (Step 2)"
23 | - The information you entered will be repeated back to you, along with some information about your WordPress install and what is going to be changed.
24 | - If you are happy the information is correct, check the confirmation checkbox and press "Lets do this!"
25 | - The script will output details of what has been changed, and your WordPress install should now work correctly
26 |
27 |
28 | I got a warning message?
29 |
30 | During Step 2 of the process, the script checks to see if the new URL matches the server URL where the migrate.php script is sitting. If they don't match the script produces a warning. This is because in most cases they should be the same, and this warning will hopefully ward off unwanted spelling errors.
31 |
32 | What if I changed the URL incorrectly?
33 |
34 | You can run the script as many times as you like and it will not cause any unwanted problems, to get it to work you only need to make sure that the "from" or "current" URL is correct. If it isn't correct, nothing bad will happen!
35 | The script does exactly the same thing each time it is run, therefore if you want to test it by changing your WordPress install to a dummy URL and back again, you can :)
36 |
37 | More Information
38 |
39 | For more details please see the blog post at: hannah.wf/migrate-announcement
40 |
41 | Contribute
42 | Feel free to raise bugs and open PRs. Try to keep to the existing code style. If you're interested in becoming a committer drop me a message.
43 |
44 | Changelog
45 |
46 |
47 | - Version 0.0.4
48 | - Bugfix / support for https:// thanks to Bteryk
49 |
50 |
--------------------------------------------------------------------------------
/script/migrate.php:
--------------------------------------------------------------------------------
1 |
91 |
92 |
93 |
94 | Migrate URLS in WordPress
95 |
115 |
116 |
117 |
118 |
119 |
ALWAYS backup your database before making changes!
120 |
Try using the WP-DB-Backup Plugin if you need help.
121 |
122 |
Migrate WordPress
123 |
124 |
125 | Cannot find config file. Please make sure this script is installed at the same level as wp-config.php and try again
');
128 | }
129 |
130 | mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD) or die('Could not connect to the database
');
131 | mysqli_select_db(DB_NAME) or die('Could not select the database
');
132 |
133 |
134 | $url_pattern = getUserSubmittedOrHardCodedUrl($_POST['url_pattern'], $current_url);
135 | $url_replace = getUserSubmittedOrHardCodedUrl($_POST['url_replace'], $replacement_url);
136 |
137 | // IF NOT SUBMITTED
138 | if((!$_POST['submit_urls'] || ($_POST['submit_urls'] && (!checkURL($url_pattern) || !checkURL($url_replace)))) && (!$_POST['submit_confirm'] || ($_POST['submit_confirm'] && !$_POST['confirm']))):
139 | ?>
140 |
141 | Step 1: Setup...
142 |
143 |
144 | Your current URL () is not a valid URL.
145 |
146 |
147 |
148 | Your current URL () is not a valid URL.
149 |
150 |
151 |
152 | Enter the URL location of your current install, and the URL location of your new install.
153 |
154 |
167 |
168 | Note: You can define these URLs permanently by editing the script.
169 |
170 |
189 | Step 1: Setup...
190 |
191 | - Current URL is set to:
192 | - Replacement URL is set to:
193 |
194 |
195 |
196 | Step 2: Confirm...
197 |
198 | - Home URL: - Home URL will be replaced' : 'Home URL is OK'; ?>
199 | - Site URL: - Site URL will be replaced' : 'Site URL is OK'; ?>
200 | - GUIDS: 0 ? $guid_count . ' need updating' : 'No updates necessary'; ?>
201 | - Content: 0 ? $content_count . ' need updating' : 'No updates necessary'; ?>
202 |
203 |
204 |
205 |
206 |
207 | Your current URL () is not the same as the current home URL (). This could cause issues. Please confirm you want to proceed below.
208 |
209 |
210 |
211 | Your current URL () is not the same as the current site URL (). This could cause issues. Please confirm you want to proceed below.
212 |
213 |
214 |
215 | Your replacement URL () is not the same as the current server URL (). Please confirm you want to proceed below.
216 |
217 |
218 |
219 |
220 | 0): ?>
221 | database entries will be migrated
222 |
223 |
224 | You must confirm the changes to continue!
225 |
226 |
227 |
228 |
229 |
242 |
243 |
244 | Nothing to migrate!
245 |
246 |
247 |
248 | Updating siteurl';
257 |
258 | $sql = "SELECT option_value FROM `" . $table_prefix . "options` WHERE option_name = 'siteurl'";
259 | $result = mysqli_query($sql);
260 | $row = mysqli_fetch_assoc($result);
261 | $old_value = $row['option_value'];
262 | $new_value = str_replace($url_pattern,$url_replace,$old_value);
263 | $update = "UPDATE `" . $table_prefix . "options` SET option_value='" . $new_value . "' WHERE option_name='siteurl'";
264 | $result2 = mysqli_query($update);
265 | if($result2)
266 | {
267 | $log .= 'Updated siteurl successfully!
';
268 | $count++;
269 | }
270 | else
271 | {
272 | $log .= 'Something went wrong, siteurl wasn\'t updated
';
273 | $error++;
274 | }
275 | }
276 |
277 | if($home !== $url_replace)
278 | {
279 | $log .= 'Updating home
';
280 |
281 | $sql = "SELECT option_value FROM `" . $table_prefix . "options` WHERE option_name = 'home'";
282 | $result = mysqli_query($sql);
283 | $row = mysqli_fetch_assoc($result);
284 | $old_value = $row['option_value'];
285 | $new_value = str_replace($url_pattern,$url_replace,$old_value);
286 | $update = "UPDATE `" . $table_prefix . "options` SET option_value='" . $new_value . "' WHERE option_name='home'";
287 | $result2 = mysqli_query($update);
288 | if($result2)
289 | {
290 | $log .= 'Updated home successfully!
';
291 | $count++;
292 | }
293 | else
294 | {
295 | $log .= 'Something went wrong, home wasn\'t updated
';
296 | $error++;
297 | }
298 | }
299 |
300 | $sql = "SELECT ID, guid FROM `" . $table_prefix . "posts`";
301 | $result = mysqli_query($sql);
302 |
303 |
304 | $log .= 'Updating ' . mysqli_num_rows($result) . ' post guids
';
305 |
306 | while($row = mysqli_fetch_assoc($result))
307 | {
308 |
309 | $id = $row['ID'];
310 | $old_guid = $row['guid'];
311 | $new_guid = str_replace($url_pattern,$url_replace,$old_guid);
312 | $log .= 'ID: ' . $id . '
OLD: ' . $old_guid . '
NEW: ' . $new_guid . '
';
313 |
314 |
315 | $update = "UPDATE `" . $table_prefix . "posts` SET guid = '" . $new_guid . "' WHERE ID = '" . $id ."'";
316 | $result2 = mysqli_query($update);
317 | if($result2)
318 | {
319 | $log .= 'GUID updated successfully!
';
320 | $count++;
321 | }
322 | else
323 | {
324 | $log .= 'Something went wrong
';
325 | $error++;
326 | }
327 | }
328 |
329 | $sql = "SELECT ID, post_title, post_content FROM `" . $table_prefix . "posts` WHERE `post_content` LIKE '%" . $url_pattern . "%'";
330 | $result = mysqli_query($sql);
331 | $log .= 'Updating ' . mysqli_num_rows($result) . ' posts contents
';
332 |
333 | while($row = mysqli_fetch_assoc($result))
334 | {
335 |
336 | $id = $row['ID'];
337 | $old_content = $row['post_content'];
338 | $new_content = str_replace($url_pattern,$url_replace,$old_content);
339 |
340 | $log .= 'ID: ' . $id . '
TITLE: ' . $row['post_title'] . '
';
341 |
342 |
343 | $update = "UPDATE `" . $table_prefix . "posts` SET post_content = '" . mysqli_real_escape_string($new_content) . "' WHERE ID = '" . $id ."'";
344 | $result2 = mysqli_query($update);
345 | if($result2)
346 | {
347 | $log .= 'Post content updated succesfully!
';
348 | $count++;
349 | }
350 | else
351 | {
352 | $log .= 'Something went wrong
';
353 | $error++;
354 | }
355 | }
356 | ?>
357 |
358 | Step 1: Setup...
359 |
360 | - Current URL is set to:
361 | - Replacement URL is set to:
362 |
363 |
364 | Step 2: Confirm...
365 |
366 | - Confirmed migration of database entries
367 |
368 |
369 | Step 3: Results...
370 |
371 |
372 | database entries migrated succesfully
373 |
374 |
375 |
376 | database entries failed to migrate
377 |
378 |
379 |
380 | Details
381 |
382 |
383 |
384 |
385 |
386 |
387 |
388 |
389 |
390 |
391 |
--------------------------------------------------------------------------------