SlideShare a Scribd company logo
© Copyright 2010 Nibiru Solutions Private Limited 1
Presented by: Rakesh
2© Copyright 2010 Nibiru Solutions Private Limited 2
Agenda
Introduction
How to create wordpress plugin
How to create shortcode
How to create theme option
Quiz Questions
3© Copyright 2010 Nibiru Solutions Private Limited 3
Introduction
This session is very important and its very interesting.
In this session I cover some important worpress prebuild function
And there uses
Deep understanding of creating worpress plugin.
Creating wordpress shortcode and uses.
How to create theme options and uses
4© Copyright 2010 Nibiru Solutions Private Limited 4
How To Create Wordpress Plugin
WordPress is not just a blogging platform and it is such a
powerful CMS with unlimited capabilities, besides having
a huge user base.
Almost anything can be scripted with wordpress. You can
extend wordpress either by means of plugin or by a theme.
i will show you how to write a “Hello World” wordpress
plugin, which unlike many believe is surprisingly easy,
once you understand the very fundamentals.
5© Copyright 2010 Nibiru Solutions Private Limited 5
How To Create Wordpress Plugin -2
Plugin Files & Names
1. Always you chose a unique name to your plugin so that it doesnt
collide with names used in other plugins.
2. Assigning unique names, documenting and organizing the
plugin files is very important part of plugin creation.
3- place the plugin php file directly into the wp-
content/plugins folder
http://wordpress.org/plugins/about/readme.txt
6© Copyright 2010 Nibiru Solutions Private Limited 6
How To Create Wordpress Plugin -3
The Plugin Basics
The heart of a wordpress plugins is the below 2 functions
(commonly called `hooks`)
add_action ($tag, $func)
add_filter ($tag,$func)
add_action –> does an action at various points of wordpress
execution
add_filter –> does filtering the data (eg. escaping quotes before mysql
insert, or during output to browser.
7© Copyright 2010 Nibiru Solutions Private Limited 7
How To Create Wordpress Plugin -4
Plugin Information
Open your hello-world.php and in the first line, add this commented plugin
information to your file.
<?php
/*
Plugin Name: Hello-World Plugin
URI: http://yourdomain.com/
Description: A simple hello world wordpress plugin
Version: 1.0
Author: Your Name
Author URI: http://yourdomain.com
License: GPL
*/
?>
Save file.
8© Copyright 2010 Nibiru Solutions Private Limited 8
How To Create Wordpress Plugin -5
Go to your wordpress admin > plugins and you will see the new
plugin listed, waiting to get activated.
But this plugin had to do something right?
-> For that we write the code using add_action below the commented plugin
information in the hello-world.php
9© Copyright 2010 Nibiru Solutions Private Limited 9
How To Create Wordpress Plugin -6
<?php
/* This calls hello_world() function when wordpress initializes.*/
add_action('init','hello_world');
function hello_world() {
echo "Hello World";
}
?>
And Your Plugin done!
When our plugin is activated, add_action command calls our hello_world() function
when wordpress starts loading.
To test Open Any index.php , page.php or single.php And place the
following code.
<?php
if(function_exists('hello_world')) {
hello_world();
}
?>
10© Copyright 2010 Nibiru Solutions Private Limited 10
Build a plugin options page in admin area :
The plugin outputs hello world (its pretty much static).
So make this to dynamic we need to create a good admin interface.
Here is what we do….
We create a options menu for Hello World in WordPress Admin > Settings.
We save the user entered data in the wordpress database. Using set_options()
function.
We retrieve the data stored in wordpress database and output it using
get_options() function.
11© Copyright 2010 Nibiru Solutions Private Limited 11
Activating/Deactivating Plugin
It is very easy to write a function on what plugin does, when it gets
activated. WordPress offers 4 very important functions
register_activation_hook -> Runs on plugin activation
register_deactivation_hook -> Runs on plugin deactivation
add_option -> Creates new database field
get_option -> Retrieves the value in database field.
12© Copyright 2010 Nibiru Solutions Private Limited 12
Activating/Deactivating Plugin -2
Example : write fallowing code in hello-word.php
<?php
/* Runs when plugin is activated */
register_activation_hook(__FILE__,'hello_world_install');
/* Runs on plugin deactivation*/
register_deactivation_hook( __FILE__, 'hello_world_remove' );
function hello_world_install() {
/* Creates new database field */
add_option("hello_world_data", 'Default', '', 'yes');
}
function hello_world_remove() {
/* Deletes the database field */
delete_option('hello_world_data');
}
?>
13© Copyright 2010 Nibiru Solutions Private Limited 13
Plugin Settings Page
All we need to create is plugin settings page in the wordpress admin area.
<?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');
}
} ?>
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.
This is how the code should flow! Refer to wordpress administration menus
14© Copyright 2010 Nibiru Solutions Private Limited 14
Plugin Settings Page – Coding Part -1
The below function has the html code for the settings page,
containing the form
<?php
function hello_world_html_page() {
?>
<div>
<h2>Hello World Options</h2>
<form method="post" action="options.php">
<?php wp_nonce_field('update-options'); ?>
<table width="510">
<tr valign="top">
<th width="92" scope="row">Enter Text</th>
<td width="406">
15© Copyright 2010 Nibiru Solutions Private Limited 15
Plugin Settings Page – Coding Part -2
<input name="hello_world_data" type="text" id="hello_world_data"
value="<?php echo get_option('hello_world_data'); ?>" />
(ex. Hello World)</td>
</tr>
</table>
<input type="hidden" name="action" value="update" />
<input type="hidden" name="page_options" value="hello_world_data" />
<p>
<input type="submit" value="<?php _e('Save Changes') ?>" />
</p>
</form>
</div>
<?php } ?>
16© Copyright 2010 Nibiru Solutions Private Limited 16
Plugin Settings Page – Coding Part -3
And finally your plugin ready and looks like following.
You must remember 2 things in the above code.
1. Specify the database field we created before in the input text box as `hello_world_data`.
<input name="hello_world_data" type="text" id="hello_world_data“ value="<?php echo
get_option('hello_world_data'); ?>" />
2. If your form has number of fields (like textbox, selectbox etc), all those should be listed
in the value field of page_options, separated by commas. For more information, refer
to wordpress documentation
<input type="hidden" name="page_options" value="hello_world_data" />
17© Copyright 2010 Nibiru Solutions Private Limited 17
Wwordpres Shortcode
The Shortcode API
 Introduced in WordPress 2.5
 A simple set of functions for creating macro codes for use in post content.
 And a simple shortcode used like [shotcode].
Lets Create a shortcode of Hello Word plugin
<?php
function show_hello_text() {
return get_option('hello_world_data');
}
add_shortcode('showtext', 'show_hello_text');
?>
Use the shortcode [showtext] into page or post content to show your hello world text.
18© Copyright 2010 Nibiru Solutions Private Limited 18
How to create custom them option
If you create your own themes you will, sooner or later, want to allow
your theme users have some control over certain appearance and/or
functional elements of your theme.
19© Copyright 2010 Nibiru Solutions Private Limited 19
How to create custom them option -2
This commonly use following functions.
add_action( $tag, $function_to_add, $priority, $accepted_args );
register_setting( $option_group, $option_name, $sanitize_callback )
add_theme_page( $page_title, $menu_title, $capability, $menu_slug, $function );
settings_fields( $option_group )
## coding section
<? php
add_action( 'admin_init', 'theme_options_init' );
add_action( 'admin_menu', 'theme_options_add_page' );
function theme_options_init(){
register_setting( 'sample_options', 'sample_theme_options');
}
function theme_options_add_page() {
add_theme_page( __( 'Theme Options', 'sampletheme' ), __( 'Theme
Options', 'sampletheme' ), 'edit_theme_options', 'theme_options',
'theme_options_do_page' );
}
1- this used in setting_fields();
2- this function name and its used html
20© Copyright 2010 Nibiru Solutions Private Limited 20
How to create custom them option -3
function theme_options_do_page() {
global $select_options;
<form method="post" action="options.php">
<?php settings_fields( 'sample_options' ); ?>
<?php $options = get_option( 'sample_theme_options' ); ?>
<input id="sample_theme_options[showintro]" name="sample_theme_options[showintro]"
type="checkbox" value="1“ <?php checked( '1', $options['showintro'] ); ?> />
<input id="sample_theme_options[fburl]" type="text"
name="sample_theme_options[fburl]" value="<?php esc_attr_e( $options['fburl'] ); ?
>" />
<textarea id="sample_theme_options[introtext]"
class="large-text" cols="50" rows="10" name="sample_theme_options[introtext]"><?php
echo esc_textarea( $options['introtext'] ); ?></textarea>
<input type="submit" value="<?php _e( 'Save Options', 'customtheme' ); ?>" />
</form>
} ?>
1
2
21© Copyright 2010 Nibiru Solutions Private Limited 21
The End Of Then Session
Thank You !

More Related Content

What's hot

Php login system with admin features evolt
Php login system with admin features   evoltPhp login system with admin features   evolt
Php login system with admin features evoltGIMT
 
Getting Into Drupal 8 Configuration
Getting Into Drupal 8 ConfigurationGetting Into Drupal 8 Configuration
Getting Into Drupal 8 Configuration
Philip Norton
 
20190118_NetadashiMeetup#8_React2019
20190118_NetadashiMeetup#8_React201920190118_NetadashiMeetup#8_React2019
20190118_NetadashiMeetup#8_React2019
Makoto Mori
 
Your Business. Your Language. Your Code - dpc13
Your Business. Your Language. Your Code - dpc13Your Business. Your Language. Your Code - dpc13
Your Business. Your Language. Your Code - dpc13Stephan Hochdörfer
 
Login and Registration form using oop in php
Login and Registration form using oop in phpLogin and Registration form using oop in php
Login and Registration form using oop in php
herat university
 
HTML5와 모바일
HTML5와 모바일HTML5와 모바일
HTML5와 모바일
ACCESS
 
Drupal 8 Services And Dependency Injection
Drupal 8 Services And Dependency InjectionDrupal 8 Services And Dependency Injection
Drupal 8 Services And Dependency Injection
Philip Norton
 
WordPress Security - WordCamp Boston 2010
WordPress Security - WordCamp Boston 2010WordPress Security - WordCamp Boston 2010
WordPress Security - WordCamp Boston 2010
Brad Williams
 
Drupal 8 Services
Drupal 8 ServicesDrupal 8 Services
Drupal 8 Services
Philip Norton
 
Bending word press to your will
Bending word press to your willBending word press to your will
Bending word press to your willTom Jenkins
 
Maven 3… so what?
Maven 3… so what?Maven 3… so what?
Maven 3… so what?
Abel Muíño
 
WordPress and Ajax
WordPress and AjaxWordPress and Ajax
WordPress and Ajax
Ronald Huereca
 
How to configure PyCharm for Odoo development in Windows?
How to configure PyCharm for Odoo development in Windows?How to configure PyCharm for Odoo development in Windows?
How to configure PyCharm for Odoo development in Windows?
Celine George
 
Firefox extension Development
Firefox extension DevelopmentFirefox extension Development
Firefox extension Development
Abhinav Chittora
 
Gail villanueva add muscle to your wordpress site
Gail villanueva   add muscle to your wordpress siteGail villanueva   add muscle to your wordpress site
Gail villanueva add muscle to your wordpress sitereferences
 
Best practices in WordPress Development
Best practices in WordPress DevelopmentBest practices in WordPress Development
Best practices in WordPress Development
Mindfire Solutions
 
Django app deployment in Azure By Saurabh Agarwal
Django app deployment in Azure By Saurabh AgarwalDjango app deployment in Azure By Saurabh Agarwal
Django app deployment in Azure By Saurabh Agarwal
ratneshsinghparihar
 
Flutter movie apps tutor
Flutter movie apps tutorFlutter movie apps tutor
Flutter movie apps tutor
Herry Prasetyo
 
Build website in_django
Build website in_django Build website in_django
Build website in_django swee meng ng
 

What's hot (20)

Php login system with admin features evolt
Php login system with admin features   evoltPhp login system with admin features   evolt
Php login system with admin features evolt
 
Getting Into Drupal 8 Configuration
Getting Into Drupal 8 ConfigurationGetting Into Drupal 8 Configuration
Getting Into Drupal 8 Configuration
 
20190118_NetadashiMeetup#8_React2019
20190118_NetadashiMeetup#8_React201920190118_NetadashiMeetup#8_React2019
20190118_NetadashiMeetup#8_React2019
 
Your Business. Your Language. Your Code - dpc13
Your Business. Your Language. Your Code - dpc13Your Business. Your Language. Your Code - dpc13
Your Business. Your Language. Your Code - dpc13
 
Login and Registration form using oop in php
Login and Registration form using oop in phpLogin and Registration form using oop in php
Login and Registration form using oop in php
 
HTML5와 모바일
HTML5와 모바일HTML5와 모바일
HTML5와 모바일
 
Drupal 8 Services And Dependency Injection
Drupal 8 Services And Dependency InjectionDrupal 8 Services And Dependency Injection
Drupal 8 Services And Dependency Injection
 
WordPress Security - WordCamp Boston 2010
WordPress Security - WordCamp Boston 2010WordPress Security - WordCamp Boston 2010
WordPress Security - WordCamp Boston 2010
 
Drupal 8 Services
Drupal 8 ServicesDrupal 8 Services
Drupal 8 Services
 
Bending word press to your will
Bending word press to your willBending word press to your will
Bending word press to your will
 
Maven 3… so what?
Maven 3… so what?Maven 3… so what?
Maven 3… so what?
 
WordPress and Ajax
WordPress and AjaxWordPress and Ajax
WordPress and Ajax
 
How to configure PyCharm for Odoo development in Windows?
How to configure PyCharm for Odoo development in Windows?How to configure PyCharm for Odoo development in Windows?
How to configure PyCharm for Odoo development in Windows?
 
Firefox extension Development
Firefox extension DevelopmentFirefox extension Development
Firefox extension Development
 
Gail villanueva add muscle to your wordpress site
Gail villanueva   add muscle to your wordpress siteGail villanueva   add muscle to your wordpress site
Gail villanueva add muscle to your wordpress site
 
Best practices in WordPress Development
Best practices in WordPress DevelopmentBest practices in WordPress Development
Best practices in WordPress Development
 
Creating a basic joomla
Creating a basic joomlaCreating a basic joomla
Creating a basic joomla
 
Django app deployment in Azure By Saurabh Agarwal
Django app deployment in Azure By Saurabh AgarwalDjango app deployment in Azure By Saurabh Agarwal
Django app deployment in Azure By Saurabh Agarwal
 
Flutter movie apps tutor
Flutter movie apps tutorFlutter movie apps tutor
Flutter movie apps tutor
 
Build website in_django
Build website in_django Build website in_django
Build website in_django
 

Similar to WordPress basic fundamental of plugin development and creating shortcode

Plug in development
Plug in developmentPlug in development
Plug in developmentLucky Ali
 
Write your first WordPress plugin
Write your first WordPress pluginWrite your first WordPress plugin
Write your first WordPress pluginAnthony Montalbano
 
Wordpress as a framework
Wordpress as a frameworkWordpress as a framework
Wordpress as a framework
Aggelos Synadakis
 
Intro to WordPress Plugin Development
Intro to WordPress Plugin DevelopmentIntro to WordPress Plugin Development
Intro to WordPress Plugin Development
Brad Williams
 
Getting started with WordPress development
Getting started with WordPress developmentGetting started with WordPress development
Getting started with WordPress development
Steve Mortiboy
 
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)
Damien Carbery
 
Creating Your First WordPress Plugin
Creating Your First WordPress PluginCreating Your First WordPress Plugin
Creating Your First WordPress Plugin
Brad Williams
 
Complete Wordpress Security By CHETAN SONI - Cyber Security Expert
Complete Wordpress Security By CHETAN SONI - Cyber Security ExpertComplete Wordpress Security By CHETAN SONI - Cyber Security Expert
Complete Wordpress Security By CHETAN SONI - Cyber Security Expert
Chetan Soni
 
Introduction to Mangento
Introduction to Mangento Introduction to Mangento
Introduction to Mangento
Ravi Mehrotra
 
Mangento
MangentoMangento
Mangento
Ravi Mehrotra
 
Creating Openbravo Workspace Widgets
Creating Openbravo Workspace WidgetsCreating Openbravo Workspace Widgets
Creating Openbravo Workspace Widgets
Rob Goris
 
Plugin development demystified 2017
Plugin development demystified 2017Plugin development demystified 2017
Plugin development demystified 2017
ylefebvre
 
Simple module Development in Joomla! 2.5
Simple module Development in Joomla! 2.5Simple module Development in Joomla! 2.5
Simple module Development in Joomla! 2.5
Vishwash Gaur
 
Working With The Symfony Admin Generator
Working With The Symfony Admin GeneratorWorking With The Symfony Admin Generator
Working With The Symfony Admin Generator
John Cleveley
 
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 pluginMainak Goswami
 
CodeIgniter PHP MVC Framework
CodeIgniter PHP MVC FrameworkCodeIgniter PHP MVC Framework
CodeIgniter PHP MVC Framework
Bo-Yi Wu
 
Behavior & Specification Driven Development in PHP - #OpenWest
Behavior & Specification Driven Development in PHP - #OpenWestBehavior & Specification Driven Development in PHP - #OpenWest
Behavior & Specification Driven Development in PHP - #OpenWestJoshua Warren
 
WordPress Developers Israel Meetup #1
WordPress Developers Israel Meetup #1WordPress Developers Israel Meetup #1
WordPress Developers Israel Meetup #1Yoav Farhi
 
WordPress Plugin Development- Rich Media Institute Workshop
WordPress Plugin Development- Rich Media Institute WorkshopWordPress Plugin Development- Rich Media Institute Workshop
WordPress Plugin Development- Rich Media Institute Workshop
Brendan Sera-Shriar
 
WordPress Plugins
WordPress PluginsWordPress Plugins
WordPress Pluginsrandyhoyt
 

Similar to WordPress basic fundamental of plugin development and creating shortcode (20)

Plug in development
Plug in developmentPlug in development
Plug in development
 
Write your first WordPress plugin
Write your first WordPress pluginWrite your first WordPress plugin
Write your first WordPress plugin
 
Wordpress as a framework
Wordpress as a frameworkWordpress as a framework
Wordpress as a framework
 
Intro to WordPress Plugin Development
Intro to WordPress Plugin DevelopmentIntro to WordPress Plugin Development
Intro to WordPress Plugin Development
 
Getting started with WordPress development
Getting started with WordPress developmentGetting started with WordPress development
Getting started with WordPress development
 
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)
 
Creating Your First WordPress Plugin
Creating Your First WordPress PluginCreating Your First WordPress Plugin
Creating Your First WordPress Plugin
 
Complete Wordpress Security By CHETAN SONI - Cyber Security Expert
Complete Wordpress Security By CHETAN SONI - Cyber Security ExpertComplete Wordpress Security By CHETAN SONI - Cyber Security Expert
Complete Wordpress Security By CHETAN SONI - Cyber Security Expert
 
Introduction to Mangento
Introduction to Mangento Introduction to Mangento
Introduction to Mangento
 
Mangento
MangentoMangento
Mangento
 
Creating Openbravo Workspace Widgets
Creating Openbravo Workspace WidgetsCreating Openbravo Workspace Widgets
Creating Openbravo Workspace Widgets
 
Plugin development demystified 2017
Plugin development demystified 2017Plugin development demystified 2017
Plugin development demystified 2017
 
Simple module Development in Joomla! 2.5
Simple module Development in Joomla! 2.5Simple module Development in Joomla! 2.5
Simple module Development in Joomla! 2.5
 
Working With The Symfony Admin Generator
Working With The Symfony Admin GeneratorWorking With The Symfony Admin Generator
Working With The Symfony Admin Generator
 
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
 
CodeIgniter PHP MVC Framework
CodeIgniter PHP MVC FrameworkCodeIgniter PHP MVC Framework
CodeIgniter PHP MVC Framework
 
Behavior & Specification Driven Development in PHP - #OpenWest
Behavior & Specification Driven Development in PHP - #OpenWestBehavior & Specification Driven Development in PHP - #OpenWest
Behavior & Specification Driven Development in PHP - #OpenWest
 
WordPress Developers Israel Meetup #1
WordPress Developers Israel Meetup #1WordPress Developers Israel Meetup #1
WordPress Developers Israel Meetup #1
 
WordPress Plugin Development- Rich Media Institute Workshop
WordPress Plugin Development- Rich Media Institute WorkshopWordPress Plugin Development- Rich Media Institute Workshop
WordPress Plugin Development- Rich Media Institute Workshop
 
WordPress Plugins
WordPress PluginsWordPress Plugins
WordPress Plugins
 

Recently uploaded

June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 

Recently uploaded (20)

June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 

WordPress basic fundamental of plugin development and creating shortcode

  • 1. © Copyright 2010 Nibiru Solutions Private Limited 1 Presented by: Rakesh
  • 2. 2© Copyright 2010 Nibiru Solutions Private Limited 2 Agenda Introduction How to create wordpress plugin How to create shortcode How to create theme option Quiz Questions
  • 3. 3© Copyright 2010 Nibiru Solutions Private Limited 3 Introduction This session is very important and its very interesting. In this session I cover some important worpress prebuild function And there uses Deep understanding of creating worpress plugin. Creating wordpress shortcode and uses. How to create theme options and uses
  • 4. 4© Copyright 2010 Nibiru Solutions Private Limited 4 How To Create Wordpress Plugin WordPress is not just a blogging platform and it is such a powerful CMS with unlimited capabilities, besides having a huge user base. Almost anything can be scripted with wordpress. You can extend wordpress either by means of plugin or by a theme. i will show you how to write a “Hello World” wordpress plugin, which unlike many believe is surprisingly easy, once you understand the very fundamentals.
  • 5. 5© Copyright 2010 Nibiru Solutions Private Limited 5 How To Create Wordpress Plugin -2 Plugin Files & Names 1. Always you chose a unique name to your plugin so that it doesnt collide with names used in other plugins. 2. Assigning unique names, documenting and organizing the plugin files is very important part of plugin creation. 3- place the plugin php file directly into the wp- content/plugins folder http://wordpress.org/plugins/about/readme.txt
  • 6. 6© Copyright 2010 Nibiru Solutions Private Limited 6 How To Create Wordpress Plugin -3 The Plugin Basics The heart of a wordpress plugins is the below 2 functions (commonly called `hooks`) add_action ($tag, $func) add_filter ($tag,$func) add_action –> does an action at various points of wordpress execution add_filter –> does filtering the data (eg. escaping quotes before mysql insert, or during output to browser.
  • 7. 7© Copyright 2010 Nibiru Solutions Private Limited 7 How To Create Wordpress Plugin -4 Plugin Information Open your hello-world.php and in the first line, add this commented plugin information to your file. <?php /* Plugin Name: Hello-World Plugin URI: http://yourdomain.com/ Description: A simple hello world wordpress plugin Version: 1.0 Author: Your Name Author URI: http://yourdomain.com License: GPL */ ?> Save file.
  • 8. 8© Copyright 2010 Nibiru Solutions Private Limited 8 How To Create Wordpress Plugin -5 Go to your wordpress admin > plugins and you will see the new plugin listed, waiting to get activated. But this plugin had to do something right? -> For that we write the code using add_action below the commented plugin information in the hello-world.php
  • 9. 9© Copyright 2010 Nibiru Solutions Private Limited 9 How To Create Wordpress Plugin -6 <?php /* This calls hello_world() function when wordpress initializes.*/ add_action('init','hello_world'); function hello_world() { echo "Hello World"; } ?> And Your Plugin done! When our plugin is activated, add_action command calls our hello_world() function when wordpress starts loading. To test Open Any index.php , page.php or single.php And place the following code. <?php if(function_exists('hello_world')) { hello_world(); } ?>
  • 10. 10© Copyright 2010 Nibiru Solutions Private Limited 10 Build a plugin options page in admin area : The plugin outputs hello world (its pretty much static). So make this to dynamic we need to create a good admin interface. Here is what we do…. We create a options menu for Hello World in WordPress Admin > Settings. We save the user entered data in the wordpress database. Using set_options() function. We retrieve the data stored in wordpress database and output it using get_options() function.
  • 11. 11© Copyright 2010 Nibiru Solutions Private Limited 11 Activating/Deactivating Plugin It is very easy to write a function on what plugin does, when it gets activated. WordPress offers 4 very important functions register_activation_hook -> Runs on plugin activation register_deactivation_hook -> Runs on plugin deactivation add_option -> Creates new database field get_option -> Retrieves the value in database field.
  • 12. 12© Copyright 2010 Nibiru Solutions Private Limited 12 Activating/Deactivating Plugin -2 Example : write fallowing code in hello-word.php <?php /* Runs when plugin is activated */ register_activation_hook(__FILE__,'hello_world_install'); /* Runs on plugin deactivation*/ register_deactivation_hook( __FILE__, 'hello_world_remove' ); function hello_world_install() { /* Creates new database field */ add_option("hello_world_data", 'Default', '', 'yes'); } function hello_world_remove() { /* Deletes the database field */ delete_option('hello_world_data'); } ?>
  • 13. 13© Copyright 2010 Nibiru Solutions Private Limited 13 Plugin Settings Page All we need to create is plugin settings page in the wordpress admin area. <?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'); } } ?> 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. This is how the code should flow! Refer to wordpress administration menus
  • 14. 14© Copyright 2010 Nibiru Solutions Private Limited 14 Plugin Settings Page – Coding Part -1 The below function has the html code for the settings page, containing the form <?php function hello_world_html_page() { ?> <div> <h2>Hello World Options</h2> <form method="post" action="options.php"> <?php wp_nonce_field('update-options'); ?> <table width="510"> <tr valign="top"> <th width="92" scope="row">Enter Text</th> <td width="406">
  • 15. 15© Copyright 2010 Nibiru Solutions Private Limited 15 Plugin Settings Page – Coding Part -2 <input name="hello_world_data" type="text" id="hello_world_data" value="<?php echo get_option('hello_world_data'); ?>" /> (ex. Hello World)</td> </tr> </table> <input type="hidden" name="action" value="update" /> <input type="hidden" name="page_options" value="hello_world_data" /> <p> <input type="submit" value="<?php _e('Save Changes') ?>" /> </p> </form> </div> <?php } ?>
  • 16. 16© Copyright 2010 Nibiru Solutions Private Limited 16 Plugin Settings Page – Coding Part -3 And finally your plugin ready and looks like following. You must remember 2 things in the above code. 1. Specify the database field we created before in the input text box as `hello_world_data`. <input name="hello_world_data" type="text" id="hello_world_data“ value="<?php echo get_option('hello_world_data'); ?>" /> 2. If your form has number of fields (like textbox, selectbox etc), all those should be listed in the value field of page_options, separated by commas. For more information, refer to wordpress documentation <input type="hidden" name="page_options" value="hello_world_data" />
  • 17. 17© Copyright 2010 Nibiru Solutions Private Limited 17 Wwordpres Shortcode The Shortcode API  Introduced in WordPress 2.5  A simple set of functions for creating macro codes for use in post content.  And a simple shortcode used like [shotcode]. Lets Create a shortcode of Hello Word plugin <?php function show_hello_text() { return get_option('hello_world_data'); } add_shortcode('showtext', 'show_hello_text'); ?> Use the shortcode [showtext] into page or post content to show your hello world text.
  • 18. 18© Copyright 2010 Nibiru Solutions Private Limited 18 How to create custom them option If you create your own themes you will, sooner or later, want to allow your theme users have some control over certain appearance and/or functional elements of your theme.
  • 19. 19© Copyright 2010 Nibiru Solutions Private Limited 19 How to create custom them option -2 This commonly use following functions. add_action( $tag, $function_to_add, $priority, $accepted_args ); register_setting( $option_group, $option_name, $sanitize_callback ) add_theme_page( $page_title, $menu_title, $capability, $menu_slug, $function ); settings_fields( $option_group ) ## coding section <? php add_action( 'admin_init', 'theme_options_init' ); add_action( 'admin_menu', 'theme_options_add_page' ); function theme_options_init(){ register_setting( 'sample_options', 'sample_theme_options'); } function theme_options_add_page() { add_theme_page( __( 'Theme Options', 'sampletheme' ), __( 'Theme Options', 'sampletheme' ), 'edit_theme_options', 'theme_options', 'theme_options_do_page' ); } 1- this used in setting_fields(); 2- this function name and its used html
  • 20. 20© Copyright 2010 Nibiru Solutions Private Limited 20 How to create custom them option -3 function theme_options_do_page() { global $select_options; <form method="post" action="options.php"> <?php settings_fields( 'sample_options' ); ?> <?php $options = get_option( 'sample_theme_options' ); ?> <input id="sample_theme_options[showintro]" name="sample_theme_options[showintro]" type="checkbox" value="1“ <?php checked( '1', $options['showintro'] ); ?> /> <input id="sample_theme_options[fburl]" type="text" name="sample_theme_options[fburl]" value="<?php esc_attr_e( $options['fburl'] ); ? >" /> <textarea id="sample_theme_options[introtext]" class="large-text" cols="50" rows="10" name="sample_theme_options[introtext]"><?php echo esc_textarea( $options['introtext'] ); ?></textarea> <input type="submit" value="<?php _e( 'Save Options', 'customtheme' ); ?>" /> </form> } ?> 1 2
  • 21. 21© Copyright 2010 Nibiru Solutions Private Limited 21 The End Of Then Session Thank You !