using actions and filters in wordpress to make a plugin your own

Post on 16-Feb-2017

601 Views

Category:

Technology

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Making a Plugin Your OwnUsing Actions and Filters in WordPress

Brian Hoggbrianhogg.com | @brianhogg

WordCamp Toronto 2015

brianhogg.com

Subtitle

wpontheside.com

Subtitle

Actions and Filters

Actions

do_action( $identifier, [ $arg1, $arg2, ... ] )

add_action( $identifier, $function_name, [ $priority, $arg_count ] )

Actions (Example)do_action( 'the_plugin_action' );

function handle_the_plugin_action() {echo 'The action is happening now!';

}

add_action( 'the_plugin_action', 'handle_the_plugin_action' );

Filters

apply_filters( $identifier, $value, [ $arg1, $arg2, ... ] )

add_filter( $identifier, $function_name, [ $priority, $arg_count ] )

Filters (Example)

echo apply_filters( 'plugin_title', 'Title' );

function change_plugin_title( $title ) {return 'New Title';

}

add_filter( 'plugin_title', 'change_plugin_title' );

Filters (Example)

echo apply_filters( 'plugin_title', 'Title' );

function change_plugin_title( $title ) {return 'New ' . $title;

}

add_filter( 'plugin_title', 'change_plugin_title' );

How do you find what you can change in a plugin?

Search for do_action and apply_filters

The Events Calendar Plugin

•apply_filters•442 occurrences

•do_action•190 occurrences

How to Find The One You Need?▪ Look at the plugin documentation (if any)▪ Look at the code▪ Look at the HTML output and backtrack

DEMO

The Events Calendar▪ Message to verify location▪ Venue -> Location▪ Cost formatting

Can’t find the one you need?▪ (Nicely) ask the developer of the plugin

▪ Direct contact information / website▪ wordpress.org support forums

▪ Look for a paid support or Pro version

▪ Submit a patch

Go make plugins your own!

top related