Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Extensible Plugins - A Case Study of Edupress

Extensible Plugins - A Case Study of Edupress

How plugins used in the Edupress project were made extensible.

Mark Wilkinson

July 12, 2014
Tweet

More Decks by Mark Wilkinson

Other Decks in Technology

Transcript

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

    plugin code itself AN EXTENSIBLE PLUGIN
  2. 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…  
  3. 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' );  
  4. $query = new WP_Query( $query_args ); while( $query->have_posts() ) :

    $query->the_post(); ?> <!-- // post output here --> <?php endwhile;
  5. $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;
  6. $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;
  7. $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 */ } }
  8. 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' );
  9. 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' );
  10. function cew_dashboard() { if( file_exists( STYLESHEETPATH . 'cew/dashboard-home.php' ) )

    { require_once STYLESHEETPATH . 'cew/dashboard-home.php'; } else { /* plugin dashboard output here */ } }
  11. <?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
  12. 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' );