my first wordpress plugin

Post on 13-Apr-2017

151 Views

Category:

Software

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

My firstWordPress Plugin

PresentationRoadmap

1. WordPress Introduction

2. Development Paths

3. Plugin Development

Q/A Session

1.WordPress Introduction

What is WordPress?

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.

Websites built on WordPress

Personal Websites

Online Magazines

Company Websites

e-commerce Sites

Custom Applications

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

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/

WordPress Core

Built-in Features

ThemesVisual Design &

Components

PluginsAdditional Features

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

2.Development Options

What options do we have as

a WP Developer?

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:

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

3.Plugin Development

Let’s develop our

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

WordPress directory structure

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

How plugins actually work?

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

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.

Common Hooks

Actionsinittemplate_redirectadmin_initafter_setup_themewp_loadedwp_headwp_footeradmin_menu

Filtersthe_contentthe_titlewp_titletemplate_includebody_classpost_class

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

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

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

Add Action

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

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

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

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

THANKS!

Any questions?You can find me at @abbas_siddiqi andabbas.siddiqi1@gmail.com

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/

top related