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.
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.
- 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-
- Plugin Name: Your Plugin Name
- Plugin URL: Your Plugin Site (if any)
- Description: Your Plugin working or functionality
- Author: Your Name
- Version: Your Plugin Version
- Author URL: Your Website (if any)
- 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:
- 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.
- Function install()
- Your Database Table Creation Query
- 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.
- function uninstall()
- Your Database Table Deletion Query
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) function shortcode()
- Your Plugin Functionality Code
- 2) function register_shortcodes()
- add_shortcode(‘Your Plugin Shortcode name’,’shortcode’);
- 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) add_action(‘admin_menu’, ‘my_first_admin_menu’);
- 2) function my_first_admin_menu()
- add_menu_page(‘Plugin Admin Options’, ‘Your Plugin Admin Panel Name’, ‘manage_options’,’my first’,’admin_panel);
- 3) function admin_panel()
- Code For Your Admin Panel Options
- 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.