word press plugin development by nyros developer
DESCRIPTION
Word Press Plugin DevelopmentTRANSCRIPT
WordPress Plugin Development
Presented ByThirupathi.J
Concepts
What is wordpress?
How to install wordpress?
What is wordpress plugin?
What do you need to make a wordpress plugin?
Plugin Structure?
Plugin API?
What is WordPress?
WordPress is an open source blog publishing application powered by PHP and MySQL which can also be used for content management. It has many features including a workflow, a plugin architecture and a templating system.
How to install WordPress?
Download the wordpress latest version from:
http://wordpress.org/download/
What is a WordPress plugin?
Little applications used to enhance functionality or add specific functions tailored to a site's specific needs.
Some plugins:
Capitalize Titles of Pages and Posts WordPress Database Backup WordPress.com StatsComment Hilite
What do you need to make a plugin?
a problem to solvesome PHP knowledge
some spare timea test server with your test wordpress (XAMPP is good.)
Plugin Directory Structure
Your Plugin:/wp-content/plugins/my-plugin
Inside “my-plugin”readme.txtscreenshot-1.pngmy-plugin.php
Always put it in a directory!
Uses 'dashes' and not 'underscores'http://codex.wordpress.org/Writing_a_Plugin#Names.2C_Files.2C_and_Locations
Plugin API
- Enabled "hooks"
- Extend functionality withoutediting the core code
- Two categories:Actions and Filters
2 Kinds of WordPress Hooks
Actions = “Do Something”
Filters = “Transform”
ActionsActions 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.
add_action( 'hook_name', 'your_function_name', [priority], [accepted_args] );
Filters
Functions that modify text, lists andvarious types of information that areused and produced by WordPress.
add_filter('hook_name', 'your_filter_function', [priority], [accepted_args]);
Writing Your First Plugin
readme.txt
• http://codex.wordpress.org/Writing_a_Plugin#Readme_File
• http://wordpress.org/extend/plugins/about/readme.txt
Useful only for publishing toWordPress Plugin Directory
Information about your plugin:Description, Installation, Changelog, Donation
Links, Tags, etc...
screenshot-1.png
•Useful only for publishing to•WordPress Plugin Directory
my-plugin.php
4 parts to a pluginPlugin HeaderHooksPHP CodeTemplate Code
File Structure
Plugin Headers
http://codex.wordpress.org/Writing_a_Plugin#Standard_Plugin_Information
Plugin Headers
http://codex.wordpress.org/Writing_a_Plugin#Standard_Plugin_Information
Always on top, no choice
Fill in with your own details
Hooks (Filters)
Hooks (Filters)
After plugin headers (my preferance)
Makes it easier to find
PHP Code
Plugin 1
Figure out what you want to do.
I want to convert all instances of “WordPress” to “WORDPRESS”in a post's content.
the_content (filter)
http://codex.wordpress.org/Plugin_API/Filter_Reference/the_content
add_filter
http://codex.wordpress.org/Plugin_API/Filter_Reference/the_content
add_filter
http://codex.wordpress.org/Plugin_API#Hook_to_WordPress
②
① Hook Name
② Callback
①
Hook Callback
Determines what PHP function to call
Callback can be either:String; orArray of 2 strings (my preference)
Hook Callback
StringCalls a function
Array of 2 stringsCalls a static function in a class
They do the same thing
I Prefer Array Callbacks
Allows me to segment my code
Lower chances of name conflicts
Easily tell which function belongs to which hook
Filters are Transformations
filters have to return a transformation
Filter return Values
A filters return value, is the result of the transformation
②① return
② transformation
①
http://php.net/manual/en/function.preg-replace.php
Plugin 2
Figure out what you want to do.
I want to BOLD all instances of “WORDPRESS”
in a post's content.
Hook Priority
http://codex.wordpress.org/Plugin_API#Hook_to_WordPress
Priority
②
② Callback
① ③②②
③ Priority (optional)
① Hook Name
http://codex.wordpress.org/Plugin_API#Hook_to_WordPress
Which one goes first?
WordPress2WORDPRESS#the_content
ABolderWordPress#the_content
Default Priority
10smaller numbers = higher prioritylarger numbers = lower priority
http://codex.wordpress.org/Plugin_API#Hook_to_WordPress
Therefore
Order of execution:
(10) WordPress2WORDPRESS#the_content(20) ABolderWordPress#the_content
THANK YOU