Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Plugin development wpmeetup010

2,048 views

Published on

The presentation I gave at WordPress meetup Rotterdam.

Published in: Technology
  • Be the first to comment

Plugin development wpmeetup010

  1. 1. PLUGIN DEVELOPMENT #wpmeetup010
  2. 2. BARRY KOOIJ Twitter : @cageNL Lead Developer WordPress @ INDICIA Freelance @ Cageworks Plugin developer What The File Sub Posts Contributor EDD & extensies Core contributor Moderator WPNL forum
  3. 3. PLUGIN DEVELOPMENT
  4. 4. MIJN SETUP Device IDE Versiebeheer MacBook Air PhpStorm GIT, GitHub / private server Commandline
  5. 5. ALTERNATIEVEN IDE GIT SVN NuSphere PhpED Bitbucket, GitLab Tower Versions / Tortoise
  6. 6. DEBUGGIN G define( 'WP_DEBUG', true ); if ( WP_DEBUG ) { define( 'SCRIPT_DEBUG', true ); define( 'WP_DEBUG_LOG', true ); define( 'WP_DEBUG_DISPLAY', true ); @ini_set( 'display_errors', 0 ); } display_errors = On; error_reporting = E_ALL | E_STRICT;
  7. 7. CODE TEMPLATES https://gist.github.com/barrykooij/7632945
  8. 8. WORDPRESS CORE Open source, maak hier gebruik van! API’s, API’S, API’s Filters & Hooks
  9. 9. API’S Dashboard Widgets API Database API HTTP API File Header API Filesystem API Metadata API Options API Plugin API Quicktags API Rewrite API Settings API Shortcode API Theme Modification API Theme Customization API Transients API Widgets API XML-RPC WordPress API
  10. 10. FILTERS & HOOKS add_action( ‘hook_name’, ‘my_function’ ); do_action( ‘hook_name’ );
  11. 11. JS “HOOKS” (EVENTS) $('body').bind(’event’, function(event, the_value) { }); $('body').trigger(’event', [ value ]);
  12. 12. BACKWARDS COMPATABILITY Deprecate code Pas later geen unit tests aan, maar voeg unit tests toe
  13. 13. CODE STANDARDS http://codex.wordpress.org/WordPress_Coding_Standards
  14. 14. NAMING CONVENTIONS function some_name( $some_variable ) { [...] } class Walker_Category extends Walker { [...] } class WP_HTTP { [...] } my-plugin-name.php class-my-class.php
  15. 15. DATABASES Gebruik altijd de API! $wpdb->prepare $wpdb->prepare( "SELECT * FROM {$wpdb>posts}" WHERE `ID` = %d", $special_id );
  16. 16. YODA CONDITIONS if ( true == $the_force ) { $victorious = you_will( $be ); } A little bizarre, it is, to read. Get used to it, you will.
  17. 17. UNIT TESTING PHPUnit /** * @ticket 22212 */ function test_get_multiple_roles_by_user_query() { $this->factory->user->create_many( 2, array( 'role' => 'subscriber’ ) ); $this->factory->user->create_many( 3, array( 'role' => 'editor’ ) ); $wp_user_search = new WP_User_Query( array( 'role' => array( 'subscriber’, 'editor' ) ) ); $users = $wp_user_search->get_results(); $this->assertEquals( 5, count( $users ) ); }
  18. 18. CHANGELOG Hou bij wat je wanneer veranderd hebt
  19. 19. SUPPORT Als je iets bouwt, support het dan Geef op je website je support tijden aan Support systemen
  20. 20. WORDPRESS.ORG REPO Header afbeelding Duidelijk omschrijving Downloads i.c.m. rating Vraag om ratings!
  21. 21. CONDITIONAL LOADING OF CODE Laad code enkel waar nodig is_admin()
  22. 22. DOCUMENTATION Schrijf je code doc direct Betere IDE suggesties
  23. 23. CODE
  24. 24. OBJECTGEORIËNTEERD OOP Singleton pattern
  25. 25. class My_Plugin { private static $instance = null; public static function get() { if( null == self::$instance ) { self::$instance = new self(); } return self::$instance; } private function __construct() { } }
  26. 26. function My_Plugin() { return My_Plugin::get(); } add_action( 'plugins_loaded', function() {My_Plugin::get(); });
  27. 27. PLUGIN DIR & FILE if ( ! defined( ’X_PLUGIN_DIR' ) ) { define( 'X_PLUGIN_DIR’, plugin_dir_path( __FILE__ ) ); } if ( ! defined( ’X_PLUGIN_FILE' ) ) { define( ’X_PLUGIN_FILE', __FILE__ ); }
  28. 28. PREFIXES WordPress : PHP version 5.2.4 or greater Namespaces : 5.3.0 or greater Tot die tijd, prefixen. class SP_Post_Link_Manager { [...] }
  29. 29. SANITIZE & ESCAPE sanitize_title is_email http://codex.wordpress.org/Data_Validation#In put_Validation esc_url esc_html
  30. 30. CAPABILITIES if ( ! current_user_can( SP_Cap_Manager::get_capability( $_GET['sp_post_link'] ) ) ) { return; }
  31. 31. NONCES Number used ONCE wp_nonce_field( plugin_basename( __FILE__ ), 'sp_sortable_nonce' ); if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], plugin_basename( __FILE__ ) ) ) { return; }
  32. 32. DIRECT ACCESS if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
  33. 33. I18N load_plugin_textdomain( 'sub-posts', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); _e( ‘my-string’, ‘sub-posts’ );
  34. 34. Q& A Twitter @cageNL WordPress & Github: barrykooij 7 januari meetup in Tilburg

×