[Snippet] Setting the timezone for PHP 5.3
PHP 5.3 requires a time zone to be set if you do any kind of date processing.
Simply set this in your php.ini
TimThumb upscale fix: stop timthumb from upscaling small images
Ever found that TimThumb is upscaling your small images and looking crap? As of version 2.8.1 TimThumb does not check if the image is smaller than the specified proportions before resizing.
Here's a fix thanks to Rein Aris, slightly updated to work with version 2.8.1
Embedding Videos with TinyMCE
By default TinyMCE strips out any code that you would use to embed videos or Flash into your site. To allow videos to be embedded you need to change how TinyMCE init's.
Mainly, the valid_elements, extended_valid_elements & valid_child_elements parts of the code.
Use the following code
Make an SEO friendly URL in PHP
Just like WordPress creates it's slugs or friendly URLs, I had to write some code to achieve the same for a customer running a custom web application.
Here's how I did it.
PHP Header Redirects
There's a few ways to redirect a page in PHP. Well, two. A right and a wrong.
Wrong Way
Right way
This is evident on IIS6 and IIS7 where the wrong redirect will just fail.
Even if you are not using IIS6 or IIS7 its good practice to set the headers correctly and exit the script.
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] Debugging Smarty on a live site
Development server? Staging server? What are they? Sometimes we have to debug code on a live server. You know it.
Adding the following code to your Smarty template will enabled the Smarty Debug Console for your eyes only.
- {if $smarty.server.REMOTE_ADDR == 'YOUR.IP.ADDRESS'}
- {debug}
- <pre>
- </pre>
- {/if}
[Snippet] Allow PHP in Smarty (CubeCart 5)
Although it is generally bad practise to put PHP code directly into your (CubeCart 5) Smarty templates, its sometimes inenvitable.
You will need to edit controllers/controller.index.inc.php
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.');
- }



