Get insights on why coding standards are important, tips for improvement and what WordPress.org is doing to encourage cleaner code
To see on-demand webinar, register at: https://hs.wpengine.com/webinar-good2great-coding-standards-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
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' );
}
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
)
);
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
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