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. 6.

    One that can be modified or extended without changing the

    plugin code itself AN EXTENSIBLE PLUGIN
  2. 7.
  3. 10.
  4. 14.
  5. 15.
  6. 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…  
  7. 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' );  
  8. 24.

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

    $query->the_post(); ?> <!-- // post output here --> <?php endwhile;
  9. 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;
  10. 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;
  11. 27.
  12. 28.
  13. 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 */ } }
  14. 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' );
  15. 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' );
  16. 34.

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

    { require_once STYLESHEETPATH . 'cew/dashboard-home.php'; } else { /* plugin dashboard output here */ } }
  17. 35.
  18. 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
  19. 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' );