Skip to content

Latest commit

 

History

History
28 lines (19 loc) · 2.75 KB

coding-guidelines.md

File metadata and controls

28 lines (19 loc) · 2.75 KB

Coding Standards & Guidelines

These are some things to keep in mind when writing code for Jetpack plugin. Please follow them to speed up the review process and get your code merged faster.

Versions supported

  • Jetpack supports PHP 5.2, so to name two examples, don't use array notation like [] or the short ternary like expr1 ?: expr3: use always array() and the long ternary expr1 ? expr2: expr3.
  • Jetpack supports the WP current version and the immediate previous version. So if WP version is 4.6, Jetpack will support it, as well as 4.5. It's desirable that when Jetpack is installed in older versions, it doesn't fail in a severe way.
  • We support the latest two versions of all major browsers, except IE, where we currently only support 11 and Edge. (see Browse Happy for current latest versions).

General

  • Install PHP Code Sniffer Code Sniffer rules for WordPress Coding Standards. They will make it easier for you to notice any missing documentation or coding standards you should respect. Most IDEs display warnings and notices inside the editor, making it easy to inspect your code.
  • If coding a module, make sure you declare the module in the inline doc, like this. The same applies for filters or actions, as shown here.
  • Sanitize URLs, attributes, everything. WordPress.com VIP has this nice article about the topic.
  • Create unit tests if you can. If you're not familiar with Unit Testing, you can check this tutorial.

Widgets

  • Make them support Customizer's Selective Refresh. Here's an article about it.
  • Some Widgets ported from WordPress.com must only be registered if Jetpack is connected.
  • Add the jetpack_widget_name filter to the widget title as shown here.

Translations

  • Where it applies, make strings available for translation.
  • Instead of __, _e, _x and similar functions, use their safe versions esc_html__, esc_html_e, esc_html_x and others where possible.
  • Add the jetpack text domain to the translation functions.