my first wordpress plugin

32
My first WordPress Plugin

Upload: abbas-siddiqi

Post on 13-Apr-2017

151 views

Category:

Software


0 download

TRANSCRIPT

Page 1: My first WordPress Plugin

My firstWordPress Plugin

Page 2: My first WordPress Plugin

PresentationRoadmap

1. WordPress Introduction

2. Development Paths

3. Plugin Development

Q/A Session

Page 3: My first WordPress Plugin

1.WordPress Introduction

What is WordPress?

Page 4: My first WordPress Plugin

Evolution of WordPress Platform

▸ WordPress as a Blogging Platform

▸ WordPress as a CMS

▸ WordPress as a Application Platform

And it is continuously evolving each year with new releases.

Page 5: My first WordPress Plugin

Websites built on WordPress

Personal Websites

Online Magazines

Company Websites

e-commerce Sites

Custom Applications

Page 6: My first WordPress Plugin
Page 7: My first WordPress Plugin
Page 8: My first WordPress Plugin
Page 9: My first WordPress Plugin

It's probably the easiest and most powerful blogging and website content management system (or CMS) in existence today.

Page 10: My first WordPress Plugin

Install & Run WordPress

▸ Setup a local Server on your machine▸ WAMP: http://www.wampserver.com/en/▸ XAMPP: https://www.apachefriends.org/index.html

▸ Download WordPress▸ https://wordpress.org/download/

▸ Follow this basic tutorialhttp://www.wpbeginner.com/wp-tutorials/how-to-install-wordpress-on-your-windows-computer-using-wamp/

Page 11: My first WordPress Plugin
Page 12: My first WordPress Plugin
Page 13: My first WordPress Plugin

WordPress Core

Built-in Features

ThemesVisual Design &

Components

PluginsAdditional Features

Themes: https://wordpress.org/themesPlugins: https://wordpress.org/plugins

Page 14: My first WordPress Plugin

2.Development Options

What options do we have as

a WP Developer?

Page 15: My first WordPress Plugin

Existing Themes1. Themeforesthttp://themeforest.net

2. WordPress.orghttps://wordpress.org/themes

As a non-programmer

Existing Plugins1. WordPress.orghttps://wordpress.org/plugins

2. Codecanyonhttp://codecanyon.net

If you don’t have programming knowledge, you can still create stunning websites using:

Page 16: My first WordPress Plugin

As a programmer

If you have basic/good knowledge of PHP, HTML, CSS and JavaScript. You can:

Create new themes Create new plugins

Modify existing themes Modify existing plugins

Page 17: My first WordPress Plugin

3.Plugin Development

Let’s develop our

first WP Plugin.

Page 18: My first WordPress Plugin

What are Plugins?

Plugins are tools to extend the functionality of WordPress.

Essentially, they are just a collection of functions that can be activated and deactivated together.

Page 19: My first WordPress Plugin

WordPress directory structure

Page 20: My first WordPress Plugin

Let’s create a very basic plugin

At its simplest, a WordPress plugin is a PHP file with a plugin header comment.

Create a new file /wp-content/plugins/hello-world.php

<?php/** Plugin Name: Hello World Basic*/

https://developer.wordpress.org/plugins/the-basics/header-requirements

Page 21: My first WordPress Plugin

How plugins actually work?

By using Hooks, you can tap into WordPress at specific points. (without editing core files)

Page 22: My first WordPress Plugin

WordPress Hooks

Hooks are triggered while WordPress run.They are of two types:

ActionsActions allow you to add or changeWordPress functionality

FiltersFilters allow you to filter or change the content as it is loaded.

Page 23: My first WordPress Plugin

Common Hooks

Actionsinittemplate_redirectadmin_initafter_setup_themewp_loadedwp_headwp_footeradmin_menu

Filtersthe_contentthe_titlewp_titletemplate_includebody_classpost_class

Page 24: My first WordPress Plugin

How hooks are fired?

To fire an Action

It will run all the functions hooked to this action

To fire a Filter:

▸ The $filter_value will be the firstargument of each hooked function

▸ apply_filters will return the filtered input

do_action( 'action_name' );

$filter_value = apply_filters( 'filter_name', $filter_value);

Page 25: My first WordPress Plugin

Responding to Hooks

Attach an Action

Attach a Filter:

add_action( 'action_name', 'func_name' );

add_filter( 'filter_name', 'function_name' );

Note!Both take two optional arguments: Priority and Accepted Arguments

Page 26: My first WordPress Plugin

We can hook our plugin functions to the core via Actions and Filters.

Page 27: My first WordPress Plugin

Add Action

add_action ( 'action_name', ’callback_function_name’,$priority = 10, $accepted_args = 1 )

Page 28: My first WordPress Plugin

What is priority?

Actions and filters are executed in the order they are added.

So this code will echo:

function first() {return ”First\n”;

}

function second() {return ”Second\n”;

}

function third() {return ”Third\n”;

}

add_action(‘demo’,’first’);add_action(‘demo’,’second’);add_action(‘demo’,’third’);

do_action(‘demo’);

FirstSecondThird

Page 29: My first WordPress Plugin

What is priority? (con..)

Priority changes this order.

Actions and filters have a default priority of 10.Using a lower number gives it higher priority.

Now this code will echo:

function first() {return ”First\n”;

}

function second() {return ”Second\n”;

}

function third() {return ”Third\n”;

}

add_action(‘demo’,’first’);add_action(‘demo’,’second’);add_action(‘demo’,’third’,9);

do_action(‘demo’);

ThirdFirstSecond

Page 30: My first WordPress Plugin

Useful Resources (+Free)

▸ If you are WordPress beginner, watch these videosYoutube - Wordpress Basics - For Beginners

▸ If you are new to programming, learn PHP in just 4 hours at Code AcademyLearn to program in PHP

▸ If you want to learn WordPress Plugin Development through videosYoutube - How to build a WordPress Plugin

▸ The best resource for WP Plugin DevelopmentWordPress official guide on Plugin Development

Page 31: My first WordPress Plugin

THANKS!

Any questions?You can find me at @abbas_siddiqi [email protected]

Page 32: My first WordPress Plugin

CREDITS

Special thanks to all the people who made and released these awesome resources for free:▸ Presentation template by http://www.slidescarnival.com▸ Content Slides http://www.slideshare.net/johntighe/how-

to-create-your-own-wordpress-plugin▸ Content Slides

http://www.slideshare.net/ylefebvre/workshop-creating-

your-first-wordpress-plugin▸ WordPress official documentation

https://developer.wordpress.org/plugins/intro/