Building better WordPress applications

606 views

Published on

10 tips to improve your WordPress themes and plugins

Published in: Technology, Business
1 Comment
2 Likes
Statistics
Notes
  • These 10 rules are essential for WordPress application. Thanks for sharing here
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total views
606
On SlideShare
0
From Embeds
0
Number of Embeds
118
Actions
Shares
0
Downloads
3
Comments
1
Likes
2
Embeds 0
No embeds

No notes for slide

Building better WordPress applications

  1. 1. Building better WordPress applications PBWEB.CO.UK @PHILL_BROWN
  2. 2. Problems with WordPress applications • Business logic in themes • Repeated code • Tight coupling • Portability
  3. 3. Rule #1 Do not write your application in functions.php
  4. 4. Decoupling plugins and themes Logic Templates Templates Plugin Theme
  5. 5. Rule #2 Every action should be hooked
  6. 6. function my_plugin_start() { // Fire up application } // Wrong my_plugin_start(); // Right add_action( ‘plugins_loaded’, ‘my_plugin_start’ );
  7. 7. Rule #3 Use WordPress
  8. 8. Core checklist • Custom post types and post meta • Roles, capabilities and user meta • Options and transients • Scheduler • Remote HTTP
  9. 9. Rule #4 Use plugin dependencies
  10. 10. • Scribu’s Plugin Dependencies • if ( ! class_exists( ‘plugin_x’ ) ) { wp_die( ‘Plugin Y requires plugin x’ ); }
  11. 11. Rule #5 Standardise code
  12. 12. • WordPress coding standards: http://codex.wordpress.org/WordPress_Coding_Standards • PHPDoc http://en.wikipedia.org/wiki/PHPDoc
  13. 13. Rule #6 Choose your PHP version
  14. 14. • WordPress core (v3.0+) – 5.1.1 • 5.2 – DateTime • 5.3 – Late static binding, closures, namespacing • 5.4 - Traits
  15. 15. Rule #7 Avoid global scoping
  16. 16. add_action( ‘init’, function() { // do something  } ); Closures
  17. 17. namespace wordpressmy_plugin; class Post {}  Namespacing class My_Plugin_Post {}  PHP 5.3 PHP 5.1
  18. 18. Rule #8 Activation hooks
  19. 19. register_activation_hook( __FILE__, ‘my_plugin_activate’ ); function my_plugin_activate() { // Create tables, roles, capabilities } register_uninstall_hook( __FILE__, ‘my_plugin_uninstall’ ); function my_plugin_uninstall() { // Cleanup data }
  20. 20. Rule #9define( ‘WP_DEBUG’, true );
  21. 21. Rule #10 Release your code
  22. 22. Questions? @PHILL_BROWN WP@PBWEB.CO.UK

×