SlideShare a Scribd company logo
1 of 26
Download to read offline
YOU’RE DOING IT WRONG




Chris Scott - @chrisscott - slideshare.net/iamzed
             photo by mimk http://www.flickr.com/photos/mimk/222612527/
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
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...
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('mybanner') ?></li>

    ... rest of sidebar ...

  </ul>
</div>




               WRONG
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
Hard-Coding WordPress
           Paths
$cb_path = get_bloginfo('wpurl')."/wp-content/
plugins/wp-codebox"; //URL to the plugin directory




               WRONG
Use Constants or Helper
        Functions
$cb_path = plugins_url('', __FILE__);   //URL to the
plugin directory




                RIGHT
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
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
Not Checking Indices or
     Object Properties
if ($_GET['wp125action'] == "deactivate") {
  ...
}




               WRONG
Checking Indices/Properties

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




                RIGHT
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);




                WRONG
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);




                WRONG
Use $wpdb Methods

global $wpdb;

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




                 RIGHT
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
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
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
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
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
• Participate in Development
  • Planning, Testing, Bug Reporting and Fixing
• Say “Thanks”


                  RIGHT

More Related Content

What's hot

Short intro to JQuery and Modernizr
Short intro to JQuery and ModernizrShort intro to JQuery and Modernizr
Short intro to JQuery and Modernizr
Jussi Pohjolainen
 
jQtouch, Building Awesome Webapps
jQtouch, Building Awesome WebappsjQtouch, Building Awesome Webapps
jQtouch, Building Awesome Webapps
Home
 
Jqeury ajax plugins
Jqeury ajax pluginsJqeury ajax plugins
Jqeury ajax plugins
Inbal Geffen
 
2012.sandiego.wordcamp
2012.sandiego.wordcamp2012.sandiego.wordcamp
2012.sandiego.wordcamp
Brandon Dove
 
Auto tools
Auto toolsAuto tools
Auto tools
祺 周
 

What's hot (20)

Codegnitorppt
CodegnitorpptCodegnitorppt
Codegnitorppt
 
WordPress Theme Design and Development Workshop - Day 3
WordPress Theme Design and Development Workshop - Day 3WordPress Theme Design and Development Workshop - Day 3
WordPress Theme Design and Development Workshop - Day 3
 
Introduction to jQuery - Barcamp London 9
Introduction to jQuery - Barcamp London 9Introduction to jQuery - Barcamp London 9
Introduction to jQuery - Barcamp London 9
 
JQuery
JQueryJQuery
JQuery
 
Short intro to JQuery and Modernizr
Short intro to JQuery and ModernizrShort intro to JQuery and Modernizr
Short intro to JQuery and Modernizr
 
18.register login
18.register login18.register login
18.register login
 
jQtouch, Building Awesome Webapps
jQtouch, Building Awesome WebappsjQtouch, Building Awesome Webapps
jQtouch, Building Awesome Webapps
 
20110820 header new style
20110820 header new style20110820 header new style
20110820 header new style
 
JavaScript & AJAX in WordPress
JavaScript & AJAX in WordPressJavaScript & AJAX in WordPress
JavaScript & AJAX in WordPress
 
Owasp & php
Owasp & phpOwasp & php
Owasp & php
 
Angular JS blog tutorial
Angular JS blog tutorialAngular JS blog tutorial
Angular JS blog tutorial
 
iPhone Appleless Apps
iPhone Appleless AppsiPhone Appleless Apps
iPhone Appleless Apps
 
Webapps without the web
Webapps without the webWebapps without the web
Webapps without the web
 
Jqeury ajax plugins
Jqeury ajax pluginsJqeury ajax plugins
Jqeury ajax plugins
 
Clearance: Simple, complete Ruby web app authentication.
Clearance: Simple, complete Ruby web app authentication.Clearance: Simple, complete Ruby web app authentication.
Clearance: Simple, complete Ruby web app authentication.
 
WordPress Kitchen 2014 - Александр Стриха: Кеширование в WordPress
WordPress Kitchen 2014 - Александр Стриха: Кеширование в WordPress WordPress Kitchen 2014 - Александр Стриха: Кеширование в WordPress
WordPress Kitchen 2014 - Александр Стриха: Кеширование в WordPress
 
2012.sandiego.wordcamp
2012.sandiego.wordcamp2012.sandiego.wordcamp
2012.sandiego.wordcamp
 
Practical PHP by example Jan Leth-Kjaer
Practical PHP by example   Jan Leth-KjaerPractical PHP by example   Jan Leth-Kjaer
Practical PHP by example Jan Leth-Kjaer
 
Auto tools
Auto toolsAuto tools
Auto tools
 
Mojolicious
MojoliciousMojolicious
Mojolicious
 

Similar to You're Doing it Wrong - WordCamp Orlando

10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
arcware
 
Using shortcode in plugin development
Using shortcode in plugin developmentUsing shortcode in plugin development
Using shortcode in plugin development
gskhanal
 
What mom never told you about bundle configurations - Symfony Live Paris 2012
What mom never told you about bundle configurations - Symfony Live Paris 2012What mom never told you about bundle configurations - Symfony Live Paris 2012
What mom never told you about bundle configurations - Symfony Live Paris 2012
D
 

Similar to You're Doing it Wrong - WordCamp Orlando (20)

Becoming a better WordPress Developer
Becoming a better WordPress DeveloperBecoming a better WordPress Developer
Becoming a better WordPress Developer
 
Using Geeklog as a Web Application Framework
Using Geeklog as a Web Application FrameworkUsing Geeklog as a Web Application Framework
Using Geeklog as a Web Application Framework
 
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
 
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
 
[Bristol WordPress] Supercharging WordPress Development
[Bristol WordPress] Supercharging WordPress Development[Bristol WordPress] Supercharging WordPress Development
[Bristol WordPress] Supercharging WordPress Development
 
Add loop shortcode
Add loop shortcodeAdd loop shortcode
Add loop shortcode
 
QA for PHP projects
QA for PHP projectsQA for PHP projects
QA for PHP projects
 
Using shortcode in plugin development
Using shortcode in plugin developmentUsing shortcode in plugin development
Using shortcode in plugin development
 
Blog Hacks 2011
Blog Hacks 2011Blog Hacks 2011
Blog Hacks 2011
 
Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8
 
Virtual Madness @ Etsy
Virtual Madness @ EtsyVirtual Madness @ Etsy
Virtual Madness @ Etsy
 
Get AngularJS Started!
Get AngularJS Started!Get AngularJS Started!
Get AngularJS Started!
 
HirshHorn theme: how I created it
HirshHorn theme: how I created itHirshHorn theme: how I created it
HirshHorn theme: how I created it
 
WCLA12 JavaScript
WCLA12 JavaScriptWCLA12 JavaScript
WCLA12 JavaScript
 
Seven deadly theming sins
Seven deadly theming sinsSeven deadly theming sins
Seven deadly theming sins
 
Drupal Development
Drupal DevelopmentDrupal Development
Drupal Development
 
What mom never told you about bundle configurations - Symfony Live Paris 2012
What mom never told you about bundle configurations - Symfony Live Paris 2012What mom never told you about bundle configurations - Symfony Live Paris 2012
What mom never told you about bundle configurations - Symfony Live Paris 2012
 
Building iPhone Web Apps using "classic" Domino
Building iPhone Web Apps using "classic" DominoBuilding iPhone Web Apps using "classic" Domino
Building iPhone Web Apps using "classic" Domino
 
Yii Introduction
Yii IntroductionYii Introduction
Yii Introduction
 
AppForum 2014 Boost Hybrid App Performance
AppForum 2014 Boost Hybrid App PerformanceAppForum 2014 Boost Hybrid App Performance
AppForum 2014 Boost Hybrid App Performance
 

Recently uploaded

“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
Muhammad Subhan
 
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptxHarnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
FIDO Alliance
 

Recently uploaded (20)

Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
 
Design Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptxDesign Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptx
 
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
 
Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024
 
Portal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russePortal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russe
 
ERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage IntacctERP Contender Series: Acumatica vs. Sage Intacct
ERP Contender Series: Acumatica vs. Sage Intacct
 
Design and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data ScienceDesign and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data Science
 
JavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate GuideJavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate Guide
 
Top 10 CodeIgniter Development Companies
Top 10 CodeIgniter Development CompaniesTop 10 CodeIgniter Development Companies
Top 10 CodeIgniter Development Companies
 
Using IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & IrelandUsing IESVE for Room Loads Analysis - UK & Ireland
Using IESVE for Room Loads Analysis - UK & Ireland
 
Long journey of Ruby Standard library at RubyKaigi 2024
Long journey of Ruby Standard library at RubyKaigi 2024Long journey of Ruby Standard library at RubyKaigi 2024
Long journey of Ruby Standard library at RubyKaigi 2024
 
Introduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptxIntroduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptx
 
Collecting & Temporal Analysis of Behavioral Web Data - Tales From The Inside
Collecting & Temporal Analysis of Behavioral Web Data - Tales From The InsideCollecting & Temporal Analysis of Behavioral Web Data - Tales From The Inside
Collecting & Temporal Analysis of Behavioral Web Data - Tales From The Inside
 
2024 May Patch Tuesday
2024 May Patch Tuesday2024 May Patch Tuesday
2024 May Patch Tuesday
 
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
“Iamnobody89757” Understanding the Mysterious of Digital Identity.pdf
 
Overview of Hyperledger Foundation
Overview of Hyperledger FoundationOverview of Hyperledger Foundation
Overview of Hyperledger Foundation
 
Intro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджераIntro in Product Management - Коротко про професію продакт менеджера
Intro in Product Management - Коротко про професію продакт менеджера
 
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
 
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptxHarnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
 
State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!
 

You're Doing it Wrong - WordCamp Orlando

  • 1. YOU’RE DOING IT WRONG Chris Scott - @chrisscott - slideshare.net/iamzed photo by mimk http://www.flickr.com/photos/mimk/222612527/
  • 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. 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...
  • 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. 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. Hard-Coding WordPress Paths $cb_path = get_bloginfo('wpurl')."/wp-content/ plugins/wp-codebox"; //URL to the plugin directory WRONG
  • 10. Use Constants or Helper Functions $cb_path = plugins_url('', __FILE__); //URL to the plugin directory RIGHT
  • 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. 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. Not Checking Indices or Object Properties if ($_GET['wp125action'] == "deactivate") { ... } WRONG
  • 14. Checking Indices/Properties if (isset($_GET['wp125action']) && $_GET['wp125action'] == "deactivate") { ... } RIGHT
  • 16. Define WP_DEBUG in wp-config.php define('WP_DEBUG', true); RIGHT
  • 17. Using Globals Instead of Helper Functions/Classes global $post; $linkname = get_the_title($post->ID); WRONG
  • 18. Use Helper Functions/ Classes $linkname = get_the_title(); RIGHT
  • 19. Writing SQL global $wpdb; $wpdb->query("update ".$articles." set review = ". $rating." where post_id = ".$post_id); WRONG
  • 20. Use $wpdb Methods global $wpdb; $wpdb->update( $articles, array('review' => $rating), compact('post_id') ); RIGHT
  • 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. 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. 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. 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. Not Contributing photo by TaranRampersad http://www.flickr.com/photos/knowprose/2294744043/ WRONG
  • 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