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
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.
[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.');
- }
Using custom CSS in cForms
Pretty much every WordPress installation I've done in the last few years has got cForms installed. Its one of the must have plugins.
Many people are unaware of the custom CSS options available in cForms. Ever edited a default style and lost it during an upgrade? Annoying isn't it?
Here's how you make a custom, upgrade proof CSS skin for your cForms.
Debugging WordPress
Debugging WordPress is actually quite simple. Stop yourself going grey and or bald.
In your wp-config.php, replace
With
This will turn on debugging and debug events will be wrote to wp-content/wp-debug.log. Bonzer!
Optionally, you can add, to turn off on screen error reporting if your php.ini isn't already doing so.
WordPress function remove_menu_page
WordPress is now being used more and more for a full site CMS and the "Links" or "Blog Roll" is pretty much redundant now. People seem to be going to great lengths to remove this from the WP admin page. I've seen people use Role Manager plugins, wierdo so called "CMS" plugins and plugins specific to removing the "Links" link.
Using WP-Ecommerce Product Downloads without checking out
I've used WP-Ecommerce for a few clients who required an online catalogue, rather than an online store.
One client required a custom product display and wanted to print out the product downloads in the single_product.php file. Apparently its not possible as we're using Product Downloads for something other than what it was designed for.
It was originally designed for electronic products, you add to basket, pay and you can download the product downloads.
Cleaning up WordPress Header
WordPress implements some HTML standards compliant code in the top of every page. Sometimes you just don't need it. I'm all for keeping page size as small as possible and ultimately quick at loading.
Lets look at the remove_action function from WordPress.
One too many WordPresseseses
No wonder I have a head ache. locate wp-config.php | cat -n reports fifty WordPress installs. If only WP-Mu was any good.
Using WordPress header and footers externally
I needed to integrate a WordPress header (header.php) and footer (footer.php) into an external application.
There are quite a few ways round this, but none are really ideal. For example, if you want to include an external page in WordPress for whatever reason, you could use the Exec-PHP plugin. Simple, hey? No.



