How to create a wordpress plugin from scratch?

by

Create a WordPress Plugin from scratch :

WordPress is the most well known open source content management system for the present world web application. WordPress Plugins permit simple alteration, customization, and upgrade of a WordPress blog. A WordPress Plugin is a program, or an arrangement of at least one capacities, written in the PHP, that includes a particular arrangement of components or administrations to the WordPress without changing the center programming of WordPress.

wordpress plugin

1) Plugin Directory Creation:

Make a directory with your Plugin name.(Like: myPlugin/)

myPlugin/

2) Main Plugin File:

In the Plugin index (myPlugin/) make a PHP record with a similar name of the Plugin directory(Like myPlugin.php).

myPlugin/

myPlugin.php

3) myPlugin.php File:

In this document, you have to keep in touch with a few codes and capacities.

This document must contain a standard Plugin data header. The data ought to be given into the remark labels.

/**

* Plugin Name: Name Of The Plugin

* Plugin URI: http://URI_Of_Page_Describing_Plugin_and_Updates

* Description: A short portrayal of the Plugin.

* Version: The Plugin’s Version Number, e.g.: 1.0

* Author: Name Of The Plugin Author

* Author URI: http://URI_Of_The_Plugin_Author

* License: A “Slug” permit name e.g. GPL2

*/

On the off chance that your Plugin has any capacity that collaborates with the database, at that point announce the $wpdb.

worldwide $wpdb;

On the off chance that you need to make some client characterized capacities, at that point make functions.php record and incorporate it.

incorporate “functions.php”;

Announce the add_action() work : add_action() work Hooks a capacity on to a particular activity.

/add_action( $tag, $function_to_add, $priority, $accepted_args );

add_action(‘admin_menu’, ‘myplugin_menu’);

Presently proclaim the capacity which you already included into add_action() work.

work myplugin_menu(){

}
4) myplugin_menu() work:

Pronounce the add_menu_page() work: add_menu_page() work makes another best level menu area in the administrator menu sidebar and registers a snare to callback your capacity for yielding the page content when the connected menu page is asked.

/add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $position );

add_menu_page(‘ My Plugin’, ” My Plugin ‘, ‘head’, ‘myplugin_settings’, ‘myplugin_ menu_page’);

Pronounce the add_submenu_page() work : add_submenu_page() work include a sub menu page.

/add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function );

add_submenu_page(‘myplugin_settings’, ‘My Plugin Submenu’, ‘My Plugin Submenu’, ‘director’, ‘myproject_submenu’, ‘myproject_submenu_page’);

5) Database Table Creation :

On the off chance that you need to make the table at the database for your module, at that point take the underneath steps.

At first pronounced a client characterized work like install_tables().Then you ought to be announced worldwide $wpdb; incorporate upgrade.php petition for database association. After that dole out a variable with the estimation of the make table SQL and pass this variable into the dbDelta() work.

work instal_tables()

{

worldwide $wpdb;

require_once(ABSPATH . ‘wp-administrator/incorporates/upgrade.php’);

$table1 = “Make TABLE “.$wpdb->prefix.”table_name (

`id` bigint(100) NOT NULL AUTO_INCREMENT,

`name` varchar(255) NOT NULL,

`email` varchar(255) NOT NULL,

Essential KEY (`id`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci”;

dbDelta($table1);

}

Presently pronounce the register_activation_hook() capacity and pass the beforehand announced capacity into register_activation_hook().

register_activation_hook(__FILE__,’instal_tables’);

6) Page view:

Presently make a catalog under the Plugin registry. At that point make a PHP petition for site hit and embed this record into the recently made index. For better seeing please take after the beneath record structure.

myPlugin/

myPlugin.php

pages/

myplugin_menu_page_view.php

The myplugin_menu_page_view.php record contains menu or sub menu page work.

This PHP document contains menu or submenus work. In the event that you need to utilize this page for menu site visit, at that point you have to pronounce the menu page work. On the off chance that you need to utilize this page for sub menu online visit, at that point, you have to announce the sub menu page work.

<?php

ob_start();

/administrator menu page work

work myplugin_menu_page()

{

/for DB Association

worldwide $wpdb;

?>

<!- – Page HTML goes here – >

<h1>This is my Plugin menu page</h1>

<?php

}

?>

7) Include view pages: 

Incorporate all documents which contain the menu and sub menu page capacities.

incorporate “pages/myplugin_menu_page_view.php”;

incorporate “pages/myplugin_submenu_page_view.php”;

A post shared by WPCtrl (@wpctrl) on Aug 8, 2017 at 2:57am PDT

8)Installation:

Presently with two ways, you can set up your Plugin at the WordPress.

To begin with, you can duplicate the entire module organizer and glue it into the WordPress Plugins index (wp-content/modules).

Second, you can make a flash of your module organizer and transfer your Plugin speed from the wp administrator panel.(login to the wp administrator board => tap on the Plugins interface from the left menu area => tap the Add New => transfer your Plugin => dynamic your module)

If you are looking for a trustworthy web development company to manage your project? Morbitstech is the best solution for your business. We can help you attract the right customers, convert leads and grow your business.

Share

Leave a Reply

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