WordPress Theme
 Plugins Development
        Best Practices
http://tareq.weDevs.com              Tareq Hasan
@tareq_cse
                          Software Engineer, Leevio
Use WordPress Coding
     Standards

 http://codex.wordpress.org/WordPress_Coding_Standards
Add Scripts/Styles
      Intelligently ..(1)


                        WRONG
http://codex.wordpress.org/Function_Reference/wp_enqueue_script
http://codex.wordpress.org/Function_Reference/wp_enqueue_style
Add Scripts/Styles
 Intelligently ..(2)


      RIGHT
Use escape functions in
      forms..(1)


        WRONG
Use escape functions in
      forms..(2)
                   esc_attr()




                esc_html()
        RIGHT
Use escape functions in
      forms..(3)
                 esc_attr()
                  esc_url()
                  esc_js()
                 esc_html()

   More validation functions
    http://codex.wordpress.org/Data_Validation
Prevent CSRF Attack
    Use Nonces


                           wp_nonce_field()

  http://codex.wordpress.org/WordPress_Nonces
Prevent CSRF Attack
    Use Nonces
             wp_nonce_field()
             wp_nonce_url()
            wp_verify_nonce()
            wp_create_nonce()
          check_admin_referer()
           check_ajax_referer()

  http://codex.wordpress.org/WordPress_Nonces
Let developers extend
  your code without
 touching your code
            do_action()
           apply_filters()


    http://codex.wordpress.org/Plugin_API
Ensure Theme/Plugins
generate no errors with
  WP_DEBUG enabled
Do not hard code
        WordPress paths
$plugin_path = get_bloginfo('wpurl')."/wp-content/plugins/wp-
                          codebox";

                                                  WRONG


           $plugin_path = plugins_url('', __FILE__);

                                                   RIGHT
Use database securely..(1)
                    Insert


                                                       Bad




                                                       Good

     http://codex.wordpress.org/Class_Reference/wpdb
Use database securely..(1)
         Update


                      Bad




                      Good
Use database securely..(1)
    Prepared Statement


                         Bad




                         Good
Make your theme child
   theme aware
    get_template_directory_uri()

                             For parent theme


    get_stylesheet_directory_uri()
                             For child theme
Localization is important
             load_theme_textdomain()
             load_plugin_textdomain()




 http://codex.wordpress.org/I18n_for_WordPress_Developers
Use the settings API

Store theme and plugin
option settings efficiently


   http://codex.wordpress.org/Settings_API
Make your plugin
    cache aware




http://codex.wordpress.org/Class_Reference/WP_Object_Cache
Thanks

Questions?

WordPress Theme & Plugin development best practices - phpXperts seminar 2011