Best Practices and Coding Standards

Best Practices and Coding Standards

1. No “cowboy coding”

All code and design changes are carried out on a testing server first before implementing on a live website. CSS to be clearly marked up with commented sections and table of contents.

  1. Use the client’s staging server.
  2. If the client does not have a staging server, clone the client’s website on the PENNInk Productions VPS as a transferrable install.
  3. If the site is too large to clone, use the PENNInk Productions VPS to create a transferable install, then just drop in client’s theme and plugins to test.

2. Themes

List of Approved Themes

All website themes must be Genesis child themes or Dynamik skins.

3. Plugins

List of Approved Plugins*

Please seek approval before adding a plugin that is not on this list. (*We will add to and grow this list.)

Never modify a plugin directly. Use functions.php in the theme or create a custom plugin. 

4. Custom Coding

We adhere to WordPress best practices broadly defined in the WordPress Codex:

Additionally:

  • All code should be compatible with the latest version of WordPress.
  • Follow the WordPress Coding Standards.
  • Data must be validated and sanitised on input and escaped on output.
  • Avoid direct calls to PHP scripts in your theme and do not try to load the WordPress environment on your own.
  • Ensure code will be both backward-compatible and future-proof using the WordPress Core APIs.
  • Encapsulate all code within a theme and plugins
    • Do not scatter scripts or other assets in other locations.
  • Use standard WordPress theme development practices.
    • Avoid overriding the native theming engine with a third party engine (e.g. Mustache or Smarty) or an unusual framework.
  • Avoid modifying the server side page rendering based on visitor or other one-off properties for unauthenticated visitors.
    • Imperative in environments with page caching enabled.
  • Avoid interacting with cookies on the server side.
    • Client side interaction (JavaScript) is fine.
  • Avoid direct interaction with database tables (SQL queries).
    • Strongly avoid scripts that alter the database structure by, for example, adding or altering database fields, and creating new tables.
  • Clean up after yourself.
    • Remove unused files and directories and any unused code fragments or debugging comments.
  • Adhere to a consistent coding style.

Under no circumstances should you ever edit WordPress core files or plugin files directly.

If you need to modify a plugin, hook from the theme’s functions.php or create a custom plugin.

5. Database

Avoid direct interaction with database tables (SQL queries)

  • In reality, 9 out of 10 times, the same result can be accomplished by using an official WordPress function or API, which often include sophisticated caching while ensuring forwards compatibility.

Strongly avoid scripts that alter the database structure

  • These include, for example, adding or altering database fields, and creating new tables.
  • In most cases, WordPress’s sophisticated custom post types, taxonomies, options, and meta data API’s can accomplish the same result with superior security and performance (especially in cache-enabled environments).
  • Scripts that alter the database structure require significantly more time to audit, review, and test.

Database manipulation functions

  • In the event that database interaction is truly essential, WordPress provides a class of functions for all database manipulations.
  • The class is called wpdb and is loosely based on the ezSQL class written and maintained by Justin Vincent.
  • Learn more about the $wpdb object in the class reference.

6. Validation and Sanitisation

Input Validation

To validate is to ensure the data you’ve requested of the user matches what they’ve submitted. There are several core methods you can use for input validation; usage obviously depends on the type of fields you’d like to validate.

Escape Output

For security on the other end of the spectrum, we have escaping. To escape is to take the data you may already have and help secure it prior to rendering it for the end user.

Ready to find out more?

If you can adhere to these standards, proceed to the job description.