Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Using Actions and Filters in WordPress to Make a Plugin Your Own

952 views

Published on

Good plugins provide actions and filters to allow others (like you!) to modify some of their functionality without having to either create a whole new plugin from scratch or hack away at the original plugin, losing your changes when that plugin gets updated down the road. Learn how to find these actions and filters in other plugins, and use them to bend the plugin to your will.

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Using Actions and Filters in WordPress to Make a Plugin Your Own

  1. 1. Making a Plugin Your Own Using Actions and Filters in WordPress Brian Hogg brianhogg.com | @brianhogg WordCamp Toronto 2015
  2. 2. brianhogg.com Subtitle
  3. 3. wpontheside.com Subtitle
  4. 4. Actions and Filters
  5. 5. Actions do_action( $identifier, [ $arg1, $arg2, ... ] ) add_action( $identifier, $function_name, [ $priority, $arg_count ] )
  6. 6. 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' );
  7. 7. Filters apply_filters( $identifier, $value, [ $arg1, $arg2, ... ] ) add_filter( $identifier, $function_name, [ $priority, $arg_count ] )
  8. 8. Filters (Example) echo apply_filters( 'plugin_title', 'Title' ); function change_plugin_title( $title ) { return 'New Title'; } add_filter( 'plugin_title', 'change_plugin_title' );
  9. 9. Filters (Example) echo apply_filters( 'plugin_title', 'Title' ); function change_plugin_title( $title ) { return 'New ' . $title; } add_filter( 'plugin_title', 'change_plugin_title' );
  10. 10. How do you find what you can change in a plugin? Search for do_action and apply_filters
  11. 11. The Events Calendar Plugin •apply_filters •442 occurrences •do_action •190 occurrences
  12. 12. 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
  13. 13. DEMO
  14. 14. The Events Calendar ▪ Message to verify location ▪ Venue -> Location ▪ Cost formatting
  15. 15. 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
  16. 16. Go make plugins your own!

×