A moan, a groan, my life story and how me, a technically minded person just can't seem to fit in with anybody.

Archive for the 'Code and Snippets' Category

Remove/edit WordPress admin footer links and version number

function change_footer_admin () {return ' ';}
add_filter('admin_footer_text', 'change_footer_admin', 9999);
function change_footer_version() {return ' ';}
add_filter( 'update_footer', 'change_footer_version', 9999);

Place the above code in your themes function file. The above code allows you to edit the admin footer version number and text links. Just alter the html in the return of each function. I recommend removing the version number for security reasons. There are a lot of tutorials out there that tell you how to remove the generator tag from your WordPress header to hide the version number put they forget if a user registers they can see the version number in the admin footer page. If you build WordPress installations for your clients this footer area is good for displaying your own support links etc.

How to stop Skype replacing telephone numbers on your web design

When a user installs Skype it auto installs some plugins to Internet Explorer and Firefox, that when it sees a telephone number on the webpage a user is viewing it will replace the number and surround it in its own formatting. Now a user can disable this function but as a web designer/developer you cannot guarantee that all your website visitors have it disabled. For those users that don’t have it disabled a nicely designed and placed telephone number in your design is replaced with an ugly and out-of-place number. Yuk! I did some searching and all the posts I could find only said how to disabled the plugin which I didn’t want. I want to disable the plugin or disable the effects of the plugin for all browsers viewing the site I was developing.

I then came across this code:


Put looks like Skype has updated and this code no longer works. For all my web design work I always work with a reset.css style sheet that is like my common settings for CSS that I use in all web development. Well I stumbled across some CSS you can use to hide the effects of the Skype plugin. Here is the nice bit of CSS code that has found its way into my reset.css style sheet:

/**** GET LOST SKYPE! ****/
span.skype_pnh_container {display:none !important;}
span.skype_pnh_print_container {display:inline !important;}

Hope it helps you out

WordPress – Show images attached to post or page in order

I’m currently building a website where a custom post type needs to show a gallery of images per post. Below image is what I was after:

To do this I would upload the images when creating the post so that the images would be attached to the post, or in other words the attachments where child posts of this post I was creating. I found some code that grabs the attachments but the code didn’t retrieve the results by the order I have specified in the upload manager when uploading the image. To get the images in order I had to write a little more code to what I had found.

Anyway here is the finished code It’s tailored to my needs but here you can see how the image attachments are being pulled and then how im sorting the results to go in the correct order. Hope it is some use to someone.

CSS/HTML – Margin goes/pushes out container block/div

I recently encountered this issue:

Margin Pushing Out

Where the margin on the H1 tag was overflowing into the container above and pushing down the H1 tag’s container. I couldnt figure out why. Here is an example:

To my logic the green should be flush against the top and a 10px gap between the red and green. After some digging around I found out the reason this is happening is due to the way block formatting works. To fix this just add overflow:hidden; to the H1 tag’s container. Fixed here:

PHP Send Email With High Importance Set

Just posting this for reference really. You need to add some extra headers to your PHP send mail script to send the email with high importance. This will show a red exclamation mark on the recipitents recieved mail if their mail client supports this feature.

Google Maps API Javascript V3 – Place Km/Mile radius/circle around point

So Google has released V3 of their Google Maps API and it appears that they have stripped out a number of useful functions that I’ve found myself using in V2. Apparently these functions have been stripped out to make a more lightweight and compact API for better performance for mobile devices. This is great but now you have to write your own function that Google has taken out.

So would you like to draw a radius around on a point on a Google map? Well I do and I managed it in the V2 API using a Google function called distanceFrom() and some custom code but now that function has been stripped out in v3. Anyway I’ve rewritten my code to do this in the V3 API. Take a look:

This requires the Google Maps API and also the latlong JS script from Movable Type. To use simply call the function drawCircle() sending your Google longitude and latitude cords and the mile radius. If you want to use Km then comment out or delete the bit of code highlighted.

Oh and you can send some other variables too if you don’t like the default colours and settings.

Example usage:

CSS Dotted/Dashed HR Style

Ever had problems styling an HR element to be dotted or dashed and look correct in all browsers?

Well here is a simple solution for you:

border:#000 1px dotted;
border-style: none none dotted;

PHP – Get users SID from Active Directory via LDAP (objectsid)

Have you ever needed to read an AD users SID so you can use it as the unique identifier it is?

Well I did but when I read out objectsid from AD for a user I found a load of weird symbols. It turned out that the data outputted was binary data. So after some digging around to see how to translate the binary data to a human readable SID like S-1-5-21-823795046-756116320-56781596-16683 I got to work to write a PHP script that could do just that.

This is what I came up with:

[PHP]$suffix =””;
$base_dn = “dc=sub,dc=mydomain,dc=co,dc=uk”;
$server = “″;

$USERNAME = “username”;
$PASSWORD = “password”;

$USERNAMETOSEARCH = “user to get sid”;

$ds = ldap_connect($server);
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ds, LDAP_OPT_REFERRALS, 0);
$r = ldap_bind($ds, $USERNAME.$suffix, $PASSWORD);
$sr = ldap_search($ds, $base_dn, “(samaccountname=”.$USERNAMETOSEARCH.”)”);
$entries = ldap_get_entries($ds, $sr);

// All SID’s begin with S-
$sid = “S-”;
// Convert Bin to Hex and split into byte chunks
$sidinhex = str_split(bin2hex($entries[0]['objectsid'][0]), 2);
// Byte 0 = Revision Level
$sid = $sid.hexdec($sidinhex[0]).”-”;
// Byte 1-7 = 48 Bit Authority
$sid = $sid.hexdec($sidinhex[6].$sidinhex[5].$sidinhex[4].$sidinhex[3].$sidinhex[2].$sidinhex[1]);
// Byte 8 count of sub authorities – Get number of sub-authorities
$subauths = hexdec($sidinhex[7]);
//Loop through Sub Authorities
for($i = 0; $i < $subauths; $i++) { $start = 8 + (4 * $i); // X amount of 32Bit (4 Byte) Sub Authorities $sid = $sid.”-”.hexdec($sidinhex[$start+3].$sidinhex[$start+2].$sidinhex[$start+1].$sidinhex[$start]); } echo $sid;[/PHP] Now this is written in PHP but I’m sure this code can be pretty much be translated to any other language.

PHP – Active Directory – Reading UserAccountControl

At the moment I’m doing a lot of work with Microsoft Active Directory and PHP. I’m building a few tools in PHP which reads data out of AD.

Now one of the things I wanted to read out was to see if the account was locked or if its password never expired. I couldn’t find these entries in AD but after searching those entries are stored in “useraccountcontrol”. But when I looked it was just a number. How does that number tell you if the account is locked?

On the above link is how that number is generated and once I understood that I got to work on writing a PHP script which translates that number into something more usable. Once I wrote the script I put it up on the Hot Scripts Forum to see if the code I wrote could be improved on and optimised. Here is what they came back with:

$userAccountArray = array(
‘NOT_USED_8000′ => 0,
‘NOT_USED_4000′ => 0,
‘NOT_USED_4′ => 0,

function ADUserAccountControl($val) {
global $userAccountArray;
$x = pow(2, count($userAccountArray) – 1);
foreach($userAccountArray as $k => $v) {
if(($val – $x) >= 0){
$userAccountArray[$k] = 1;
$val -= $x;
} else {
$userAccountArray[$k] = 0;
$x = $x / 2;

Simply pass your useraccountcontrol value to the function and read the results out of the array.

Javascript Same Height Div’s Update

A while back I posted a way of making same height div’s but came across an issue when padding was involved. Well I’ve modified my code to take into account padding. Now the obvious thing to do would be to be to check padding on a div and subtract it from the height, but it’s not that easy. You would have to check three things: padding, paddingTop and paddingBottom. For some reason when I was checking padding I couldn’t get a value from JavaScript, this had me really stumped but after a nights sleep I came up with a better and more simpler way of sorting the padding issue. This is to let the code run and let it re-height the div’s and let the padding mess things up then run the same thing again and check for height differences from last time we checked. Oooohhh look the height has gone up 10px from last time thanks to a padding of 5px on the div. Now we know there is 10px of padding lets remove it. Sorted!

JavaScript Code:
function sameHeight(divs) // Bring in an array of your divs
var highest = 0;
var heighttu = 0;
for(i = 0; i < divs.length; i++) // Loop through the divs { // Check to see if this div is the highest? if(document.getElementById(divs[i]).offsetHeight > highest)
// Yes its the highest so set the highest value to this div’s height
highest = document.getElementById(divs[i]).offsetHeight;
// Loop through divs and set their hieght all the same
for(i = 0; i < divs.length; i++) { document.getElementById(divs[i]).style.height = highest+"px"; } // now get offset hieght again and we may found we have gone higher this is because of padding if(document.getElementById(divs[0]).offsetHeight > highest)
// correct the height
highest = highest – (document.getElementById(divs[0]).offsetHeight – highest);
// Correct divs
for(i = 0; i < divs.length; i++) { document.getElementById(divs[i]).style.height = highest+”px”; } } }[/js]