Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
WordPress coding standards configuration for PhpStorm

Now Native

PhpStorm now bundles WordPress coding style natively, starting from version 8.

  1. Go to Project Settings > Code Style > PHP.
  2. Select Set From... (top right of window) > Predefined Style > WordPress.

No longer need to muck with this import! :)

@johnpbloch

This comment has been minimized.

Show comment Hide comment
@johnpbloch

johnpbloch Jul 30, 2012

Just a quick note, on Mac OS X 10.7, rather than being in ~/.WebIde40, the configuration folders were located in ~/Library/Preferences/WebIde40. Don't know about any other versions of OS X, though.

Just a quick note, on Mac OS X 10.7, rather than being in ~/.WebIde40, the configuration folders were located in ~/Library/Preferences/WebIde40. Don't know about any other versions of OS X, though.

@thinkstylestudio

This comment has been minimized.

Show comment Hide comment
@thinkstylestudio

thinkstylestudio Aug 21, 2012

Mac OS X 10.6 is the save as johnpbloch 's comment.

Mac OS X 10.6 is the save as johnpbloch 's comment.

@BronsonQuick

This comment has been minimized.

Show comment Hide comment
@BronsonQuick

BronsonQuick Jan 10, 2013

Hey @Rarst,

Just wanted to say an epic thanks for this! I've been using PhpStorm for about 18 months now for all our WordPress client work but I've only tried to commit code back to core a few times and all my formatting settings were never right in PhpStorm so I'd always cop some flack for my formatting. This has done the trick :)

You rock! \m/

Hey @Rarst,

Just wanted to say an epic thanks for this! I've been using PhpStorm for about 18 months now for all our WordPress client work but I've only tried to commit code back to core a few times and all my formatting settings were never right in PhpStorm so I'd always cop some flack for my formatting. This has done the trick :)

You rock! \m/

@KingYes

This comment has been minimized.

Show comment Hide comment
@KingYes

KingYes Feb 6, 2013

You need add new role for arrays.. $var['test'] and $var[ $key ]

Good job. :)

KingYes commented Feb 6, 2013

You need add new role for arrays.. $var['test'] and $var[ $key ]

Good job. :)

@Rarst

This comment has been minimized.

Show comment Hide comment
@Rarst

Rarst Feb 7, 2013

@BronsonQuick you are welcome :)

@KingYes unfortunately PhpStorm does not support such logic yet, I have created ticket about that while back http://youtrack.jetbrains.com/issue/WI-12039

Owner

Rarst commented Feb 7, 2013

@BronsonQuick you are welcome :)

@KingYes unfortunately PhpStorm does not support such logic yet, I have created ticket about that while back http://youtrack.jetbrains.com/issue/WI-12039

@KingYes

This comment has been minimized.

Show comment Hide comment
@KingYes

KingYes Mar 31, 2013

Good job @Rarst.

KingYes commented Mar 31, 2013

Good job @Rarst.

@tannerm

This comment has been minimized.

Show comment Hide comment
@tannerm

tannerm Apr 10, 2013

Awesome! Thanks @Rarst!!

For PhpStorm 6.0 on Mac on OSX 10.8.2 I followed @johnbloch's instructions for storing the file and to import it to PhpStorm had to go File->Default Settings->Code Style and then select the Wordpress scheme from there.

tannerm commented Apr 10, 2013

Awesome! Thanks @Rarst!!

For PhpStorm 6.0 on Mac on OSX 10.8.2 I followed @johnbloch's instructions for storing the file and to import it to PhpStorm had to go File->Default Settings->Code Style and then select the Wordpress scheme from there.

@Rarst

This comment has been minimized.

Show comment Hide comment
@Rarst

Rarst Apr 14, 2013

@tannerm that's strange, did it not just appear as available? I don't think I ever touched Default Settings for anything, but I mostly deal with giant project for my whole local test stack.

Owner

Rarst commented Apr 14, 2013

@tannerm that's strange, did it not just appear as available? I don't think I ever touched Default Settings for anything, but I mostly deal with giant project for my whole local test stack.

@iandunn

This comment has been minimized.

Show comment Hide comment
@iandunn

iandunn May 4, 2013

Same as @tannerm with a fresh install of PhpStorm 6 on 10.8.3, except I had to restart PhpStorm before it would show up.

iandunn commented May 4, 2013

Same as @tannerm with a fresh install of PhpStorm 6 on 10.8.3, except I had to restart PhpStorm before it would show up.

@theantichris

This comment has been minimized.

Show comment Hide comment
@theantichris

theantichris May 21, 2013

Quick question. If these are based off this page http://make.wordpress.org/core/handbook/coding-standards/php/ it credits PEAR standards so I assume it is based off that.

PEAR standards have tabs and indents at 4 spaces not 2.

What is the reason for 2 in this file?

Quick question. If these are based off this page http://make.wordpress.org/core/handbook/coding-standards/php/ it credits PEAR standards so I assume it is based off that.

PEAR standards have tabs and indents at 4 spaces not 2.

What is the reason for 2 in this file?

@Rarst

This comment has been minimized.

Show comment Hide comment
@Rarst

Rarst May 21, 2013

PEAR standards have tabs and indents at 4 spaces not 2. What is the reason for 2 in this file?

WP standard currently doesn't specify number of spaces per tab. PEAR might, but there is no explicit or implicit statement that rules missing in WP standard should be sourced from it.

2 is just my personal preference (as well as convention at past job), feel free to adjust. If standard makes it 4 explicitly I will probably move to that, until then it is rule that isn't officially defined.

Since bulk of indentation is real tabs anyway this doesn't have much impact.

Owner

Rarst commented May 21, 2013

PEAR standards have tabs and indents at 4 spaces not 2. What is the reason for 2 in this file?

WP standard currently doesn't specify number of spaces per tab. PEAR might, but there is no explicit or implicit statement that rules missing in WP standard should be sourced from it.

2 is just my personal preference (as well as convention at past job), feel free to adjust. If standard makes it 4 explicitly I will probably move to that, until then it is rule that isn't officially defined.

Since bulk of indentation is real tabs anyway this doesn't have much impact.

@theantichris

This comment has been minimized.

Show comment Hide comment
@theantichris

theantichris May 29, 2013

Cool deal. Thanks.

Cool deal. Thanks.

@sscovil

This comment has been minimized.

Show comment Hide comment
@sscovil

sscovil Jul 28, 2013

This is fantastic, thank you!

sscovil commented Jul 28, 2013

This is fantastic, thank you!

@pdewouters

This comment has been minimized.

Show comment Hide comment
@pdewouters

pdewouters Aug 5, 2013

thanks for this, I keep recommending it to others!

thanks for this, I keep recommending it to others!

@fjarrett

This comment has been minimized.

Show comment Hide comment
@fjarrett

fjarrett Oct 5, 2013

Thanks for taking the time. /five

fjarrett commented Oct 5, 2013

Thanks for taking the time. /five

@alexVauch

This comment has been minimized.

Show comment Hide comment
@alexVauch

alexVauch Nov 15, 2013

Good job. Thanks.
What about this line:

<option name="ELSE_ON_NEW_LINE" value="true" />

But in codex there is no new line between "}" and "else".

Good job. Thanks.
What about this line:

<option name="ELSE_ON_NEW_LINE" value="true" />

But in codex there is no new line between "}" and "else".

@Rarst

This comment has been minimized.

Show comment Hide comment
@Rarst

Rarst Nov 15, 2013

Hmm, I am not sure if else thing was as strongly worded in earlier versions of coding style. Might be oversight on my part.

Owner

Rarst commented Nov 15, 2013

Hmm, I am not sure if else thing was as strongly worded in earlier versions of coding style. Might be oversight on my part.

@Viper007Bond

This comment has been minimized.

Show comment Hide comment
@Viper007Bond

Viper007Bond Dec 4, 2013

For those looking for a 4 space width tab indent instead of Rarst's 2 spaces, you can find my code style file here:

https://github.com/Automattic/PhpStorm-Resources/blob/master/WordPress.xml

I made it from scratch and it's similar but has some other changes as well.

Pull requests welcome.

For those looking for a 4 space width tab indent instead of Rarst's 2 spaces, you can find my code style file here:

https://github.com/Automattic/PhpStorm-Resources/blob/master/WordPress.xml

I made it from scratch and it's similar but has some other changes as well.

Pull requests welcome.

@Rarst

This comment has been minimized.

Show comment Hide comment
@Rarst

Rarst Jan 13, 2014

Updated for 4 spaces per tab, more mainstream and was causing issues with CodeSniffer because continuation indent didn't match.

Owner

Rarst commented Jan 13, 2014

Updated for 4 spaces per tab, more mainstream and was causing issues with CodeSniffer because continuation indent didn't match.

@tivnet

This comment has been minimized.

Show comment Hide comment
@tivnet

tivnet Jan 14, 2014

@Rarst There was something about spaces vs tabs for JS. I believe lint/hint wanted spaces.

tivnet commented Jan 14, 2014

@Rarst There was something about spaces vs tabs for JS. I believe lint/hint wanted spaces.

@Rarst

This comment has been minimized.

Show comment Hide comment
@Rarst

Rarst Jan 14, 2014

WP's JavaScript Coding Standards say tabs. I do little JS so no promises on state of it in this config. :)

Owner

Rarst commented Jan 14, 2014

WP's JavaScript Coding Standards say tabs. I do little JS so no promises on state of it in this config. :)

@pablopaul

This comment has been minimized.

Show comment Hide comment
@pablopaul

pablopaul Jan 29, 2014

Thanks @Rarst, for me under Mac OS X 10.9.1 and PhpStorm 7.0 I could find the file under this path:

~/Library/Preferences/WebIde70/codestyles

No more "config" folder before "codestyles"

Thanks @Rarst, for me under Mac OS X 10.9.1 and PhpStorm 7.0 I could find the file under this path:

~/Library/Preferences/WebIde70/codestyles

No more "config" folder before "codestyles"

@Rarst

This comment has been minimized.

Show comment Hide comment
@Rarst

Rarst Jan 30, 2014

I still have config level on Windows. Best refer to linked part of manual on it.

Owner

Rarst commented Jan 30, 2014

I still have config level on Windows. Best refer to linked part of manual on it.

@HappyPlugins

This comment has been minimized.

Show comment Hide comment
@HappyPlugins

HappyPlugins Apr 26, 2014

@Rarst, thank you for that

@Rarst, thank you for that

@missjwo

This comment has been minimized.

Show comment Hide comment
@missjwo

missjwo Jul 25, 2014

@Rarst, this is amazing! Thank you soo much for creating it!

missjwo commented Jul 25, 2014

@Rarst, this is amazing! Thank you soo much for creating it!

@andizer

This comment has been minimized.

Show comment Hide comment
@andizer

andizer Aug 11, 2014

The file removes the space between ! and function. Seems to be a bug, because the codestyle for wordpress says there has to be a space between them.

See: http://make.wordpress.org/core/handbook/coding-standards/php/#space-usage

andizer commented Aug 11, 2014

The file removes the space between ! and function. Seems to be a bug, because the codestyle for wordpress says there has to be a space between them.

See: http://make.wordpress.org/core/handbook/coding-standards/php/#space-usage

@Rarst

This comment has been minimized.

Show comment Hide comment
@Rarst

Rarst Aug 13, 2014

@andizer

That shoudn't be the case (<option name="SPACE_AROUND_UNARY_OPERATOR" value="true" />). Check your code style settings for changes (Project Settings > Code Style > PHP > Spaces > Around Operators > Unary Operators).

Owner

Rarst commented Aug 13, 2014

@andizer

That shoudn't be the case (<option name="SPACE_AROUND_UNARY_OPERATOR" value="true" />). Check your code style settings for changes (Project Settings > Code Style > PHP > Spaces > Around Operators > Unary Operators).

@tacoverdo

This comment has been minimized.

Show comment Hide comment
@tacoverdo

tacoverdo Sep 2, 2014

@Rarst It seems that the setting has been moved in the EAP version of PHPStorm that @andizer and I are running.

Checking Project Settings > Code Style > PHP > Spaces > Other > After unary Not (!) solves this issue.

@Rarst It seems that the setting has been moved in the EAP version of PHPStorm that @andizer and I are running.

Checking Project Settings > Code Style > PHP > Spaces > Other > After unary Not (!) solves this issue.

@Rarst

This comment has been minimized.

Show comment Hide comment
@Rarst

Rarst Sep 2, 2014

EAP should ship with native WP style as far as I know? If it's wrong in that one should probably be reported as bug...

Owner

Rarst commented Sep 2, 2014

EAP should ship with native WP style as far as I know? If it's wrong in that one should probably be reported as bug...

@Rarst

This comment has been minimized.

Show comment Hide comment
@Rarst

Rarst Oct 8, 2014

Yeah, there seems to be mild upgrade issue with that setting going from 7 to 8, hit it too. :)

Owner

Rarst commented Oct 8, 2014

Yeah, there seems to be mild upgrade issue with that setting going from 7 to 8, hit it too. :)

@momin-ctg

This comment has been minimized.

Show comment Hide comment
@momin-ctg

momin-ctg Aug 31, 2016

How to auto Complete for wordpress comments and function definition in PhpStorm?

/**
 * The Header template for our theme
 *
 * Displays all of the <head> section and everything up till <div id="main">
 *
 * @package Hasan_WordPress
 * @subpackage Hasan
 * @since Hasan 1.0
 */

How to auto Complete for wordpress comments and function definition in PhpStorm?

/**
 * The Header template for our theme
 *
 * Displays all of the <head> section and everything up till <div id="main">
 *
 * @package Hasan_WordPress
 * @subpackage Hasan
 * @since Hasan 1.0
 */

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment