Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Coding Well - Good Practices

Coding Well - Good Practices

#wcsea

Kailey Lampert

June 08, 2013
Tweet

More Decks by Kailey Lampert

Other Decks in Technology

Transcript

  1. USE APIS • at least 17 APIs provided in core

    http://codex.wordpress.org/WordPress_APIs • they make your life better use APIs, core does all the work don’t and you do all the work again and again e.g. mysql_* Use the database API, and don’t worry about deprecation in PHP 5.5! or...
  2. Ever do this? update_option( "mods_$theme_name", $mods ); and one day

    it stopped working right? thats because you should have used set_theme_mod( $mod, $value ); which would have automatically accounted for the option name change to "theme_mods_$theme_slug"
  3. USE DEBUG define('WP_DEBUG', true); http://codex.wordpress.org/Debugging_in_WordPress A few helpful plugins: http://wordpress.org/plugins/debug-bar/

    http://wordpress.org/plugins/debug-bar-extender/ http://wordpress.org/plugins/debug-bar-console/ http://wordpress.org/plugins/log-deprecated-notices/ http://wordpress.org/plugins/developer/
  4. FRESH TEST Test your code with Twenty Twelve and on

    a fresh install • Make sure you’re not accidentally dependent on something • Easily catch ‘undefined index’ errors
  5. NEVER ASSUME Did you know it’s possible to move wp-content/?

    People have been known to change the names of plugin folders
  6. TEST MORE THAN ONCE Your local dev environment (MAMP, WAMP,

    XAMPP) is your environment, check again on an real server. Tools like Vagrant make it easy to replicate production servers. vagrantup.com
  7. BE NICE • Don’t be spammy • Don’t delete what’s

    not yours (nothing is yours) • http://wordpress.org/plugins/about/guidelines/
  8. LOCALIZE Not everyone speaks your language. You don’t have to

    translate, but you should make it possible for those who want to. __( ‘Your string to be translatable.’, ‘text-domain’ );
  9. COMMENTS Another person* should be able to understand your code.

    *Your future self counts as another person $tax_drop = wp_list_categories( $tax_dp_args ); $tax_drop = '<option href="#search_all">Select Offer Type</option>'. $tax_drop; $tax_drop = preg_replace("#<li([^>]*)>#", "", $tax_drop); $tax_drop = str_replace( '</li>','',$tax_drop); $tax_drop = str_replace( '<a', '<option', $tax_drop ); $tax_drop = str_replace( '</a>', '</option>', $tax_drop ); $tax_drop = str_replace( 'View all posts filed under', '', $tax_drop); $tax_drop = preg_replace( "#href=\"([^\"]*)\"#", "href=\"$1\"", $tax_drop); $tax_drop = preg_replace("#<\/option> \(([0-9]*)\)<option ([^>]*)>([a- zA-Z]*)#", "</option>$2<option $2> ($1) $3", $tax_drop);
  10. PRETTY CODE WordPress coding standards http://make.wordpress.org/core/handbook/coding-standards/ • indentation, tabs or

    spaces • consistency in convention: _underscores_, camelCase, lowercase, etc. • trim trailing spaces Code is poetry!