Easy Extensible Plugins

Easy Extensible Plugins

We all love WordPress, many of use because of the ease in which we can extend and modify its functionality. Plugins themselves take advantage of this to add something extra to WordPress. In my experience most plugins are never exactly as you want them. Therefore being allowed to change them is essential.

Mark will introduce methods you can use when developing your plugin that will allow others to extend or modify its functionality or output. The talk is suitable for beginners and intermediate developers.

31af50af29856a3e6734bdae0a0d68cf?s=128

Mark Wilkinson

July 15, 2017
Tweet

Transcript

  1. @wpmark https://highrise.digital Easy Extensible Plugins Mark Wilkinson (@wpmark) WordPress Leeds

    July 2017
  2. @wpmark https://highrise.digital Mark Wilkinson Using & building WordPress sites for

    over 10 years as a WordPress developer Owner of Highrise Digital Follow me: @wpmark
  3. @wpmark https://highrise.digital What? Why? Tools / Functions

  4. @wpmark https://highrise.digital Plugin and or Theme

  5. @wpmark https://highrise.digital An Extensible Plugin

  6. @wpmark https://highrise.digital An Extensible Plugin is a plugin that can

    be modified or extended without changing the plugin code itself
  7. @wpmark https://highrise.digital Why?

  8. @wpmark https://highrise.digital Safe Functionality Modification

  9. @wpmark https://highrise.digital Safe Front-end Output Modification

  10. @wpmark https://highrise.digital https://www.flickr.com/photos/damndirty/10166197684

  11. @wpmark https://highrise.digital

  12. @wpmark https://highrise.digital How does core do extensibility?

  13. @wpmark https://highrise.digital Hooks Actions & Filters

  14. @wpmark https://highrise.digital Hooks Actions & Filters do_action()

  15. @wpmark https://highrise.digital Hooks Actions & Filters apply_filters()

  16. @wpmark https://highrise.digital

  17. @wpmark https://highrise.digital /wp-admin/edit-form-advanced.php apply_filters( 'enter_title_here', __( 'Enter title here' ),

    $post );
  18. @wpmark https://highrise.digital function wpmark_title_here( $title, $post ) { if (

    'post' === get_post_type( $post ) ) { $title = 'Article Title'; } return $title; } add_action( 'enter_title_here', 'wpmark_title_here', 10, 2 ); apply_filters( 'enter_title_here', __( 'Enter title here' ), $post ); /wp-admin/edit-form-advanced.php
  19. @wpmark https://highrise.digital apply_filters( 'enter_title_here', __( 'Enter title here' ), $post

    ); /wp-admin/edit-form-advanced.php function wpmark_title_here( $title, $post ) { if ( 'post' === get_post_type( $post ) ) { $title = 'Article Title'; } return $title; } add_action( 'enter_title_here', 'wpmark_title_here', 10, 2 );
  20. @wpmark https://highrise.digital Implementing this in our plugins

  21. @wpmark https://highrise.digital Implementing this in our plugins Setting up arrays

    Before / after HTML Output Function returns
  22. @wpmark https://highrise.digital Setting up arrays $job_posts = new WP_Query( array(

    ‘post_type’ => ‘wpmark_job’, ‘posts_per_page => 12 ) );
  23. @wpmark https://highrise.digital Setting up arrays $job_posts = new WP_Query( apply_filters(

    ‘wpmark_job_post_query_args’, array( ‘post_type’ => ‘wpmark_job’, ‘posts_per_page => 12 ) ) );
  24. @wpmark https://highrise.digital Before / after while ( $job_posts->have_posts() ) :

    $job_posts->the_post(); // do stuff with each post. endwhile;
  25. @wpmark https://highrise.digital Before / after while ( $job_posts->have_posts() ) :

    $job_posts->the_post(); do_action( ‘wpmark_before_job_post’, $post ); // do stuff with each post. do_action( ‘wpmark_after_job_post’, $post ); endwhile;
  26. @wpmark https://highrise.digital Even better? while ( $job_posts->have_posts() ) : $job_posts->the_post();

    do_action( ‘wpmark_job_post’, $post ); endwhile;
  27. @wpmark https://highrise.digital Function returns function wpmark_sub_title( $post_id = 0 )

    { return get_post_meta( $post_id, ‘subtitle’, true ); }
  28. @wpmark https://highrise.digital Function returns function wpmark_sub_title( $post_id = 0 )

    { return apply_filters( ‘wpmark_sub_title’, get_post_meta( $post_id, ‘subtitle, true ), $post_id ); }
  29. @wpmark https://highrise.digital Other examples of extensibility Template overides Filterable views

    - outputting messages etc. Widget & shortcode templates Plugin adds functionality using hooks
  30. @wpmark https://highrise.digital Thank you for listening Any questions?