kieranbarnes Independent PHP, WordPress & CubeCart Programmer

[Snippet] Setting the timezone for PHP 5.3

Posted on January 25, 2012

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

  1. // London, England, Europe
  2. date.timezone = "Europe/London"
  3. date.default_latitude = 51.500181
  4. date.default_longitude = -0.12619

TimThumb upscale fix: stop timthumb from upscaling small images

Posted on December 5, 2011

 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

Posted on December 1, 2011

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_elementsvalid_child_elements parts of the code.

Use the following code

Make an SEO friendly URL in PHP

Posted on November 20, 2011

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.

Tagged as: , , , Continue reading

PHP Header Redirects

Posted on November 4, 2011

There's a few ways to redirect a page in PHP. Well, two. A right and a wrong.

Wrong Way

  1. header('Location: foo.php ');

Right way

  1. header('HTTP/1.0 302 Found');
  2. header('Location: foo.php ');

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.

Tagged as: , No Comments

WordPress/Shopp Shipping Calculator/Options Access-Control-Allow-Origin Error

Posted on November 4, 2011

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

Posted on November 3, 2011

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.

  1. {if $smarty.server.REMOTE_ADDR == 'YOUR.IP.ADDRESS'}
  2. {debug}
  3. <pre>
  4. {$smarty.request|@print_r}
  5. </pre>
  6. {/if}

 

 

[Snippet] Allow PHP in Smarty (CubeCart 5)

Posted on September 28, 2011

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

Posted on September 21, 2011

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!

Filed under: PHP, WordPress No Comments

[Snippet] Programmatically add a WordPress User

Posted on September 15, 2011

Here's how I would programmatically add a WordPress User

  1. require('../wp-blog-header.php');
  2.  
  3. $user_name ='kieran';
  4. $user_email = 'kieran@bl0ke.org';
  5.  
  6. $user_id = username_exists( $user_name );
  7. if ( !$user_id ) {
  8. $random_password = wp_generate_password( 12, false );
  9. $user_id = wp_create_user( $user_name, $random_password, $user_email );
  10. } else {
  11. $random_password = __('User already exists. Password inherited.');
  12. }
Tagged as: No Comments
Page 1 of 1012345...10...Last »