Easy Extensible Plugins

Easy Extensible Plugins

Extensible plugins are often the ones the WordPress community consider to be the best as they take advantage of the WordPress license and allow developers to build on and edit them.

In this talk I will outline some of the methods which can be used to make your plugins extensible, allowing others to edit and build upon them.

31af50af29856a3e6734bdae0a0d68cf?s=128

Mark Wilkinson

June 28, 2014
Tweet

Transcript

  1. EASY EXTENSIBLE PLUGINS Mark Wilkinson @wpmark markwilkinson.me

  2. Secondary School Computing Teacher

  3. Freelance Developer working from home

  4. None
  5. 31,491 PLUGINS *as of 05/06/2014

  6. WHAT? WHY? TOOLS/FUNCTIONS EXAMPLES

  7. PLUGIN and or THEME

  8. One that can be modified or extended without changing the

    plugin code itself AN EXTENSIBLE PLUGIN is
  9. WHY?

  10. SAFE MODIFICATION FUNCTIONALITY

  11. SAFE MODIFICATION FRONT END OUTPUT

  12. https://www.flickr.com/photos/damndirty/10166197684

  13. None
  14. TOOLS FUNCTIONS

  15. ACTIONS & FILTERS

  16. do_action();

  17. None
  18. 'do_action( 'twentyfourteen_credits’ );

  19. function wpmark_notice() { echo '<p>Site by Mark Wilkinson</p>'; } add_action(

    'twentyfourteen_credits', 'wpmark_notice' );  
  20. apply_filters();

  21. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus malesuada

    sem at sapien rutrum, eu…   Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus malesuada sem at sapien rutrum, eu…  
  22. '<div class="latest-tweets">'. apply_filters( 'latest_tweets_render_before', '' ). $list. apply_filters( 'latest_tweets_render_after', ''

    ). '</div>';  
  23. function wpmark_twitter( $content ) { /* get the twitter url

    from site options */ $url = get_option( ‘twitter_url' ); $content = '<a href="' . esc_url( $url ) . '">@' . basename( $url ) . '</a>'; return $content; } add_filter( 'latest_tweets_render_before', ’wpmark_twitter' );  
  24. IMPEMENTATION INTO YOUR OWN PLUGINS

  25. SETTING UP ARRAYS BEFORE/AFTER HTML OUTPUT BEFORE/AFTER SETUP

  26. $query_args = array( 'post_type' => 'page', 'cat' => 1 );

  27. $query_args = apply_filters( 'wpmark_query_args', array( 'post_type' => 'page', 'cat' =>

    1 ) );
  28. $query = new WP_Query( $query_args ); while( $query->have_posts() ) :

    $query->the_post(); ?> <!-- // post output here --> <?php endwhile;
  29. $query = new WP_Query( $query_args ); while( $query->have_posts() ) :

    $query->the_post(); do_action( ‘wpmark_before_post’, get_the_ID() ); ?> <!-- // post output here --> <?php endwhile;
  30. $query = new WP_Query( $query_args ); while( $query->have_posts() ) :

    $query->the_post(); do_action( ‘wpmark_before_post’, get_the_ID() ); ?> <!-- // post output here --> <?php do_action( ‘wpmark_after_post’, get_the_ID() ); endwhile;
  31. EXAMPLES

  32. None
  33. apply_filters( ‘gform_field_value_date’ );

  34. function populate_date( $value ) { return "10/10/2010"; } add_filter( ‘gform_field_value_date’,

    ‘populate_date’ );
  35. None
  36. function wpmark_product_wrapper() { echo '<div class="products-wrapper">Something before the loop.</div>'; }

    add_action( 'woocommerce_before_shop_loop', 'wpmark_product_wrapper’ );
  37. CONCLUSION

  38. do_action(); apply_filters() OUR FRIENDS

  39. THANK YOU Mark Wilkinson @wpmark markwilkinson.me

  40. QUESTIONS