kieranbarnes Independent PHP, WordPress & CubeCart Programmer

Protect wp-admin with Nginx

Posted on May 1, 2012

Posted by kieran

Are you running WordPress on nginx? A massive security win is securing your wp-admin area by limiting IP access. How? Easy.

Drop these lines into your nginx.conf or relevant vhost config file

Loading jQuery in the footer

Posted on April 3, 2012

Posted by kieran

Loading Javascript in the footer has many benefits such as speed, you give priority to visual elements of your site. Your site will render for the visitor, then it will load the Javascript.

By loading Javascript at the end of the page, it immediately has access to the whole DOM, no waiting. If you are really clever, you can do away with your document.ready() function too

With WordPress its really easy to move the Javascript into the footer.

Use the following in your functions.php file

  1. wp_deregister_script('jquery');
  2. wp_register_script('jquery', '/wp-includes/js/jquery/jquery.js', false, false, true);
  3. wp_enqueue_script('jquery');
Tagged as: , Continue reading

[Snippet] Adding your custom taxonomy to post/page list in WordPress

Posted on March 5, 2012

Posted by kieran

Custom Taxonomies are amazing for organising your post data. Here's a simple way of showing your custom taxonomies on the post/page list in wp-admin.

In the image below you can see we are now showing the custom taxo Brand in the post list.

 

Here's how I did it

Automatic Photo Blogging with WordPress

Posted on March 5, 2012

Posted by kieran

My latest WordPress challenge was to automate a photo blog site. The photo blog post content would just consist of a title and a featured image. No content. As per normal photo blog style sites.

This solution takes an image at random from a folder and posts it in WordPress. It relies on a healthy collection of images to work from.

Really simply, it needed to select a photo at random and post it. Sounds easy, until to you start to code it.

Here's my solution.

Using Persistent Cache in WordPress (with APC)

Posted on January 9, 2012

Posted by kieran

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,

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

Posted on November 4, 2011

Posted by kieran

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

Posted on September 15, 2011

Posted by kieran

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

Using custom CSS in cForms

Posted on July 14, 2011

Posted by kieran

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

Posted on May 20, 2011

Posted by kieran

Debugging WordPress is actually quite simple. Stop yourself going grey and or bald.

In your wp-config.php, replace

  1. define('WP_DEBUG', false);

With

  1. define('WP_DEBUG', true);
  2. define('WP_DEBUG_LOG', true);

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.

  1. define('WP_DEBUG_DISPLAY', false);
  2. @ini_set('display_errors', 0);

 

Tagged as: , 1 Comment

WordPress function remove_menu_page

Posted on May 20, 2011

Posted by kieran

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.

Page 1 of 3123