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.
YOU’RE DOING IT WRONG




Chris Scott - @chrisscott - slideshare.net/iamzed
             photo by mimk http://www.flickr.co...
Thanks
• Dion Hulse’s (DD32) two part series on doing it
    wrong:
    • http://dd32.id.au/2009/11/01/youre-doing-it-
   ...
New Features in a Year:
         2.7 - 2.8.6
• Sticky posts
• Comment threading and paging
• Widgets API
• Load scripts mi...
Wrong and Right
Not Upgrading




 WRONG
Upgrading




RIGHT
Calling Functions That
           Don’t Exist
<div id="sidebar" role="complementary">
  <ul>
     <li><?php wp_ozh_wsa('my...
Check for Functions Before
          Calling
<div id="sidebar" role="complementary">
  <ul>
     <?php if (function_exists...
Hard-Coding WordPress
           Paths
$cb_path = get_bloginfo('wpurl')."/wp-content/
plugins/wp-codebox"; //URL to the pl...
Use Constants or Helper
        Functions
$cb_path = plugins_url('', __FILE__);   //URL to the
plugin directory




      ...
Echoing Scripts/CSS in
        Header/Footer
function codebox_header() {
  $hHead .= "<script language="javascript" type=
...
Enqueue Scripts and Styles

function codebox_header() {
  wp_enqueue_script(
     'codebox',
     plugins_url('js/ codebox...
Not Checking Indices or
     Object Properties
if ($_GET['wp125action'] == "deactivate") {
  ...
}




               WRONG
Checking Indices/Properties

if (isset($_GET['wp125action']) &&
  $_GET['wp125action'] == "deactivate") {
  ...
}




    ...
Not Using WP_DEBUG




    WRONG
Define WP_DEBUG in
       wp-config.php
define('WP_DEBUG', true);




                RIGHT
Using Globals Instead of
  Helper Functions/Classes
global $post;

$linkname = get_the_title($post->ID);




             ...
Use Helper Functions/
           Classes
$linkname = get_the_title();




                RIGHT
Writing SQL

global $wpdb;

$wpdb->query("update ".$articles." set review = ".
  $rating." where post_id = ".$post_id);


...
Use $wpdb Methods

global $wpdb;

$wpdb->update(
   $articles,
   array('review' => $rating),
   compact('post_id')
);



...
Not Validating/Escaping
         User Input
<label for="title"><?php echo
get_option('my_plugin_option_title'); ?></label>...
Validate and Escape User
            Input
<label for="title"><?php echo
esc_html(get_option('my_plugin_option_title')); ?...
Not Using Caching

$response = wp_remote_get($url);
if (!is_wp_error($response)
     && $response['response']['code'] == '...
Use Caching

if (!$data = wp_cache_get('my_external_data')) {
  $response = wp_remote_get($url);
  if (!is_wp_error($respo...
Not Contributing




photo by TaranRampersad http://www.flickr.com/photos/knowprose/2294744043/




           WRONG
Contributing
http://codex.wordpress.org/
Contributing_to_WordPress

• Edit the Codex
• Answer Forum Support Questions
• Pa...
Upcoming SlideShare
Loading in …5
×

You're Doing it Wrong - WordCamp Orlando

4,771 views

Published on

Slides from my WordCamp Orlando 2009 presentation "You're Doing it Wrong".

Published in: Technology, Design

You're Doing it Wrong - WordCamp Orlando

  1. 1. YOU’RE DOING IT WRONG Chris Scott - @chrisscott - slideshare.net/iamzed photo by mimk http://www.flickr.com/photos/mimk/222612527/
  2. 2. Thanks • Dion Hulse’s (DD32) two part series on doing it wrong: • http://dd32.id.au/2009/11/01/youre-doing-it- wrong-1/ • http://dd32.id.au/2009/11/01/youre-doing-it- wrong-2/ • http://dd32.id.au/2009/11/24/how-to-do-it-right- part-0/ • Michael Pretty for ideas and telling me what I’m doing wrong • Sean O’Shaughnessy for ideas and graphics
  3. 3. New Features in a Year: 2.7 - 2.8.6 • Sticky posts • Comment threading and paging • Widgets API • Load scripts minified by default • Load scripts in the footer • esc_* functions • security fixes • and much more...
  4. 4. Wrong and Right
  5. 5. Not Upgrading WRONG
  6. 6. Upgrading RIGHT
  7. 7. Calling Functions That Don’t Exist <div id="sidebar" role="complementary"> <ul> <li><?php wp_ozh_wsa('mybanner') ?></li> ... rest of sidebar ... </ul> </div> WRONG
  8. 8. Check for Functions Before Calling <div id="sidebar" role="complementary"> <ul> <?php if (function_exists('wp_ozh_wsa')) : ?> <li><?php wp_ozh_wsa('mybanner') ?></li> <?php endif; ?> ... rest of sidebar ... </ul> </div> RIGHT
  9. 9. Hard-Coding WordPress Paths $cb_path = get_bloginfo('wpurl')."/wp-content/ plugins/wp-codebox"; //URL to the plugin directory WRONG
  10. 10. Use Constants or Helper Functions $cb_path = plugins_url('', __FILE__); //URL to the plugin directory RIGHT
  11. 11. Echoing Scripts/CSS in Header/Footer function codebox_header() { $hHead .= "<script language="javascript" type= "text/javascript" src="".get_bloginfo('wpurl')."/ wp-includes/js/jquery/jquery.js"></script>n"; $hHead .= "<script language="javascript" type= "text/javascript" src="{$cb_path}/js/codebox.js" ></script>n"; print($hHead); } add_action('wp_head', 'codebox_header'); WRONG
  12. 12. Enqueue Scripts and Styles function codebox_header() { wp_enqueue_script( 'codebox', plugins_url('js/ codebox.js', __FILE__), array('jquery') ); } add_action('template_redirect', 'codebox_header'); RIGHT
  13. 13. Not Checking Indices or Object Properties if ($_GET['wp125action'] == "deactivate") { ... } WRONG
  14. 14. Checking Indices/Properties if (isset($_GET['wp125action']) && $_GET['wp125action'] == "deactivate") { ... } RIGHT
  15. 15. Not Using WP_DEBUG WRONG
  16. 16. Define WP_DEBUG in wp-config.php define('WP_DEBUG', true); RIGHT
  17. 17. Using Globals Instead of Helper Functions/Classes global $post; $linkname = get_the_title($post->ID); WRONG
  18. 18. Use Helper Functions/ Classes $linkname = get_the_title(); RIGHT
  19. 19. Writing SQL global $wpdb; $wpdb->query("update ".$articles." set review = ". $rating." where post_id = ".$post_id); WRONG
  20. 20. Use $wpdb Methods global $wpdb; $wpdb->update( $articles, array('review' => $rating), compact('post_id') ); RIGHT
  21. 21. Not Validating/Escaping User Input <label for="title"><?php echo get_option('my_plugin_option_title'); ?></label> <input type="text" id="value" name="value" value="<? php echo get_option('my_plugin_option_value')); ?>"> WRONG
  22. 22. Validate and Escape User Input <label for="title"><?php echo esc_html(get_option('my_plugin_option_title')); ?></ label> <input type="text" id="value" name="value" value="<? php echo esc_attr(get_option('my_plugin_option_value')); ?>"> RIGHT
  23. 23. Not Using Caching $response = wp_remote_get($url); if (!is_wp_error($response) && $response['response']['code'] == '200') { $data = $response['body']; } ... do something with data ... WRONG
  24. 24. Use Caching if (!$data = wp_cache_get('my_external_data')) { $response = wp_remote_get($url); if (!is_wp_error($response) && $response['response']['code'] == '200') { $data = $response['body']; wp_cache_set('my_external_data', $data); } } ... do something with data ... RIGHT
  25. 25. Not Contributing photo by TaranRampersad http://www.flickr.com/photos/knowprose/2294744043/ WRONG
  26. 26. Contributing http://codex.wordpress.org/ Contributing_to_WordPress • Edit the Codex • Answer Forum Support Questions • Participate in Development • Planning, Testing, Bug Reporting and Fixing • Say “Thanks” RIGHT

×