Last week while doing some Google searching, I notice my SEO meta data on this site had been hacked. Oh joy… A little poking around quickly confirmed the issue/problem. Oh joy, again… Time for a little cleanup. Thought I’d share the process in case any of you find yourselves in this predicament.
- Make a backup, just in case things go horribly wrong. For me, since I knew what I wanted to preserve, I just grabbed a copy of my database and uploads folder. If you’re not familiar with WordPress, you might just want to grab everything.
- Quick assessment/documentation of the site – plugins, theme, site configurations – anything you’ll need to put back.
- Decision time: to clean it up or blow away and start fresh. For me, I decided it’d be easier to blow everything away and start fresh – I only have about 500-ish posts and only about a 100 or so uploads. And this site has been through various themes, conversions, etc., so the database, along with the hack had grown way beyond anything I wanted to try and clean up. Miss something and all that effort could go down the drain, so it’s was just easier to start fresh. Your mileage may vary.
- Next I disabled any plugins I wasn’t interest in keeping – an attempt to make the export process as clean and simple as possible.
- Export “all content” using the export feature of WordPress. You want to be sure you’re exporting from the most current version of wordpress. More precisely, you want to make sure whatever version you export from will be the same version you’ll reimport into.
- Now that you have your content (the XML file WordPress just exported for you) and other important files you snagged from the backup process, you’re ready to blow away your existing WordPress install. For me: I simply created a new database, along with a new database users and password for safety. I then blew away all the WordPress files except for my /wp-content/uploads folder. Now, you need to systematically go through your uploads folder and verify everything in there belongs and is clean – don’t just assume – verify or all this work could be for nothing.
- Now go download new/clean copy of WordPress – don’t use your existing files since they could have been compromised. Again, it’s important that your versions remain consistent, so be sure to use the same version you exported with earlier. Upload your new files and configure WordPress to use your new database. The configuration/install process is triggered by simply accessing your website URL after you’ve finished uploading WordPress. Be sue you use a new admin password, you old one is compromised – it’s also a good idea to steer clear of the “admin” username period.
- Now that WordPress is functional, but empty, go download plugins and themes you may need. Again, these should be fresh downloads, being sure you keep the versions consistent.
- Ready for import. Simply click on tools import – WordPress. You’ll have to download and install the WordPress import plugin, but if you made it this far, you’ll make it through that. Once the plugin in installed, you simply import the content. You’ll have the option to reattribute post to existing or other users. You can also decide wether or not you wan to download/import files.
A couple of things about about the import process. At the time I’m writing this it’s WordPress is 3.7.1 and the importer is 0.6.1, things do change. The first time I ran the importer I didn’t check the “download and import file attachment” option. Remember, I left my “cleaned” wp-content/uploads directory in place. This preserved all my image links and such, but didn’t populate the media library – it was empty. Not exactly what I wanted, so I dropped all the table in the database and went through the WordPress configuration and import process again, this time checking the “download and import file attachment” option. That populated the media library, but create a couple new problems:
- It duplicated, and in couple of cases tripled all of my files. I assume this was because the import process was acquiring/downloading and writing the files to the same directory and simply append the file names with a 1, 2 or 3. Oh well – no biggie.
- But on some posts it also didn’t edit the img link correctly to reflect the new file name it just created during the import process.
- Most, if not all, relationships between the media library files and the posts they were used in were broken – not attached.
Not to worry, all isn’t lost. I simply examined all the post that had image links. Using the Search Regex plugin I searched all posts for img tags. That’ll help you identify the posts, then basically you just have to examine and repair any posts where the image link got fouled up. During this process I also relinked these posts to the media library file so those relationships would exist. Finally I went back through my uploads folder and deleted all the duplicate files the importer plugin had created.
All-in-all, it sounds a lot worse that what it was. If the importer plugin had worked correctly, this would have been a piece of cake, even so, it just took a little extra effort to clean up from the import process. My almost 50MB database had been reduced to just over 1MB, the site nice and speedy again and my Google searches where no longer polluted with a bunched of hacked up meat data after a few days.
This time I’ll do a better job of keeping my WordPress, plugins and themes updated.