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 (20)

PDF
Php login system with admin features evolt
GIMT
 
PDF
Getting Into Drupal 8 Configuration
Philip Norton
 
PDF
20190118_NetadashiMeetup#8_React2019
Makoto Mori
 
PDF
Your Business. Your Language. Your Code - dpc13
Stephan Hochdörfer
 
PDF
Login and Registration form using oop in php
herat university
 
KEY
HTML5와 모바일
ACCESS
 
PDF
Drupal 8 Services And Dependency Injection
Philip Norton
 
PPT
WordPress Security - WordCamp Boston 2010
Brad Williams
 
PDF
Drupal 8 Services
Philip Norton
 
PDF
Bending word press to your will
Tom Jenkins
 
PDF
Maven 3… so what?
Abel Muíño
 
PPT
WordPress and Ajax
Ronald Huereca
 
PPTX
How to configure PyCharm for Odoo development in Windows?
Celine George
 
PDF
Firefox extension Development
Abhinav Chittora
 
PDF
Gail villanueva add muscle to your wordpress site
references
 
ODP
Best practices in WordPress Development
Mindfire Solutions
 
DOCX
Creating a basic joomla
shailendra vishwakarma
 
PPTX
Django app deployment in Azure By Saurabh Agarwal
ratneshsinghparihar
 
PDF
Flutter movie apps tutor
Herry Prasetyo
 
PDF
Build website in_django
swee meng ng
 
Php login system with admin features evolt
GIMT
 
Getting Into Drupal 8 Configuration
Philip Norton
 
20190118_NetadashiMeetup#8_React2019
Makoto Mori
 
Your Business. Your Language. Your Code - dpc13
Stephan Hochdörfer
 
Login and Registration form using oop in php
herat university
 
HTML5와 모바일
ACCESS
 
Drupal 8 Services And Dependency Injection
Philip Norton
 
WordPress Security - WordCamp Boston 2010
Brad Williams
 
Drupal 8 Services
Philip Norton
 
Bending word press to your will
Tom Jenkins
 
Maven 3… so what?
Abel Muíño
 
WordPress and Ajax
Ronald Huereca
 
How to configure PyCharm for Odoo development in Windows?
Celine George
 
Firefox extension Development
Abhinav Chittora
 
Gail villanueva add muscle to your wordpress site
references
 
Best practices in WordPress Development
Mindfire Solutions
 
Creating a basic joomla
shailendra vishwakarma
 
Django app deployment in Azure By Saurabh Agarwal
ratneshsinghparihar
 
Flutter movie apps tutor
Herry Prasetyo
 
Build website in_django
swee meng ng
 

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

PPTX
Plug in development
Lucky Ali
 
KEY
Intro to WordPress Plugins
zamoose
 
PPT
WordPress plugins
Christopher Ross
 
PDF
Wordpress Plugin Development Short Tutorial
Christos Zigkolis
 
PDF
Write your first WordPress plugin
Anthony Montalbano
 
PPSX
Extending WordPress
Jonathan Bossenger
 
PDF
Laying the proper foundation for plugin and theme development
Tammy Hart
 
PPT
WordPress Plugin Basics
Amanda Giles
 
PDF
How to Create a Custom WordPress Plugin
Andolasoft Inc
 
PDF
Wordpress as a framework
Aggelos Synadakis
 
PDF
My first WordPress Plugin
Abbas Siddiqi
 
PPT
Word press Plugins by WordPress Experts
Yameen Khan
 
PDF
Write Your First WordPress Plugin
Ibrahim Abdel Fattah Mohamed
 
PDF
Extending WordPress - a guide to building your first plugin
Jonathan Bossenger
 
PPTX
WordPress plugin development
arryaas
 
PPT
Introduction to Wordpress
Reuben Rock
 
PPTX
How to create your own WordPress plugin
John Tighe
 
PPT
WordPress Plugins
OpenSource Technologies Pvt. Ltd.
 
PDF
Using Wordpress with Reclaim Hosting
Cindy Royal
 
PPTX
Creating Customizable Widgets for Unpredictable Needs
Amanda Giles
 
Plug in development
Lucky Ali
 
Intro to WordPress Plugins
zamoose
 
WordPress plugins
Christopher Ross
 
Wordpress Plugin Development Short Tutorial
Christos Zigkolis
 
Write your first WordPress plugin
Anthony Montalbano
 
Extending WordPress
Jonathan Bossenger
 
Laying the proper foundation for plugin and theme development
Tammy Hart
 
WordPress Plugin Basics
Amanda Giles
 
How to Create a Custom WordPress Plugin
Andolasoft Inc
 
Wordpress as a framework
Aggelos Synadakis
 
My first WordPress Plugin
Abbas Siddiqi
 
Word press Plugins by WordPress Experts
Yameen Khan
 
Write Your First WordPress Plugin
Ibrahim Abdel Fattah Mohamed
 
Extending WordPress - a guide to building your first plugin
Jonathan Bossenger
 
WordPress plugin development
arryaas
 
Introduction to Wordpress
Reuben Rock
 
How to create your own WordPress plugin
John Tighe
 
Using Wordpress with Reclaim Hosting
Cindy Royal
 
Creating Customizable Widgets for Unpredictable Needs
Amanda Giles
 
Ad

Recently uploaded (20)

PDF
IMP NAAC-Reforms-Stakeholder-Consultation-Presentation-on-Draft-Metrics-Unive...
BHARTIWADEKAR
 
PPTX
Latest Features in Odoo 18 - Odoo slides
Celine George
 
PPTX
Gall bladder, Small intestine and Large intestine.pptx
rekhapositivity
 
PPTX
How to Configure Prepayments in Odoo 18 Sales
Celine George
 
PPTX
HYDROCEPHALUS: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
PPTX
SCHOOL-BASED SEXUAL HARASSMENT PREVENTION AND RESPONSE WORKSHOP
komlalokoe
 
PPTX
Pyhton with Mysql to perform CRUD operations.pptx
Ramakrishna Reddy Bijjam
 
PDF
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
PPTX
Nutri-QUIZ-Bee-Elementary.pptx...................
ferdinandsanbuenaven
 
PPTX
Optimizing Cancer Screening With MCED Technologies: From Science to Practical...
i3 Health
 
PPTX
How to Configure Access Rights of Manufacturing Orders in Odoo 18 Manufacturing
Celine George
 
PDF
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
PPTX
Accounting Skills Paper-I, Preparation of Vouchers
Dr. Sushil Bansode
 
PPTX
Optimizing Cancer Screening With MCED Technologies: From Science to Practical...
i3 Health
 
PPTX
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
PPTX
CONVULSIVE DISORDERS: NURSING MANAGEMENT.pptx
PRADEEP ABOTHU
 
PPT
digestive system for Pharm d I year HAP
rekhapositivity
 
PPTX
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
PPTX
How to Manage Access Rights & User Types in Odoo 18
Celine George
 
PDF
BÀI TẬP BỔ TRỢ THEO LESSON TIẾNG ANH - I-LEARN SMART WORLD 7 - CẢ NĂM - CÓ ĐÁ...
Nguyen Thanh Tu Collection
 
IMP NAAC-Reforms-Stakeholder-Consultation-Presentation-on-Draft-Metrics-Unive...
BHARTIWADEKAR
 
Latest Features in Odoo 18 - Odoo slides
Celine George
 
Gall bladder, Small intestine and Large intestine.pptx
rekhapositivity
 
How to Configure Prepayments in Odoo 18 Sales
Celine George
 
HYDROCEPHALUS: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
SCHOOL-BASED SEXUAL HARASSMENT PREVENTION AND RESPONSE WORKSHOP
komlalokoe
 
Pyhton with Mysql to perform CRUD operations.pptx
Ramakrishna Reddy Bijjam
 
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
Nutri-QUIZ-Bee-Elementary.pptx...................
ferdinandsanbuenaven
 
Optimizing Cancer Screening With MCED Technologies: From Science to Practical...
i3 Health
 
How to Configure Access Rights of Manufacturing Orders in Odoo 18 Manufacturing
Celine George
 
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
Accounting Skills Paper-I, Preparation of Vouchers
Dr. Sushil Bansode
 
Optimizing Cancer Screening With MCED Technologies: From Science to Practical...
i3 Health
 
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
CONVULSIVE DISORDERS: NURSING MANAGEMENT.pptx
PRADEEP ABOTHU
 
digestive system for Pharm d I year HAP
rekhapositivity
 
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
How to Manage Access Rights & User Types in Odoo 18
Celine George
 
BÀI TẬP BỔ TRỢ THEO LESSON TIẾNG ANH - I-LEARN SMART WORLD 7 - CẢ NĂM - CÓ ĐÁ...
Nguyen Thanh Tu Collection
 
Ad

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 !