Setting up sublime text spacing for WordPress PHP coding standards

WordPress’ PHP coding standards has this to say about the use of spaces:

Put spaces on both sides of the opening and closing parenthesis of ifelseifforeachfor, and switch blocks.

You can configure Sublime Text to do some of this for you when it auto closes brackets.

sublime text key bindings

To set this up, open Sublime Text > Preferences > Key Bindings - Default and search for // Auto-pair brackets to find this block of code:

Copy the first two keys sections (the bit shown above) to your clipboard and open up Sublime Text > Preferences > Key Bindings - User. Unless you have previously set up custom key bindings, this file will be empty. Paste in the contents you copied and add a space after the ( and before
the ) in the contents values for both key blocks as so:

This will automatically insert a space after the opening ( and before the ) for you.

If you would like this to only apply to PHP files, you can add this also add this line to each block:

Happy coding!