PHP Coding Standards - spthemes/best-practices GitHub Wiki

Indentation

Tabs should be used at the beginning of the line for indentation, while spaces should be used mid-line for alignment.

[tab]$foo   = 'somevalue';
[tab]$foo2  = 'somevalue2';
[tab]$foo34 = 'somevalue3';
[tab]$foo5  = 'somevalue4';

For associative arrays, values should start on a new line. Include a comma after the last array item:

$my_array = array(
[tab]'foo'   => 'somevalue',
[tab]'foo2'  => 'somevalue2',
[tab]'foo3'  => 'somevalue3',
[tab]'foo45' => 'somevalue4',
);

Braces

Braces should always be used, even when they are not required:

if ( condition ) {
    action0();
}

Naming Conventions

Use lowercase letters in variable, action, and function names. Separate words via underscores. Don’t abbreviate variable names unnecessarily; let the code be unambiguous and self-documenting.

function theme_function_name( $some_variable ) { [...] }

Files should be named descriptively using lowercase letters. Hyphens should separate words.

style-front.css

Space Usage

  • Always put spaces after commas, and on both sides of logical, comparison, string and assignment operators.
  • There should be a new line at the end of each file.