WordPress Harrisburg Meetup - Best Practices

17
doing_it_right() with Wordpress Ryan Duff Harrisburg WordPress Meetup February 19th, 2013

Transcript of WordPress Harrisburg Meetup - Best Practices

Page 1: WordPress Harrisburg Meetup - Best Practices

doing_it_right() with Wordpress

Ryan DuffHarrisburg WordPress Meetup

February 19th, 2013

Page 2: WordPress Harrisburg Meetup - Best Practices

Why do it right

• Save yourself time

• Save others time

• Save your clients money

• Save everybody from headaches

Page 3: WordPress Harrisburg Meetup - Best Practices

Ways to do it right

• Learn to organize your code

•... document your code

• ... optimize your code

• Don’t reinvent the wheel

• Action Hooks and Filters

• Other very bad things to avoid

Page 4: WordPress Harrisburg Meetup - Best Practices

First things first

• Use the debug bar plugin

define(‘WP_DEBUG’, true);define(‘WP_DEBUG_DISPLAY, false);define(‘SAVEQUERIES’, true);

Page 5: WordPress Harrisburg Meetup - Best Practices

Organize your code

• What goes in a plugin?

• What goes in a theme?

• Utilize mu-plugins/

Page 6: WordPress Harrisburg Meetup - Best Practices

Organize your code

http://codex.wordpress.org/Template_Hierarchy

Page 7: WordPress Harrisburg Meetup - Best Practices

Document your code

/** * Simple and uniform HTTP request API. * * Standardizes the HTTP requests for WordPress. Handles cookies, gzip encoding and decoding, chunk * decoding, if HTTP 1.1 and various other difficult HTTP protocol implementations. * * @link http://trac.wordpress.org/ticket/4779 HTTP API Proposal * * @package WordPress * @subpackage HTTP * @since 2.7.0 */

Page 8: WordPress Harrisburg Meetup - Best Practices

Optimize your code

• Cache

• Get rid of rotten database queries

Page 9: WordPress Harrisburg Meetup - Best Practices

Optimize your code

set_transient( $transient, $value, $expiration );

get_transient( $transient );

delete_transient( $transient );

Page 10: WordPress Harrisburg Meetup - Best Practices

Optimize your code

• Make sure the code you’re expecting matches

• Use $wpdb class in the correct cases, WP_Query otherwise

• Sanitize everything http://codex.wordpress.org/Data_Validation

Page 11: WordPress Harrisburg Meetup - Best Practices

Don’t reinvent the wheel

• Clever code is not clever.

• Use built in APIs and methods

Page 12: WordPress Harrisburg Meetup - Best Practices

WordPress APIs

Page 13: WordPress Harrisburg Meetup - Best Practices

Action hooks and filters

• Hooks are places to DO things

• Filters are ways to CHANGE things

Page 14: WordPress Harrisburg Meetup - Best Practices

More things not to do

• Don’t downgrade jQuery

• Don’t create unnecessary settings

• Don’t forget to update

Page 15: WordPress Harrisburg Meetup - Best Practices

Secure code

• esc_html()

• esc_attr()

• esc_url()

• $wpdb->prepare()

http://codex.wordpress.org/Data_Validation

Page 16: WordPress Harrisburg Meetup - Best Practices

How to learn more

• Read the code and contribute http://core.trac.wordpress.org

• Ask questions in #wordpress on freenode

Page 17: WordPress Harrisburg Meetup - Best Practices

Questions?

Ryan DuffFusionized Technologyhttp://fusionized.com

@ryancduff