My Blog

Menu

Custom Plugin.

Posted: November 24, 2021. | By: Admin

We  all Know that plugins are php files that are located in a folder  called wpcontents/plugins/folder'.

In this article i am going to create a sample plugin which you can use it in the front end with the help of a short code, even the shotcode creation will explaned. And we are going to manage our created plugin in admin module as well.

Just follow up with me one by one you will get to know how to create an awesome plugin. The final code will be available at the end of this articles.

Create a follder in 'wpcontents/plugins/Awesome Plugin'

Then inside the created folder create a php file 'awesomeplugin.php'

 

Inside the created php file paste the following code later you will understand why we have pasted this code.

/*

Plugin Name: Awesome Plugin

Plugin URL: http://awesomeplugin.com

Description: This is my First Custom Plugin, which is going to do a great job in wordpress

Version: 1.0

Author: Kranthi Godari

Author URL: http://yoururl.com

*/

?>

The above lines of  code will create a plugin in your plugins folder in admin side, you can go and  check in the admin module and can activate it and deactivate it.

Description of above code is here: 

All the plugin related details should be written in  between /*  'details' */ so that wordpress understands these are the details of the created module.

All the details what you have entered will be shown on the screen when you click on to view.

Managing Plugin From Admin Module :

Plugin has created in our admin module. Now we are going to display our plugin in admin dashboard so that we can manage it form there.

Check the following code so that you will understand how we can manage it from admin module.In the same php file you created, paste the following  code.

 add_action('admin_menu','awesome_plugin_setup');

function awesome_plugin_setup() {

add_menu_page('awesome_plugin','Awesome','manage_options','awesome_plugin','awesome_init');

 

}

function awesome_init() {

 echo "

Hello World

";

if(!current_user_can('manage_options')) {

wp die('You do not have sufficient permissions to access this page'); 

} else {

//include you code which shows its actions

echo "Template";

}

}

Now check your admin panel dashboard you can see your plugin name is displaying.

Note: Activate the plugin. And check your dashboard,

Click you plugin you can see a page opened . So, now you can write code as per your requirements. so that users can manage your plugin from here.

Creating shotCode for our plugin: 

The following code can create a short code which we can use it in all over your wordpress site. Go through the code you can easily understand how it works

add_shortcode ('awesome_short_code_name', 'awesome_shortcode');

//The 'awesome_short_code_name' is your short code which you //  // are going to use in all over your wordpress site which // can reflect in forntend.

function awesome_shotcode() {

ob_start(); 

// You business logic for what your plugin is ment for

echo "your short code has been successfully created";

//End of your logic

return ob_get_clean();

}

Your plugin has been created. Now simply go to your admin panel and activate the plugin and place this shortcode '[awesome_short_code_name]' in any page or post . Now visit the page from front end you can see  the message is printed. In the same way write your business logic in your short code created module you can see awesome results.

Conclusion:

To your clear understanding, All the code, realted to creating custom plugin is given below.

/*

Plugin Name: Awesome Plugin

Plugin URL: http://awesomeplugin.com

Description: This is my First Custom Plugin, which is going to do a great job in wordpress

Version: 1.0

Author: Kranthi Godari

Author URL: http://yoururl.com

*/

add_action('admin_menu','awesome_plugin_setup');

function awesome_plugin_setup() {

add_menu_page('awesome_plugin','Awesome','manage_options','awesome_plugin','awesome_init');

}

function awesome_init() {

 echo "

Hello World

";

if(!current_user_can('manage_options')) {

wp die('You do not have sufficient permissions to access this page'); 

} else {

//include you code which shows its actions

echo "Template";

}

}

add_shortcode ('awesome_short_code', 'awesome_shortcode');

//The 'awesome_short_code' is your short code which you //  // are going to use in all over your wordpress site which // can reflect in forntend.

function awesome_shotcode() {

ob_start(); 

// You business logic for what your plugin is ment for

echo "your short code has been successfully created";

//End of your logic

return ob_get_clean();

}

?>

 

 

 

 

 

About

Aapthi Technologies,Hyderabad offers a complete range of web solutions including web designing, developing, web hosting, Internet marketing and many more. With our electrifying presence, we have swirled the scenario of web solutions. We consistently invigorate our skill-set and tech-expertise and work with a high-level of integrity. Our keen-eye on emerging trends of online business as well as technical spheres has empowered us to render the most innovative solutions. Persistent development is the key drive of Aapthi Technologies, be it in terms of infrastructure, skill-set or technology. Team Aapthi Technologies, is fully committed to render back hundred percent value for the money paid by client.

Social Links

Our Bunker

Plot No -596, Near Reliance Fresh,
Vivekananda nagar colony, Kukatpally,
Hyderabad - 500072, India.