SlideShare a Scribd company logo
Jonathan Bossenger
Let’s Code
Learn.WordPress.org
WordPress Coding Standards
2
👋🏽
Welcome!
As you join, please let us know in the chat where
you’re joining us from, and what the weather’s like in
your part of the world…
Hello!
○ My name is Jonathan Bossenger
○ From Cape Town, South Africa
○ Developer educator at Automattic
○ Sponsored to work with the Training Team
○ jonathanbossenger.com
Learn.WordPress.org
WordPress Coding
Standards
Jonathan Bossenger
Announcements
○ A note on today’s presentation…
Announcements
○ Welcome, and thanks to Laura for co-hosting.
○ Please let me know if you can’t see this slide!
○ We are presenting in focus mode, but please feel free to enable your video.
○ You are welcome to ask questions.
○ You are welcome to post questions in the chat, or unmute to ask questions.
Announcements
○ The example code from today’s presentation
• https://github.com/jonathanbossenger/wp-learn-coding-
standards/releases/download/1.0.0/wp-learn-coding-standards.1.0.0.zip
• https://www.howtogeek.com/789559/how-to-stop-safari-from-automatically-
unzipping-downloaded-files-on-mac/
○ If I am going too fast, please let me know!
○ We will be posting this session to https://wordpress.tv/ afterwards
○ For more WordPress focused content please visit https://learn.wordpress.org/
Learning Outcomes
1. What are Coding Standards?
2. Coding Standards for WordPress
• HTML and CSS Coding Standards
⁃ Validating your HTML and CSS code
• PHP and JavaScript Coding Standards
⁃ Linting your PHP and JavaScript code
3. WordPress Code Examples Starter
Let’s code lint.
What are Coding Standards?
1. Wikipedia defines them as a set of guidelines for a specific programming language
that recommend programming style, practices, and methods for each aspect of a
program written in that language
2. Coding standards create a baseline for collaboration and review within various
aspects of an open source project and community
3. Coding standards help avoid common coding errors, improve the readability of
code, and simplify modification
What are Coding Standards?
1. If you are planning to contribute to WordPress core, you need to familiarize
yourself with these standards, as any code you submit will need to comply with
them.
2. While it is not strictly a requirement, it's also a good idea to follow these standards
when developing plugins and themes
3. It will make your code easier to read and understand, and will make it easier for
other developers to contribute to your code.
WordPress Coding Standards
https://developer.wordpress.org/coding-standards/
HTML and CSS Coding Standards:
○ https://developer.wordpress.org/coding-standards/wordpress-coding-standards/html/
○ https://developer.wordpress.org/coding-standards/wordpress-coding-standards/css/
These standards follow the World Wide Web Consortium (or W3C) standards for HTML
and CSS
○ https://www.w3.org/standards/webdesign/htmlcss
○ https://validator.w3.org/
○ https://jigsaw.w3.org/css-validator/
WordPress Coding Standards
https://developer.wordpress.org/coding-standards/
PHP and JavaScript Coding Standards:
○ https://developer.wordpress.org/coding-standards/wordpress-coding-standards/php/
○ https://developer.wordpress.org/coding-standards/wordpress-coding-standards/javascript/
These standards were extended from other style guides at the time, but how now been
formalised and are unique to the WordPress project.
Fortunately, there are some linting tools that the project has made available, to check
your code.
WordPress Code Linters
PHP
○ https://github.com/squizlabs/PHP_CodeSniffer
○ https://github.com/WordPress/WordPress-Coding-Standards
○ Requires https://getcomposer.org/
WordPress Code Linters
PHP - Composer package installation
○ composer require --dev dealerdirect/phpcodesniffer-composer-installer
○ composer require --dev squizlabs/php_codesniffer
○ composer require --dev wp-coding-standards/wpcs
WordPress Code Linters
PHP - phpcs.xml configuration
<?xml version="1.0"?>
<ruleset name="WordPress Coding Standards">
<rule ref="WordPress"/>
<arg name="extensions" value="php"/>
<file>.</file>
<!-- Exclude Vendor directory -->
<exclude-pattern>*/vendor/*</exclude-pattern>
<exclude-pattern>*/node_modules/*</exclude-pattern>
</ruleset>
WordPress Code Linters
PHP - run command
./vendor/bin/phpcs --standard=phpcs.xml
WordPress Code Linters
JavaScript
○ https://developer.wordpress.org/block-editor/reference-guides/packages/packages-
scripts/
○ Requires https://nodejs.org/en
WordPress Code Linters
JavaScript - npm package installation
○ npm init
○ npm install @wordpress/scripts --save-dev
WordPress Code Linters
JavaScript - package.json scripts
"scripts": {
"build": "wp-scripts build",
"check-engines": "wp-scripts check-engines",
"check-licenses": "wp-scripts check-licenses",
"format": "wp-scripts format",
"lint:css": "wp-scripts lint-style",
"lint:js": "wp-scripts lint-js",
"lint:md:docs": "wp-scripts lint-md-docs",
"lint:pkg-json": "wp-scripts lint-pkg-json",
"packages-update": "wp-scripts packages-update",
"plugin-zip": "wp-scripts plugin-zip",
"start": "wp-scripts start",
"test:e2e": "wp-scripts test-e2e",
"test:unit": "wp-scripts test-unit-js"
}
WordPress Code Linters
JavaScript - run command
npm run lint:js
WordPress Code Examples Starter
https://github.com/ryanwelcher/wordpress-project-template
Resources
○ https://github.com/jonathanbossenger/wp-learn-coding-standards/releases/download/1.0.0/wp-
learn-coding-standards.1.0.0.zip
○ https://en.wikipedia.org/wiki/Coding_conventions
○ https://developer.wordpress.org/coding-standards/
○ https://developer.wordpress.org/coding-standards/wordpress-coding-standards/html/
○ https://developer.wordpress.org/coding-standards/wordpress-coding-standards/css/
○ https://www.w3.org/standards/webdesign/htmlcss
○ https://validator.w3.org/
○ https://jigsaw.w3.org/css-validator/
Resources
○ https://github.com/squizlabs/PHP_CodeSniffer
○ https://github.com/WordPress/WordPress-Coding-Standards
○ https://getcomposer.org/
○ https://developer.wordpress.org/block-editor/reference-guides/packages/packages-scripts/
○ https://nodejs.org/en/download

More Related Content

PDF
Oteniendo una lista de blobs desde el blob storage
DOC
Les Poux de Mahomet
PPT
Infaq Fee Sabeelillah
PDF
Answers to Geographical allegations on the Quran
PDF
PPTX
Bar equipments powerpoint
PPTX
Surah az Zukhruf New PPT
Oteniendo una lista de blobs desde el blob storage
Les Poux de Mahomet
Infaq Fee Sabeelillah
Answers to Geographical allegations on the Quran
Bar equipments powerpoint
Surah az Zukhruf New PPT

What's hot (8)

RTF
Collection of durood sharief english, arabic translation and transliteration
PPTX
Hope in Islam-power point for MSM PRPFCON -PATHANAMTHITTA
DOCX
Types of coffee
PDF
FSMR - FIRE SAFETY MAINTENANCE REPORT FORM.pdf
PPTX
Surah Qaaf New PPT
PDF
Qasas un-nabiyeen volume 4 قصص النبيين الجلد الرابع
PPTX
Surah At-Tin
Collection of durood sharief english, arabic translation and transliteration
Hope in Islam-power point for MSM PRPFCON -PATHANAMTHITTA
Types of coffee
FSMR - FIRE SAFETY MAINTENANCE REPORT FORM.pdf
Surah Qaaf New PPT
Qasas un-nabiyeen volume 4 قصص النبيين الجلد الرابع
Surah At-Tin
Ad

Similar to WordPress Coding Standards (20)

PPTX
Global Styles Variations in Block Themes.pptx
PPTX
Let's code! Diving into theme.json
PPTX
Developing Blocks without React - Controls.pptx
PPTX
Let's code! Converting a Shortcode into a Block
PPTX
Let's code: developing WordPress User Roles and Capabilities
PPTX
Developing Blocks without React - Block Supports.pptx
PPTX
Using Block Patterns in your Block Theme.pptx
PPTX
Internationalisation in Block Themes.pptx
PPTX
Developing Blocks without React - Part 1
PPTX
Let's code: custom content & custom capabilities
PPTX
Creating a WordPress multisite network
PPTX
Debugging in WordPress
PPTX
Developing Blocks without React - Part 2.pptx
PPTX
Developing Blocks without React - Part 2
PPTX
Developing Blocks without React - Attributes.pptx
PPTX
Testing plugins for PHP 8
PPTX
WordPress Plugin Security
PPTX
WP REST API Authentication, custom fields and updating resources
PPTX
Using the WP REST API
PPTX
Let's code: WordPress multisite experiments
Global Styles Variations in Block Themes.pptx
Let's code! Diving into theme.json
Developing Blocks without React - Controls.pptx
Let's code! Converting a Shortcode into a Block
Let's code: developing WordPress User Roles and Capabilities
Developing Blocks without React - Block Supports.pptx
Using Block Patterns in your Block Theme.pptx
Internationalisation in Block Themes.pptx
Developing Blocks without React - Part 1
Let's code: custom content & custom capabilities
Creating a WordPress multisite network
Debugging in WordPress
Developing Blocks without React - Part 2.pptx
Developing Blocks without React - Part 2
Developing Blocks without React - Attributes.pptx
Testing plugins for PHP 8
WordPress Plugin Security
WP REST API Authentication, custom fields and updating resources
Using the WP REST API
Let's code: WordPress multisite experiments
Ad

More from Jonathan Bossenger (20)

PPTX
New WordPress Developer APIs The Interactivity API
PPTX
The WordPress HTML API
PPTX
The WordPress Create Block tool
PPTX
PHP compatibility testing with PHPCompatibilityWP
PPTX
Common WordPress APIs_ Settings API
PPTX
Common WordPress APIs - Options API
PPTX
Common WordPress APIs_ HTTP API.pptx
PPTX
Common WordPress APIs: Metadata
PPTX
What’s new for developers_ (August 2023).pptx
PPTX
Testing your plugins for PHP version compatibility
PPTX
Common WordPress APIs_ Global Variables
PPTX
Common WordPress APIs_ Internationalization
PPTX
Testing WordPress 6.3 - Developer edition
PPTX
Common WordPress APIs: Responsive Images
PPTX
Common WordPress APIs - Dashboard Widgets
PPTX
Custom Tables in WordPress
PPTX
The WordPress Database
PPTX
Managing a WordPress Multisite Network
PPTX
Introduction to WordPress Multisite Networks
PPTX
Developing for multisite
New WordPress Developer APIs The Interactivity API
The WordPress HTML API
The WordPress Create Block tool
PHP compatibility testing with PHPCompatibilityWP
Common WordPress APIs_ Settings API
Common WordPress APIs - Options API
Common WordPress APIs_ HTTP API.pptx
Common WordPress APIs: Metadata
What’s new for developers_ (August 2023).pptx
Testing your plugins for PHP version compatibility
Common WordPress APIs_ Global Variables
Common WordPress APIs_ Internationalization
Testing WordPress 6.3 - Developer edition
Common WordPress APIs: Responsive Images
Common WordPress APIs - Dashboard Widgets
Custom Tables in WordPress
The WordPress Database
Managing a WordPress Multisite Network
Introduction to WordPress Multisite Networks
Developing for multisite

Recently uploaded (20)

PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Empathic Computing: Creating Shared Understanding
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
MYSQL Presentation for SQL database connectivity
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Approach and Philosophy of On baking technology
PDF
Encapsulation theory and applications.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Machine learning based COVID-19 study performance prediction
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
Cloud computing and distributed systems.
Chapter 3 Spatial Domain Image Processing.pdf
NewMind AI Weekly Chronicles - August'25-Week II
Review of recent advances in non-invasive hemoglobin estimation
Empathic Computing: Creating Shared Understanding
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
MYSQL Presentation for SQL database connectivity
The AUB Centre for AI in Media Proposal.docx
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Approach and Philosophy of On baking technology
Encapsulation theory and applications.pdf
Unlocking AI with Model Context Protocol (MCP)
20250228 LYD VKU AI Blended-Learning.pptx
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
Machine learning based COVID-19 study performance prediction
Reach Out and Touch Someone: Haptics and Empathic Computing
Assigned Numbers - 2025 - Bluetooth® Document
Network Security Unit 5.pdf for BCA BBA.
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Cloud computing and distributed systems.

WordPress Coding Standards

  • 2. 2 👋🏽 Welcome! As you join, please let us know in the chat where you’re joining us from, and what the weather’s like in your part of the world… Hello! ○ My name is Jonathan Bossenger ○ From Cape Town, South Africa ○ Developer educator at Automattic ○ Sponsored to work with the Training Team ○ jonathanbossenger.com
  • 4. Announcements ○ A note on today’s presentation…
  • 5. Announcements ○ Welcome, and thanks to Laura for co-hosting. ○ Please let me know if you can’t see this slide! ○ We are presenting in focus mode, but please feel free to enable your video. ○ You are welcome to ask questions. ○ You are welcome to post questions in the chat, or unmute to ask questions.
  • 6. Announcements ○ The example code from today’s presentation • https://github.com/jonathanbossenger/wp-learn-coding- standards/releases/download/1.0.0/wp-learn-coding-standards.1.0.0.zip • https://www.howtogeek.com/789559/how-to-stop-safari-from-automatically- unzipping-downloaded-files-on-mac/ ○ If I am going too fast, please let me know! ○ We will be posting this session to https://wordpress.tv/ afterwards ○ For more WordPress focused content please visit https://learn.wordpress.org/
  • 7. Learning Outcomes 1. What are Coding Standards? 2. Coding Standards for WordPress • HTML and CSS Coding Standards ⁃ Validating your HTML and CSS code • PHP and JavaScript Coding Standards ⁃ Linting your PHP and JavaScript code 3. WordPress Code Examples Starter
  • 9. What are Coding Standards? 1. Wikipedia defines them as a set of guidelines for a specific programming language that recommend programming style, practices, and methods for each aspect of a program written in that language 2. Coding standards create a baseline for collaboration and review within various aspects of an open source project and community 3. Coding standards help avoid common coding errors, improve the readability of code, and simplify modification
  • 10. What are Coding Standards? 1. If you are planning to contribute to WordPress core, you need to familiarize yourself with these standards, as any code you submit will need to comply with them. 2. While it is not strictly a requirement, it's also a good idea to follow these standards when developing plugins and themes 3. It will make your code easier to read and understand, and will make it easier for other developers to contribute to your code.
  • 11. WordPress Coding Standards https://developer.wordpress.org/coding-standards/ HTML and CSS Coding Standards: ○ https://developer.wordpress.org/coding-standards/wordpress-coding-standards/html/ ○ https://developer.wordpress.org/coding-standards/wordpress-coding-standards/css/ These standards follow the World Wide Web Consortium (or W3C) standards for HTML and CSS ○ https://www.w3.org/standards/webdesign/htmlcss ○ https://validator.w3.org/ ○ https://jigsaw.w3.org/css-validator/
  • 12. WordPress Coding Standards https://developer.wordpress.org/coding-standards/ PHP and JavaScript Coding Standards: ○ https://developer.wordpress.org/coding-standards/wordpress-coding-standards/php/ ○ https://developer.wordpress.org/coding-standards/wordpress-coding-standards/javascript/ These standards were extended from other style guides at the time, but how now been formalised and are unique to the WordPress project. Fortunately, there are some linting tools that the project has made available, to check your code.
  • 13. WordPress Code Linters PHP ○ https://github.com/squizlabs/PHP_CodeSniffer ○ https://github.com/WordPress/WordPress-Coding-Standards ○ Requires https://getcomposer.org/
  • 14. WordPress Code Linters PHP - Composer package installation ○ composer require --dev dealerdirect/phpcodesniffer-composer-installer ○ composer require --dev squizlabs/php_codesniffer ○ composer require --dev wp-coding-standards/wpcs
  • 15. WordPress Code Linters PHP - phpcs.xml configuration <?xml version="1.0"?> <ruleset name="WordPress Coding Standards"> <rule ref="WordPress"/> <arg name="extensions" value="php"/> <file>.</file> <!-- Exclude Vendor directory --> <exclude-pattern>*/vendor/*</exclude-pattern> <exclude-pattern>*/node_modules/*</exclude-pattern> </ruleset>
  • 16. WordPress Code Linters PHP - run command ./vendor/bin/phpcs --standard=phpcs.xml
  • 17. WordPress Code Linters JavaScript ○ https://developer.wordpress.org/block-editor/reference-guides/packages/packages- scripts/ ○ Requires https://nodejs.org/en
  • 18. WordPress Code Linters JavaScript - npm package installation ○ npm init ○ npm install @wordpress/scripts --save-dev
  • 19. WordPress Code Linters JavaScript - package.json scripts "scripts": { "build": "wp-scripts build", "check-engines": "wp-scripts check-engines", "check-licenses": "wp-scripts check-licenses", "format": "wp-scripts format", "lint:css": "wp-scripts lint-style", "lint:js": "wp-scripts lint-js", "lint:md:docs": "wp-scripts lint-md-docs", "lint:pkg-json": "wp-scripts lint-pkg-json", "packages-update": "wp-scripts packages-update", "plugin-zip": "wp-scripts plugin-zip", "start": "wp-scripts start", "test:e2e": "wp-scripts test-e2e", "test:unit": "wp-scripts test-unit-js" }
  • 20. WordPress Code Linters JavaScript - run command npm run lint:js
  • 21. WordPress Code Examples Starter https://github.com/ryanwelcher/wordpress-project-template
  • 22. Resources ○ https://github.com/jonathanbossenger/wp-learn-coding-standards/releases/download/1.0.0/wp- learn-coding-standards.1.0.0.zip ○ https://en.wikipedia.org/wiki/Coding_conventions ○ https://developer.wordpress.org/coding-standards/ ○ https://developer.wordpress.org/coding-standards/wordpress-coding-standards/html/ ○ https://developer.wordpress.org/coding-standards/wordpress-coding-standards/css/ ○ https://www.w3.org/standards/webdesign/htmlcss ○ https://validator.w3.org/ ○ https://jigsaw.w3.org/css-validator/
  • 23. Resources ○ https://github.com/squizlabs/PHP_CodeSniffer ○ https://github.com/WordPress/WordPress-Coding-Standards ○ https://getcomposer.org/ ○ https://developer.wordpress.org/block-editor/reference-guides/packages/packages-scripts/ ○ https://nodejs.org/en/download

Editor's Notes

  • #2: TITLE SLIDE: Make a copy of this presentation to your Google Drive, and edit to replace with your details.