Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Your code stinks. WPCS can help.

276 views

Published on

WordPress coding standards exist for a reason. They provide a level of continuity among developers so that you can expect a certain level of quality and readability in code written for WordPress. WPCS is a set of rules for PHPCS (PHP Code Sniffer) that makes it super easy to comply with WordPress coding standards by showing you the areas of your code that do not comply. In this presentation at WordCamp San Diego, I covered setting up PHPCS with WPCS as well as other tools to help make your code beautiful.

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Your code stinks. WPCS can help.

  1. 1. Cory Webb WordCamp San Diego April 15, 2018 Your code stinks! WPCS can help. Your code stinks. WPCS can help. Cory Webb
  2. 2. Your code stinks. WPCS can help. Cory Webb Who is this guy? • Cory Webb • Senior Full-Stack Developer at Reaktiv Studios • Joomla guy turned WordPress guy • Author Beginning Joomla Web Site Development • Pitcher on my slow-pitch softball team
  3. 3. Your code stinks. WPCS can help. Cory Webb What’s he talking about? • Why your code stinks • WordPress Coding Standards • Why it matters • Using PHPCS + WPCS to make your code stink less
  4. 4. Your code stinks. WPCS can help. Cory Webb Why your code stinks • Code is ugly and difficult to read • No comments • Confusing or inconsistent naming conventions • Ignores internationalization • No escaping of output
  5. 5. Your code stinks. WPCS can help. Cory Webb Code is ugly and difficult to read
  6. 6. Your code stinks. WPCS can help. Cory Webb No comments
  7. 7. Your code stinks. WPCS can help. Cory Webb Confusing or inconsistent naming conventions
  8. 8. Your code stinks. WPCS can help. Cory Webb Ignores internationalization
  9. 9. Your code stinks. WPCS can help. Cory Webb No escape
  10. 10. Your code stinks. WPCS can help. Cory Webb WordPress Coding Standards • Single and double quotes • Indentation • Braces • PHP tags • Spaces • Naming Conventions • Yoda conditions • Readability over cleverness or brevity • Internationalization • Data Validation Complete List: https://make.wordpress.org/core/handbook/best-practices/coding-standards/php/
  11. 11. Your code stinks. WPCS can help. Cory Webb Single and Double Quotes
  12. 12. Your code stinks. WPCS can help. Cory Webb Indentation
  13. 13. Your code stinks. WPCS can help. Cory Webb Braces
  14. 14. Your code stinks. WPCS can help. Cory Webb PHP Tags
  15. 15. Your code stinks. WPCS can help. Cory Webb Spaces
  16. 16. Your code stinks. WPCS can help. Cory Webb Naming Conventions
  17. 17. Your code stinks. WPCS can help. Cory Webb Yoda Conditions
  18. 18. Your code stinks. WPCS can help. Cory Webb Readability Over Cleverness or Brevity
  19. 19. Your code stinks. WPCS can help. Cory Webb Internationalization
  20. 20. Your code stinks. WPCS can help. Cory Webb Data Validation
  21. 21. Your code stinks. WPCS can help. Cory Webb Why it matters
  22. 22. Your code stinks. WPCS can help. Cory Webb –Martin Fowler “Any fool can write code that a computer can understand. Good programmers write code that humans can understand.”
  23. 23. Your code stinks. WPCS can help. Cory Webb Why it matters • Readability: Write code for humans, not computers. • Consistency: If we all follow the same standards, it’s easier to collaborate • Quality: Coding standards force you to put more thought and care into your code, resulting in better quality.
  24. 24. Your code stinks. WPCS can help. Cory Webb PHPCS + WPCS
  25. 25. Your code stinks. WPCS can help. Cory Webb PHPCS • PHP_CodeSniffer • “Tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.”
 
 
 
 https://github.com/squizlabs/PHP_CodeSniffer
  26. 26. Your code stinks. WPCS can help. Cory Webb WPCS • WordPress Coding Standards • Set of rules (sniffs) for PHPCS to enforce WordPress coding standards
 
 
 
 https://github.com/WordPress-Coding-Standards/ WordPress-Coding-Standards
  27. 27. Your code stinks. WPCS can help. Cory Webb Demo • https://github.com/corywebb/stinky-code • Sublime Linter • http://www.sublimelinter.com • https://github.com/WordPress-Coding-Standards/ WordPress-Coding-Standards/wiki/Setting-up-WPCS- to-work-in-Sublime-Text
  28. 28. Twitter/Github: @corywebb Questions? Your code stinks. WPCS can help. Cory Webb

×