SlideShare une entreprise Scribd logo
Writing Code That Scales 
by Dave Jesch 
LA WordCamp - September 6, 2014
Write a Plugin Popularity Unrecognizable Code 
© 2014 SpectrOMtech.com. All Rights Reserved.
Scalability: Think Big, Focus Small. 
© 2014 SpectrOMtech.com. All Rights Reserved.
Warning: 
There will be code. 
© 2014 SpectrOMtech.com. All Rights Reserved.
Follow Slides: 
http://SpectrOMTech.com/presentations/wcla2014/ 
© 2014 SpectrOMtech.com. All Rights Reserved.
Dave Jesch, Lifetime Geek & CTO @ .com 
Scalability 
➔Custom Plugins 
➔Web Architecture 
➔Everything eCommerce 
© 2014 SpectrOMtech.com. All Rights Reserved.
Procedural Object Oriented 
(est. 1800’s) (est. 1990’s) 
© 2014 SpectrOMtech.com. All Rights Reserved.
Big Take-Away: 
Only call in the code you need. 
© 2014 SpectrOMtech.com. All Rights Reserved.
Today’s Goals: 
1. Best Practices 
2. Code Organization 
3. Code Techniques 
© 2014 SpectrOMtech.com. All Rights Reserved.
1. Best Practices 
© 2014 SpectrOMtech.com. All Rights Reserved.
Coding Standards 
● WordPress Coding Standards 
http://codex.wordpress.org/WordPress_Coding_Standards 
o Indentation 
o Placement of Braces 
o Class / Function / Variable Naming 
© 2014 SpectrOMtech.com. All Rights Reserved.
Data Handling 
● Validate All Input 
http://codex.wordpress.org/Data_Validation 
● Escape Output 
● Escape Data in SQL Queries 
http://codex.wordpress.org/Class_Reference/wpdb#Protect_Queries_Agai 
nst_SQL_Injection_Attacks 
© 2014 SpectrOMtech.com. All Rights Reserved.
2. Code Organization 
© 2014 SpectrOMtech.com. All Rights Reserved.
Separate Code into Logical Areas 
1. Admin Only 
2. Front-end Only 
3. Common 
© 2014 SpectrOMtech.com. All Rights Reserved.
Sample Organization 
● Main Plugin File plugin_directory/my_plugin.php 
● Admin Code 
plugin_directory/include/admin.php 
© 2014 SpectrOMtech.com. All Rights Reserved. 
● Front-end code 
plugin_directory/include/frontend.php 
● Common Code 
plugin_directory/include/some_code.php 
plugin_directory/include/more_code.php 
● Assets 
plugin_directory/assets/css/plugin.css 
plugin_directory/assets/js/plugin.js
Minimize Code Usage 
● Test for Front-end vs. Admin page request 
● Register scripts/styles; don’t enqueue until you need to 
● Separate out install/uninstall code 
● Separate out Cron code 
© 2014 SpectrOMtech.com. All Rights Reserved.
Determining Page Request 
● is_admin() 
● if (defined('DOING_AJAX') && DOING_AJAX) 
● if (defined('DOING_CRON') && DOING_CRON) 
● Understand WordPress’ Initialization Sequence 
http://codex.wordpress.org/Plugin_API/Action_Reference 
© 2014 SpectrOMtech.com. All Rights Reserved.
3. Code Techniques 
© 2014 SpectrOMtech.com. All Rights Reserved.
Sample Techniques (1 of 8) 
© 2014 SpectrOMtech.com. All Rights Reserved. 
In main plugin file: 
define('PLUGIN_FILE', __FILE__); 
define('PLUGIN_DIR', plugin_dir_path(PLUGIN_FILE)); 
define('PLUGIN_INCLUDE', PLUGIN_DIR . 'include/'); 
define('PLUGIN_ASSETS', PLUGIN_DIR . 'assets/'); 
define('PLUGIN_ASSETS_URL', plugin_dir_url(PLUGIN_FILE) . 'assets/' 
define('PLUGIN_VERSION', '1.0');
Sample Techniques (2 of 8) 
Check for Plugin Activation: 
register_activation_hook(PLUGIN_FILE, 'plugin_activation'); 
function plugin_activation() 
{ 
require_once(PLUGIN_INCLUDE . 'activate.php'); 
© 2014 SpectrOMtech.com. All Rights Reserved. 
}
Sample Techniques (3 of 8) 
Load code appropriate for page request: 
if (defined(DOING_CRON) && DOING_CRON) 
require_once(PLUGIN_INCLUDE . 'cron_code.php'); 
else if (is_admin()) 
require_once(PLUGIN_INCLUDE . 'admin.php'); 
© 2014 SpectrOMtech.com. All Rights Reserved. 
else 
require_once(PLUGIN_INCLUDE . 'frontend.php');
Sample Techniques (4 of 8) 
admin.php: 
add_action('admin_init', 'plugin_initialize'); 
function plugin_initialize() 
{ 
add_menu_page('title', 'menu title', 'Administrator', 'plugin-slug', 
'plugin_menu_page'); 
© 2014 SpectrOMtech.com. All Rights Reserved. 
} 
function plugin_menu_page() 
{ 
include(PLUGIN_INCLUDE . 'plugin_page_contents.php'); 
} 
include(PLUGIN_INCLUDE . 'some_code.php');
Sample Techniques (5 of 8) 
frontend.php: 
add_action('wp_enqueue_scripts', 'plugin_register_script') 
function plugin_register_script() 
{ 
wp_register_script('plugin_javascript', PLUGIN_ASSETS . 'js/javascript.js', 
array('jquery'), PLUGIN_VERSION, TRUE); 
} 
add_shortcode('sample_shortcode', 'plugin_shortcode') 
function plugin_shortcode($attr) 
{ 
wp_enqueue_script('plugin_javascript'); 
return ('<img src="' . PLUGIN_ASSETS_URL . 
'images/plugin_image.png" width="16" height="16" />'); 
© 2014 SpectrOMtech.com. All Rights Reserved. 
} 
include(PLUGIN_INCLUDE . 'some_code.php');
Sample Techniques (6 of 8) 
© 2014 SpectrOMtech.com. All Rights Reserved. 
some_code.php: 
add_action('widget_init', 'plugin_register_widgets') 
function plugin_register_widgets() 
{ 
include(PLUGIN_INCLUDE . 'widget.php'); 
register_widget('PluginWidget'); 
}
Sample Techniques (7 of 8) 
widget.php: 
class PluginWidget extends WP_Widget 
{ 
public function widget() 
{ 
// display widget contents 
} 
public function form() 
{ 
include(PLUGIN_INCLUDE . 'widget_form.php'); 
} 
public function update() 
{ 
include(PLUGIN_INCLUDE . 'widget_update.php'); 
© 2014 SpectrOMtech.com. All Rights Reserved. 
} 
}
Sample Techniques (8 of 8) 
Use Transients When Appropriate: 
// get data from transient 
if (false === ($menu = get_transient('main_nav_menu'))) { 
// nothing in transient, generate menu 
$args = array(..., 'echo' => 0); 
$menu = wp_nav_menu($args); 
// save data from menu in transient 
set_transient('main_nav_menu', $menu, 86400); 
© 2014 SpectrOMtech.com. All Rights Reserved. 
} 
echo $menu;
Only call in the code you need. 
© 2014 SpectrOMtech.com. All Rights Reserved.
Scalability Achieved! 
1. Organize Your Code 
2. Load Only What’s Needed 
3. Use Your Actions 
4. Always Learn More 
© 2014 SpectrOMtech.com. All Rights Reserved.
Learning more about... 
OOPin 
Connect with us at Hello@SpectrOMTech.com 
Live as if you were to die tomorrow. Learn as if you were to live forever. ~ Mahatma Gandhi 
© 2014 SpectrOMtech.com. All Rights Reserved.
More References 
PHP Optimization Presentation OC WordCamp: 
http://wordpress.tv/2014/06/26/dave-jesch-php-optimization-getting-the-most-out- 
of-your-php-code/ 
http://www.slideshare.net/djesch/php-optimization-35545593 
© 2014 SpectrOMtech.com. All Rights Reserved.

Contenu connexe

Tendances

Design Patterns every Android developer should know
Design Patterns every Android developer should knowDesign Patterns every Android developer should know
Design Patterns every Android developer should know
muratcanbur
 
Javascript Security - Three main methods of defending your MEAN stack
Javascript Security - Three main methods of defending your MEAN stackJavascript Security - Three main methods of defending your MEAN stack
Javascript Security - Three main methods of defending your MEAN stack
Ran Bar-Zik
 
Night Watch with QA
Night Watch with QANight Watch with QA
Night Watch with QA
Carsten Sandtner
 
Automatic constraints as a team maturity accelerator for startups
Automatic constraints as a team maturity accelerator for startupsAutomatic constraints as a team maturity accelerator for startups
Automatic constraints as a team maturity accelerator for startups
François-Guillaume Ribreau
 
Unit testing @ WordPress Meetup Tilburg 7 januari 2014
Unit testing @ WordPress Meetup Tilburg 7 januari 2014Unit testing @ WordPress Meetup Tilburg 7 januari 2014
Unit testing @ WordPress Meetup Tilburg 7 januari 2014
Barry Kooij
 
How Testing Changed My Life
How Testing Changed My LifeHow Testing Changed My Life
How Testing Changed My Life
Nikolay Bachiyski
 
html5 & phonegap
html5 & phonegaphtml5 & phonegap
html5 & phonegap
Caesar Chi
 
Testing nightwatch, by David Torroija
Testing nightwatch, by David TorroijaTesting nightwatch, by David Torroija
Testing nightwatch, by David Torroija
David Torroija
 
How QCLean Works? Introduction to Browser Extensions
How QCLean Works? Introduction to Browser ExtensionsHow QCLean Works? Introduction to Browser Extensions
How QCLean Works? Introduction to Browser Extensions
Qing-Cheng Li
 
Aprende, contribuye, y surfea Cloud Native Java - GuateJUG 2021
Aprende, contribuye, y surfea Cloud Native Java - GuateJUG 2021Aprende, contribuye, y surfea Cloud Native Java - GuateJUG 2021
Aprende, contribuye, y surfea Cloud Native Java - GuateJUG 2021
César Hernández
 
Morden F2E Education - Think of Progressive Web Apps
Morden F2E Education - Think of Progressive Web AppsMorden F2E Education - Think of Progressive Web Apps
Morden F2E Education - Think of Progressive Web Apps
Caesar Chi
 

Tendances (11)

Design Patterns every Android developer should know
Design Patterns every Android developer should knowDesign Patterns every Android developer should know
Design Patterns every Android developer should know
 
Javascript Security - Three main methods of defending your MEAN stack
Javascript Security - Three main methods of defending your MEAN stackJavascript Security - Three main methods of defending your MEAN stack
Javascript Security - Three main methods of defending your MEAN stack
 
Night Watch with QA
Night Watch with QANight Watch with QA
Night Watch with QA
 
Automatic constraints as a team maturity accelerator for startups
Automatic constraints as a team maturity accelerator for startupsAutomatic constraints as a team maturity accelerator for startups
Automatic constraints as a team maturity accelerator for startups
 
Unit testing @ WordPress Meetup Tilburg 7 januari 2014
Unit testing @ WordPress Meetup Tilburg 7 januari 2014Unit testing @ WordPress Meetup Tilburg 7 januari 2014
Unit testing @ WordPress Meetup Tilburg 7 januari 2014
 
How Testing Changed My Life
How Testing Changed My LifeHow Testing Changed My Life
How Testing Changed My Life
 
html5 & phonegap
html5 & phonegaphtml5 & phonegap
html5 & phonegap
 
Testing nightwatch, by David Torroija
Testing nightwatch, by David TorroijaTesting nightwatch, by David Torroija
Testing nightwatch, by David Torroija
 
How QCLean Works? Introduction to Browser Extensions
How QCLean Works? Introduction to Browser ExtensionsHow QCLean Works? Introduction to Browser Extensions
How QCLean Works? Introduction to Browser Extensions
 
Aprende, contribuye, y surfea Cloud Native Java - GuateJUG 2021
Aprende, contribuye, y surfea Cloud Native Java - GuateJUG 2021Aprende, contribuye, y surfea Cloud Native Java - GuateJUG 2021
Aprende, contribuye, y surfea Cloud Native Java - GuateJUG 2021
 
Morden F2E Education - Think of Progressive Web Apps
Morden F2E Education - Think of Progressive Web AppsMorden F2E Education - Think of Progressive Web Apps
Morden F2E Education - Think of Progressive Web Apps
 

Similaire à WordCamp LA 2014- Writing Code that Scales

Building and managing applications fast for IBM i
Building and managing applications fast for IBM iBuilding and managing applications fast for IBM i
Building and managing applications fast for IBM i
Zend by Rogue Wave Software
 
Write your first WordPress plugin
Write your first WordPress pluginWrite your first WordPress plugin
Write your first WordPress plugin
Anthony Montalbano
 
PHP QA Tools
PHP QA ToolsPHP QA Tools
PHP QA Tools
rjsmelo
 
Introduction to Client Side Dev in SharePoint Workshop
Introduction to Client Side Dev in SharePoint WorkshopIntroduction to Client Side Dev in SharePoint Workshop
Introduction to Client Side Dev in SharePoint Workshop
Mark Rackley
 
Pyramid Deployment and Maintenance
Pyramid Deployment and MaintenancePyramid Deployment and Maintenance
Pyramid Deployment and Maintenance
Jazkarta, Inc.
 
Sst hackathon express
Sst hackathon expressSst hackathon express
Sst hackathon express
Aeshan Wijetunge
 
Programmable infrastructure with FlyScript
Programmable infrastructure with FlyScriptProgrammable infrastructure with FlyScript
Programmable infrastructure with FlyScript
Riverbed Technology
 
Pyramid deployment
Pyramid deploymentPyramid deployment
Pyramid deployment
Carlos de la Guardia
 
WordPress Plugin Development 201
WordPress Plugin Development 201WordPress Plugin Development 201
WordPress Plugin Development 201
ylefebvre
 
React django
React djangoReact django
React django
Heber Silva
 
Django Tutorial | Django Web Development With Python | Django Training and Ce...
Django Tutorial | Django Web Development With Python | Django Training and Ce...Django Tutorial | Django Web Development With Python | Django Training and Ce...
Django Tutorial | Django Web Development With Python | Django Training and Ce...
Edureka!
 
Android Jump Start
Android Jump StartAndroid Jump Start
Android Jump Start
Haim Michael
 
API Services: Building State-of-the-Art APIs
API Services: Building State-of-the-Art APIsAPI Services: Building State-of-the-Art APIs
API Services: Building State-of-the-Art APIs
Apigee | Google Cloud
 
Joomla! Day Chicago 2011 Presentation - Steven Pignataro
Joomla! Day Chicago 2011 Presentation - Steven PignataroJoomla! Day Chicago 2011 Presentation - Steven Pignataro
Joomla! Day Chicago 2011 Presentation - Steven Pignataro
Steven Pignataro
 
Webinar: Extend The Power of The ForgeRock Identity Platform Through Scripting
Webinar: Extend The Power of The ForgeRock Identity Platform Through ScriptingWebinar: Extend The Power of The ForgeRock Identity Platform Through Scripting
Webinar: Extend The Power of The ForgeRock Identity Platform Through Scripting
ForgeRock
 
Introduction to Using PHP & MVC Frameworks
Introduction to Using PHP & MVC FrameworksIntroduction to Using PHP & MVC Frameworks
Introduction to Using PHP & MVC Frameworks
Gerald Krishnan
 
Avoid the Vendor Lock-in Trap (with App Deployment)
Avoid the Vendor Lock-in Trap (with App Deployment)Avoid the Vendor Lock-in Trap (with App Deployment)
Avoid the Vendor Lock-in Trap (with App Deployment)
Peter Bittner
 
Benefit of CodeIgniter php framework
Benefit of CodeIgniter php frameworkBenefit of CodeIgniter php framework
Benefit of CodeIgniter php framework
Bo-Yi Wu
 
Introduction phonegap
Introduction phonegapIntroduction phonegap
Introduction phonegap
Rakesh Jha
 
Advanced programing in phonegap
Advanced programing in phonegapAdvanced programing in phonegap
Advanced programing in phonegap
Rakesh Jha
 

Similaire à WordCamp LA 2014- Writing Code that Scales (20)

Building and managing applications fast for IBM i
Building and managing applications fast for IBM iBuilding and managing applications fast for IBM i
Building and managing applications fast for IBM i
 
Write your first WordPress plugin
Write your first WordPress pluginWrite your first WordPress plugin
Write your first WordPress plugin
 
PHP QA Tools
PHP QA ToolsPHP QA Tools
PHP QA Tools
 
Introduction to Client Side Dev in SharePoint Workshop
Introduction to Client Side Dev in SharePoint WorkshopIntroduction to Client Side Dev in SharePoint Workshop
Introduction to Client Side Dev in SharePoint Workshop
 
Pyramid Deployment and Maintenance
Pyramid Deployment and MaintenancePyramid Deployment and Maintenance
Pyramid Deployment and Maintenance
 
Sst hackathon express
Sst hackathon expressSst hackathon express
Sst hackathon express
 
Programmable infrastructure with FlyScript
Programmable infrastructure with FlyScriptProgrammable infrastructure with FlyScript
Programmable infrastructure with FlyScript
 
Pyramid deployment
Pyramid deploymentPyramid deployment
Pyramid deployment
 
WordPress Plugin Development 201
WordPress Plugin Development 201WordPress Plugin Development 201
WordPress Plugin Development 201
 
React django
React djangoReact django
React django
 
Django Tutorial | Django Web Development With Python | Django Training and Ce...
Django Tutorial | Django Web Development With Python | Django Training and Ce...Django Tutorial | Django Web Development With Python | Django Training and Ce...
Django Tutorial | Django Web Development With Python | Django Training and Ce...
 
Android Jump Start
Android Jump StartAndroid Jump Start
Android Jump Start
 
API Services: Building State-of-the-Art APIs
API Services: Building State-of-the-Art APIsAPI Services: Building State-of-the-Art APIs
API Services: Building State-of-the-Art APIs
 
Joomla! Day Chicago 2011 Presentation - Steven Pignataro
Joomla! Day Chicago 2011 Presentation - Steven PignataroJoomla! Day Chicago 2011 Presentation - Steven Pignataro
Joomla! Day Chicago 2011 Presentation - Steven Pignataro
 
Webinar: Extend The Power of The ForgeRock Identity Platform Through Scripting
Webinar: Extend The Power of The ForgeRock Identity Platform Through ScriptingWebinar: Extend The Power of The ForgeRock Identity Platform Through Scripting
Webinar: Extend The Power of The ForgeRock Identity Platform Through Scripting
 
Introduction to Using PHP & MVC Frameworks
Introduction to Using PHP & MVC FrameworksIntroduction to Using PHP & MVC Frameworks
Introduction to Using PHP & MVC Frameworks
 
Avoid the Vendor Lock-in Trap (with App Deployment)
Avoid the Vendor Lock-in Trap (with App Deployment)Avoid the Vendor Lock-in Trap (with App Deployment)
Avoid the Vendor Lock-in Trap (with App Deployment)
 
Benefit of CodeIgniter php framework
Benefit of CodeIgniter php frameworkBenefit of CodeIgniter php framework
Benefit of CodeIgniter php framework
 
Introduction phonegap
Introduction phonegapIntroduction phonegap
Introduction phonegap
 
Advanced programing in phonegap
Advanced programing in phonegapAdvanced programing in phonegap
Advanced programing in phonegap
 

Dernier

Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
shyamraj55
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
SitimaJohn
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
Postman
 
Webinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data WarehouseWebinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data Warehouse
Federico Razzoli
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
Zilliz
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
Mariano Tinti
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Jeffrey Haguewood
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
Jakub Marek
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
Chart Kalyan
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Wask
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
Daiki Mogmet Ito
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Speck&Tech
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
Edge AI and Vision Alliance
 

Dernier (20)

Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with SlackLet's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
Let's Integrate MuleSoft RPA, COMPOSER, APM with AWS IDP along with Slack
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
 
Webinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data WarehouseWebinar: Designing a schema for a Data Warehouse
Webinar: Designing a schema for a Data Warehouse
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
Cosa hanno in comune un mattoncino Lego e la backdoor XZ?
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
 

WordCamp LA 2014- Writing Code that Scales

  • 1. Writing Code That Scales by Dave Jesch LA WordCamp - September 6, 2014
  • 2. Write a Plugin Popularity Unrecognizable Code © 2014 SpectrOMtech.com. All Rights Reserved.
  • 3. Scalability: Think Big, Focus Small. © 2014 SpectrOMtech.com. All Rights Reserved.
  • 4. Warning: There will be code. © 2014 SpectrOMtech.com. All Rights Reserved.
  • 5. Follow Slides: http://SpectrOMTech.com/presentations/wcla2014/ © 2014 SpectrOMtech.com. All Rights Reserved.
  • 6. Dave Jesch, Lifetime Geek & CTO @ .com Scalability ➔Custom Plugins ➔Web Architecture ➔Everything eCommerce © 2014 SpectrOMtech.com. All Rights Reserved.
  • 7. Procedural Object Oriented (est. 1800’s) (est. 1990’s) © 2014 SpectrOMtech.com. All Rights Reserved.
  • 8. Big Take-Away: Only call in the code you need. © 2014 SpectrOMtech.com. All Rights Reserved.
  • 9. Today’s Goals: 1. Best Practices 2. Code Organization 3. Code Techniques © 2014 SpectrOMtech.com. All Rights Reserved.
  • 10. 1. Best Practices © 2014 SpectrOMtech.com. All Rights Reserved.
  • 11. Coding Standards ● WordPress Coding Standards http://codex.wordpress.org/WordPress_Coding_Standards o Indentation o Placement of Braces o Class / Function / Variable Naming © 2014 SpectrOMtech.com. All Rights Reserved.
  • 12. Data Handling ● Validate All Input http://codex.wordpress.org/Data_Validation ● Escape Output ● Escape Data in SQL Queries http://codex.wordpress.org/Class_Reference/wpdb#Protect_Queries_Agai nst_SQL_Injection_Attacks © 2014 SpectrOMtech.com. All Rights Reserved.
  • 13. 2. Code Organization © 2014 SpectrOMtech.com. All Rights Reserved.
  • 14. Separate Code into Logical Areas 1. Admin Only 2. Front-end Only 3. Common © 2014 SpectrOMtech.com. All Rights Reserved.
  • 15. Sample Organization ● Main Plugin File plugin_directory/my_plugin.php ● Admin Code plugin_directory/include/admin.php © 2014 SpectrOMtech.com. All Rights Reserved. ● Front-end code plugin_directory/include/frontend.php ● Common Code plugin_directory/include/some_code.php plugin_directory/include/more_code.php ● Assets plugin_directory/assets/css/plugin.css plugin_directory/assets/js/plugin.js
  • 16. Minimize Code Usage ● Test for Front-end vs. Admin page request ● Register scripts/styles; don’t enqueue until you need to ● Separate out install/uninstall code ● Separate out Cron code © 2014 SpectrOMtech.com. All Rights Reserved.
  • 17. Determining Page Request ● is_admin() ● if (defined('DOING_AJAX') && DOING_AJAX) ● if (defined('DOING_CRON') && DOING_CRON) ● Understand WordPress’ Initialization Sequence http://codex.wordpress.org/Plugin_API/Action_Reference © 2014 SpectrOMtech.com. All Rights Reserved.
  • 18. 3. Code Techniques © 2014 SpectrOMtech.com. All Rights Reserved.
  • 19. Sample Techniques (1 of 8) © 2014 SpectrOMtech.com. All Rights Reserved. In main plugin file: define('PLUGIN_FILE', __FILE__); define('PLUGIN_DIR', plugin_dir_path(PLUGIN_FILE)); define('PLUGIN_INCLUDE', PLUGIN_DIR . 'include/'); define('PLUGIN_ASSETS', PLUGIN_DIR . 'assets/'); define('PLUGIN_ASSETS_URL', plugin_dir_url(PLUGIN_FILE) . 'assets/' define('PLUGIN_VERSION', '1.0');
  • 20. Sample Techniques (2 of 8) Check for Plugin Activation: register_activation_hook(PLUGIN_FILE, 'plugin_activation'); function plugin_activation() { require_once(PLUGIN_INCLUDE . 'activate.php'); © 2014 SpectrOMtech.com. All Rights Reserved. }
  • 21. Sample Techniques (3 of 8) Load code appropriate for page request: if (defined(DOING_CRON) && DOING_CRON) require_once(PLUGIN_INCLUDE . 'cron_code.php'); else if (is_admin()) require_once(PLUGIN_INCLUDE . 'admin.php'); © 2014 SpectrOMtech.com. All Rights Reserved. else require_once(PLUGIN_INCLUDE . 'frontend.php');
  • 22. Sample Techniques (4 of 8) admin.php: add_action('admin_init', 'plugin_initialize'); function plugin_initialize() { add_menu_page('title', 'menu title', 'Administrator', 'plugin-slug', 'plugin_menu_page'); © 2014 SpectrOMtech.com. All Rights Reserved. } function plugin_menu_page() { include(PLUGIN_INCLUDE . 'plugin_page_contents.php'); } include(PLUGIN_INCLUDE . 'some_code.php');
  • 23. Sample Techniques (5 of 8) frontend.php: add_action('wp_enqueue_scripts', 'plugin_register_script') function plugin_register_script() { wp_register_script('plugin_javascript', PLUGIN_ASSETS . 'js/javascript.js', array('jquery'), PLUGIN_VERSION, TRUE); } add_shortcode('sample_shortcode', 'plugin_shortcode') function plugin_shortcode($attr) { wp_enqueue_script('plugin_javascript'); return ('<img src="' . PLUGIN_ASSETS_URL . 'images/plugin_image.png" width="16" height="16" />'); © 2014 SpectrOMtech.com. All Rights Reserved. } include(PLUGIN_INCLUDE . 'some_code.php');
  • 24. Sample Techniques (6 of 8) © 2014 SpectrOMtech.com. All Rights Reserved. some_code.php: add_action('widget_init', 'plugin_register_widgets') function plugin_register_widgets() { include(PLUGIN_INCLUDE . 'widget.php'); register_widget('PluginWidget'); }
  • 25. Sample Techniques (7 of 8) widget.php: class PluginWidget extends WP_Widget { public function widget() { // display widget contents } public function form() { include(PLUGIN_INCLUDE . 'widget_form.php'); } public function update() { include(PLUGIN_INCLUDE . 'widget_update.php'); © 2014 SpectrOMtech.com. All Rights Reserved. } }
  • 26. Sample Techniques (8 of 8) Use Transients When Appropriate: // get data from transient if (false === ($menu = get_transient('main_nav_menu'))) { // nothing in transient, generate menu $args = array(..., 'echo' => 0); $menu = wp_nav_menu($args); // save data from menu in transient set_transient('main_nav_menu', $menu, 86400); © 2014 SpectrOMtech.com. All Rights Reserved. } echo $menu;
  • 27. Only call in the code you need. © 2014 SpectrOMtech.com. All Rights Reserved.
  • 28. Scalability Achieved! 1. Organize Your Code 2. Load Only What’s Needed 3. Use Your Actions 4. Always Learn More © 2014 SpectrOMtech.com. All Rights Reserved.
  • 29. Learning more about... OOPin Connect with us at Hello@SpectrOMTech.com Live as if you were to die tomorrow. Learn as if you were to live forever. ~ Mahatma Gandhi © 2014 SpectrOMtech.com. All Rights Reserved.
  • 30. More References PHP Optimization Presentation OC WordCamp: http://wordpress.tv/2014/06/26/dave-jesch-php-optimization-getting-the-most-out- of-your-php-code/ http://www.slideshare.net/djesch/php-optimization-35545593 © 2014 SpectrOMtech.com. All Rights Reserved.