Save 37% off PRO during our Black Friday Sale! »

Bending WordPress to Your Will (October 2018)

Bending WordPress to Your Will (October 2018)

These slides are slightly modified from a previous talk I gave with the same title.

WordPress is an incredibly powerful platform and framework for development, but until you learn how to use it you won't be able to make full use of its flexibility. In this session you will learn the core principles of WordPress development that will enable you to start taking full advantage of everything that it offers.

I gave this presentation at the Cape Town Develop UG on 29 October 2018: https://www.meetup.com/DeveloperUG/events/bcqgbqyxnbdc/

51eec74fdf430271ce134e58b811e5b9?s=128

Hugh Lashbrooke

October 29, 2018
Tweet

Transcript

  1. Bending WordPress To Your Will

  2. None
  3. Folder Structure Headers Events Plugin Development

  4. wp-content/plugins/plugin-slug > plugin-slug.php > readme.txt Folder Structure

  5. 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: https://hugh.blog/ * Requires at least: 4.6 * Tested up to: 4.9.8 * * Text Domain: seriously-simple-podcasting */
  6. PHP call_user_func() WordPress do_action() apply_filters() Events

  7. do_action( ‘hook’ ); add_action( ‘hook’, ‘my_function’ ); Events: Hooks

  8. <div id=”container”> <?php do_action( ‘div_content’ ); ?> </div> Events: Hooks

    - Example
  9. add_action( ‘div_content’, ‘my_content’ ); function my_content() { echo “<span>Hello world!</span>”;

    } Events: Hooks - Example
  10. <div id=”container”> <span>Hello world!</span> </div> Events: Hooks - Example

  11. add_action( ‘hook’, ‘my_function’, 10 ); Lower number == higher priority

    Events: Priorities
  12. add_action( ‘hook’, ‘my_function’, 10, 2 ); function my_function ( $foo,

    $bar ) { ... } Events: Parameters
  13. apply_filters( ‘filter’, $foo ); add_filter( ‘filter’, ‘my_function’ ); Filters must

    always return a value Events: Filters
  14. $v = apply_filters( 'body_class', $classes ); Events: Filters - Example

  15. add_filter( ‘body_class’, ‘add_my_class’ ); function add_my_class( $classes ) { $classes[]

    = ‘my-class’; return $classes; } Events: Filters - Example
  16. remove_action( ‘hook’, ‘function’ ); remove_filter( ‘filter’, ‘function’ ); Priorities must

    match original hook/filter Removing Hooks & Filters
  17. <?php /* * Plugin Name: YouTube Redirect * Version: 1.0

    */ add_action( ‘init’, ‘youtube_redirect’ ); function youtube_redirect () { if( isset( $_GET[‘youtube_redirect’] ) ) { wp_redirect( ‘https://youtube.com’, 302 ); exit; } } ?> Bringing it Together
  18. Varying Vagrant Vagrants: varyingvagrantvagrants.org Plugin Developer Info: wordpress.org/plugins/developers Coding Standards:

    make.wordpress.org/core/handbook/best-practices/coding-standards Plugin Template: github.com/hlashbrooke/WordPress-Plugin-Template
  19. hugh.blog @hlashbrooke automattic.com make.wordpress.org