Extensible Plugins - A Case Study of Edupress

Extensible Plugins - A Case Study of Edupress

How plugins used in the Edupress project were made extensible.

31af50af29856a3e6734bdae0a0d68cf?s=128

Mark Wilkinson

July 12, 2014
Tweet

Transcript

  1. EXTENSIBLE A Case Study of Edupress PLUGINS Mark Wilkinson Ÿ

    @wpmark
  2. Professional, affordable websites for schools and the education sector

  3. 31,491 PLUGINS *as of 05/06/2014

  4. WHAT? WHY? TOOLS/FUNCTIONS EXAMPLES

  5. PLUGIN and or THEME

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

    plugin code itself AN EXTENSIBLE PLUGIN
  7. WHY?

  8. SAFE MODIFICATION FUNCTIONALITY Ÿ FRONT END OUTPUT

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

  10. None
  11. TOOLS FUNCTIONS

  12. ACTIONS & FILTERS

  13. do_action();

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

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

  17. 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…  
  18. '<div class="latest-tweets">'. apply_filters( 'latest_tweets_render_before', '' ). $list. apply_filters( 'latest_tweets_render_after', ''

    ). '</div>';  
  19. 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' );  
  20. IMPEMENTATION INTO YOUR OWN PLUGINS

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

  22. $query_args = array( 'post_type' => ’post', 'cat' => 1 );

  23. $query_args = apply_filters( 'wpmark_query_args', array( 'post_type' => ’post', 'cat' =>

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

    $query->the_post(); ?> <!-- // post output here --> <?php endwhile;
  25. $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;
  26. $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;
  27. EXAMPLES

  28. None
  29. $cew_feature_controls = apply_filters( 'cew_feature_control_output', array() // plugins will fill this

    array ); if( ! empty( $cew_feature_controls ) ) { foreach( $cew_feature_controls as $cew_feature_control ) { /* output feature controls here */ } }
  30. function cew_usefulinfo_register_feature_control_setting() { /* register the settings */ register_setting( 'cew_feature_control_settings',

    'useful_info_control' ); } add_action( 'admin_init', 'cew_usefulinfo_register_feature_control_setting' );
  31. function cew_featurecontrol_output( $controls ) { /* add our control to

    the controls array */ $controls[] = array( 'setting_name' => 'useful_info_control', 'setting_label' => 'Useful Info' ); return $controls; } add_filter( 'cew_feature_control_output', 'cew_featurecontrol_output' );
  32. TEMPLATE OVERIDES

  33. add_menu_page( 'Site Administration', 'Dashboard', 'edit_posts', 'cew_dashboard', 'cew_dashboard', ‘div’, 1 );

  34. function cew_dashboard() { if( file_exists( STYLESHEETPATH . 'cew/dashboard-home.php' ) )

    { require_once STYLESHEETPATH . 'cew/dashboard-home.php'; } else { /* plugin dashboard output here */ } }
  35. None
  36. do_action( 'cew_admin_before_content_blocks' );

  37. do_action( 'cew_admin_after_content_blocks' );

  38. <?php $cew_add_content_blocks = apply_filters( 'cew_add_content_blocks', array() // plugins filter this

    array ); /* loop through each section outputting its content to the page */ foreach( $cew_add_content_blocks as $cew_add_content_block ) { ?> <div class=“block <?php echo esc_html( strtolower( $cew_add_content_block[ 'class' ] ) ); ?>"> <!-- // output each content block here --> </div> <?php } // end loop through each block
  39. function cew_add_media_block( $array ) { /* add to our filtered

    array */ $array[] = array( 'title' => 'Media', 'description' => '<p>Description here.</p>', 'view_all_link' => admin_url( 'upload.php'), 'add_new_link' => admin_url( 'media-new.php' ), 'class' => 'media-block' ); return $array; } add_filter( 'cew_add_content_blocks', 'cew_add_media_block' );
  40. do_action(); add_action(); apply_filters(); add_filter(); OUR FRIENDS

  41. THANK YOU QUESTIONS? Mark Wilkinson | @wpmark