you're doing it wrong - wordcamp orlando

26
Chris Scott - @chrisscott - slideshare.net/iamzed photo by mimk http://www.flickr.com/photos/mimk/222612527/ YOU’RE DOING IT WRONG

Upload: chris-scott

Post on 17-May-2015

3.447 views

Category:

Technology


4 download

DESCRIPTION

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

TRANSCRIPT

Page 1: You're Doing it Wrong - WordCamp Orlando

Chris Scott - @chrisscott - slideshare.net/iamzedphoto by mimk http://www.flickr.com/photos/mimk/222612527/

YOU’RE DOING IT WRONG

Page 3: You're Doing it Wrong - WordCamp Orlando

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...

Page 4: You're Doing it Wrong - WordCamp Orlando

Wrong and Right

Page 5: You're Doing it Wrong - WordCamp Orlando

Not Upgrading

WRONG

Page 6: You're Doing it Wrong - WordCamp Orlando

Upgrading

RIGHT

Page 7: You're Doing it Wrong - WordCamp Orlando

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

Page 8: You're Doing it Wrong - WordCamp Orlando

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

Page 9: You're Doing it Wrong - WordCamp Orlando

Hard-Coding WordPress Paths

$cb_path = get_bloginfo('wpurl')."/wp-content/plugins/wp-codebox"; //URL to the plugin directory

WRONG

Page 10: You're Doing it Wrong - WordCamp Orlando

Use Constants or Helper Functions

$cb_path = plugins_url('', __FILE__); //URL to the plugin directory

RIGHT

Page 11: You're Doing it Wrong - WordCamp Orlando

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

Page 12: You're Doing it Wrong - WordCamp Orlando

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

Page 13: You're Doing it Wrong - WordCamp Orlando

Not Checking Indices or Object Properties

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

WRONG

Page 14: You're Doing it Wrong - WordCamp Orlando

Checking Indices/Properties

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

RIGHT

Page 15: You're Doing it Wrong - WordCamp Orlando

Not Using WP_DEBUG

WRONG

Page 16: You're Doing it Wrong - WordCamp Orlando

Define WP_DEBUG in wp-config.php

RIGHT

define('WP_DEBUG', true);

Page 17: You're Doing it Wrong - WordCamp Orlando

Using Globals Instead of Helper Functions/Classes

global $post;

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

WRONG

Page 18: You're Doing it Wrong - WordCamp Orlando

Use Helper Functions/Classes

$linkname = get_the_title();

RIGHT

Page 19: You're Doing it Wrong - WordCamp Orlando

Writing SQL

global $wpdb;

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

WRONG

Page 20: You're Doing it Wrong - WordCamp Orlando

Use $wpdb Methods

global $wpdb;

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

RIGHT

Page 21: You're Doing it Wrong - WordCamp Orlando

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

Page 22: You're Doing it Wrong - WordCamp Orlando

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

Page 23: You're Doing it Wrong - WordCamp Orlando

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

Page 24: You're Doing it Wrong - WordCamp Orlando

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

Page 25: You're Doing it Wrong - WordCamp Orlando

Not Contributing

WRONG

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

Page 26: You're Doing it Wrong - WordCamp Orlando

Contributing

RIGHT

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”