Slide 1

Slide 1 text

https://highrise.digital @wpmark The Fundamentals of Creating Sound Plugins Mark Wilkinson
 WordCamp Manchester 2017

Slide 2

Slide 2 text

https://highrise.digital @wpmark #1 Security

Slide 3

Slide 3 text

https://highrise.digital @wpmark sanitize_*() sanitize_text_field() / sanitize_email() sanitize_option() / sanitize_title_with_dashes() sanitize_option() …

Slide 4

Slide 4 text

https://highrise.digital @wpmark esc_*() esc_url() / esc_html() esc_attr() / esc_textarea() esc_js() …

Slide 5

Slide 5 text

https://highrise.digital @wpmark Others wp_kses_post() absint() / intval() wp_redirect() / wp_safe_redirect() $wpdb->* / is_email() array_map( 'absint', $array ) …

Slide 6

Slide 6 text

https://highrise.digital @wpmark

Slide 7

Slide 7 text

https://highrise.digital @wpmark $title = sanitize_text_field( $_POST['title'] ); update_post_meta( $post_id, 'title', $title );

Slide 8

Slide 8 text

https://highrise.digital @wpmark $title = sanitize_text_field( $_POST['title'] ); update_post_meta( $post_id, 'title', $title ); $title = get_post_meta( $post_id, 'title', true ); echo esc_html( $title );

Slide 9

Slide 9 text

https://highrise.digital @wpmark #2 Reliability / Scalability

Slide 10

Slide 10 text

https://highrise.digital @wpmark Watch out for notices & warnings 'WP_DEBUG' = true

Slide 11

Slide 11 text

https://highrise.digital @wpmark

Slide 12

Slide 12 text

https://highrise.digital @wpmark Efficient Queries posts_per_page = -1

Slide 13

Slide 13 text

https://highrise.digital @wpmark Efficient Queries posts_per_page = -1 posts_per_page = 100

Slide 14

Slide 14 text

https://highrise.digital @wpmark Efficient Queries posts_per_page = -1 posts_per_page = 100 meta_query = array( … )

Slide 15

Slide 15 text

https://highrise.digital @wpmark Efficient Queries posts_per_page = -1 posts_per_page = 100 meta_query = array( … ) tax_query = array( … )

Slide 16

Slide 16 text

https://highrise.digital @wpmark Efficient Queries posts_per_page = -1 posts_per_page = 100 meta_query = array( … ) tax_query = array( … ) https://10up.github.io/Engineering-Best-Practices/php/

Slide 17

Slide 17 text

https://highrise.digital @wpmark Complex Queries Cache ‘em get_transient() set_transient() wp_cache_set() wp_cache_get()

Slide 18

Slide 18 text

https://highrise.digital @wpmark Don’t re-invent the wheel! Use WordPress functions

Slide 19

Slide 19 text

https://highrise.digital @wpmark #3 Maintainability

Slide 20

Slide 20 text

https://highrise.digital @wpmark Activation / De-activation register_activation_hook( __FILE__, ‘hd_function_to_run’ );

Slide 21

Slide 21 text

https://highrise.digital @wpmark Activation / De-activation register_deactivation_hook( __FILE__, ‘hd_function_to_run’ );

Slide 22

Slide 22 text

https://highrise.digital @wpmark uninstall.php Runs when a user deletes the plugin Clean up options, removing DB tables https://developer.wordpress.org/plugins/the-basics/uninstall-methods/

Slide 23

Slide 23 text

https://highrise.digital @wpmark Use functions / methods get_option( 'hd_version' );

Slide 24

Slide 24 text

https://highrise.digital @wpmark Use functions / methods get_option( 'hd_version' ); hd_get_version();

Slide 25

Slide 25 text

https://highrise.digital @wpmark #4 Compatibility

Slide 26

Slide 26 text

https://highrise.digital @wpmark prefix_all get_version();

Slide 27

Slide 27 text

https://highrise.digital @wpmark prefix_all get_version(); hd_get_version();

Slide 28

Slide 28 text

https://highrise.digital @wpmark Enqueue Scripts / Styles wp_enqueue_script(); wp_enqueue_style();

Slide 29

Slide 29 text

https://highrise.digital @wpmark #5 Extensibility https://wordpress.tv/2014/08/29/mark-wilkinson-easy-extensible-plugins/

Slide 30

Slide 30 text

https://highrise.digital @wpmark Template Overrides if ( file_exists( STYLESHEETPATH . '/file.php' ) { // load template from theme. } else { // load template from plugin. }

Slide 31

Slide 31 text

https://highrise.digital @wpmark Function Overrides if ( ! function_exists( 'hd_function' ) { function hd_function() { // some function stuff! } }

Slide 32

Slide 32 text

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

Slide 33

Slide 33 text

https://highrise.digital @wpmark #6 Usability

Slide 34

Slide 34 text

https://highrise.digital @wpmark

Slide 35

Slide 35 text

https://highrise.digital @wpmark

Slide 36

Slide 36 text

https://highrise.digital @wpmark Mark Wilkinson WordPress Developer & Co-founder @ Highrise Digital https://highrise.digital @wpmark