16
Creating Wordpress Plugins

Creating Wordpress Plugins. Who is Here? PHP GTA Meetup Wordpress Toronto Meetup East Toronto Web Design Meetup

  • View
    213

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Creating Wordpress Plugins. Who is Here? PHP GTA Meetup Wordpress Toronto Meetup East Toronto Web Design Meetup

Creating Wordpress Plugins

Page 2: Creating Wordpress Plugins. Who is Here? PHP GTA Meetup Wordpress Toronto Meetup East Toronto Web Design Meetup

Who is Here?

• PHP GTA Meetup

• Wordpress Toronto Meetup

• East Toronto Web Design Meetup

Page 3: Creating Wordpress Plugins. Who is Here? PHP GTA Meetup Wordpress Toronto Meetup East Toronto Web Design Meetup

About Me – Peter Meth

• Degree in Computer Science

• Full time web application developer

• Also do websites, hosting, consulting

• PHP, MySQL, HTML, CSS, Javascript

• Wordpress, Joomla

Page 4: Creating Wordpress Plugins. Who is Here? PHP GTA Meetup Wordpress Toronto Meetup East Toronto Web Design Meetup

What is Wordpress?

• Most popular Blogging System in the World

• Most popular Content Management System in the World

• Used by 13% of the world's top million websites

• It’s free and Open Source

Page 5: Creating Wordpress Plugins. Who is Here? PHP GTA Meetup Wordpress Toronto Meetup East Toronto Web Design Meetup

What is a Plugin?

• Add functionality without changing core files

• Use Wordpress API to interact with Wordpress

• Not overwritten when Wordpress gets updated

• 13,000+ Free Plugins on Wordpress.org

• Commercial Plugins also available

Page 6: Creating Wordpress Plugins. Who is Here? PHP GTA Meetup Wordpress Toronto Meetup East Toronto Web Design Meetup

Why Create Plugins for Wordpress?

• Add functionality for existing Wordpress users

• Take advantage of Wordpress security, stability, infrastructure, templates

• Exposure to a huge userbase

• You may have your own reasons

Page 7: Creating Wordpress Plugins. Who is Here? PHP GTA Meetup Wordpress Toronto Meetup East Toronto Web Design Meetup

Naming & File Structure

• Give your plugin a unique name

• Create a main php file

• You can create your own directory structure

• gets installed in plugins directory:– {pathtowordpress}/wp-content/plugins/

Page 8: Creating Wordpress Plugins. Who is Here? PHP GTA Meetup Wordpress Toronto Meetup East Toronto Web Design Meetup

Standard Header

<?php

/*

Plugin Name: Name Of The Plugin

Description: A brief description of the Plugin.

..

..

*/

?>

Page 9: Creating Wordpress Plugins. Who is Here? PHP GTA Meetup Wordpress Toronto Meetup East Toronto Web Design Meetup

Activating Your Plugin

• Copy all files to – {pathtowordpress}/wp-content/plugins/

• Load the wordpress adminhttp://www.yoursite.com/wordpress/wp-admin

• go to the Plugins menu, click Activate

• Let’s have a look...

Page 10: Creating Wordpress Plugins. Who is Here? PHP GTA Meetup Wordpress Toronto Meetup East Toronto Web Design Meetup

Filters

• Filters change text as it gets written or processed

• add_filter('hook_name','myfilter')

function myfilter($content) {

...

return $content;

}

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

• Let’s have a look...

Page 11: Creating Wordpress Plugins. Who is Here? PHP GTA Meetup Wordpress Toronto Meetup East Toronto Web Design Meetup

Actions

• Actions are the steps that Wordpress takes to create a page

• add_action('hook_name','myaction')

function myaction() {

...

}

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

Page 12: Creating Wordpress Plugins. Who is Here? PHP GTA Meetup Wordpress Toronto Meetup East Toronto Web Design Meetup

Creating a Menu

• Create a new function

• call add_menu_page(..) within it

• add your function to the admin_menu actionadd_action('admin_menu','mymenu');

• use if(is_admin()) for safety

• Let’s have a look...

Page 13: Creating Wordpress Plugins. Who is Here? PHP GTA Meetup Wordpress Toronto Meetup East Toronto Web Design Meetup

Creating a Settings Page

• Create a function that outputs a form• In the form set action=“options.php”

• call settings_fields(..) inside your form• register your fields register_setting(..)

• use get_option(..) to retrieve values

• Let’s have a look...

Page 14: Creating Wordpress Plugins. Who is Here? PHP GTA Meetup Wordpress Toronto Meetup East Toronto Web Design Meetup

Other Ways to Manage Data

• Create your own tables and forms

• Use Wordpress built in Options mechanism

• Use Custom Fields mechanism to add fields to Posts

• Beyond Scope of this presentation

Page 15: Creating Wordpress Plugins. Who is Here? PHP GTA Meetup Wordpress Toronto Meetup East Toronto Web Design Meetup

Want More Information?

• http://wordpress.org/extend/plugins

• http://codex.wordpress.org

• http://www.lynda.com – (paid videos)

• http://www.wpplugins.com – (commercial plugins)

• B2Template plugin by Dan Imbrogno

Page 16: Creating Wordpress Plugins. Who is Here? PHP GTA Meetup Wordpress Toronto Meetup East Toronto Web Design Meetup

Questions & Answers