SlideShare ist ein Scribd-Unternehmen logo
1 von 20
WordPress

Plugin Development
What is a Plugin?
Plugins are tools to extend the functionality of WordPress.
Plugins offer custom functions and features so that each user can tailor their site to
their specific needs.
WordPress is gaining more and more popularity each day, not just as a blogging
platform but also as a basic CMS, thus improving and extending its basic
functionality becoming a day-to-day necessity for a lot of developers. Fortunately,
the WordPress developers have foreseen these needs and added the possibility of
customizing the basic functionality by adding plugins. Basically, a WordPress
plugin is a (more or less) stand-alone piece of code that can be executed in different
sections and stages within a page or site
Steps to Create New PlugIn.

We will create a very simple plugin in this presentation. This
example will surely make u understand about the core concept of developing
plugins. Once you have idea of plugins, u can create more plugins by following the
same method and altering the code according to your need. Follow the step by step
procedure given below.
Plugins reside in WordpressWp-ContentPlugins

Step1. Create a Folder in Plugins directory and name it as Hello_World.
Step2. Create a php file with the same name in Hello_World folder.
i.e. Hello_World.php.
Step3. Add this code in the start of newly created file.
This code will let the wordpress understand that this is a plugin file. After Adding
this code You can check in DashboardPlugins, here u can see you plugin with all
the specification given in commented code.
<?php
/*
Plugin Name: Hello_World
Plugin URI: www.HellowWorld.com/
Description: A simple hello world wordpress plugin
Version: 1.0
Author: AliShah
Author URI: AliShah_120@yahoo.com
License: GPL
*/
?>
Activate Your Plugin.
Step4. Up till Now we have created a plugin, which has been activated
but it performs no functionality. This plugin should do something. So we place a
code which will print HelloWorld. For this purpose we will create a function which
will print hello world. And we will initiate this function with startup of wordpress
site . In this code a function will be used.
<?php
Add_action ('init','Hello_World');
function Hello_World()
{
Echo „ This Plugin is Working Fine‟;
}
?>
Add this code in Hello_World.php plugin file. Add_action is a function which
hooks a function with some action. In our example This calls Hello_World()
function when wordpress initializes.
Now you can see that „This Plugin is Working Fine‟ is written
somewhere on your website . If you can see this line. It means you are
doing good uptill now. Our Hello_World.php file has the following code
uptill now.
Our Hello World plugin is nearly done and with just few lines of code.
When our plugin is activated, add_action command calls our
hello_world() function when wordpress starts loading.
Why not, we build a plugin options page in admin area and provide a
backend for plugin users?
Right now, the plugin outputs hello world (its pretty much static) and if
somebody wants to output „„This Plugin is Working Fine‟ , they need to
open the php file and make changes everytime to print different text.
Asking the user to edit plugin files isnt a good idea! As a wordpress
plugin developer, it is you, who has to provide a good wordpress options
interface in the wp-admin area.
What should a Plugin do?
Here is what we do….
•When plugin gets activated, we create new database field `wp_hello_world_data`
using set_options() function.

•When plugin gets deactivated, we delete the database field `wp_hello_world_data`
•We create a options menu for Hello World in WordPress Admin > Settings.
•We save the user entered data in the wordpress database.
•We retrieve the data stored in wordpress database and output it using get_options()
function.
•Why we are creating database field? because the saved data must be saved
somewhere? ie. in wordpress database. This way the plugin outputs user entered
text, instead of the static “Hello World”.
Hooks
Hooks are provided by WordPress to allow your plugin to 'hook
into' the rest of WordPress; that is, to call functions in your plugin at specific times,
and thereby set your plugin in motion. There are two kinds of hooks:
Actions: Actions are the hooks that the WordPress core launches at specific points
during execution, or when specific events occur. Your plugin can specify that one
or more of its PHP functions are executed at these points, using the Action API.
Filters: Filters are the hooks that WordPress launches to modify text of various
types before adding it to the database or sending it to the browser screen. Your
plugin can specify that one or more of its PHP functions is executed to modify
specific types of text at these times, using the Filter API.
1.

Register_ Activation_Hook

Description
The register_activation_hook function registers a plugin function to be run when
the plugin is activated.
Syntax
<?php register_activation_hook( $file, $function ); ?>
Parameters...
$file: (string) (required) Path to the main plugin file inside the wp-content/plugins
directory. A full path will work. Default: None
$function:
The function to be run when the plugin is activated.
Example
register_activation_hook( __FILE__, „Hello_World_Install' );
2.

Register_ Deactivation _Hook

Description
The function register_deactivation_hook (introduced in WordPress 2.0) registers a
plugin function to be run when the plugin is deactivated.

Syntax
<?php register_deactivation_hook($file, $function); ?>
Parameters...
$file: (string) (required) Path to the main plugin file inside the wp-content/plugins
directory. A full path will work. Default: None
$function:
$function:
The function to be run when the plugin is activated.
Example
register_deactivation_hook( __FILE__, „Hello_World_Remove‟ );
Add Option Functions
Add _Option
This function will be used in Hello_World_Install(function). Add_Option is used to
set the user given value to plugin .

Syntax
<?php add_option( $option, $value, $deprecated, $autoload ); ?>
Parameters...
$option: Name of the option to be added. This is going to be placed into the database.
$value: Default value since we explicitly set it.
$deprecated: description. No need to give for versions after 2.0.
$autoload: should this option be automatically loaded when the page load . The value
may be Yes or No.
Example
<?php Add_option(„‟Hello_World_Data‟‟, „Default‟, „‟, „yes‟)
Delete Option Functions
Delete _Option
This function will be used in Hello_World_remove(function). A safe way of removing
a named option/value pair from the options database table.

Syntax
<?php delete_option( $option ); ?>
Parameters...
$option: Name of the option to be added. This is going to be deleted.
Example
<?php delete_option(„‟Hello_World_Data‟‟) ?>
In our example
Plugin Settings Page
This is our final step. All we need to create is plugin
settings page in the wordpress admin area. The settings page will update and
save the data to the database field `hello_world_data` which we created while
activating the plugin.
Here is a very important thing to remember:
The add_action for admin_menu should call a function
hello_world_admin_menu() containing add_options_page, which in turn
should call a function hello_world_html_code() containing html code.
Plugin Settings Page
So , first task is to add the Hello_World options in the
DashboardSettingsHello World .
For this purpose we will use the conditional tag for
confirmation of admin.
The tag is
If (is_admin() )
{
Run this code(here we will write the code for showing the
setting page for admin)
}
In this if condition an add_action () function is used which will call a
function „Hello_world_admin_menu().‟
Plugin Settings Page
<?php
if ( is_admin() )
{

/* Call the html code */
add_action ('admin_menu', 'hello_world_admin_menu');
function hello_world_admin_menu()
{
add_options_page('Hello World', 'Hello World', 'administrator',
'hello-world', 'hello_world_html_page');
}
}
?>
Plugin Settings Page
add_action ('admin_menu', 'hello_world_admin_menu');
Add_action is calling a function named 'hello_world_admin_menu„
in the body of this called function there is another function which is calling
for html page. This call is through an other function
„hello_world_html_page‟.
function hello_world_admin_menu()
{
add_options_page ('Hello World', 'Hello World', 'administrator',
'hello-world', 'hello_world_html_page');
}
}
?>
Add_Options_page

Function

Description
Add sub menu page to the Settings menu.
Syntax<?php
add_options_page ( $page_title, $menu_title, $capability, $menu_slug, $function);
?>
Parameters...
$page_title: this is the title of settings page.
$menu_Title: this is the title in dashboardsettings title
$capability: here we can give user who have permissions. i.e Admin
$menu-slug: brief info about menu.
$function: here the name of function. Which is to call.
Example
add_options_page('Hello World', 'Hello World Menu', 'administrator',
'hello-world', 'hello_world_html_page');
html Page
This is the last step. In previous slide , on add_options_page function we called a
function name „hello_world_html_page‟. Now we have to this function. We will
create a text filed and button, under the form object. User will write the desired
string and press the update button the value will be saved in data base.

Weitere ähnliche Inhalte

Was ist angesagt?

Rails 3: Dashing to the Finish
Rails 3: Dashing to the FinishRails 3: Dashing to the Finish
Rails 3: Dashing to the Finish
Yehuda Katz
 
php-and-zend-framework-getting-started
php-and-zend-framework-getting-startedphp-and-zend-framework-getting-started
php-and-zend-framework-getting-started
tutorialsruby
 

Was ist angesagt? (17)

Understanding Technologies - Presentation for College Students
Understanding Technologies - Presentation for College StudentsUnderstanding Technologies - Presentation for College Students
Understanding Technologies - Presentation for College Students
 
Devise and Rails
Devise and RailsDevise and Rails
Devise and Rails
 
ADF 2.4.0 And Beyond
ADF 2.4.0 And BeyondADF 2.4.0 And Beyond
ADF 2.4.0 And Beyond
 
How to build crud application using vue js, graphql, and hasura
How to build crud application using vue js, graphql, and hasuraHow to build crud application using vue js, graphql, and hasura
How to build crud application using vue js, graphql, and hasura
 
CodeIgniter PHP MVC Framework
CodeIgniter PHP MVC FrameworkCodeIgniter PHP MVC Framework
CodeIgniter PHP MVC Framework
 
Rails 3: Dashing to the Finish
Rails 3: Dashing to the FinishRails 3: Dashing to the Finish
Rails 3: Dashing to the Finish
 
Pundit
PunditPundit
Pundit
 
How to Webpack your Django!
How to Webpack your Django!How to Webpack your Django!
How to Webpack your Django!
 
Symfony tips and tricks
Symfony tips and tricksSymfony tips and tricks
Symfony tips and tricks
 
Caldera Learn - LoopConf WP API + Angular FTW Workshop
Caldera Learn - LoopConf WP API + Angular FTW WorkshopCaldera Learn - LoopConf WP API + Angular FTW Workshop
Caldera Learn - LoopConf WP API + Angular FTW Workshop
 
Introduction to plugin development
Introduction to plugin developmentIntroduction to plugin development
Introduction to plugin development
 
Writing Pluggable Software
Writing Pluggable SoftwareWriting Pluggable Software
Writing Pluggable Software
 
php-and-zend-framework-getting-started
php-and-zend-framework-getting-startedphp-and-zend-framework-getting-started
php-and-zend-framework-getting-started
 
Implementing Testing for Behavior-Driven Development Using Cucumber
Implementing Testing for Behavior-Driven Development Using CucumberImplementing Testing for Behavior-Driven Development Using Cucumber
Implementing Testing for Behavior-Driven Development Using Cucumber
 
Top laravel packages to install handpicked list from expert
Top laravel packages to install handpicked list from expertTop laravel packages to install handpicked list from expert
Top laravel packages to install handpicked list from expert
 
Refactoring Large Web Applications with Backbone.js
Refactoring Large Web Applications with Backbone.jsRefactoring Large Web Applications with Backbone.js
Refactoring Large Web Applications with Backbone.js
 
In The Trenches With Tomster, Upgrading Ember.js & Ember Data
In The Trenches With Tomster, Upgrading Ember.js & Ember DataIn The Trenches With Tomster, Upgrading Ember.js & Ember Data
In The Trenches With Tomster, Upgrading Ember.js & Ember Data
 

Andere mochten auch (9)

Tranzeo
TranzeoTranzeo
Tranzeo
 
Ss Ton 2008 Final
Ss Ton 2008 FinalSs Ton 2008 Final
Ss Ton 2008 Final
 
Suman Jlt
Suman JltSuman Jlt
Suman Jlt
 
Woban Prototype Ieee Network
Woban Prototype Ieee NetworkWoban Prototype Ieee Network
Woban Prototype Ieee Network
 
Wls2
Wls2Wls2
Wls2
 
S06 S10 P05
S06 S10 P05S06 S10 P05
S06 S10 P05
 
33
3333
33
 
Guidelines For Point To Point
Guidelines For Point To PointGuidelines For Point To Point
Guidelines For Point To Point
 
Pid967241
Pid967241Pid967241
Pid967241
 

Ähnlich wie Plug in development

Write your first WordPress plugin
Write your first WordPress pluginWrite your first WordPress plugin
Write your first WordPress plugin
Anthony Montalbano
 
Bending word press to your will
Bending word press to your willBending word press to your will
Bending word press to your will
Tom Jenkins
 
Step by step guide for creating wordpress plugin
Step by step guide for creating wordpress pluginStep by step guide for creating wordpress plugin
Step by step guide for creating wordpress plugin
Mainak Goswami
 

Ähnlich wie Plug in development (20)

WordPress basic fundamental of plugin development and creating shortcode
WordPress basic fundamental of plugin development and creating shortcodeWordPress basic fundamental of plugin development and creating shortcode
WordPress basic fundamental of plugin development and creating shortcode
 
Write your first WordPress plugin
Write your first WordPress pluginWrite your first WordPress plugin
Write your first WordPress plugin
 
How To Write a WordPress Plugin
How To Write a WordPress PluginHow To Write a WordPress Plugin
How To Write a WordPress Plugin
 
Getting started with WordPress development
Getting started with WordPress developmentGetting started with WordPress development
Getting started with WordPress development
 
Intro to WordPress Plugin Development
Intro to WordPress Plugin DevelopmentIntro to WordPress Plugin Development
Intro to WordPress Plugin Development
 
Bending word press to your will
Bending word press to your willBending word press to your will
Bending word press to your will
 
Wordpress as a framework
Wordpress as a frameworkWordpress as a framework
Wordpress as a framework
 
Step by step guide for creating wordpress plugin
Step by step guide for creating wordpress pluginStep by step guide for creating wordpress plugin
Step by step guide for creating wordpress plugin
 
Word press Plugins by WordPress Experts
Word press Plugins by WordPress ExpertsWord press Plugins by WordPress Experts
Word press Plugins by WordPress Experts
 
WordPress Plugins
WordPress PluginsWordPress Plugins
WordPress Plugins
 
How to Create a Custom WordPress Plugin
How to Create a Custom WordPress PluginHow to Create a Custom WordPress Plugin
How to Create a Custom WordPress Plugin
 
WordPress Plugin development
WordPress Plugin developmentWordPress Plugin development
WordPress Plugin development
 
Demystifying Hooks, Actions & Filters - WordCamp Belfast 2018
Demystifying Hooks, Actions & Filters - WordCamp Belfast 2018Demystifying Hooks, Actions & Filters - WordCamp Belfast 2018
Demystifying Hooks, Actions & Filters - WordCamp Belfast 2018
 
How to create your own WordPress plugin
How to create your own WordPress pluginHow to create your own WordPress plugin
How to create your own WordPress plugin
 
Debugging - Figuring it out yourself (WordCamp Dublin 2019)
Debugging - Figuring it out yourself (WordCamp Dublin 2019)Debugging - Figuring it out yourself (WordCamp Dublin 2019)
Debugging - Figuring it out yourself (WordCamp Dublin 2019)
 
WordPress plugin #2
WordPress plugin #2WordPress plugin #2
WordPress plugin #2
 
Cakephp's Cache
Cakephp's CacheCakephp's Cache
Cakephp's Cache
 
Magento++
Magento++Magento++
Magento++
 
WordPress Structure and Best Practices
WordPress Structure and Best PracticesWordPress Structure and Best Practices
WordPress Structure and Best Practices
 
Jumping Into WordPress Plugin Programming
Jumping Into WordPress Plugin ProgrammingJumping Into WordPress Plugin Programming
Jumping Into WordPress Plugin Programming
 

Mehr von Lucky Ali (10)

Sulphur crested coockatoo
Sulphur crested coockatooSulphur crested coockatoo
Sulphur crested coockatoo
 
Using resource materials
Using resource materialsUsing resource materials
Using resource materials
 
Health education
Health educationHealth education
Health education
 
Fat and ntfs
Fat and ntfsFat and ntfs
Fat and ntfs
 
Joomla 3-versions
Joomla 3-versionsJoomla 3-versions
Joomla 3-versions
 
Joomla 2-cms working
Joomla 2-cms workingJoomla 2-cms working
Joomla 2-cms working
 
Joomla 1-introduction
Joomla 1-introductionJoomla 1-introduction
Joomla 1-introduction
 
Introduction to word press
Introduction to word pressIntroduction to word press
Introduction to word press
 
Custome page template
Custome page templateCustome page template
Custome page template
 
Post and page in word press
Post and page in word pressPost and page in word press
Post and page in word press
 

Kürzlich hochgeladen

Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
ssuserdda66b
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 

Kürzlich hochgeladen (20)

Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 

Plug in development

  • 2. What is a Plugin? Plugins are tools to extend the functionality of WordPress. Plugins offer custom functions and features so that each user can tailor their site to their specific needs. WordPress is gaining more and more popularity each day, not just as a blogging platform but also as a basic CMS, thus improving and extending its basic functionality becoming a day-to-day necessity for a lot of developers. Fortunately, the WordPress developers have foreseen these needs and added the possibility of customizing the basic functionality by adding plugins. Basically, a WordPress plugin is a (more or less) stand-alone piece of code that can be executed in different sections and stages within a page or site
  • 3. Steps to Create New PlugIn. We will create a very simple plugin in this presentation. This example will surely make u understand about the core concept of developing plugins. Once you have idea of plugins, u can create more plugins by following the same method and altering the code according to your need. Follow the step by step procedure given below. Plugins reside in WordpressWp-ContentPlugins Step1. Create a Folder in Plugins directory and name it as Hello_World. Step2. Create a php file with the same name in Hello_World folder. i.e. Hello_World.php.
  • 4. Step3. Add this code in the start of newly created file. This code will let the wordpress understand that this is a plugin file. After Adding this code You can check in DashboardPlugins, here u can see you plugin with all the specification given in commented code. <?php /* Plugin Name: Hello_World Plugin URI: www.HellowWorld.com/ Description: A simple hello world wordpress plugin Version: 1.0 Author: AliShah Author URI: AliShah_120@yahoo.com License: GPL */ ?> Activate Your Plugin.
  • 5. Step4. Up till Now we have created a plugin, which has been activated but it performs no functionality. This plugin should do something. So we place a code which will print HelloWorld. For this purpose we will create a function which will print hello world. And we will initiate this function with startup of wordpress site . In this code a function will be used. <?php Add_action ('init','Hello_World'); function Hello_World() { Echo „ This Plugin is Working Fine‟; } ?> Add this code in Hello_World.php plugin file. Add_action is a function which hooks a function with some action. In our example This calls Hello_World() function when wordpress initializes.
  • 6. Now you can see that „This Plugin is Working Fine‟ is written somewhere on your website . If you can see this line. It means you are doing good uptill now. Our Hello_World.php file has the following code uptill now. Our Hello World plugin is nearly done and with just few lines of code. When our plugin is activated, add_action command calls our hello_world() function when wordpress starts loading. Why not, we build a plugin options page in admin area and provide a backend for plugin users? Right now, the plugin outputs hello world (its pretty much static) and if somebody wants to output „„This Plugin is Working Fine‟ , they need to open the php file and make changes everytime to print different text. Asking the user to edit plugin files isnt a good idea! As a wordpress plugin developer, it is you, who has to provide a good wordpress options interface in the wp-admin area.
  • 7. What should a Plugin do? Here is what we do…. •When plugin gets activated, we create new database field `wp_hello_world_data` using set_options() function. •When plugin gets deactivated, we delete the database field `wp_hello_world_data` •We create a options menu for Hello World in WordPress Admin > Settings. •We save the user entered data in the wordpress database. •We retrieve the data stored in wordpress database and output it using get_options() function. •Why we are creating database field? because the saved data must be saved somewhere? ie. in wordpress database. This way the plugin outputs user entered text, instead of the static “Hello World”.
  • 8. Hooks Hooks are provided by WordPress to allow your plugin to 'hook into' the rest of WordPress; that is, to call functions in your plugin at specific times, and thereby set your plugin in motion. There are two kinds of hooks: Actions: Actions are the hooks that the WordPress core launches at specific points during execution, or when specific events occur. Your plugin can specify that one or more of its PHP functions are executed at these points, using the Action API. Filters: Filters are the hooks that WordPress launches to modify text of various types before adding it to the database or sending it to the browser screen. Your plugin can specify that one or more of its PHP functions is executed to modify specific types of text at these times, using the Filter API.
  • 9. 1. Register_ Activation_Hook Description The register_activation_hook function registers a plugin function to be run when the plugin is activated. Syntax <?php register_activation_hook( $file, $function ); ?> Parameters... $file: (string) (required) Path to the main plugin file inside the wp-content/plugins directory. A full path will work. Default: None $function: The function to be run when the plugin is activated. Example register_activation_hook( __FILE__, „Hello_World_Install' );
  • 10. 2. Register_ Deactivation _Hook Description The function register_deactivation_hook (introduced in WordPress 2.0) registers a plugin function to be run when the plugin is deactivated. Syntax <?php register_deactivation_hook($file, $function); ?> Parameters... $file: (string) (required) Path to the main plugin file inside the wp-content/plugins directory. A full path will work. Default: None $function: $function: The function to be run when the plugin is activated. Example register_deactivation_hook( __FILE__, „Hello_World_Remove‟ );
  • 11. Add Option Functions Add _Option This function will be used in Hello_World_Install(function). Add_Option is used to set the user given value to plugin . Syntax <?php add_option( $option, $value, $deprecated, $autoload ); ?> Parameters... $option: Name of the option to be added. This is going to be placed into the database. $value: Default value since we explicitly set it. $deprecated: description. No need to give for versions after 2.0. $autoload: should this option be automatically loaded when the page load . The value may be Yes or No. Example <?php Add_option(„‟Hello_World_Data‟‟, „Default‟, „‟, „yes‟)
  • 12. Delete Option Functions Delete _Option This function will be used in Hello_World_remove(function). A safe way of removing a named option/value pair from the options database table. Syntax <?php delete_option( $option ); ?> Parameters... $option: Name of the option to be added. This is going to be deleted. Example <?php delete_option(„‟Hello_World_Data‟‟) ?>
  • 14. Plugin Settings Page This is our final step. All we need to create is plugin settings page in the wordpress admin area. The settings page will update and save the data to the database field `hello_world_data` which we created while activating the plugin. Here is a very important thing to remember: The add_action for admin_menu should call a function hello_world_admin_menu() containing add_options_page, which in turn should call a function hello_world_html_code() containing html code.
  • 15. Plugin Settings Page So , first task is to add the Hello_World options in the DashboardSettingsHello World . For this purpose we will use the conditional tag for confirmation of admin. The tag is If (is_admin() ) { Run this code(here we will write the code for showing the setting page for admin) } In this if condition an add_action () function is used which will call a function „Hello_world_admin_menu().‟
  • 16. Plugin Settings Page <?php if ( is_admin() ) { /* Call the html code */ add_action ('admin_menu', 'hello_world_admin_menu'); function hello_world_admin_menu() { add_options_page('Hello World', 'Hello World', 'administrator', 'hello-world', 'hello_world_html_page'); } } ?>
  • 17. Plugin Settings Page add_action ('admin_menu', 'hello_world_admin_menu'); Add_action is calling a function named 'hello_world_admin_menu„ in the body of this called function there is another function which is calling for html page. This call is through an other function „hello_world_html_page‟. function hello_world_admin_menu() { add_options_page ('Hello World', 'Hello World', 'administrator', 'hello-world', 'hello_world_html_page'); } } ?>
  • 18. Add_Options_page Function Description Add sub menu page to the Settings menu. Syntax<?php add_options_page ( $page_title, $menu_title, $capability, $menu_slug, $function); ?> Parameters... $page_title: this is the title of settings page. $menu_Title: this is the title in dashboardsettings title $capability: here we can give user who have permissions. i.e Admin $menu-slug: brief info about menu. $function: here the name of function. Which is to call. Example add_options_page('Hello World', 'Hello World Menu', 'administrator', 'hello-world', 'hello_world_html_page');
  • 19.
  • 20. html Page This is the last step. In previous slide , on add_options_page function we called a function name „hello_world_html_page‟. Now we have to this function. We will create a text filed and button, under the form object. User will write the desired string and press the update button the value will be saved in data base.