Test Driven Development

In this post we will be investigating what is test driven development and how we can use it to improve our development process.

What Is Test Driven Development?

Test driven development is a development process that is exactly what it sounds like, we develop our applications driven by a number of different tests. This involves writing all your tests up front before any development has taken place. At the start this will seem strange as all the tests are going to fail but then we can develop our application to make sure all these tests will pass.

Test Driven Development can lead to your code being simpler, more defensive and less feature creep. This is because you only need to write the code to make the tests pass and nothing else. You can also make sure that you aren't about to create functionality that isn't needed by writing your tests first and then running them, if some of your new tests pass then that functionality for the test already exists.

These two principles of development are known as:

  • KISS - Keep it simple, stupid.
  • YAGNI - You ain't gonna need it.

Continue reading »

Using The New Twitter API V1.1

From March 5th 2013 Twitter are removing there current API and it will be fully replaced with the new API V1.1. This means that any application that is currently using the old API will stop working on March 5th. The main feature of the API is that requests need to be authenticated before they will work correctly. This is so Twitter can prevent abusive behaviour of their API.

A while ago I wrote a WordPress widget that will display your latest Twitter posts, this widget will now need to be updated and replaced with the new API.

In this tutorial we are going to investigate the changes we need to make to update a Twitter application from version 1 to version 1.1, in the previous tutorial we used WordPress to cache and display the Tweets and will continue to use WordPress with the new API.

Create An Application On Twitter

To start using the new API you need to be authenticated, which means Twitter needs to have certain information about your application and how it is going to be used so that it will provide you with access keys to use the API.

To get the access keys you need to create an application on the Twitter Developer site.

Create an application - Twitter Developers

Twitter Developers
Continue reading »

Alert Theme Users To Required Plugins

One of things that I've said about premium WordPress themes before is the amount of features that are included in the theme options panel page. Most of these theme options have so many settings which aren't needed, or there is already a well known WordPress plugin that performs this action.

The best example of this is SEO settings, there are premium WordPress themes that allow you to put in SEO settings into your theme options panel. This is marketed at being a great feature of the theme as you don't need install a new WordPress plugin to do this for you. But I feel this isn't a benefit to the theme and it's just added bloat to the theme that the user really shouldn't use.

I'm saying this because people should be using a WordPress plugin to perform this functionality, mainly because if the user changes the theme then they have now lots all the SEO settings for their site. Other benefits is that these massive plugins are continuously being updated adding better functionality to your site.

I understand the benefit of having the SEO settings in the theme options panel as the user only has to go to one place to customise their whole site but I feel we as developers need to provide the best WordPress experience to users. This includes using WordPress best practises and separating functionality and styling. The reason to have functionality in a plugin is so that it will work exactly the same no matter what theme you are using.

An example is if you want to add Google analytics to your website, use a plugin so that if you change your theme you still have this functionality.
Continue reading »

Create A Custom Background To WordPress

Custom backgrounds is a WordPress theme feature that allows the users of the theme to change the style of the background. It allows the users to pick a new color or a new image for the background.

When the user selects a new background WordPress will add a new style to the body tag inside the HTML head tag like this code.

<style type="text/css" id="custom-background-css">
body.custom-background { background-color: #3c3640; }
</style>

Since WordPress 3.4 you have been able to use the add_theme_support() function to add additional features to your theme. These include:

  • post-formats
  • post-thumbnails
  • custom-background
  • custom-header
  • automatic-feed-links
  • menus
add_theme_support( 'post-formats' );
add_theme_support( 'post-thumbnails' );
add_theme_support( 'custom-background' );
add_theme_support( 'custom-header' );
add_theme_support( 'automatic-feed-links' );
add_theme_support( 'menus' );

Custom Background

Custom Background
In this tutorial we are going to look at how to use the custom background feature on your themes.

To start off you need to add the add_theme_support( 'custom-background' ); to the functions.php file.
Continue reading »

Free Premium Files For February 2013

Each month the Envato marketplace brings you free premium standard files.

Envato is a web marketplace where you can get premium files for different areas of your website. My favourite marketplaces is the script marketplace CodeCanyon and the theme marketplace ThemeForest.

Here are the files which you can get for free for February 2013.

jQuery TimelineXML

jQuery TimelineXML

309 purchases at the price of $8.
Continue reading »

Create A Page Template For Logged In Users

There are times that you would want a page only to be accessible for users which have logged into your the WordPress user manager. Such as if you have a members only area of your website which is only for logged in users, you need to make sure that the page can not be seen by any users who haven't logged in yet.

WordPress has an inbuilt feature that allows you to easily manage users and roles for these users. Using the WordPress user manager you can define different roles to your users but they will all be able to log into WordPress and it doesn't matter which role they are assigned to.

As you are using the built in WordPress user manager then you can use a WordPress functions to check if a user is logged in or not.

This WordPress function is called is_user_logged_in(). This function will return a true or false on if the user is currently logged in and works just like the code below.
Continue reading »

Create Post Tags With CSS

In this tutorial we are going to create post tags using CSS, we will also create a WordPress widget that will allow you to display these post tags in the sidebar of your WordPress site.

CSS-post-tags

The above image shows the tags we are going to create. In WordPress you can also display the amount of the posts that have these tags assigned to them, we will display this number on the right of the tag and will display the count on the hover of the tags.

View the demo to see what we are going to create.

Demo

To start with we are going to define the HTML we need to use, the tags are going to be list items inside the list items is going to be a span tag with the number of posts that have this tag assigned to them.
Continue reading »

Stop Loading Stylesheets And Javascript In WordPress

In a previous post I wrote about how you can add stylesheets and Javascript files to WordPress correctly by using the wp_enqueue_style() function. By using this function you can make sure that you are not adding the same stylesheet twice, this also allows you to prioritise the order of adding the style sheets.

In this article we are going to look at the opposite of this function the wp_dequeue_style() function. As you can guess this function will remove the stylesheets from the enqueue. There is also an opposite function for adding Javascript files to the page with wp_deregister_script() function.

Remove Stylesheets That Has Been Enqueued

WordPress will create a queue of stylesheets to load and will import these when it runs the wp_head function. The benefit of this system is that you can call the wp_enqueue_style function from any plugin and it will be placed at the top of the where it's meant to be.
Continue reading »

Restrict Admin Area To Only Admin Users

Lock
When you create a new user in the WordPress user manager they will be able to login to your site by going to the default WordPress login page /wp-login.php. Depending on the role you have assigned to this user they will see different options in the admin area.

Even if the user has the lowest level of role a Subscriber assigned to them they will be able to log into the WordPress admin area but all they will be able to do is edit their own profile. But if your not doing anything with this profile information then there is no need for them to login to edit the profile.

If you don't want other users to be able to log in to your WordPress admin area you can restrict access depending on a certain role.

In this example we are just going to allow admin users access to login to the admin area. We are going to use the WordPress action admin_init which will run when you access any admin page, from here we can check the access right of the user and redirect if we need to.
Continue reading »

Introduce Your Plugin With WordPress Pointers

In version 3.3 WordPress released a new feature called pointers. These are little pop-up notification boxes which you can use to point to new information on your WordPress admin area.

Pointer

This is a great idea if you are a plugin or theme developer, you can make it so that when a user installs your new plugin you can use the pointers to show exactly how they are suppose to use it.

For example if the plugin adds a new menu item to the WordPress admin area, you can use pointers to show the user that there is a new menu item and what it allows you to do with your wordpress site.

You can assign a pointer to be displayed on any HTML ID or class, it is just a jQuery widget which has a title bar, text area and close button.
Continue reading »