SlideShare ist ein Scribd-Unternehmen logo
1 von 45
Downloaden Sie, um offline zu lesen
#wpewebinar
February 28, 2018
#wpewebinar
#wpewebinar
CROP IMAGE
TO GRAY BOX
We’ll answer as many questions as we can after
the presentation
ASK QUESTIONS AS WE GO
Slides and recording will be
made available shortly after
the webinar
Use the “Questions” pane
throughout the webinar
#wpewebinar
WHAT YOU’LL LEARN:
● Why coding standards are important
● Common mistakes even good developers make
● Tips for becoming an even better developer
● Resources available to learn more
● What Tide is and what’s coming to WordPress.org
● Q&A
#wpewebinar
Director of Product & Innovation
XWP
Luke Carbis
● Film photography hobbyist
● Bullet Journal devotee
● Has lived in Rome and Jerusalem
(now in Brisbane)
Innovation Program Manager
WP Engine
Steven Word
● Makes Instrumental Hip-Hop
● Loves Hiking
● Craft Beer Enthusiast
Luke Carbis
From Good to Great
Coding Standards and WordPress
Scripts & Styles
Prefixing
Sanitising & Escaping
Formatting Standards
But… why?
If it ‘aint broke, why fix it?
— Terrible advice of unknown origin.
Wordpress
What’s wrong here?
WordPress
Capital P, dangit!
Why are these conventions so important, anyway?
● Prevent conflicts
Why are these conventions so important, anyway?
● Prevent conflicts
● Prevent loading unnecessary files
Why are these conventions so important, anyway?
● Prevent conflicts
● Prevent loading unnecessary files
● Readability
Why are these conventions so important, anyway?
● Prevent conflicts
● Prevent loading unnecessary files
● Readability
● Maintainability
Why are these conventions so important, anyway?
● Prevent conflicts
● Prevent loading unnecessary files
● Readability
● Maintainability
● Prevent conflicts with other plugins
● Automatic minification
● Dependencies loaded
● Include all WordPress functionality
● Handling security nonces correctly
● Prevent SQL injection attacks
● Encourage community support
Better, Faster, and Stronger.
Best practices exist to make your site
Learn to write code you can be proud of.
Scripts & Styles
Do not…
add html directly into your theme:
or
or even
<link href="style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
var foo = 'bar';
</script>
<script src="//code.jquery.com/jquery-latest.min.js"></script>
This is better:
In your plugin, or in your functions.php file, use the wp_enqueue_script and wp_enqueue_style
functions:
wp_register_script( 'select2', get_template_directory_uri() . 'ui/select2/select2.m
wp_register_style( 'select2', get_template_directory_uri() . 'ui/select2/select2.cs
wp_enqueue_script( 'select2' );
wp_enqueue_style( 'select2' );
wp_enqueue_script( 'my-script', 'ui/main.js', array( 'jquery', 'select2', 'heartbea
or
This is even better:
Wrap your wp_enqueue_script and _style calls in a function, which fires at the right time.
add_action( 'wp_enqueue_scripts', 'my_plugin_enqueue_scripts' ) );
my_plugin_enqueue_scripts() {
wp_register_script( 'select2', get_template_directory_uri() . 'ui/select2/selec
wp_register_style( 'select2', get_template_directory_uri() . 'ui/select2/select
wp_enqueue_script( 'select2' );
wp_enqueue_style( 'select2' );
}
Prefixing
Do not name your functions
custom_meta_box()
or
save_options()
This is better:
my_plugin_custom_meta_box()
or
my_plugin_save_options()
This is even better
class Akismet {
function init() {
// …
}
function save() {
// …
}
}
$GLOBALS['akismet'] = new Akismet;
Sanitising & Escaping
Don’t do this:
echo $permalink;
Do this:
echo esc_url( $permalink );
Escape Outputs
Don’t do this:
Do this:
$foo = $_GET[ 'foo' ];
$bar = $_GET[ 'bar' ];
echo '<p id="' . $foo . '">' . $bar . '</p>';
echo wp_kses_post(
sprintf(
'<p id="%s">%s</p>',
esc_attr( $_GET[ 'foo' ] ),
esc_html( $_GET[ 'bar' ] )
)
);
Escape Outputs
Don’t do this:
Do this:
Sanitise Inputs
$title = $_POST['title'];
update_post_meta( $post->ID, 'title', $title );
$title = sanitize_text_field( $_POST['title'] );
update_post_meta( $post->ID, 'title', $title );
Don’t do this:
Do this:
Sanitise Inputs
$secondary_email = $_POST[ 'email' ];
update_user_meta( $user_id, 'secondary_email', $secondary_email );
$secondary_email = sanitize_email( $_POST[ 'email' ] );
update_user_meta( $user_id, 'secondary_email', $secondary_email );
Sanitise with $wpdb
This is one way of getting all posts attributed to a particular author:
global $wpdb;
$post_author = $_POST['author_id'];
$results = $wpdb->get_results(
"SELECT ID, post_title
FROM $wpdb->posts
WHERE post_status = 'publish' AND post_author = $post_author"
);
Sanitise with $wpdb
This is a safer way of doing the same thing:
global $wpdb;
$post_author = intval( $_POST['author_id'] );
$results = $wpdb->get_results(
$wpdb->prepare(
"SELECT ID, post_title
FROM $wpdb->posts
WHERE post_status = %s AND post_author = %d",
'publish',
$post_author
)
);
Formatting Standards
Indentation
Use real tabs and not spaces.
Yoda Conditions
if ( true === $the_force ) {
$victorious = you_will( $be );
}
This is clever:
Clever Code
isset( $var ) || $var = some_function();
But this is readable:
if ( ! isset( $var ) ) {
$var = some_function();
}
Always use braces, even where not required.
Not this:
Braces
if ( condition() )
return true;
if ( condition() ) {
return true;
}
This:
Scripts & Styles
Prefixing
Sanitising & Escaping
Formatting Standards
Tide
Tide is a series of automated tests run against every plugin and
theme in the WordPress directory.
Tide currently tests for Coding Standards and PHP Compatibility.
https://make.wordpress.org/tide
PHP CodeSniffer
with WordPress Coding Standards rules
https://github.com/WordPress-Coding-Standards/
Thank You
xwp.co
#wpewebinar
Slides and recording will be made available
shortly after the webinar
QUESTIONS AND ANSWERS
#wpewebinar
RESOURCES
Tide: A Path to Better Code Across the WordPress Ecosystem
Webinar Links, Snippets and Resources
WordPress Coding Standards Handbook - WordPress.org
Tide
#wpewebinar
CROP IMAGE
TO GRAY BOX
NEXT UP...
Register Now:
http://wpeng.in/
ml-wp
Wednesday, Mar 7
11:00 a.m. CST,
12:00 p.m. EST,
9:00 a.m. PST,
17:00 UTC/GMT
#wpewebinar
HELP US IMPROVE
#wpewebinar
THANK YOU
#wpewebinar
@wpengine

Weitere ähnliche Inhalte

Mehr von WP Engine

Best Practices for Site Deployment With Local.pdf
Best Practices for Site Deployment With Local.pdfBest Practices for Site Deployment With Local.pdf
Best Practices for Site Deployment With Local.pdfWP Engine
 
Site Monitoring: The Intersection of Product, UX Design & Research .pdf
Site Monitoring: The Intersection of Product, UX Design & Research .pdfSite Monitoring: The Intersection of Product, UX Design & Research .pdf
Site Monitoring: The Intersection of Product, UX Design & Research .pdfWP Engine
 
Front End: Building Future-Proof eCommerce Sites.pdf
Front End: Building Future-Proof eCommerce Sites.pdfFront End: Building Future-Proof eCommerce Sites.pdf
Front End: Building Future-Proof eCommerce Sites.pdfWP Engine
 
Gutenberg and Headless WordPress.pdf
Gutenberg and Headless WordPress.pdfGutenberg and Headless WordPress.pdf
Gutenberg and Headless WordPress.pdfWP Engine
 
Blueprints and Other Local Features for Agencies.pdf
Blueprints and Other Local Features for Agencies.pdfBlueprints and Other Local Features for Agencies.pdf
Blueprints and Other Local Features for Agencies.pdfWP Engine
 
Modern Theming & The Future of WordPress- Working with Full Site Editing and ...
Modern Theming & The Future of WordPress- Working with Full Site Editing and ...Modern Theming & The Future of WordPress- Working with Full Site Editing and ...
Modern Theming & The Future of WordPress- Working with Full Site Editing and ...WP Engine
 
6 WooCommerce Dev Tricks for Building Fast eCommerce Websites.pdf
6 WooCommerce Dev Tricks for Building Fast eCommerce Websites.pdf6 WooCommerce Dev Tricks for Building Fast eCommerce Websites.pdf
6 WooCommerce Dev Tricks for Building Fast eCommerce Websites.pdfWP Engine
 
Headless 101 for WordPress Developers.pdf
Headless 101 for WordPress Developers.pdfHeadless 101 for WordPress Developers.pdf
Headless 101 for WordPress Developers.pdfWP Engine
 
Be the Change: The Future of WordPress with WP Engine's Developer Relations Team
Be the Change: The Future of WordPress with WP Engine's Developer Relations TeamBe the Change: The Future of WordPress with WP Engine's Developer Relations Team
Be the Change: The Future of WordPress with WP Engine's Developer Relations TeamWP Engine
 
An Atlas of Atlas.pdf
An Atlas of Atlas.pdfAn Atlas of Atlas.pdf
An Atlas of Atlas.pdfWP Engine
 
2022 – Year of the WordPress Developer.pdf
2022 – Year of the WordPress Developer.pdf2022 – Year of the WordPress Developer.pdf
2022 – Year of the WordPress Developer.pdfWP Engine
 
Using WooCommerce to Scale Your Store
Using WooCommerce to Scale Your StoreUsing WooCommerce to Scale Your Store
Using WooCommerce to Scale Your StoreWP Engine
 
Growing Your WooCommerce Store Without Knowing Code
Growing Your WooCommerce Store Without Knowing CodeGrowing Your WooCommerce Store Without Knowing Code
Growing Your WooCommerce Store Without Knowing CodeWP Engine
 
Between a Block & a Hard Place
Between a Block & a Hard PlaceBetween a Block & a Hard Place
Between a Block & a Hard PlaceWP Engine
 
Under the Hood with Headless WordPress and the Google Cloud Platform
Under the Hood with Headless WordPress and the Google Cloud PlatformUnder the Hood with Headless WordPress and the Google Cloud Platform
Under the Hood with Headless WordPress and the Google Cloud PlatformWP Engine
 
Going From Project To Project To Monthly Recurring Revenue with Growth Suite
Going From Project To Project To Monthly Recurring Revenue with Growth Suite Going From Project To Project To Monthly Recurring Revenue with Growth Suite
Going From Project To Project To Monthly Recurring Revenue with Growth Suite WP Engine
 
Why Protection From DDoS Attacks is Critical For Your Business
Why Protection From DDoS Attacks is Critical For Your BusinessWhy Protection From DDoS Attacks is Critical For Your Business
Why Protection From DDoS Attacks is Critical For Your BusinessWP Engine
 
Top Insights for Your WordPress Site
Top Insights for Your WordPress SiteTop Insights for Your WordPress Site
Top Insights for Your WordPress SiteWP Engine
 
Growing Your WooCommerce Store Without Knowing Code
Growing Your WooCommerce Store Without Knowing CodeGrowing Your WooCommerce Store Without Knowing Code
Growing Your WooCommerce Store Without Knowing CodeWP Engine
 
How To Work Faster & More Profitably With Client Site Starter Templates
How To Work Faster & More Profitably With Client Site Starter TemplatesHow To Work Faster & More Profitably With Client Site Starter Templates
How To Work Faster & More Profitably With Client Site Starter TemplatesWP Engine
 

Mehr von WP Engine (20)

Best Practices for Site Deployment With Local.pdf
Best Practices for Site Deployment With Local.pdfBest Practices for Site Deployment With Local.pdf
Best Practices for Site Deployment With Local.pdf
 
Site Monitoring: The Intersection of Product, UX Design & Research .pdf
Site Monitoring: The Intersection of Product, UX Design & Research .pdfSite Monitoring: The Intersection of Product, UX Design & Research .pdf
Site Monitoring: The Intersection of Product, UX Design & Research .pdf
 
Front End: Building Future-Proof eCommerce Sites.pdf
Front End: Building Future-Proof eCommerce Sites.pdfFront End: Building Future-Proof eCommerce Sites.pdf
Front End: Building Future-Proof eCommerce Sites.pdf
 
Gutenberg and Headless WordPress.pdf
Gutenberg and Headless WordPress.pdfGutenberg and Headless WordPress.pdf
Gutenberg and Headless WordPress.pdf
 
Blueprints and Other Local Features for Agencies.pdf
Blueprints and Other Local Features for Agencies.pdfBlueprints and Other Local Features for Agencies.pdf
Blueprints and Other Local Features for Agencies.pdf
 
Modern Theming & The Future of WordPress- Working with Full Site Editing and ...
Modern Theming & The Future of WordPress- Working with Full Site Editing and ...Modern Theming & The Future of WordPress- Working with Full Site Editing and ...
Modern Theming & The Future of WordPress- Working with Full Site Editing and ...
 
6 WooCommerce Dev Tricks for Building Fast eCommerce Websites.pdf
6 WooCommerce Dev Tricks for Building Fast eCommerce Websites.pdf6 WooCommerce Dev Tricks for Building Fast eCommerce Websites.pdf
6 WooCommerce Dev Tricks for Building Fast eCommerce Websites.pdf
 
Headless 101 for WordPress Developers.pdf
Headless 101 for WordPress Developers.pdfHeadless 101 for WordPress Developers.pdf
Headless 101 for WordPress Developers.pdf
 
Be the Change: The Future of WordPress with WP Engine's Developer Relations Team
Be the Change: The Future of WordPress with WP Engine's Developer Relations TeamBe the Change: The Future of WordPress with WP Engine's Developer Relations Team
Be the Change: The Future of WordPress with WP Engine's Developer Relations Team
 
An Atlas of Atlas.pdf
An Atlas of Atlas.pdfAn Atlas of Atlas.pdf
An Atlas of Atlas.pdf
 
2022 – Year of the WordPress Developer.pdf
2022 – Year of the WordPress Developer.pdf2022 – Year of the WordPress Developer.pdf
2022 – Year of the WordPress Developer.pdf
 
Using WooCommerce to Scale Your Store
Using WooCommerce to Scale Your StoreUsing WooCommerce to Scale Your Store
Using WooCommerce to Scale Your Store
 
Growing Your WooCommerce Store Without Knowing Code
Growing Your WooCommerce Store Without Knowing CodeGrowing Your WooCommerce Store Without Knowing Code
Growing Your WooCommerce Store Without Knowing Code
 
Between a Block & a Hard Place
Between a Block & a Hard PlaceBetween a Block & a Hard Place
Between a Block & a Hard Place
 
Under the Hood with Headless WordPress and the Google Cloud Platform
Under the Hood with Headless WordPress and the Google Cloud PlatformUnder the Hood with Headless WordPress and the Google Cloud Platform
Under the Hood with Headless WordPress and the Google Cloud Platform
 
Going From Project To Project To Monthly Recurring Revenue with Growth Suite
Going From Project To Project To Monthly Recurring Revenue with Growth Suite Going From Project To Project To Monthly Recurring Revenue with Growth Suite
Going From Project To Project To Monthly Recurring Revenue with Growth Suite
 
Why Protection From DDoS Attacks is Critical For Your Business
Why Protection From DDoS Attacks is Critical For Your BusinessWhy Protection From DDoS Attacks is Critical For Your Business
Why Protection From DDoS Attacks is Critical For Your Business
 
Top Insights for Your WordPress Site
Top Insights for Your WordPress SiteTop Insights for Your WordPress Site
Top Insights for Your WordPress Site
 
Growing Your WooCommerce Store Without Knowing Code
Growing Your WooCommerce Store Without Knowing CodeGrowing Your WooCommerce Store Without Knowing Code
Growing Your WooCommerce Store Without Knowing Code
 
How To Work Faster & More Profitably With Client Site Starter Templates
How To Work Faster & More Profitably With Client Site Starter TemplatesHow To Work Faster & More Profitably With Client Site Starter Templates
How To Work Faster & More Profitably With Client Site Starter Templates
 

Kürzlich hochgeladen

Gram Darshan PPT cyber rural in villages of india
Gram Darshan PPT cyber rural  in villages of indiaGram Darshan PPT cyber rural  in villages of india
Gram Darshan PPT cyber rural in villages of indiaimessage0108
 
VIP Kolkata Call Girl Salt Lake 👉 8250192130 Available With Room
VIP Kolkata Call Girl Salt Lake 👉 8250192130  Available With RoomVIP Kolkata Call Girl Salt Lake 👉 8250192130  Available With Room
VIP Kolkata Call Girl Salt Lake 👉 8250192130 Available With Roomishabajaj13
 
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...Sheetaleventcompany
 
Russian Call Girls in Kolkata Ishita 🤌 8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Ishita 🤌  8250192130 🚀 Vip Call Girls KolkataRussian Call Girls in Kolkata Ishita 🤌  8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Ishita 🤌 8250192130 🚀 Vip Call Girls Kolkataanamikaraghav4
 
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine ServiceHot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Servicesexy call girls service in goa
 
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark WebGDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark WebJames Anderson
 
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Russian Call Girls in Kolkata Samaira 🤌 8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Samaira 🤌  8250192130 🚀 Vip Call Girls KolkataRussian Call Girls in Kolkata Samaira 🤌  8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Samaira 🤌 8250192130 🚀 Vip Call Girls Kolkataanamikaraghav4
 
How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)Damian Radcliffe
 
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...APNIC
 
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779Delhi Call girls
 
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
VIP Call Girls Kolkata Ananya 🤌 8250192130 🚀 Vip Call Girls Kolkata
VIP Call Girls Kolkata Ananya 🤌  8250192130 🚀 Vip Call Girls KolkataVIP Call Girls Kolkata Ananya 🤌  8250192130 🚀 Vip Call Girls Kolkata
VIP Call Girls Kolkata Ananya 🤌 8250192130 🚀 Vip Call Girls Kolkataanamikaraghav4
 
VIP Kolkata Call Girls Salt Lake 8250192130 Available With Room
VIP Kolkata Call Girls Salt Lake 8250192130 Available With RoomVIP Kolkata Call Girls Salt Lake 8250192130 Available With Room
VIP Kolkata Call Girls Salt Lake 8250192130 Available With Roomgirls4nights
 
Call Girls Dubai Prolapsed O525547819 Call Girls In Dubai Princes$
Call Girls Dubai Prolapsed O525547819 Call Girls In Dubai Princes$Call Girls Dubai Prolapsed O525547819 Call Girls In Dubai Princes$
Call Girls Dubai Prolapsed O525547819 Call Girls In Dubai Princes$kojalkojal131
 
On Starlink, presented by Geoff Huston at NZNOG 2024
On Starlink, presented by Geoff Huston at NZNOG 2024On Starlink, presented by Geoff Huston at NZNOG 2024
On Starlink, presented by Geoff Huston at NZNOG 2024APNIC
 
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...SofiyaSharma5
 

Kürzlich hochgeladen (20)

Gram Darshan PPT cyber rural in villages of india
Gram Darshan PPT cyber rural  in villages of indiaGram Darshan PPT cyber rural  in villages of india
Gram Darshan PPT cyber rural in villages of india
 
VIP Kolkata Call Girl Salt Lake 👉 8250192130 Available With Room
VIP Kolkata Call Girl Salt Lake 👉 8250192130  Available With RoomVIP Kolkata Call Girl Salt Lake 👉 8250192130  Available With Room
VIP Kolkata Call Girl Salt Lake 👉 8250192130 Available With Room
 
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
Call Girls Service Chandigarh Lucky ❤️ 7710465962 Independent Call Girls In C...
 
Russian Call Girls in Kolkata Ishita 🤌 8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Ishita 🤌  8250192130 🚀 Vip Call Girls KolkataRussian Call Girls in Kolkata Ishita 🤌  8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Ishita 🤌 8250192130 🚀 Vip Call Girls Kolkata
 
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine ServiceHot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
 
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark WebGDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
GDG Cloud Southlake 32: Kyle Hettinger: Demystifying the Dark Web
 
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Sukhdev Vihar Delhi 💯Call Us 🔝8264348440🔝
 
Russian Call Girls in Kolkata Samaira 🤌 8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Samaira 🤌  8250192130 🚀 Vip Call Girls KolkataRussian Call Girls in Kolkata Samaira 🤌  8250192130 🚀 Vip Call Girls Kolkata
Russian Call Girls in Kolkata Samaira 🤌 8250192130 🚀 Vip Call Girls Kolkata
 
How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)
 
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
'Future Evolution of the Internet' delivered by Geoff Huston at Everything Op...
 
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
 
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
 
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Defence Colony Delhi 💯Call Us 🔝8264348440🔝
 
Call Girls In South Ex 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICE
Call Girls In South Ex 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICECall Girls In South Ex 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICE
Call Girls In South Ex 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SERVICE
 
VIP Call Girls Kolkata Ananya 🤌 8250192130 🚀 Vip Call Girls Kolkata
VIP Call Girls Kolkata Ananya 🤌  8250192130 🚀 Vip Call Girls KolkataVIP Call Girls Kolkata Ananya 🤌  8250192130 🚀 Vip Call Girls Kolkata
VIP Call Girls Kolkata Ananya 🤌 8250192130 🚀 Vip Call Girls Kolkata
 
VIP Kolkata Call Girls Salt Lake 8250192130 Available With Room
VIP Kolkata Call Girls Salt Lake 8250192130 Available With RoomVIP Kolkata Call Girls Salt Lake 8250192130 Available With Room
VIP Kolkata Call Girls Salt Lake 8250192130 Available With Room
 
Call Girls Dubai Prolapsed O525547819 Call Girls In Dubai Princes$
Call Girls Dubai Prolapsed O525547819 Call Girls In Dubai Princes$Call Girls Dubai Prolapsed O525547819 Call Girls In Dubai Princes$
Call Girls Dubai Prolapsed O525547819 Call Girls In Dubai Princes$
 
On Starlink, presented by Geoff Huston at NZNOG 2024
On Starlink, presented by Geoff Huston at NZNOG 2024On Starlink, presented by Geoff Huston at NZNOG 2024
On Starlink, presented by Geoff Huston at NZNOG 2024
 
Rohini Sector 6 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 6 Call Girls Delhi 9999965857 @Sabina Saikh No AdvanceRohini Sector 6 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 6 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
 
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
Low Rate Young Call Girls in Sector 63 Mamura Noida ✔️☆9289244007✔️☆ Female E...
 

Webinar - From Good to Great: Coding Standards and WordPress

  • 2. #wpewebinar CROP IMAGE TO GRAY BOX We’ll answer as many questions as we can after the presentation ASK QUESTIONS AS WE GO Slides and recording will be made available shortly after the webinar Use the “Questions” pane throughout the webinar
  • 3. #wpewebinar WHAT YOU’LL LEARN: ● Why coding standards are important ● Common mistakes even good developers make ● Tips for becoming an even better developer ● Resources available to learn more ● What Tide is and what’s coming to WordPress.org ● Q&A
  • 4. #wpewebinar Director of Product & Innovation XWP Luke Carbis ● Film photography hobbyist ● Bullet Journal devotee ● Has lived in Rome and Jerusalem (now in Brisbane) Innovation Program Manager WP Engine Steven Word ● Makes Instrumental Hip-Hop ● Loves Hiking ● Craft Beer Enthusiast
  • 5. Luke Carbis From Good to Great Coding Standards and WordPress
  • 6. Scripts & Styles Prefixing Sanitising & Escaping Formatting Standards
  • 7. But… why? If it ‘aint broke, why fix it? — Terrible advice of unknown origin.
  • 10. Why are these conventions so important, anyway? ● Prevent conflicts
  • 11. Why are these conventions so important, anyway? ● Prevent conflicts ● Prevent loading unnecessary files
  • 12. Why are these conventions so important, anyway? ● Prevent conflicts ● Prevent loading unnecessary files ● Readability
  • 13. Why are these conventions so important, anyway? ● Prevent conflicts ● Prevent loading unnecessary files ● Readability ● Maintainability
  • 14. Why are these conventions so important, anyway? ● Prevent conflicts ● Prevent loading unnecessary files ● Readability ● Maintainability ● Prevent conflicts with other plugins ● Automatic minification ● Dependencies loaded ● Include all WordPress functionality ● Handling security nonces correctly ● Prevent SQL injection attacks ● Encourage community support
  • 15. Better, Faster, and Stronger. Best practices exist to make your site
  • 16. Learn to write code you can be proud of.
  • 18. Do not… add html directly into your theme: or or even <link href="style.css" rel="stylesheet" type="text/css" /> <script type="text/javascript"> var foo = 'bar'; </script> <script src="//code.jquery.com/jquery-latest.min.js"></script>
  • 19. This is better: In your plugin, or in your functions.php file, use the wp_enqueue_script and wp_enqueue_style functions: wp_register_script( 'select2', get_template_directory_uri() . 'ui/select2/select2.m wp_register_style( 'select2', get_template_directory_uri() . 'ui/select2/select2.cs wp_enqueue_script( 'select2' ); wp_enqueue_style( 'select2' ); wp_enqueue_script( 'my-script', 'ui/main.js', array( 'jquery', 'select2', 'heartbea or
  • 20. This is even better: Wrap your wp_enqueue_script and _style calls in a function, which fires at the right time. add_action( 'wp_enqueue_scripts', 'my_plugin_enqueue_scripts' ) ); my_plugin_enqueue_scripts() { wp_register_script( 'select2', get_template_directory_uri() . 'ui/select2/selec wp_register_style( 'select2', get_template_directory_uri() . 'ui/select2/select wp_enqueue_script( 'select2' ); wp_enqueue_style( 'select2' ); }
  • 22. Do not name your functions custom_meta_box() or save_options()
  • 24. This is even better class Akismet { function init() { // … } function save() { // … } } $GLOBALS['akismet'] = new Akismet;
  • 26. Don’t do this: echo $permalink; Do this: echo esc_url( $permalink ); Escape Outputs
  • 27. Don’t do this: Do this: $foo = $_GET[ 'foo' ]; $bar = $_GET[ 'bar' ]; echo '<p id="' . $foo . '">' . $bar . '</p>'; echo wp_kses_post( sprintf( '<p id="%s">%s</p>', esc_attr( $_GET[ 'foo' ] ), esc_html( $_GET[ 'bar' ] ) ) ); Escape Outputs
  • 28. Don’t do this: Do this: Sanitise Inputs $title = $_POST['title']; update_post_meta( $post->ID, 'title', $title ); $title = sanitize_text_field( $_POST['title'] ); update_post_meta( $post->ID, 'title', $title );
  • 29. Don’t do this: Do this: Sanitise Inputs $secondary_email = $_POST[ 'email' ]; update_user_meta( $user_id, 'secondary_email', $secondary_email ); $secondary_email = sanitize_email( $_POST[ 'email' ] ); update_user_meta( $user_id, 'secondary_email', $secondary_email );
  • 30. Sanitise with $wpdb This is one way of getting all posts attributed to a particular author: global $wpdb; $post_author = $_POST['author_id']; $results = $wpdb->get_results( "SELECT ID, post_title FROM $wpdb->posts WHERE post_status = 'publish' AND post_author = $post_author" );
  • 31. Sanitise with $wpdb This is a safer way of doing the same thing: global $wpdb; $post_author = intval( $_POST['author_id'] ); $results = $wpdb->get_results( $wpdb->prepare( "SELECT ID, post_title FROM $wpdb->posts WHERE post_status = %s AND post_author = %d", 'publish', $post_author ) );
  • 33. Indentation Use real tabs and not spaces.
  • 34. Yoda Conditions if ( true === $the_force ) { $victorious = you_will( $be ); }
  • 35. This is clever: Clever Code isset( $var ) || $var = some_function(); But this is readable: if ( ! isset( $var ) ) { $var = some_function(); }
  • 36. Always use braces, even where not required. Not this: Braces if ( condition() ) return true; if ( condition() ) { return true; } This:
  • 37. Scripts & Styles Prefixing Sanitising & Escaping Formatting Standards
  • 38. Tide Tide is a series of automated tests run against every plugin and theme in the WordPress directory. Tide currently tests for Coding Standards and PHP Compatibility. https://make.wordpress.org/tide
  • 39. PHP CodeSniffer with WordPress Coding Standards rules https://github.com/WordPress-Coding-Standards/
  • 41. #wpewebinar Slides and recording will be made available shortly after the webinar QUESTIONS AND ANSWERS
  • 42. #wpewebinar RESOURCES Tide: A Path to Better Code Across the WordPress Ecosystem Webinar Links, Snippets and Resources WordPress Coding Standards Handbook - WordPress.org Tide
  • 43. #wpewebinar CROP IMAGE TO GRAY BOX NEXT UP... Register Now: http://wpeng.in/ ml-wp Wednesday, Mar 7 11:00 a.m. CST, 12:00 p.m. EST, 9:00 a.m. PST, 17:00 UTC/GMT