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

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.

Mark Wilkinson

July 15, 2017
Tweet

More Decks by Mark Wilkinson

Other Decks in Technology

Transcript

  1. @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
  2. @wpmark https://highrise.digital An Extensible Plugin is a plugin that can

    be modified or extended without changing the plugin code itself
  3. @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
  4. @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 );
  5. @wpmark https://highrise.digital Setting up arrays $job_posts = new WP_Query( array(

    ‘post_type’ => ‘wpmark_job’, ‘posts_per_page => 12 ) );
  6. @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 ) ) );
  7. @wpmark https://highrise.digital Before / after while ( $job_posts->have_posts() ) :

    $job_posts->the_post(); // do stuff with each post. endwhile;
  8. @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;
  9. @wpmark https://highrise.digital Function returns function wpmark_sub_title( $post_id = 0 )

    { return get_post_meta( $post_id, ‘subtitle’, true ); }
  10. @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 ); }
  11. @wpmark https://highrise.digital Other examples of extensibility Template overides Filterable views

    - outputting messages etc. Widget & shortcode templates Plugin adds functionality using hooks