Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
August 4, 2015 07:18 pm

Toolbox of the Smart WordPress Developer: WXR File Splitter and WP Serialized Search & Replace

In the introduction part of this series, I mentioned that "WordPress tools" can't be defined in one specific medium: A WordPress tool can be in the shape of a WordPress plugin, a single PHP file, a website or even a desktop application.



In this part of the "Toolbox of the Smart WordPress Developer" series, we're going to go through two different tools in two different types of medium: WXR File Splitter (as a desktop application) and WP Serialized Search & Replace (as a PHP file).



Splitting Large Backup Files



If you're a freelance web designer or working at a web design agency, and you're reading this article, chances are you regularly install WordPress on servers, so you know a bit (or a lot) about migrating WordPress. And if you're one of the lucky few WordPress developers, you might have had a client with a huge website that needs to be migrated between two servers.



While there are dozens of different techniques and options out there to move WordPress installations, in some cases, we might have none other than the most reliable one: the WordPress Extended RSS (WXR) backups.

What if your client gives you the old, crappy shared server's WP-Admin credentials and nothing else? What if that new hip WordPress plugin can't migrate from your old server to the new one? When the dark times come, you must be ready and prepared.



If the WXR backup is huge (and I mean gigabytes of huge), the WXR File Splitter will be the one that dashes away your tears.



Working With the WXR File Splitter

WXR File Splitter screenshot


Bad news first: This tool, which works in Windows, is old. Super old. And it doesn't work. I mean it doesn't work with the newer WordPress versions (for the last two years, probably). I'm not joking.



But of course, I'm not going to write about a tool that's totally useless. So the good news is, it's extremely easy to make it work—so easy that you'll just need to do a quick search & replace in your backup file.



Let's go over the steps:




  1. Download the tool here (before that website goes down as well).

  2. Download your backup file from your admin panel's Tools > Export page.

  3. Open your backup file and make all your <item> tags uppercase (by searching and replacing the opening tags only—no need to do the same with </item> tags) and save the file.

  4. Open the WXRsplit.exe file.

  5. Set the size of the output files (and the number of files will be calculated automagically).

  6. Click on the Split Files button.



Ordeal? Well, it should be: If your client hands over the admin panel of a website that's hosted on servers used in World War II, the solution to your migration problem shouldn't be easy. Right?



Oh, and there's a Mac OS X version developed by an unrelated developer—but I haven't had the chance to try it (and have a nervous breakdown because of it) because I don't own a Mac.



Now, let's move on to our second tool: WP Serialized Search & Replace.



Safe Search & Replace Operations in Your WordPress Database With WP Serialized Search & Replace



I worked at a web design agency once, back in 2012. On my first day, I reviewed some past projects to see how we worked with our clients. I saw that when we landed a client, we started building their website in a subdomain of our own brand domain and showed our work to the client when necessary; and when everything was set (including getting the last payment), we moved the website to the client's domain.



That day I immediately proposed to change this workflow with our clients, because it slowed down our work; but the boss rejected my proposal because of "financial reasons". He explained that in the past, some clients had tried to steal our work right before the last payment, and that's why we were working like this. "Nonsense", I thought, but he was the boss after all.



My first work was a high-priority client that needed the website as fast as possible. (Luckily, the content was sent beforehand.) I quickly installed WordPress to a subdomain of our website and activated the theme (selected by the client) along with some plugins. I adjusted all the settings of the core, theme and plugins, and then started working with the content.



When I'd finished (and impressed the boss by speed-painting a whole website in less than four hours), we showed the website to the client and immediately got an approval and a message saying the website should be up and running tomorrow as they were going to visit an expo.



With confidence, I decided to do some overtime and move the website that day. I downloaded all the files from FTP and instead of doing a quick WXR backup, I did an SQL backup in phpMyAdmin. After changing the website URLs in the wp_options table, I uploaded the files and submitted the SQL to the client's website's database. Oh, and I quickly deleted everything in the development subdomain.



When I noticed that the featured images were broken, I reviewed the SQL file and saw that they all still had URLs from our own website's subdomain. I did a quick search & replace, saved the changes in the backup, and overwrote the database with the new SQL. When I visited the website, I saw not onlythatthe images were still broken, but also that all the posts were gone, even though they were still in the database.



That's the day I learned about "serialized entries". (I also got back home at midnight, because I worked the rest of my day building the same website once again on the client's server.) From that experience, I learned that serialized entries are stored with character count, and if the character count isn't consistent with the string, WordPress omits the entry altogether.



So, how do we do a search & replace in WordPress, including the serialized entries? With WP Serialized Search & Replace, of course.



Using WP Serialized Search & Replace



WP Serialized Search and Replace screenshot


WP Serialized Search & Replace is more like a portable tool: You just upload the folder (into your WordPress installation directory) and run the index.php file. So, if your WordPress files are in mywebsite.com/wp/ directory, you should run the tool from mywebsite.com/wp/srtool/index.php (the name of the tool's folder doesn't matter so you can change the folder name if you want).



After running the tool, you'll see five sections:




  1. Search/Replace: Has two input fields for "search" and "replace" fields, and a checkbox to turn on regular expressions.

  2. Database: Has four input fields for your database credentials. The tool auto-fills these fields by checking the wp-config.php file.

  3. Tables: By default, the tool will work in all database tables, but if you want to, you can select individual tables by clicking on the "Select Tables" radio box, or by filling the two input fields to exclude or include tables.

  4. Actions: There are five actions in this section: "Update Details" reconnects to the database if you change database credentials, "Dry Run" simulates the search & replace process, "Live Run" actually runs the search & replace process, "Convert to InnoDB" converts the database engine into InnoDB, and "Convert to UTF8 Unicode" converts database tables' character sets into Unicode.

  5. Delete: Deletes the tool, the whole folder.



I must say, I really liked the design, but I believe this tool would work better as a WordPress plugin.



Wrapping Up for Today



We picked up the pace a little for this part only and went over two little WordPress tools in a single post. I believe both of them deserve credit, despite being a bit off the radar in the WordPress community.



What do you think about these tools? Do you know better alternatives? Share your thoughts and experience with us in the Comments section below. And if you liked the article, don't forget to share it with your friends!



See you in the next part where we'll be talking about the WordPress GitHub Plugin Updater, a great tool to handle the update process for WordPress plugins hosted on GitHub.


Original Link:

Share this article:    Share on Facebook
No Article Link

TutsPlus - Code

Tuts+ is a site aimed at web developers and designers offering tutorials and articles on technologies, skills and techniques to improve how you design and build websites.

More About this Source Visit TutsPlus - Code