WP-Facebook-Auth Launched on GitHub

I’ve launched my (super scruffy) WP-Facebook-Auth code on GitHub . It is a WordPress Authentication Wrapper for Facebook.

Use it when you have an application that reads or writes from Facebook.

This wrapper allows WordPress admins to (semi) automatically authenicate with Facebook for use with the Facebook API. If you use the Facebook API to pull data, you’ll find that you need to authenticate with Facebook using OAUTH. These tokens don’t last forever and need to be renewed every so often. (3 monnths). This code will update the OAUTH token whenever an administrator logs into the WordPress Admin interface, which hopefully will be more than once every 3 months.


Hide WordPress plugin update notifications for non-admin users

WordPress plugin update notifications can be annoying. They can also be confusing for less technical customers, even worse, customers kept phoning me saying “WordPress says it wants to update, but it won’t let me – it’s broke”. No, it’s not broke, you don’t have permissions. I needed a way to hide plugin update notices for non-admin users.

global $user_login;
if (!current_user_can('update_plugins')) { // checks to see if current user can update plugins
add_action( 'init', create_function( '$a', "remove_action( 'init', 'wp_version_check' );" ), 2 );
add_filter( 'pre_option_update_core', create_function( '$a', "return null;" ) );

[Snippet] Parsing mentions, hashtags and links in Twitter JSON

A quick snippet for parsing user mentions (@username), hashtags  (#hashtag) and links (http://) items in Twitter posts.

I use this code quite a lot to provide custom styled or moderated Twitter feed integration into applications and websites for customers using the Twitter 1.1 API or Firehose.

Continue reading “[Snippet] Parsing mentions, hashtags and links in Twitter JSON”

CakePHP and Redis

I recently had to upscale a client’s CakePHP application across multiple front-end web servers on AWS. CakePHP’s file system cache and session storage doesn’t cut it any more. I needed a way of sharing sessions and cached objects. Step in Redis. A centralised, in-memory database, much like memcache – but nicer!

Continue reading “CakePHP and Redis”

How I installed Batik for HighCharts

Batik for HighCharts allows you to create static PNGs from dynamic data. HightCharts offers a hosted export server, sometimes I don’t want to use a 3rd party service.
Here’s how I installed the Apache Batik SVG Toolkit to create PNGs from HightCharts on CentOS

You’ll need a HighCharts download also.

yum install batik
yum install batik-rasterizer
chmod 777  highcharts/exporting-server/php/php-batik/temp
wget http://mirrors.enquira.co.uk/apache/xmlgraphics/batik/batik-1.7-jre13.zip
unzip batik-1.7-jre13.zip     
cd batik-1.7             
cp batik-rasterizer.jar lib/ ../highcharts/exporting-server/php/php-batik/ -r       
yum install bitmap*   
yum install dejavu*     
ln -s /usr/share/fonts/dejavu /usr/share/fonts/dejavu-lgc


[Snippet] Add parent page slug to body class

WordPress adds a huge range of styles to the body class. Sometimes that’s not enough. I wanted to add the post parent to the body class too for some specific styling. Here’s how it’s done.

function body_class_section($classes) {
    global $wpdb, $post;
    if (is_page()) {
        if ($post->post_parent) {
            $parent  = end(get_post_ancestors($current_page_id));
        } else {
            $parent = $post->ID;
        $post_data = get_post($parent, ARRAY_A);
        $classes[] = 'section-' . $post_data['post_name'];
    return $classes;

PHP Crons and a hostname $_SERVER[‘HOSTNAME’]

Whilst running a cron on the PHP variable $_SERVER[‘HOSTNAME’] is not available. This can cause issues if you are using server decision logic in the code to run in different environments (development/staging/live), or if you need the cron to log where it was run. Continue reading “PHP Crons and a hostname $_SERVER[‘HOSTNAME’]”

Changing OpenCart file cache to memory

You cannot stop OpenCart writing cache files to disk, usually in the site’s system/cache directory. This can cause OpenCart to appear slow in some circumstances.
There’s a quick and easy fix, just use a tmpfs (memory based file system) for system/cache. Continue reading “Changing OpenCart file cache to memory”

Determine site protocol with PHP (and Apache)

The $_SERVER variable provides a wealth of information about the server and current PHP script. One thing it doesn’t directly show you is the protocol used to serve the page.

We can use this function to assist

function getSiteURL() {
$Protocol = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
$DomainName = $_SERVER['HTTP_HOST'];
return $Protocol.$DomainName;