word press plugin development by nyros developer

40
WordPress Plugin Development Presented By Thirupathi.J

Upload: nyros-technologies

Post on 06-May-2015

2.296 views

Category:

Documents


2 download

DESCRIPTION

Word Press Plugin Development

TRANSCRIPT

Page 1: Word Press Plugin Development By Nyros Developer

WordPress Plugin Development

Presented ByThirupathi.J

Page 2: Word Press Plugin Development By Nyros Developer

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?

Page 3: Word Press Plugin Development By Nyros Developer

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.

Page 4: Word Press Plugin Development By Nyros Developer

How to install WordPress?

Download the wordpress latest version from:

http://wordpress.org/download/

Page 5: Word Press Plugin Development By Nyros Developer

What is a WordPress plugin?

Little applications used to enhance functionality or add specific functions tailored to a site's specific needs.

Page 6: Word Press Plugin Development By Nyros Developer

Some plugins:

Capitalize Titles of Pages and Posts WordPress Database Backup WordPress.com StatsComment Hilite

Page 7: Word Press Plugin Development By Nyros Developer

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.)

Page 8: Word Press Plugin Development By Nyros Developer

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

Page 9: Word Press Plugin Development By Nyros Developer

Plugin API

- Enabled "hooks"

- Extend functionality withoutediting the core code

- Two categories:Actions and Filters

Page 10: Word Press Plugin Development By Nyros Developer

2 Kinds of WordPress Hooks

Actions = “Do Something”

Filters = “Transform”

Page 11: Word Press Plugin Development By Nyros Developer

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] );

Page 12: Word Press Plugin Development By Nyros Developer

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]);

Page 13: Word Press Plugin Development By Nyros Developer

Writing Your First Plugin

Page 14: Word Press Plugin Development By Nyros Developer

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...

Page 15: Word Press Plugin Development By Nyros Developer

screenshot-1.png

•Useful only for publishing to•WordPress Plugin Directory

Page 16: Word Press Plugin Development By Nyros Developer

my-plugin.php

4 parts to a pluginPlugin HeaderHooksPHP CodeTemplate Code

Page 17: Word Press Plugin Development By Nyros Developer

File Structure

Page 18: Word Press Plugin Development By Nyros Developer

Plugin Headers

http://codex.wordpress.org/Writing_a_Plugin#Standard_Plugin_Information

Page 19: Word Press Plugin Development By Nyros Developer

Plugin Headers

http://codex.wordpress.org/Writing_a_Plugin#Standard_Plugin_Information

Always on top, no choice

Fill in with your own details

Page 20: Word Press Plugin Development By Nyros Developer

Hooks (Filters)

Page 21: Word Press Plugin Development By Nyros Developer

Hooks (Filters)

After plugin headers (my preferance)

Makes it easier to find

Page 22: Word Press Plugin Development By Nyros Developer

PHP Code

Page 23: Word Press Plugin Development By Nyros Developer

Plugin 1

Figure out what you want to do.

I want to convert all instances of “WordPress” to “WORDPRESS”in a post's content.

Page 24: Word Press Plugin Development By Nyros Developer

the_content (filter)

http://codex.wordpress.org/Plugin_API/Filter_Reference/the_content

Page 25: Word Press Plugin Development By Nyros Developer

add_filter

http://codex.wordpress.org/Plugin_API/Filter_Reference/the_content

Page 26: Word Press Plugin Development By Nyros Developer

add_filter

http://codex.wordpress.org/Plugin_API#Hook_to_WordPress

① Hook Name

② Callback

Page 27: Word Press Plugin Development By Nyros Developer

Hook Callback

Determines what PHP function to call

Callback can be either:String; orArray of 2 strings (my preference)

Page 28: Word Press Plugin Development By Nyros Developer

Hook Callback

StringCalls a function

Array of 2 stringsCalls a static function in a class

Page 29: Word Press Plugin Development By Nyros Developer

They do the same thing

Page 30: Word Press Plugin Development By Nyros Developer

I Prefer Array Callbacks

Allows me to segment my code

Lower chances of name conflicts

Easily tell which function belongs to which hook

Page 31: Word Press Plugin Development By Nyros Developer

Filters are Transformations

filters have to return a transformation

Page 32: Word Press Plugin Development By Nyros Developer

Filter return Values

A filters return value, is the result of the transformation

②① return

② transformation

http://php.net/manual/en/function.preg-replace.php

Page 33: Word Press Plugin Development By Nyros Developer
Page 34: Word Press Plugin Development By Nyros Developer

Plugin 2

Figure out what you want to do.

I want to BOLD all instances of “WORDPRESS”

in a post's content.

Page 35: Word Press Plugin Development By Nyros Developer

Hook Priority

http://codex.wordpress.org/Plugin_API#Hook_to_WordPress

Page 36: Word Press Plugin Development By Nyros Developer

Priority

② Callback

① ③②②

③ Priority (optional)

① Hook Name

http://codex.wordpress.org/Plugin_API#Hook_to_WordPress

Page 37: Word Press Plugin Development By Nyros Developer

Which one goes first?

WordPress2WORDPRESS#the_content

ABolderWordPress#the_content

Page 38: Word Press Plugin Development By Nyros Developer

Default Priority

10smaller numbers = higher prioritylarger numbers = lower priority

http://codex.wordpress.org/Plugin_API#Hook_to_WordPress

Page 39: Word Press Plugin Development By Nyros Developer

Therefore

Order of execution:

(10) WordPress2WORDPRESS#the_content(20) ABolderWordPress#the_content

Page 40: Word Press Plugin Development By Nyros Developer

THANK YOU