How-To: Fix WordPress plugin updates and DB backups not working

If you, like me, got too big for your boots and tried to lock down your server using ‘best practice’ pre-rolled apache server config settings without fully understanding how they work – then good on us both for trying, but let’s never do it again.

Specifically, I tried to lock-down click-jacking like this in my httpd.conf:

There’s lots to read about click-jacking, but what was most important to me was that it pretty much knackered my WordPress install to the point where I could only update a single plugin at a time, and after every plugin updated I had to delete the “.maintenance” file to get the site back running. That and WordPress and theme updates would complete, but never TELL me they’d completed, so I’d just have to wait a while then go back to the admin page and hope for the best.

Anyway – if you have this issue, and have used X-Frame twiddling stuff in your apache config, the short answer is: Don’t.

How To: Disable the Proofreader in WordPress

I liked the WordPress proofreading service at first, but then it started telling me that basically everything I wrote was wrong, and that I should dumb down every single post to include only words which lifetime readers of the Sunday Sport would understand. So I wanted to disable it – only I couldn’t find the option…

It’s under Users > Your-Profile

WordPress Proofreading Settings

If I’d thought of it as a per-user setting I’d have looked there – and admittedly, it makes sense for it to be a per-user setting.

But damned if I could find it.

Site Change Pending – Welcome to 2011

I managed to break this site the other day when the theme I’m using (Freshy 2) decided to use a different set of options. I obviously triggered it somehow, but I’ve no idea how – and then it all got confused about which options and CSS adjunct to use, and didn’t want to work with the customize plugin and… yeah, it all went a bit Pete Tong. Given that the Freshy 2 theme is unsupported and doesn’t really work that well past WordPress 2.7 (which is pretty legacy), it’s no wonder strange things have been just waiting to occur, but I’ve got it back to a semblance on sanity (as you might be able to tell since you’re reading this, and noticing it doesn’t look a million miles different from before – apart from comment threading, promise me you won’t look!). I even backed up the entire www folder three days before it all went to hell, but when I restored the backup it’s still shafted, so the Freshy options must be stored elsewhere (like in the database somewhere)… but anyway, I digress; it’s time to shake things up.

Kicking and Screaming

I started reading about CSS3 the other day, and began knocking up examples of all the cool things you can do with opacity and 2D transitions and stuff – and it’s awesome. I had absolutely no idea you could do such cool stuff without JavaScript or Flash, and if you apply it to the experience layer (as opposed to the core functionality layer), then even if people are viewing your site in older browsers it can gracefully degrade and leave those running some archaic IE variant none the wiser that should they be seeing the site in Chrome or FF5 or such it’s got a lot more swish. I might even try some HTML5 shenanigans…

This isn’t going to change the core content for the better (sadly), but if the medium is truly the message, then perhaps by giving the medium an overhaul and a good lick of paint I can emphasize the message to a certain extent.

I don’t want to even think about how much time I could waste on 3D transitions… the sky’s the limit, ya know?

Stepping Up

So, to get the site all sorted, I have a (not especially cunning) plan:

  1. Get an offline version of the site running locally so I can twiddle the hell out of it. [COMPLETE]
  2. Rip the Freshy theme to bits, and combine all the CSS and CSS adjucts (which get pulled in and override the core styles) into a single CSS file. [COMPLETE – 2011-08-08]
  3. Remove all the cruft from the Freshy CSS and PHP. And there’s a lot of it. Tons. [96% COMPLETE 2011-08-10]
  4. Rewrite the core layout utilising CSS3 and perhaps HTML5 elements to make it look beautiful. [60% COMPLETE 2011-08-09]
  5. Bask in the radiant glory of a modern, dynamic website. [PENDING]
  6. Write good articles =P [ARGUABLE]

Speaking of which, I’ll write an article on getting an offline version of a site running soon – it actually took me a couple of hours to get everything installed, configured, database suitably modified (to keep me on the local copy at all times) & imported into MySQL etc. But now I have, I don’t have to do surgery on a live site, and can thus afford to break the hell out of my local copy, because things tend to get a lot worse before they get a lot better, and this version will still be up and running in 99% “good enough” mode.

Honestly though, CSS3 is amazing – check it out. I can’t wait to see what I can come up with =D

How To: Disable All WordPress Plugins from the Database

I added a couple of WordPress plugins the other day to tack on a little bit of extended functionality to the site, but things went badly, and some bizarre interactions between plugins meant that I couldn’t log in to the WordPress administration interface – it would just throw me back to the main site without even having the option to log in… As such, I couldn’t disable the plugins (because you need to be in the administration interface to do that!), so what the heck to do?

You might think to ssh in to the box and remove the plugins from the …/wp-content/plugins/ folder to disable them (as I did) – only this won’t work. What we really need to do is disable the plugins directly from the database – and luckily for us it’s a pretty simple process as long as we can ssh into the box!

Note: If you dont’ have ssh access to your server, you could always take the phpMyAdmin route to achieve the same goal through a web interface, but if the problem you have is related to being redirected all the time (like mine was) then the direct DB access way is really the only way to go!

Gaining SSH Access

If you’re running linux you’ve already got a ssh client built in, if you’re on Windows then you’ll probably want to get yourself a copy of PuTTY or such.

Assuming the IP address of your server is 1.2.3.4, then you can ssh to the box with:

In the above command the switch is “minus lower-case-L”, not “minus pipe-symbol” or anything, and if you’ve changed your ssh port away from the default of 22, then you can just add the switch -p , so if my ssh daemon was running on port 2233, and I wanted to log in as the user bob, I’d use:

Connect to MySQL

Once you’ve got a ssh connection to the server, the next thing you’ll want to do is connect to your database, with the following command:

So if I had a MySQL administrator called dbAdmin I’d use:

The -p switch on the end will prompt you to enter the password for your MySQL admin user account – don’t worry if you’ve forgotten the credentials you should use – they’ll be in your WordPress wp-config.php file, which is usually located in your www or htdocs root folder (on Linux this is usually /var/www).

Quick Tip: By placing your wp-config.php file in the web root it’s possible for it to be accessed by malicious types, but you don’t have to place it here! You can, in fact, move the file one level up so that it’s outside of the web-root and WordPress will still be able to find it, but scoundrels won’t! So if you’re running WordPress with all your files in /var/www/ just move the wp-config.php file up to /var/ and it’ll still work and be safer! You can do this from the ssh terminal with:

Manipulate the Database

Once you’ve got administrator access to MySQL you need to connect to your database (again, the database name will be in your wp-config.php file), so if we’d called our database myWebDB then we could connect to it through the MySQL command line interface with:

Once this has connected successfully, all you have to do to disable all plugins is issue the following command:

That’s it! Attempt to access your site! Any plugins which were causing mayhem will now be disabled, and you can then add them back one-by-one until you find the combination that’s stuffing things up!

Cheers!

Props: Many thanks to Jeff Star of PerishablePress for his article Quickly Disable or Enable All WordPress Plugins via the Database which saved my bacon, and prompted me to write this quick guide.
Flattr this

How To: Assign WordPress Posts to Specific Pages

WordPress is a really nice WCMS and I’ve been really happy with it ever since I first migrated over back in February ’09, but it definitely has some limitations with regard to how you can structure your site.

Let’s take an example: Joe Blow has a site on hunting, camping and fishing – he writes regular articles on each of these specific categories, and he wants these posts to turn up either just in the specific Hunting/Camping/Fishing pages he’s created, or he wants them to turn up on the home page and also in the category specific pages.

I came up against this problem when I wanted to import a bunch of articles from back when I ran r3dux.org on PHP-Nuke – I didn’t want the “new” (i.e. imported from Nuke) posts cluttering up the home page of the site, I wasn’t going to run the old Nuke portal because it’s full of deprecated code & security flaws – but I wanted the old posts added and available from an “Old Site” page which I could put in the header – so how do we go about this? Easily – via a couple of useful plugins!

Definitions

Before we continue, it’s worth spelling out exactly how WordPress defines Posts, Pages and Categories so we don’t get our terminology all mixed up and make things harder than they have to be:

  • A Post is a single article entry, with at least one category (even if that category is the “uncategorised” category!) and may optionally contain some some tags which are keywords for the article.
  • A Page is a static, single post which can be easily be linked into the header of your site. It does not contain other posts – it is simply a single post with a special tag that makes it easy to link in the header, and is commonly used to put information about the website author, FAQs, contact pages etc.
  • A Category is a database field associated with an article to categorise it, such “Hunting”, “Fishing”, “Humour”, “Politics” etc. You usually set up a bunch of categories, and then select one or more of them to categorise your article, so for a funny joke about fishing, you might have the post categorised with both the “Fishing” and “Humour” categories, and you can then select to view all posts which are classified as this category or that category in a single page (or all posts of some category, showing 5/10/20 posts at a time etc.).

The Fix

This is all well and good – but it’s this static, single post nature of Pages that what’s so unintuitive and can easily trip us up – we can’t link to categories from a page (well, you can, but you have to link from inside the static page, and then you just get a list of article links – which sucks), so we need something to be able to do that for us – and this is where the plugins come in. Specifically we’re going to be using:

  • Mark Jaquith’s Page Links To plugin, and
  • The RYO Category Visibility plugin [optional – get the beta version from the bottom of the post to use with WordPress 3.01 and higher!]

In combination these two plugins will set a page (i.e. header link) so that instead of it going to a single static “Page”, it instead links to a category list of posts of a given category, and (if you want to) additionally stop posts assigned to specific category from turning up on the main “home” page…

Installing and Configuring

  1. Go to both of the above links and download the WordPress plugin .zip file from each (you don’t need the category visibility plugin if you don’t want to hide posts from the main “home” page)
  2. Log in to your WordPress dashboard and click on the Plugins link in the left administration bar, then click the Add New button at the top and point it at a plugin .zip file and click upload. Once it’s uploaded and installed, don’t forget to activate each plugin. Do both plugins if you want them…
  3. To use the Page Links To plugin you just create a new page (or edit an existing one) and right at the bottom of the WordPress page where you enter the “Page” details, you’ll see this section:

    WordPress Page Links To plugin

    You can fill in the URL to be anything you like, so in my case I’m linking to a list of all posts in the “Old-Site” category – you can link any category or specific post on your site, or link to http://www.google.com or http://news.bbc.co.uk – it’s entirely up to you!

  4. Next, if you want to hide posts from the main page, go back to the Dashboard and look for the RYO Plugins button right at the bottom on the left (underneath Settings) and click it!

    WordPress Category Visibility Plugin

    From here you can see the list of categories along with their numeric IDs, and you can see that I’ve unticked the boxes on the Old-Site category for the Front and Feed options – which will ensure that any posts I put under the category Old-Site don’t appear on my home page or in the RSS Feed!

Conclusion

WordPress can be a little counter-intuitive and inflexible on its own, but because of its fantastic plugin architecture, and due to the great work of so many plugin authors, you have an incredible range of tools and techniques at your disposal to make your site work the way you want it to! So if you want to put posts about Gaming or Music or Films or anything into its own page, you can work around the architecture and get it done with just a couple of clicks. Good stuff :)