Using Persistent Cache in WordPress (with APC)
Ever since WordPress 2.5, the WP Cache functions haven't been persistent, so the cached objects are only available for the page load (or script run). This means that data stored in the cache resides in memory only and only for the duration of the request.
Upto version 2.5 we could have simply added define('WP_CACHE', true) to the wp-config.php and we got persistent cache features. This is no longer the case and isn't really very well documented.
The later versions need a Persistent Cache Plugin. I'm not a fan of some of the larger caching plugins like W3 Total Cache or WP Super Cache as they tend to add complexity and can cause other problems. Besides, as developers, we're better off writing the code ourselves.
Before going any furuther its probably worth pointing out WordPress has two persistent caching methods.
The first method is the WP Transients API,
- Not much documentation
- Only allows caching of objects to the database so may not be faster
- http://codex.wordpress.org/Transients_API
The second method is extending the existing WP Object Cache that is currently throughout your WordPress site already.
- Extending this object is much more flexible
- Can extend into APC, memcache or similar
- Provides a fast cache for basic WordPress functions even before you write your own code
New Site: Lizzie Lane – Hand Selected Beautiful Jewellery and Gifts
Today I completed work on another customer's site: Lizzie Lane - Hand Selected Beautiful Jewellery and Gifts.
My tasks were to develop some custom templates for it's Thesis based theme, many Shopp modifications including fixing an XSS issue in Shopp, making Shopp work with SSL (something it does not do out of the box), some CSS work and various other Shopp modifications.
WordPress Auto Install Script for cPanel
I have released version one of my WordPress Auto Install Script for cPanel.
This script can be run from /scripts/postwwwacct to automatically download, install WordPress and create the required database and database username.
No 3rd party licenses, scripts, FTP sessions. No outdated versions, always grabs the latest version from WordPress.org
This script is available upon request for £50. Get in touch for details.
WordPress/Shopp Shipping Calculator/Options Access-Control-Allow-Origin Error
I've recently been debugging a customer's WordPress/Shopp store. When the customer set the Cart & Checkout to be served over SSL the shipping calculator failed.
Serving Cart / Checkout / My Account pages over SSL is not built into Shopp for some reason. I have a post on this - SSL/HTTPS for Shopp pages or checkout process only. If you use a shipping calculator, or offer different shipping methods this will fail.
How To List A Custom Post Type’s Taxonomies And Terms
Jennifer M. Dodd has published a brilliant article on listing post taxonomies / terms / formats & categories. I love it!
Entitled How To List A Custom Post Type's Taxonomies And Terms, she offers two functions that cover displaying all custom taxonomies, terms, post formats, categories and tags.
Just saved me hours writing my own. Thanks!
[Snippet] Programmatically add a WordPress User
Here's how I would programmatically add a WordPress User
- require('../wp-blog-header.php');
-
- $user_name ='kieran';
- $user_email = 'kieran@bl0ke.org';
-
- $user_id = username_exists( $user_name );
- if ( !$user_id ) {
- $random_password = wp_generate_password( 12, false );
- $user_id = wp_create_user( $user_name, $random_password, $user_email );
- } else {
- $random_password = __('User already exists. Password inherited.');
- }
Highlighting current page in WordPress Menus
By default, wp_nav_menu doesn't create a .current_page_item or .current-menu-item class for certain elements in a wp_nav_menu, for example if you are viewing a custom post type archive or single page.
Here's some code to fix that. Bang it in functions.php
Don't forget to create your CSS classes if you already haven't done so.
Redirecting a custom post type
Ever had to rename a custom post type? Pain in the ass. Lets just redirect it instead.
Edit your functions.php
- add_rewrite_tag('/<old name>/','<new name>','top');
Simple as that.
WP-Ecommerce documentation still sucks
WP-Ecommerce documentation still sucks.
I'm sorry too!
Splitting WordPress content with ‘more’ on single pages
WordPress uses the "More" button to create a small snippet of content, usually used on the blog page, to create article teasers and such. WordPress ignores the "More" function on single posts, pages and several other pages.
Here's some code of make use of the "More" function on single pages and single posts. Perhaps splitting the content into columns or hiding extra content in an accordion or pretty much anything. Look, I'm going to press the "More" button right now.




