WordPress, the common open source platform that will use globally to create amazing websites, eCommerce portals and much more. Developers love to work with it due to its ease of access functionality. That ease of access, functionality comes through the different WordPress Plugins that allows a developer to use drag and drop feature including various admin features.

Wordpress Plugin

Although an expert WordPress Developer generally develops or moderate WordPress Plugins according to their specific requirement, but it’s a quite irritating for new developers to create a WordPress Plugin according to their requirement.

Here, we disclose different steps to create WordPress Plugin without any need of expertise.

Folder Hierarchy

  • Whenever you use WordPress, usually you see different files and folders under WordPress folder. Here in a WP – content folder, usually a folder exists named – plugin (if not create it through new folder creation process)

    WordPress -> WP-content -> plugins

  • After that you need to create another folder under plugins where you will store your files and folders. In this folder you need to create a file (plugin file) where you will write different sections of your plugin code.
  • You can choose a name of this file according to your convenience, we started with “testfile.php”.

Plugin Activation and Deactivation Concept

  • Authorization is always required so, before everything puts your name, plugin name, plugin version, plugin description and your URL in the “testfile.php”
  • After including briefing, you can now add different functions like – activation, deactivation and short-codes of your plugin.
  • Let’s take a look at the configuration of your plugin beneath-
  1. /*
  2. Plugin Name: Your Plugin Name
  3. Plugin URL: Your Plugin Site (if any)
  4. Description: Your Plugin working or functionality
  5. Author: Your Name
  6. Version: Your Plugin Version
  7. Author URL: Your Website (if any)
  8. */
  • Your plugin is created and now you can check it in your dashboard (Dashboard Panel -> Plugins)
  • After configuring your demo file, now you need to put the basic functionality of your plugin in the “testfile.php”
  • Now, you can use register_activation_hook() function that can help to activate your plugin’s functionality likewise:
  1. register_activation_hook(__FILE__.’install’);
  • In the above function, the second parameter “install” will allow you to implement WordPress database table creation query, which is required for the functionality.

Note: if you have your install function in the same file, then you should write first parameter as it is, otherwise you need to provide path of another file.

  1. Function install()
  2. {
  3. Your Database Table Creation Query
  4. }
  • f you activate your function, then it’s necessary to provide deactivation function as well. For deactivation you can use register_deactivation_hook() function, which helps a user to deactivate your plugin.
  1. register_deactivation_hook(__FILE__,’uninstall’);
  2. function uninstall()
  3. {
  4. Your Database Table Deletion Query
  5. }

Shortcode Creation for your plugin

  • To include a plugin in the GUI, it needs a shortcode. So, you can consider it as the sole concept of your plugin functionality.
  • Don’t worry about it, creation of a shortcode is a simple three step process, look beneath and try it.
  1. 1) function shortcode()
  2. {
  3. Your Plugin Functionality Code
  4. }
  5. 2) function register_shortcodes()
  6. {
  7. add_shortcode(‘Your Plugin Shortcode name’,’shortcode’);
  8. }
  9. 3) add_action(‘init’,’register_shortcodes’);
  • In the beginning there is your first step, where you create a function for the shortcode. Here you need to include your plugin code that needed to implement the functionality.
  • In the next step, you need to choose a name for your plugin to register your shortcode.
  • In the last step, you initialize your action function, which is needed to execute your shortcode.

Note: you can choose any name according to your theme or the use, but keep in mind that

1. It should be in lowercase.

2. You can use letters, numbers and underscores (not dashes)

Create an Admin Panel Option for Your Plugin

  • You have created a plugin, but without admin access for customization it’s not as worthy as you think.
  • Here in this section, you can oblige your users by providing customization options.
  • As like shortcode concept, admin panel is also a simple three step process:
  1. 1) add_action(‘admin_menu’, ‘my_first_admin_menu’);
  2. 2) function my_first_admin_menu()
  3. {
  4. add_menu_page(‘Plugin Admin Options’, ‘Your Plugin Admin Panel Name’, ‘manage_options’,’my first’,’admin_panel);
  5. }
  6. 3) function admin_panel()
  7. {
  8. Code For Your Admin Panel Options
  9. }

 

  • With this implementation, you can recognize a new menu option in your WordPress dashboard – Admin Panel, which is added through the first step of above code.
  • In the next step, where we add a function to provide a specific name for your plugin admin panel.
  • At the end, you need to provide functionality of your admin panel that allows a user to customize it.

For the detailed guide about plugin creation, you can read GitHub post here.

If you are a business owner and wants to develop a unique functionality for your WordPress website, be free to contact us for any kind of web development requirement either for web application, eCommerce portal or plugins.