define('DISALLOW_FILE_EDIT', true); define('DISALLOW_FILE_MODS', true); Blog | WP Hosting

Blog

How to switch between several PHP versions in MAMP 2.x

Posted by on 12:50 pm in Knowledge Base | Comments Off on How to switch between several PHP versions in MAMP 2.x

Sometimes you need to test your projects against multiple versions of PHP. If you’re using MAMP that’s fairly easy to do: head over to the MAMP Start Screen, select Preferences and see two versions to choose from. Here I’m using MAMP 2.2 (even though 3.x has been released already) and I have PHP 5.2.17 and PHP 5.5.3. When I switch to the other version MAMP restarts and I can refresh my browser to see my project running on the other PHP version. That’s all good if I actually needed either version – but sadly 5.2.x...

read more

How to check the size of a file in PHP

Posted by on 2:59 pm in Knowledge Base | Comments Off on How to check the size of a file in PHP

PHP has a handy function called filesize() which can help us display how big a file is. It does this in bytes by default, but with a bit of tinkering we can easily convert this into kilobytes or megabytes. Let’s first see how this works in bytes: $file = '/path/to/your/file'; $filesize = filesize($file); echo "The size of your file is $filesize bytes."; Converting bytes into kilobytes works by dividing the value by 1024. PHP is very accurate and will give you 12 decimal digits – perhaps a little overkill. To...

read more

How to list a directory in PHP and only show ZIP files

Posted by on 2:00 pm in Knowledge Base | Comments Off on How to list a directory in PHP and only show ZIP files

I wanted to list a directory in PHP. At the same time, I wanted to make sure only files are listed – not subdirectories or dot directories. More specifically, I only wanted to include files with the ending .zip. Two tools come to the rescue here: scandir() to list the directory and give us an array and the super handy pathinfo() to check a file extension Here’s how I did it function list_zipfiles($mydirectory) { // directory we want to scan $dircontents = scandir($mydirectory); // list the contents echo '<ul>';...

read more

How to test which HTML form button was pressed in PHP

Posted by on 11:30 pm in Knowledge Base | Comments Off on How to test which HTML form button was pressed in PHP

Imagine you have a HTML form with several values and two buttons at the bottom. One could say “Do This” and the other “Do That”. How do you know which one was pressed by the user? It’s fairly easy – but I keep forgetting this time and time again. We do this by accessing the name attribute of the HTML button in PHP. Consider this HTML form: <form> <input type="submit" name="button1" class="button-primary" value="Do This" /> <input type="submit"...

read more

How to create a recursive ZIP Archive from a directory in PHP

Posted by on 11:13 pm in Knowledge Base | Comments Off on How to create a recursive ZIP Archive from a directory in PHP

I’ve just realised how (relatively) easy it is to make PHP create a ZIP Archive from a directory and its sub directories. Previously I had relied on the Linux Shell Command zip or tar to do this which is a convenient one liner. I had assumed that in PHP we had to go through each directory and add the files manually – until I’ve discovered the RecursiveIterator class variants. In this example I’m defining a root path and a file name for my archive (change at will), then iterate through each file in each directory (and...

read more

How to use ZEN DASH for WordPress

Posted by on 10:37 pm in Knowledge Base, Plugins | Comments Off on How to use ZEN DASH for WordPress

I’ve just released Version 1.3 of ZEN DASH and thought a quick video demonstration is in order – and here it is: In this podcast I will show you how to use ZEN DASH for WordPress and explain how you can easily hide menu options, dashboard widgets, admin footer links and suppress Update Notifications (for WordPress core, plugins and themes). This plugin comes in handy if you’d like to hide functionality before giving the site over to a client. For example, you may not want your client to have access to plugins so he can...

read more

Introducing Child Theme Wizard for WordPress

Posted by on 12:17 am in Knowledge Base, Plugins | Comments Off on Introducing Child Theme Wizard for WordPress

I’ve just finished writing a new WordPress Plugin to help you create Child Themes with a single click, and no need for any external tools. The Child Theme Wizard is a super slim assistant which can be accessed under Tools – Child Theme Wizard. Pick a Parent Theme, enter additional information, click Create Child Theme and you’re all set! Child Theme Wizard in action   If all goes well you’ll see this   In case something went wrong Child Theme Wizard allows you to enter the following details: Theme Name...

read more

How to add elements to an array in PHP

Posted by on 9:23 pm in Knowledge Base | Comments Off on How to add elements to an array in PHP

It’s extremely easy to add elements to an existing array in PHP – so easy in fact that I regularly forget how to do it! I’m used to initialising and setting up my variables from Objective C, but PHP is so much easier and deals with it on the fly. Here we do it – ideal for loops: // create the array $myArray = array(); // add three elements to it $myArray[] = 'Hello'; $myArray[] = 'I must'; $myArray[] = 'be going'; // loop through all elements foreach ($myArray as $item) { echo $item; }...

read more

How to test if your theme is a Child Theme

Posted by on 9:02 pm in Knowledge Base | Comments Off on How to test if your theme is a Child Theme

You may need to know which of your themes are child themes, or in fact if the current theme you’re using is a parent or a child theme. Here’s how you can test both options. The following code snippet will iterate through all themes that are currently installed and displays the title and if it is a child theme or not: $allThemes = wp_get_themes(); echo '<ol>'; foreach ($allThemes as $theme) { echo '<li>'; // print the theme title echo $theme->get('Name'); // determine whether it's a...

read more

Handy Cheat Sheet for PHP File Operations thanks…

Posted by on 8:28 pm in Knowledge Base | Comments Off on Handy Cheat Sheet for PHP File Operations thanks…

Handy Cheat Sheet for PHP File Operations – thanks to @davidwalshblog http://davidwalsh.name/basic-php-file-handling-create-open-read-write-append-close-delete

read more