Slide 1

Slide 1 text

@wpmark https://highrise.digital Easy Extensible Plugins Mark Wilkinson (@wpmark) WordPress Leeds July 2017

Slide 2

Slide 2 text

@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

Slide 3

Slide 3 text

@wpmark https://highrise.digital What? Why? Tools / Functions

Slide 4

Slide 4 text

@wpmark https://highrise.digital Plugin and or Theme

Slide 5

Slide 5 text

@wpmark https://highrise.digital An Extensible Plugin

Slide 6

Slide 6 text

@wpmark https://highrise.digital An Extensible Plugin is a plugin that can be modified or extended without changing the plugin code itself

Slide 7

Slide 7 text

@wpmark https://highrise.digital Why?

Slide 8

Slide 8 text

@wpmark https://highrise.digital Safe Functionality Modification

Slide 9

Slide 9 text

@wpmark https://highrise.digital Safe Front-end Output Modification

Slide 10

Slide 10 text

@wpmark https://highrise.digital https://www.flickr.com/photos/damndirty/10166197684

Slide 11

Slide 11 text

@wpmark https://highrise.digital

Slide 12

Slide 12 text

@wpmark https://highrise.digital How does core do extensibility?

Slide 13

Slide 13 text

@wpmark https://highrise.digital Hooks Actions & Filters

Slide 14

Slide 14 text

@wpmark https://highrise.digital Hooks Actions & Filters do_action()

Slide 15

Slide 15 text

@wpmark https://highrise.digital Hooks Actions & Filters apply_filters()

Slide 16

Slide 16 text

@wpmark https://highrise.digital

Slide 17

Slide 17 text

@wpmark https://highrise.digital /wp-admin/edit-form-advanced.php apply_filters( 'enter_title_here', __( 'Enter title here' ), $post );

Slide 18

Slide 18 text

@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

Slide 19

Slide 19 text

@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 );

Slide 20

Slide 20 text

@wpmark https://highrise.digital Implementing this in our plugins

Slide 21

Slide 21 text

@wpmark https://highrise.digital Implementing this in our plugins Setting up arrays Before / after HTML Output Function returns

Slide 22

Slide 22 text

@wpmark https://highrise.digital Setting up arrays $job_posts = new WP_Query( array( ‘post_type’ => ‘wpmark_job’, ‘posts_per_page => 12 ) );

Slide 23

Slide 23 text

@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 ) ) );

Slide 24

Slide 24 text

@wpmark https://highrise.digital Before / after while ( $job_posts->have_posts() ) : $job_posts->the_post(); // do stuff with each post. endwhile;

Slide 25

Slide 25 text

@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;

Slide 26

Slide 26 text

@wpmark https://highrise.digital Even better? while ( $job_posts->have_posts() ) : $job_posts->the_post(); do_action( ‘wpmark_job_post’, $post ); endwhile;

Slide 27

Slide 27 text

@wpmark https://highrise.digital Function returns function wpmark_sub_title( $post_id = 0 ) { return get_post_meta( $post_id, ‘subtitle’, true ); }

Slide 28

Slide 28 text

@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 ); }

Slide 29

Slide 29 text

@wpmark https://highrise.digital Other examples of extensibility Template overides Filterable views - outputting messages etc. Widget & shortcode templates Plugin adds functionality using hooks

Slide 30

Slide 30 text

@wpmark https://highrise.digital Thank you for listening Any questions?