This is a workshop that I presented at PHP South Africa 2017 - these slides were just the intro and the rest of the workshop was building a basic WordPress plugin.
Bending WordPressTo Your Will
View Slide
Folder StructureHeadersEventsPlugin Development
wp-content/plugins/plugin-slugplugin-slug.phpreadme.txtFolder Structure
Headers/** Plugin Name: Seriously Simple Podcasting* Version: 1.9.6* Plugin URI: https://wordpress.org/plugins/seriously-simple-podcasting/* Description: Podcasting the way it's meant to be.* Author: Hugh Lashbrooke* Author URI: http://www.hughlashbrooke.com/* Requires at least: 4.0* Tested up to: 4.2** Text Domain: seriously-simple-podcasting* Domain Path: /lang/*/
PHPcall_user_func()WordPressdo_action()apply_filters()Events
do_action( ‘hook’ );add_action( ‘hook’, ‘my_function’ );Events: Hooks
add_action( ‘init’, ‘init_function’ );function init_function() {...}Events: Hooks
add_action( ‘hook’, ‘my_function’, 10 );Lower number == higher priorityEvents: Priorities
add_action( ‘hook’, ‘my_function’, 10, 2 );function my_function ( $foo, $bar ) {...}Events: Parameters
apply_filters( ‘filter’, $foo );add_filter( ‘filter’, ‘my_function’ );Filters must always return a valueEvents: Filters
add_filter( ‘body_class’, ‘my_function’ );function my_function( $classes ) {$classes[] = ‘my-class’;return $classes;}Events: Filters
remove_action( ‘hook’, ‘function’ );remove_filter( ‘filter’, ‘function’ );Priorities must match original hook/filterRemoving Hooks & Filters
/** Plugin Name: Google Redirect* Version: 1.0*/add_action( ‘init’, ‘google_redirect’ );function google_redirect () {if( isset( $_GET[‘google_redirect’] ) ) {wp_redirect( ‘http://www.google.com’, 302 );exit;}}?>Bringing it Together
Plugin Developer Info: wordpress.org/plugins/developers/Coding Standards: codex.wordpress.org/WordPress_Coding_StandardsAction Reference: codex.wordpress.org/Plugin_API/Action_ReferencePlugin Template: github.com/hlashbrooke/WordPress-Plugin-TemplateHelpful Links
https://github.com/hlashbrooke/Post-View-CounterDemo Plugin
automattic.commake.wordpress.orghugh.blog@hlashbrooke