The Fundamentals of Creating Sound Plugins

The Fundamentals of Creating Sound Plugins

Thanks to WordPress core making plugins to add functionality is not that difficult. However for each plugin you make, there are some sound principles you should follow in order to make your plugin the best it can be.

This talk will teach you some of the principles to follow when making your plugins, which will make it easier for you to develop and upgrade your plugin, as well as allowing other developers to make changes in a safer way and keep things secure. Ideal for beginners and intermediate developers in plugin development.

31af50af29856a3e6734bdae0a0d68cf?s=128

Mark Wilkinson

October 28, 2017
Tweet

Transcript

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


    WordCamp Manchester 2017
  2. https://highrise.digital @wpmark #1 Security

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

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

  5. https://highrise.digital @wpmark Others wp_kses_post() absint() / intval() wp_redirect() / wp_safe_redirect()

    $wpdb->* / is_email() array_map( 'absint', $array ) …
  6. https://highrise.digital @wpmark <input type="text" name="title" value="" />

  7. https://highrise.digital @wpmark <input type="text" name="title" value="" /> $title = sanitize_text_field(

    $_POST['title'] ); update_post_meta( $post_id, 'title', $title );
  8. https://highrise.digital @wpmark <input type="text" name="title" value="" /> $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 );
  9. https://highrise.digital @wpmark #2 Reliability / Scalability

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

    true
  11. https://highrise.digital @wpmark

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

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

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

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

    meta_query = array( … ) tax_query = array( … )
  16. 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/
  17. https://highrise.digital @wpmark Complex Queries Cache ‘em get_transient() set_transient() wp_cache_set() wp_cache_get()

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

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

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

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

  22. 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/
  23. https://highrise.digital @wpmark Use functions / methods get_option( 'hd_version' );

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

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

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

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

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

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

  30. https://highrise.digital @wpmark Template Overrides if ( file_exists( STYLESHEETPATH . '/file.php'

    ) { // load template from theme. } else { // load template from plugin. }
  31. https://highrise.digital @wpmark Function Overrides if ( ! function_exists( 'hd_function' )

    { function hd_function() { // some function stuff! } }
  32. https://highrise.digital @wpmark Actions & Filters do_action(); apply_filters();

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

  34. https://highrise.digital @wpmark

  35. https://highrise.digital @wpmark

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

    Digital https://highrise.digital @wpmark