|
2 | 2 |
|
3 | 3 | WP Engine Coding Standards for WordPress |
4 | 4 |
|
| 5 | +If [WordPress Coding Standards](https://make.wordpress.org/core/handbook/best-practices/coding-standards/) offer a baseline for developers to use when contributing to or extending WordPress, think of WP Engine Coding Standards as an additional layer of best practices that: |
| 6 | + |
| 7 | +- help developers achieve greater consistency within their themes and plugins |
| 8 | +- assist developers in meeting the requirements of a WP Engine Solution Partner |
| 9 | +- ensure that all software listed in the WP Engine Solution Center is of the highest quality |
| 10 | +- offer users maximum performance and security benefits when using those themes and plugins in a modern hosting environment (PHP 7+) |
| 11 | + |
| 12 | +The information included here walks you through the process of installing and using WP Engine Coding Standards to lint your code. |
| 13 | + |
5 | 14 | ## Requirements |
6 | 15 |
|
| 16 | +WP Engine Coding Standards (WPECS) uses [Composer](https://getcomposer.org/) to install these main dependencies: |
| 17 | + |
| 18 | +* [PHP_Codesniffer (PHPCS)](https://github.com/squizlabs/PHP_CodeSniffer) |
| 19 | +* [WordPress Coding Standards](https://github.com/WordPress/WordPress-Coding-Standards) |
| 20 | +* [PHPCompatibilityWP](https://github.com/PHPCompatibility/PHPCompatibilityWP). |
| 21 | + |
| 22 | +If you're using Homebrew on Mac, you can install Composer with: `brew install composer`. Otherwise, follow the official installation instructions for Composer. |
| 23 | + |
7 | 24 | ## Installation |
8 | 25 |
|
9 | | -You can install WPECS globally with the following command: |
| 26 | +### Global installation |
| 27 | + |
| 28 | +1. Clone the repository and install the dependencies: |
| 29 | + |
| 30 | +```bash |
| 31 | +git clone [email protected]:wpengine/wpengine-coding-standards.git |
| 32 | +cd wpengine-coding-standards |
| 33 | +composer install |
| 34 | +``` |
| 35 | + |
| 36 | +2. Link your coding standards to your `phpcs` installation: |
| 37 | + |
| 38 | +```bash |
| 39 | +phpcs --config-set installed_paths /path/to/wp-engine-coding-standards |
| 40 | +``` |
| 41 | + |
| 42 | +### Install as a dependency |
| 43 | + |
| 44 | +You can also install the coding standards as a dependency in your local project. Here's how |
| 45 | + |
| 46 | +1. Add the following repository to your composer.json |
| 47 | + |
| 48 | +```json |
| 49 | +"repositories": [ |
| 50 | + { |
| 51 | + "type": "git", |
| 52 | + "url": "https://github.com/wpengine/wpengine-coding-standards.git" |
| 53 | + } |
| 54 | + ] |
| 55 | +``` |
| 56 | + |
| 57 | +2. Manually add the following to `require-dev` in composer.json |
| 58 | + |
| 59 | +```json |
| 60 | +"wpengine/wpengine-coding-standards": "dev-master" |
| 61 | +``` |
| 62 | + |
| 63 | +3. Run `composer install` or `composer update` to ensure your project is configured. |
| 64 | + |
| 65 | +4. You can now use `WP-Engine` or `WP-Engine-Strict` in any IDE that uses the local phpcs. If you already have a phpcs.xml in your project, simply add the following to it: |
| 66 | + |
| 67 | +```xml |
| 68 | + <rule ref="WP-Engine-Strict"/> |
| 69 | + ``` |
| 70 | + |
| 71 | +### Alternative Install (wpecs command) |
| 72 | + |
| 73 | +Clone or download this repository. From terminal, navigate to the download location and install WPECS globally with the following command: |
10 | 74 |
|
11 | 75 | make install |
12 | 76 |
|
13 | | -You will then be able to run WPECS from the any directory: |
| 77 | +You will then be able to run WPECS from any directory. |
| 78 | + |
| 79 | +Running `make install` will install WPECS dependencies and register coding standards with PHPCS. |
| 80 | + |
| 81 | +* Note you might need to manually move the binaries to your path, or properly set path, if make fails. |
| 82 | + |
| 83 | +## Usage |
| 84 | + |
| 85 | +### Command line |
| 86 | + |
| 87 | +Run the `phpcs` command line tool on a given file or directory, for example: |
| 88 | + |
| 89 | +```bash |
| 90 | +phpcs --standard=WP-Engine wp-load.php |
| 91 | +``` |
| 92 | + |
| 93 | +**WP-Engine Coding Standard** |
| 94 | + |
| 95 | +_The required standard for secure WordPress development._ |
| 96 | + |
| 97 | +`wpecs .` |
| 98 | + |
| 99 | +**WP-Engine-Strict Coding Standard** |
| 100 | + |
| 101 | +_The recommend standard for WP Engine authored plugins._ |
| 102 | + |
| 103 | +`wpecs --standard="WP-Engine-Strict" .` |
| 104 | + |
| 105 | +### Using PHPCS and WP Engine Coding Standards from within your IDE |
| 106 | + |
| 107 | +While the following is based on the parent WordPress Coding Standards, simply swap out the ruleset you need for `WP-Engine` or `WP-Engine-Strict` as appropriate. |
| 108 | + |
| 109 | +* **PhpStorm** : Please see "[PHP Code Sniffer with WordPress Coding Standards Integration](https://confluence.jetbrains.com/display/PhpStorm/WordPress+Development+using+PhpStorm#WordPressDevelopmentusingPhpStorm-PHPCodeSnifferwithWordPressCodingStandardsIntegrationinPhpStorm)" in the PhpStorm documentation. |
| 110 | +* **Sublime Text** : Please see "[Setting up WPCS to work in Sublime Text](https://github.com/WordPress/WordPress-Coding-Standards/wiki/Setting-up-WPCS-to-work-in-Sublime-Text)" in the wiki. |
| 111 | +* **Atom**: Please see "[Setting up WPCS to work in Atom](https://github.com/WordPress/WordPress-Coding-Standards/wiki/Setting-up-WPCS-to-work-in-Atom)" in the wiki. |
| 112 | +* **Visual Studio**: Please see "[Setting up PHP CodeSniffer in Visual Studio Code](https://tommcfarlin.com/php-codesniffer-in-visual-studio-code/)", a tutorial by Tom McFarlin. |
| 113 | +* **Eclipse with XAMPP**: Please see "[Setting up WPCS when using Eclipse with XAMPP](https://github.com/WordPress/WordPress-Coding-Standards/wiki/How-to-use-WPCS-with-Eclipse-and-XAMPP)" in the wiki. |
| 114 | + |
| 115 | +### Alternative usage (wpecs) |
| 116 | + |
| 117 | +USAGE: wpecs [--strict] [phpcs-options] <path> |
| 118 | +<wpecs> Run the specified path against the WP Engine Coding Standards |
| 119 | +<wpecbf> Attempt to fix sniffs against the WP Engine Strict Coding Standards |
14 | 120 |
|
15 | | - USAGE: wpecs [--strict] [phpcs-options] <path> |
16 | | - <wpecs> Run the specified path against the WP Engine Coding Standards |
17 | | - <wpecbf> Attempt to fix sniffs against the WP Engine Strict Coding Standards |
| 121 | +## Results |
18 | 122 |
|
19 | | - Try using 'wpecbf' to fix the sniff violations automatically. |
| 123 | +For help understanding errors or warnings and suggestions for troubleshooting specific issues, please refer to the full [WP Engine Coding Standards Documentation](https://github.com/wpengine/wpengine-coding-standards/wiki). |
0 commit comments