WordPress serialized data fixer
Changed your site address with a plain text search and replace, and now settings look empty? Repair the broken lengths here, or build the command that does it right.
Everything runs in your browser. Your text and files are never uploaded, saved or logged.
A Repair broken serialized data
Paste one value, or a whole .sql file. Only the wrong length numbers are changed. Everything else stays exactly as it was.
B Build a safe search-replace command
This is how to change your address without breaking serialized data. WP-CLI reads serialized data and writes the lengths correctly as it replaces.
Type both addresses to see the commands.
Back up first, always
The first command above saves your database with wp db export. Keep that file until you have clicked through the new site. To go back, run wp db import before-address-change.sql.
No WP-CLI on your host?
Then this command cannot be run for you. Ask your host whether they offer WP-CLI, or use a tool that is made to replace addresses in a WordPress database and that handles serialized data. If a plain text replace was already done, use part A above to repair the values.
How it works
Serialized text looks like s:5:"hello";. The 5 is the length of hello in bytes. After a plain replace the text changes but the 5 does not, so PHP cannot read the value.
Part A, the repair
- It reads the whole structure (arrays, objects, numbers, true and false, null, nested values), not just the text pieces.
- For a string with the wrong length, it tries each place where the string could end, and keeps the one after which the rest of the value still fits. A string that contains
";is handled this way. - In a SQL dump, it reads the quoted values, undoes the escaping to count the real bytes, and changes only the digits. Every other byte of the dump stays the same. A dump with nothing broken comes out identical.
- A serialized value stored inside another serialized string is fixed first, then the outer length.
- It does not guess. A value that is cut off, or that fits more than one way, is left alone and reported.
Part B, the command
It builds wp search-replace commands. WP-CLI reads serialized data and keeps the lengths right while it replaces, which is why it is the safe way. The builder puts a database backup first and a dry run before the real change. Flags were checked against the WP-CLI search-replace documentation.
Limits
- The text must be UTF-8. A file in another encoding is refused.
- Very deep values (over 1000 levels) are left alone.
- Browsers change Windows line breaks when you paste, and drop invisible NUL characters, so a pasted value may not match the database byte for byte. The tool warns when it sees the signs. See Move a WordPress site for the full job.
- It does not run commands and does not connect to your site.
FAQ
Why did my settings break after I changed my address?
WordPress stores some settings as PHP serialized text, such as s:19:"https://example.com";. The number is the length of the text in bytes. A plain search-and-replace changes the text but not the number. PHP then refuses to read the value, and WordPress treats it as empty, so widgets, theme options or plugin settings can look reset.
Why does the length count bytes, not letters?
PHP counts bytes. A letter like é takes two bytes, many Chinese or Japanese characters take three, and an emoji takes four. This tool counts bytes in UTF-8, the same way.
What does "could not fix safely" mean?
The tool only repairs a value when exactly one reading of the text fits the PHP format. If the value is cut off, was edited by hand, or two readings fit equally well, it is left exactly as it was and listed with the reason. A wrong guess would damage your data, so it does not guess.
Can I trust the result?
Only the digits of a length are ever changed. Every repaired value is checked again before it is shown, with a second length count. Still, back up your database first, and check your site after you put the repaired data back. Pasted text can lose Windows line breaks and invisible characters, so loading a file is the surest way.
How do I get the value out of my database?
In phpMyAdmin or a similar tool, open the table (for options it is usually wp_options), open the row and copy the cell text. For a whole database, export it as a .sql file and load that file here. With WP-CLI, wp db export writes a .sql file. Note that wp option get offers the formats var_export, json and yaml, not the raw serialized text.
Why is the guid column skipped?
WordPress's own guide to moving a site says a post's guid must never change, even when the address does. Feed readers use it to tell whether they have already seen a post, and changing it can make old posts show up as new. The same guide's WP-CLI example uses --skip-columns=guid.
Is there an easier way to move settings between two sites?
If you only need the settings, not the posts and media, WellTend Settings Snapshots exports them to a file and imports them on the other site after a preview, so nobody edits the database by hand. It does not move content, and it is not a backup.
What if I cannot use WP-CLI?
Then part B cannot be run for you. Ask your host whether they provide WP-CLI. If a plain replace was already done, part A can repair the values. Make a database backup before either step.