JANUARY PROMOTION: Only $17 get Bonsai WordPress theme

LEARN MORE
-2833Days -18Hours -25Mins -13Secs
  • Home
  • Themes
    • Bonsai WP – $49 (Limited Sales $21)
    • Moonlight
      • Moonlight WP
      • Moonlight PSD
    • Kids
      • Kids WP
      • Kids PSD
    • Mercy
      • Mercy WP
      • Mercy – PSD
    • H Decor
      • Hdecor WP
      • H Decor – PSD
    • ASLAN
      • ASLAN
      • Aslan PSD
    • Lincoln
      • LINCOLN – Education WP Theme
      • LINCOLN – Education PSD
      • Lincoln HTML
    • Primary
      • PRIMARY – Kindergarten WP Theme
      • Primary PSD
      • PRIMARY – Kindergarten HTML
    • Jakiro
      • JAKIRO – Fashion Shop WP Theme
      • JAKIRO – Pretashop
      • Jakiro – Multi Store HTML Template
      • JAKIRO – Fashion Shop PSD
      • Jakiro – Virtuemart
      • Jakiro – HTML
      • Jakiro – Shopify Theme
    • Furion
      • FURION – Portfolio WP Theme
      • Furion – Responsive HTML
      • FURION – Creative PSD
    • Ink
      • INK – Magazine WP Theme
      • INK – Magazine PSD
    • Lucy
      • LUCY – Feminine HTML
      • LUCY – Multipurpose PSD
    • Knight
      • Knight – Corporate PSD
      • Knight – Shopify
    • Tower
      • TOWER – Business WP Theme
      • TOWER – Creative Business HTML
      • Tower – Business PSD
    • Platinum
      • PLATINUM – Webshop PSD
      • Platinum Prestashop
      • Platinum HTML
    • Neveda
      • NEVEDA – Fashion PSD
      • Neveda – eCommerce WP
    • Steve Cadey
      • STEVE CADEY – PSD
      • STEVE CADEY – WP
    • 1989
      • 1989 – PSD
  • Freebies
    • Summer Freebie packages
    • FOLIO – Portfolio HTML5
    • MYTHEMES – Cooking PSD
    • PAPER – Blog PSD
    • INSTAISM – Portfolio PSD
    • Breviter – PSD Template
    • Free Fonts Collected
    • Free Plugins Collected
    • Free Icon Collected
    • Free Mock-up Collected
  • Blog
    • News
    • Theme Collection
    • Tips and Tricks
    • Theme Release
    • Theme Updates
    • Freebies
    • Hot Deals
    • Change Logs
    • Customers’ Sites
      • Lincoln Sites
      • Furion Sites
      • Jakiro Sites
      • INK Sites
  • Services
    • Installation
    • Customization
    • Migration
    • PSD to WordPress
  • Support
    • Dedicated Ticket
    • Jakiro Dedicated support
    • FAQs
    • Contact Us

WordPress Tutorial: 9 Must-Remember Things for WordPress Plugin Developers

By Chloe September 30, 2016 0

Hello everyone! It must have been a long time since we last met each other on this series of WordPress Tutorial. For fear that you guys might forget about me, today I’m making a come-back. As this is an important event, I have been thinking really hard about the topic for this come-back, and realized nothing is better than giving some tutorial as well as some encouraging words to those enthusiastic, hard-working people of the WordPress community. Guess who I am talking about! Actually, you guys can see it right from the title! Yes, let use this article to honor our WordPress Plugin Developers, the ultimate creators of all amazing plugins we are using at the moment!

No one can ever doubt the importance of plugins nowadays. Everyone who uses the Internet can sense how vital it is to have some plugins. Especially us, WordPress users. We must know that thanks to these plugins, WordPress is able to power millions of blogs and websites, including ours.

Having the skills needed to extend WordPress to satisfy all the needs is not something easy. Understanding this hardship, I have consulted with several masters of WordPress plugin development I know in order to write this WordPress Tutorial for you. This article consists of some handy tips for every WordPress plugin developer. If you have just come to the game, this article is a must-read.

Now, let’s get our journey started, will we?

Debugging Comes First

 

debugging-comes-first-wordpress-tutorial

 

Whatever you do, remember to enable debugging and leave it working the entire time you write a plugin. This may alert you when things go wrong by displaying error messages and warnings. It also lets you know if you use any deprecated functions. So, do not underestimate this step.

1. Enabling Debugging

Because debugging is turned off by default, you have to turn it on first. Before instructing you how to do it, I must suggest making a copy of the wp-config.php so that you can always go back to it if something goes wrong. Then, it’s time to open the wp-config.php in the root of WordPress installation. Check if you see this line:

define(‘WP_DEBUG’, false);

If you do, replace it with the following lines:

// 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);

After adding those lines, you can be assured that your debugging is now turned on.

2. Logging Your Debug Statements

It would be useless if you enabled debugging yet doing nothing more, right?! So let me lead to another stage of debugging, that is logging your own debug statements. There are quite many ways to achieve the end result, but here I will show you the simplest way. This way is to use echo and see the message on the page. Although this measure can be considered a dirty-hack way to debug, it is indeed quick and it is used by everyone. However, if you feel guilty, there is another way which is to create a function. This function helps you do the job, and let you see all of your own debug statements in the debug.log file.

Here’s that function you can utilize:

function log_me($message) {

if (WP_DEBUG === true) {

if (is_array($message) || is_object($message)) {             error_log(print_r($message, true));

} else {

error_log($message);

}

}

}

After that, feel free to call the log_me function like below:

log_me(array(‘This is a message’ => ‘for debugging purposes’));

log_me(‘This is a message for debugging purposes’);

Make Full Use of Codes

 

make-full-use-of-codes-wordpress-tutorial

 

1. Knowing Short Codes is Essential

Short codes are amazing in making your end users feel satisfied with your plugin. Provided that you are already familiar with WordPress, you must have run into short codes once or twice. Its basic form is the key word between square brackets. What do short codes do literally? They provide customers with ease. So, if you can master the use of short codes in your plugins, chances are that they will return to you for future projects.

2. Understand the Difference Between include, include_once, require, require_once

This is not about short codes, but just codes. Well, somewhere along the development path of your plugin, you may wish to insert code into other files. This can help maintaining your plugin turn an easier job. For example, people usually create a functions.php file that has all of the common functions.

Let’s take an example, if you name your main plugin file myplugin.php and you want to create the functions.php file. Then, add these lines to it:

include ‘functions.php’; include_once ‘functions.php’; require ‘functions.php’; require_once ‘functions.php’;

However, you should really distinguish between the 4 popular codes, that is include, include_once, require, and require_once. In this way, you can choose to use one among them based on the outcome you expect:

  • include: Includes and assesses the specific file, presenting a warning incase users cannot find the file.
  • include_once: Functions just like include, but when the file has already been included it will not be included again.
  • require: Includes and assesses the specific file, but rather than a warning once the file cannot be found, it gives a fatal error.
  • require_once: Functions just like require, but if the file has already been included it will not be included again.

Keep Up with WordPress Development

 

keep-up-with-wordpress-development-wordpress-tutorial

 

1. Keep the Plugin Version for Updates

If you have been writing WordPress plugin for some time, I bet you should know that updates are unavoidable under any circumstances. In many cases, you will be confused when experiencing the upgrade. So is there any way to make it as convenient as possible? Yes there is, indeed.

Keep the plugin version is what. By this way you can always read it later to decide on the level of upgrading for your plugin. How to do it? Well, all you need is to create some more variables and call on theadd_option() function:

if (!defined(‘MYPLUGIN_VERSION_KEY’))     define(‘MYPLUGIN_VERSION_KEY’, ‘myplugin_version’);

if (!defined(‘MYPLUGIN_VERSION_NUM’))     define(‘MYPLUGIN_VERSION_NUM’, ‘1.0.0’);

add_option(MYPLUGIN_VERSION_KEY, MYPLUGIN_VERSION_NUM);

And when it’s time to check if you need to perform upgrade actions, your plugin will show codes that look like this:

$new_version = ‘2.0.0’;

if (get_option(MYPLUGIN_VERSION_KEY) != $new_version) {

// Execute your upgrade logic here

// Then update the version value

update_option(MYPLUGIN_VERSION_KEY, $new_version);

}

2. Pay Attention to All Types of WordPress Development

In this WordPress Tutorial, besides keeping up with the upgrades of your own plugin, you are also recommended to take into consideration all kinds of WordPress development. As a part of this community, this is definitely your duty and right. For example, it is advisable to keep a close watch on upcoming new WordPress version release. At the same time, check if there are any vulnerabilities in the version you are using. Where to check up on those information? Development blogs, of course.

In this regard, may I introduce to you some WordPress websites and blogs that will not only update you on WordPress news, but also give you precious tips and hacks. Those include WordPress Beginner and WordPress Tavern.

Master Plugin Activation/Deactivation Hook

 

master-activation-deactivation-hook-wordpress-tutorial

 

You can activate any plugin by clicking Activate Link presented in the plugin list. While a simple plugin will not require you to do any activation, an advanced one will make you carry out stuff like initializing plugin options, creating plugin tables, etc. In this step I will show you how to handle plugin activation and deactivation.

1. Plugin Activation Hook

In fact, WordPress has a function called register_activation_hook. This function is triggered when the plugin is activated. However, we can add a custom function to bring plugin activation into effect by adding the lines below:

function wp_sample_activation() {

}

register_activation_hook(__FILE__, ‘wp_sample_activation’);

Please note that you will have go through the path of the file containing the activation function being the first parameter and the function name being the second one.

In case the activation function lies inside the main plugin file, you are advised to use __FILE__  as shown in the code. With this, you can do tasks like validations, initializations and table creations within the activation function.

2. Plugin Deactivation Hook

For deactivation of a plugin, we can use the register_deactivation_hook, . With the same syntax as for activation, you can tidy up the plugin resources, options and tables within the deactivation function.

function wp_sample_deactivation() {

}

register_deactivation_hook(__FILE__, ‘wp_sample_deactivation’);

Add Option Boxes

 

add-option-boxes-wordpress-tutorial

 

A WordPress Tutorial cannot be called one if it doesn’t tell you important pieces of information. One of them is that WordPress supplies us with a default set of such fields as title, content, image, and excerpt all laid out in the content creation screen. To add additional behavior, we need custom fields. To be specific, well, we need to supplement separate fields if checkboxes are required, as well as radio buttons, drop downs and such.

In order to create option boxes to add additional fields, do as follows:

add_action(‘add_meta_boxes’, ‘add_custom_fields_box’);

function add_custom_fields_box() {

add_meta_box(‘custom_fields_box_id’, ‘Custom Info’, ‘display_custom_info_box’, ‘post’, ‘normal’, ‘high’);

}   function display_custom_info_box() {

global $post;

$html = “<table><tr><td>Custom Checkbox</td><td><input id=’custom_checkbox’ type=’checkbox’ name=’custom_checkbox’  /></td></tr> <tr><td>Custom Selecy</td><td><select name=’custom_select’  > <option>Option 1</option> </select></td></tr> <tr><td>Custom Upload</td><td><input id=’custom_file’ type=’file’ name=’custom_file’  /></td></tr></table>”;

echo $html;

}

Conclusion

So, here’s the end of the ultimate WordPress Tutorial for WordPress Plugin Developers! To advanced developers, I hope that you have at least found something useful or taken something into experience after reading my post. As for those who have just stepped into the industry, do not worry if things get complicated a little bit while reading this. As long as you are strong enough to get through, you will become the master very soon.

Have any more tips for WordPress plugin developers? Let us know in the comment section, please!

Category: Tips and Tricks Tags: tips for wordpress plugin developers wordpress WordPress plugins wordpress tips wordpress tutorial
SHARING:
  • Divider With No Text
PREVIOUS POST WordPress Tutorial: Using Tweaks to Enhance WordPress Security
NEXT POST The Ultimate WordPress Tutorial on Caching
avatar
About The Author: Chloe
Currently a student at DAV, I'm studying English Linguistics at the same time with nurturing my passion for WordPress and Open CMS, love to curate WordPress Resources.
single-banner

MOST POPULAR POSTS

OCTOBER PROMOTION: Chances to get free PSD Templates!

October 20, 2017
hdecor winner

HDecor: Winner for Theme of the Day!

August 2, 2017

ASLAN Update: Homepage 06 Release

July 21, 2017

Change Logs – Aslan WordPress

July 21, 2017
mercy winner

Mercy: Winner for Theme of the Day!

July 19, 2017

ALL CATEGORIES

  • Change Logs
  • Freebies
  • General
  • Hot Deals
  • News
  • Services
  • Theme Collection
  • Theme Release
  • Theme Updates
  • Tips and Tricks

About Lunartheme

We provide Premium WordPress Themes coupled with clean design and advanced features. Personalize the look and functionality of your site using our Theme Options panel though they are ready to use out of the box.

Get Free Tips to Your Inbox

From Our Blog

OCTOBER PROMOTION: Chances to get free PSD Templates! By Lunar Theme . In Hot Deals News WELCOME TO OUR BIGGEST PROMOTION OF THE YEAR EVER! Do you know that October is the ultimate month for deal & promotion hunters? Yes, you are reading that right. And…

 

  • HDecor: Winner for Theme of the Day!
  • ASLAN Update: Homepage 06 Release
  • Change Logs – Aslan WordPress
  • Mercy: Winner for Theme of the Day!

No Risk! Buy With Confidence

Our niche products have been in top popular products of its category for serveral weeks, won a couple of CSS design awards and featured on a number of magazines. Experience yourself to understand the difference
  • Check out our portfolio on ThemeForest
  • Check out support center
  • Dedicated Ticket
  • Contact Us
  • Terms and Conditions
  • Privacy Policy
  • Home
  • Themes
    • Bonsai WP – $49 (Limited Sales $21)
    • Moonlight
      • Moonlight WP
      • Moonlight PSD
    • Kids
      • Kids WP
      • Kids PSD
    • Mercy
      • Mercy WP
      • Mercy – PSD
    • H Decor
      • Hdecor WP
      • H Decor – PSD
    • ASLAN
      • ASLAN
      • Aslan PSD
    • Lincoln
      • LINCOLN – Education WP Theme
      • LINCOLN – Education PSD
      • Lincoln HTML
    • Primary
      • PRIMARY – Kindergarten WP Theme
      • Primary PSD
      • PRIMARY – Kindergarten HTML
    • Jakiro
      • JAKIRO – Fashion Shop WP Theme
      • JAKIRO – Pretashop
      • Jakiro – Multi Store HTML Template
      • JAKIRO – Fashion Shop PSD
      • Jakiro – Virtuemart
      • Jakiro – HTML
      • Jakiro – Shopify Theme
    • Furion
      • FURION – Portfolio WP Theme
      • Furion – Responsive HTML
      • FURION – Creative PSD
    • Ink
      • INK – Magazine WP Theme
      • INK – Magazine PSD
    • Lucy
      • LUCY – Feminine HTML
      • LUCY – Multipurpose PSD
    • Knight
      • Knight – Corporate PSD
      • Knight – Shopify
    • Tower
      • TOWER – Business WP Theme
      • TOWER – Creative Business HTML
      • Tower – Business PSD
    • Platinum
      • PLATINUM – Webshop PSD
      • Platinum Prestashop
      • Platinum HTML
    • Neveda
      • NEVEDA – Fashion PSD
      • Neveda – eCommerce WP
    • Steve Cadey
      • STEVE CADEY – PSD
      • STEVE CADEY – WP
    • 1989
      • 1989 – PSD
  • Freebies
    • Summer Freebie packages
    • FOLIO – Portfolio HTML5
    • MYTHEMES – Cooking PSD
    • PAPER – Blog PSD
    • INSTAISM – Portfolio PSD
    • Breviter – PSD Template
    • Free Fonts Collected
    • Free Plugins Collected
    • Free Icon Collected
    • Free Mock-up Collected
  • Blog
    • News
    • Theme Collection
    • Tips and Tricks
    • Theme Release
    • Theme Updates
    • Freebies
    • Hot Deals
    • Change Logs
    • Customers’ Sites
      • Lincoln Sites
      • Furion Sites
      • Jakiro Sites
      • INK Sites
  • Services
    • Installation
    • Customization
    • Migration
    • PSD to WordPress
  • Support
    • Dedicated Ticket
    • Jakiro Dedicated support
    • FAQs
    • Contact Us
  • EDITABLE PHP & CSS FILES
  • ONE CLICK AUTO-INSTALL
  • PREMIUM SUPPORT
  • DOMAIN USE LICENSE
  • THEME UPDATES
  • LAYERED PHOTOSHOP FILES
  • ACCESS ALL THEMES
BUY THIS THEME Lorem ipsum dolor sit amet
  • EDITABLE PHP & CSS FILES
  • ONE CLICK AUTO-INSTALL
  • PREMIUM SUPPORT
  • DOMAIN USE LICENSE LIMITED
  • THEME UPDATES
  • LAYERED PHOTOSHOP FILES
  • ACCESS ALL THEMES
  • $ Purchase
CLUB MEMBER Lorem ipsum dolor sit amet
  • EDITABLE PHP & CSS FILES
  • ONE CLICK AUTO-INSTALL
  • PREMIUM SUPPORT
  • DOMAIN USE LICENSE UNLIMITED
  • THEME UPDATES
  • LAYERED PHOTOSHOP FILES
  • ACCESS ALL THEMES
  • $ Buy Now