Tag Archives: development

Redirect Page to First Child

I had the need to redirect a parent page to its first child with no user interaction. Quite simple really…

Add Product Images into Shopp Receipt

[php]
## ADD THIS INTO FUNCTIONS.PHP
add_filter(‘shopp_tag_purchase_item-image’,’purchased_image’,10, 3);
function purchased_image($result, $options, $Purchase) {
$item = current($Purchase->purchased);
$product = new Product($id=$item->product);
return $product->tag($property=’coverimage’);
}

## NOW YOU CAN SHOW THE IMAGES INSIDE THE PURCHASED ITEMS WHILE LOOP
shopp(‘purchase’,’item-image’);
[/php]
I’ve long said Shopp is a total bellend, they totally missed out putting the product image tags into half the hooks. The above, will allow you to show the product image in the receipt, after all – its always nice to show you what you have bought after you’ve paid good money.

Get a grip Shopp – I’m so moving to WooCommerce.

WordPress Dynamic Navigation

Sometimes in WordPress you don’t want to use the custom menus for some navigation parts, like sub navigations in sidebars or something. Sometimes custom menus are just over kill, especially if every page has a sub navigation made up of child pages.

Heres an easy way of generating the sub navigations of Parent / Child pages & also showing the Parent page title above it.

Plugin Spotlight: Advanced Custom Fields

What’s this? Plugin Spotlight!? I don’t know, I just wanted to show this bad boy off!

Its nice to get into the meat of WordPress and make plugins, learning loads of new tricks along the way however if you are making a plugin you should really check the WordPress Plugin Directory beforehand, chances are someone has had your problem and resolved it.

I’ve been using custom attributes for image sliders for a long time & to be perfectly honest, its a bit of a round about way for the end user to show an image on the front page, users want a simple interface, this plugin does just that! There may be others that are even better or more geared towards uploading images etc however this one has lots of different settings which I just love!

First time I’ve used it and its probably saved me about an hours work already. :]

Author: Elliot Condon
WordPress Plugin: Advanced Custom Fields

Gauging cPanel Diskspace Usage w/ PHP & Google Charts

Along time ago, I used to be cPanels #1 fan, after using alternative control panels, that quickly faded due to WHM/cPanels bulky nature. I recently came back to using cPanel, as its the industries #1 control panel & my clients adore it, now, I’m glad I gave it that all important second chance.

cPanel is adorable. Its hard & common exterior is found throughout the web, hundreds of thousands of web hosts use, millions of users interact with it each day. Because of this, the folk over at cPanel have created an amazing set of APIs, intelligently structured & a breeze to use.

cPanel has an absolutely stunning XML API, its simple, its fast & and opens doors to so much more. I introduce to you, my first (of many) cPanel related tutorial. Showing accounts disk usage, with Google Charts. Lets roll!

First of all, for this, you need WHM access, Ill post other user related examples soon, lets start off simple though :]. Login to WHM and go to Setup Remote Access Key. Once you have this massive hash read on.

[php]
## ROOT USERNAME AND ACCESS KEY
$whmusername = “root”;
$whmhash = “098A7SDF89AS07DF897ASDF987SD987VXZC897BV98Z7XCV87
ZXC7V908Z7XC9V870X97ZC98V790Z7V9087CV907ZXC7V9ZCV9087ZX987V98
7ZXCV7ZX8C7V897ZXC8V78ZX7VC87XZC87V89XZ7CV878X9ZC7V8XZ7CV897Z
X89CV789XZ7CV897ZXC8V789XCZ7V87ZXC8V798XZ7CV897XZC89V7ZX89C7V
89XZ7CV897XZC8V789ZX7VC89Z7XCV87Z89XC7V89Z7XCV8ZX7V987XZVCGFD”; // ONLY AN EXAMPLE ;)

## THE QUERY WE ARE SENDING TO THE SERVER
$query = “https://127.0.0.1:2087/json-api/accountsummary?user=paulor”;

## CRAZY CURL STUFF TO AUTHENTICATE, CHECK FOR ERRORS AND
## RETURN OUT JSON ENCODED DATA
$curl = curl_init();
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,0);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER,1);
$header[0] = “Authorization: WHM $whmusername:” . preg_replace(“‘(\r|\n)’”,””,$whmhash);
curl_setopt($curl,CURLOPT_HTTPHEADER,$header);
curl_setopt($curl, CURLOPT_URL, $query);
$result = curl_exec($curl);
if ($result == false) {
error_log(“curl_exec threw error \”” . curl_error($curl) . “\” for $query”);
}
curl_close($curl);
[/php]

What we are doing here is connecting to cPanels XMLAPI via cURL, authenticating with the server and then returning any errors, the $query string, is what we are pulling from cPanel, in this case, its near enough all the information that the account with the username ‘paulor’ has, such as: creation date, plans, disk space, suspended?, ftp accounts, sql accounts, email accounts etc etc etc, what it does lack however, for reasons still unknown to me, is bandwidth usage and limits. Thats a different query alltogether.

We query WHM with this query and it returns to us a lovely JSON feed.

[php]
$obj = json_decode($result);
$array = $obj->{‘acct’};

$space_used = str_replace(‘M’, ”, $array[0]->diskused);
$space_avail = str_replace(‘M’, ”, $array[0]->disklimit);
[/php]

First we are decoding the JSON results and then putting the account details into an array, next, because we are making a disk space meter, we don’t want the MB (or M in this case) to be attached to the end of the value, so we just chop that off with str_replace().

We are then going to use the Google Charts API to make our gauge and show the results.

[php]


[/php]

Now you can see we have inserted the $space_used$space_avail variables into the javascript, this is bog standard Google Interactive Charts javascript which you can grab from their website, We then set a div for it to show in.

[php]

[/php]

And we have a very sexy gauge to show diskspace usage.

Now, isn’t that great? What other cPanel API related gizmos would you be interested in?