Daniel Pataki

Web Developer

So Code.
Much Development.

I’ve noticed through our customers on Themeforest that quite a number of people have very old versions of PHP running on their servers. I’m talking pre 5.3 here which is now almost 5 years old. Here’s a quick way to make sure the plugin can’t be activated in this case, along with a friendly message.

function my_activation_check() {

	$php = '5.3';

	if ( version_compare( PHP_VERSION, $php, '<' ) ) {
		deactivate_plugins( basename( __FILE__ ) );

' . sprintf( __( 'My Awesome Plugin can not be activated because it requires a PHP version greater than %1$s. Your PHP version can be updated by your hosting company.', 'textdomain' ), $php ) . '

' . __( 'go back', 'textdomain' ) . '' ); } return; } register_activation_hook( __FILE__, 'my_activation_check' );

If you require a specific WordPress version you could include that as well in a similar fashion.

For an awesome new WordPress theme I have bought the wonderfull Glyphicons package. For various reasons I needed to rename all the 800+ files removing the ‘glyphicons_003_’ bit from the beginning. I thought automator would help, but it turns out that it’s search and replace doesn’t support wildcards or regular expressions! Batch renaming with the terminal was the only way forward.

read on

I’ve wanted to get around to standardizing WordPress menus for a while now. When you use the wp_nav_menu() function and the user does not have a default menu set for the location in question the wp_page_menu() function will be used. This function outputs a different structure and uses different classes. This makes it harder to style menus consistently with CSS.

Here’s a little snippet I worked on which tries to standardize these two WordPress menus. It’s still in beta, I’m testing it for a new theme so if you find any problems please do let me know.

read on

The most useful thing I’ve come across in a while is how to auto select layers in Photoshop. I’ve been doing this by clicking the checkbox in the toolbar but this is just wasteful as I generally need to untick it when I move something. While not a keyboard shortcut for auto select you can use Command+Control+Click to select the layer of the pixel the mouse cursor is over. This will probably save me 10 minutes daily!

I have no idea why I didn’t realize this before, but you can use the white-space CSS property to make elements line break nicely. I’ve been using this in menus and other places, but I had an epiphany today: this is ideal for post meta sections. I’m probably the last one in the World to realize this…

read on

A neat trick you might need sometimes is to enable users to only show posts with featured images (galleries, etc). This is easily done using the WP_Query class like so:

$args = array(
    'post_type'        => 'post',
    'post_status'      => 'publish',
    'order'            => 'DESC',
    'meta_query'       => array(
            'key'     => '_thumbnail_id',
            'value'   => '',
            'compare' => '!=',
$awesome_posts = new WP_Query( $args );

You can add multiple meta fields to query with, just take a look at the Codex

WordPress is awesome, but one of the top features not yet included on my list is the availability of a built in “just after the opening body tag” hook. You can hook anything into the header using wp_head() or anything just before the closing body tag using wp_footer() but there’s nothing for the opening body tag, so let’s code it ourselves.

read on

Adding meta boxes to posts is fairly easy using the documentation found in the Codex. Restricting them to post types is a no-brainer, the functionality is built in using the fourth parameter of the <code>add_meta_box()</code> function. How about restricting meta boxes to page templates? All you need is 2 extra lines of code to detect which post you are currently on when using the function.

add_action( 'add_meta_boxes', 'my_meta_boxes' );

function my_meta_boxes() {
	$post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'] ;

	if( get_post_meta( $post_id, '_wp_page_template', true) == 'template-mashup.php' ) {

	        __( 'Select Content Types', TEXTDOMAIN ),


All I’ve added is the detection of the post ID and to determine the template I grab the info from the _wp_page_template meta field.

I use Beanstalk as an SVN server and I absolutely love it! One of the great features it has is “Web Hooks” which can run before and/or after a deployment. You can read a bit about this on the Beanstalk Support Center, but here’s a quick and dirty working example.


$data = @file_get_contents('php://input');
$data = json_decode( $data );

	create_function('', 'return "text/html";')

$headers[] = 'From: Daniel Pataki <myemail@mydomain.com>';

		"<?php echo $data->comment ?>"

	<h3 style='margin:0 0 3px 0; padding: 0 0 3px 0; border-bottom:1px solid #ddd'>

			<td style='text-align:right; padding-right:11px;'>
			<td> <?php echo $data->repository ?></td>
			<td style='text-align:right; padding-right:11px;'>
			<td> <?php echo $data->revision ?></td>
			<td style='text-align:right; padding-right:11px;'>
			<td> <?php echo $data->deployed_at ?></td>
			<td style='text-align:right; padding-right:11px;'>
			<td> <?php echo $data->environment ?></td>
			<td style='text-align:right; padding-right:11px;'>
			<td> <?php echo $data->author_name ?></td>

$message = ob_get_clean();

	$data->repository . ' | new revision (' . $data->revision . ')', 

I include wp-load.php just because WordPress is there anyway and it gives me access to wp_mail(). You can use the regular old mail() function or any other method of course.

The point here is that the data can be retrieved using file_get_contents('php://input') and once you json_decode() it you can use all the available parameters. If you use my code, you’ll get something like the image blow in Gmail.

Google Web Fonts is a wonderfully easy way to add beautiful fonts to your website using CSS only, if you’re still using cufon, shame on you!

Using Google Web Fonts is very easy, but if you build themes or similar things you might want to show your users a list of available fonts. It turns out this is pretty easy to do, just get the contents of the following url.


To get an API key you might want to visit the Developer Console. From here on out it’s a trivial matter to present the data, especially since the data is returned in json.

$fonts = json_decode( 
        file_get_contents( 'https://www.googleapis.com/webfonts/v1/webfonts?key=' . WEBFONTS_API_KEY )