10 Must-Knows For Every WordPress Plugin Developer

Plugins form a crucial aspect of every WordPress powered blog and website. If you own a WordPress blog/site, you might be well familiar with the plugins that can be effectively utilized for extending the respective blog/site’s functionality. Its this ability to extend the website/blog functionality that makes WordPress stand out from the crowd of web development tools available in the web world.

10 Must-Knows For Every WordPress Plugin Developer

My aim behind penning down this blog is to make you familiar with some crucial aspects that must be known by every WordPress plugin developer. Hope the details mentioned here will encourage you to choose the right direction when it comes to developing plugins for WordPress enriched blogs and websites.

When exactly does one need to develop plugins?

Although WordPress comes loaded with plugins that can be used for extending the functionality of a website/blog, there are times when these plugins can’t be sufficient enough to solve the purpose. It is here when the role of WordPress plugin development comes to play. You might require website functionalities that the in-built plugins can’t help you achieve. So, it is recommended to hire the services of a professionally qualified WordPress plugin developer who’ll make sure to analyze your requirements to serve you with a plugin that enables you to perform the required functionality extension part without facing any kind of troubles/inconveniences.

Now, let’s dive into the 10 must-knows for every WordPress plugin developer

10 Must-Knows For Every WordPress Plugin Developer

1: Prefix your functions

A key aspect that strikes every WordPress plugin developer is that a majority of other plugin developers are also into the habit of using the same names for functions used by him/her. For example, function names such as save_data(), copy_file() and database_table_exists() have fair chances of being used by a majority of WordPress plugin developers residing in different corners of the world. The sole reason for this being that when WordPress activates a plugin, PHP loads the functions from the plugin into the WordPress execution space where all functions from all plugins are being consolidated. Hence, there is no isolation of functions for each plugin and each function is being named uniquely. Well, an easy way to ensure the separation of each plugin is naming all of the plugin functions with a prefix. Here’s a look at how the common functions would now look like:

function myplugin_copy_file() {
}

function myplugin_save_data() {
}

function myplugin_database_table_exists() {
}

Yet another effective naming convention is to use a prefix that is actually an abbreviation of the plugin’s name. For example, if the plugin’s name is “My Awesome WordPress Plugin”, then the function names would be like this:

function mawp_copy_file() {
}

function mawp_save_data() {
}

function mawp_database_table_exists() {
}

As a WordPress plugin developer, you need to keep a vigil eye on the debug .log file to get an assurance that you’re on the right track when it comes to explicitly prefixing your functions.

2: Don’t proceed ahead without debugging

The very first thing that you need to do when developing a WordPress plugin is to enable the debugging option. Rather, you must keep the option “ON” throughout the process of writing the plugin code. By enabling the debugging feature, you also turn on the WordPress notices option. This option makes you familiar with any deprecated functions that exist in the plugin code. Hence, if you tend to detect a deprecated function within the code, it will be easier for you to find its replacement. Also, all the future versions of the respective WordPress plugin will hence not contain any deprecated functions.

Follow the steps to enable debugging:

By default, WordPress debugging feature is turned off and hence you need to enable it to enjoy bug-free coding. For this, all you need to do is open wp-config.php file available in the root of your WordPress installation and search for the below mentioned line of code:

define('WP_DEBUG', false);

Once you’re able to find the aforementioned line, replace the same with the following:

// Turns WordPress debugging on
define('WP_DEBUG', true);

// Tells WordPress to log everything to the /wp-content/debug.log file
define('WP_DEBUG_LOG', true);

// Doesn't force the PHP 'display_errors' variable to be on
define('WP_DEBUG_DISPLAY', false);

// Hides errors from being displayed on-screen
@ini_set('display_errors', 0);

Once you’re done with adding the above lines of code to your wp-config.php file, the debugging option will be fully enabled for your WordPress plugin development project.

3: Don’t forget to store the plugin version for future upgrades

As a WordPress plugin developer, one of the most important aspects that need to be considered is the upgrades part. For example, if the first version of your plugin required one database table, its not necessary that the next version would also require the same database table. So, in order to prevent yourself from falling into such a situation where you don’t know whether you should run the code that creates the second database table, I recommend you storing the plugin versions in the WordPress database table. Doing this will enable you to gain an instant access to the plugin code and decide about the actions that the plugin should take.

4: Replace bloginfo(‘url’) With bloginfo(‘wpurl’)

Although as a standard operating procedure, WordPress is installed in the root folder of a website, every now and then you’ll actually come across sites that install WordPress into a separate sub-directory under the root. If you go to the “General Settings” section of the WordPress admin panel, you’ll find the WordPress address(URL) and Site address(URL) settings.

Here, it is important to be familiar with the following:

  1. bloginfo('url') is equal to the “Site address(URL)” setting
  2. bloginfo('wpurl') is equal to the “WordPress address(URL)” setting

By using bloginfo('wpurl') instead of bloginfo('url'), you can easily go ahead with building links and URLs inside the plugin. The reason for this is that this function works in both scenarios viz: when WordPress is installed in the root of the website and when it is installed in a sub-directory.

5: Addition of settings page or Admin menus aids in tweaking the settings or options for the plugin

There are many WordPress plugins that require users to tweak the settings for the plugin to operate properly. As a plugin developer, you can either add a new settings page to an existing menu or add a new top-level admin menu to core WordPress. A key advantage of adding your own custom admin menu is that it becomes easier for the users to find the settings for your plugin. This is simply because they aren’t bound to the built-in WordPress admin menu but can gain an easy access to the custom-built admin menu and its features.

6: Include images, CSS Into the PHP code

Plain coding will not make your plugin look great. You need to include some images, CSS and a little JavaScript to make your plugin stand out from the crowd. Moreover, you’ll need to organize these files into their respective folders such as “images”, “css” and “js”. I recommend you to create your own global paths that can hence be used anywhere in the plugin code. Doing this will let you know how you should code your plugin so that it can always detect the image, css and javascript files irrespective of the domain the plugin is running under.

7: Create/Update Database tables using dbDelta()

If your plugin runs on its customized database tables, you’ll definitely need to modify these tables in the future versions of the plugin. Well, this task can be a bit tricky and hence I recommend you to use the dbDelta() function. This function can be used for creating and updating tables.

8: Familiarize yourself with the difference between include, include_once, require and require_once

During the plugin development process, there might be a situation where you’ll want to put the code into other files. One of the best techniques of doing so is creating a functions.php file that includes all the shared functions which can be used by all the files in the plugin. It is essential for you to abreast yourself with the difference between include, include_once, require and require_once.

9: Get a completed idea about how and when to use Actions and Filters

Since WordPress allows developers to add their own code by providing various hooks, you need to be well familiar with the different forms of these hooks. You must have a complete idea about Actions and Filters. While WordPress invokes the former hook at certain points during the execution request, it uses the latter one to modify the text before adding it to the database and displaying it on the screen.

10: Include a shortcut to your Settings Page using Plugin Action Links

Quite similar to the benefits of a custom admin menu, the plugin action links also render a sense of well-rounded WordPress plugin. You can use the plugin action links for adding a quick shortcut to your most commonly used admin menu page.

Final Words

So that was a collection of 10 must-knows for every novice as well as professional WordPress plugin developer. Hope by now you’d have got a clear idea about the things you should do and the ones that you should avoid during plugin development process.

Please don’t forget to share your feedback on the above post. For this, you may use the comments box provided right under this post.

Like it? Share it.

9 Comments

  1. These are very helpful tips. Thanks for the incite!

  2. Thanks for your valuable post. It seems very useful for me as well as others.

  3. This is great tutorial, very helpful thanks..

Leave a Comment Yourself

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>