├── .github
├── CODEOWNERS
├── ISSUE_TEMPLATE
│ ├── bug_report.md
│ └── feature_request.md
├── PULL_REQUEST_TEMPLATE.md
└── workflows
│ ├── validate-composer-config.yml
│ └── verify-dependencies-install.yml
├── .gitignore
├── .phpcs.xml.dist
├── CONTRIBUTING.md
├── DEVELOPMENT.md
├── Makefile
├── README.md
├── WP-Engine-Strict
└── ruleset.xml
├── WP-Engine
└── ruleset.xml
├── bin
├── wpecbf
└── wpecs
└── composer.json
/.github/CODEOWNERS:
--------------------------------------------------------------------------------
1 | * @anthonyburchell
2 | * @wpengine/merlin
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: '🐛 Bug Report'
3 | about: Report a reproducible bug or regression.
4 | title: 'Bug: '
5 | labels: 'Status: Unconfirmed'
6 | ---
7 |
8 |
13 |
14 | ### Version information
15 | - Coding Standards version: x.x.x
16 | - WordPress version: x.x.x
17 | - Operating system:
18 |
19 | ## Steps To Reproduce
20 |
21 |
22 | 1.
23 | 2.
24 |
25 | ## The current behavior
26 |
27 |
28 | ## The expected behavior
29 |
30 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/feature_request.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: '💬 Feature Request/General Improvements'
3 | about: Requests for new features, or general improvements
4 | title: ''
5 | labels: 'Status: Unconfirmed'
6 | ---
7 |
8 |
11 |
--------------------------------------------------------------------------------
/.github/PULL_REQUEST_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | ## Description
2 |
3 |
6 |
7 | ## Related Issue(s):
8 |
9 |
14 |
15 | ## Testing
16 |
17 |
20 |
--------------------------------------------------------------------------------
/.github/workflows/validate-composer-config.yml:
--------------------------------------------------------------------------------
1 | name: Validate Composer Config
2 | on: pull_request
3 | jobs:
4 | test:
5 | runs-on: ubuntu-latest
6 | steps:
7 | - uses: actions/checkout@v3
8 | - uses: shivammathur/setup-php@v2
9 | - name: Validate Composer Config
10 | run: |
11 | composer validate --strict
12 |
--------------------------------------------------------------------------------
/.github/workflows/verify-dependencies-install.yml:
--------------------------------------------------------------------------------
1 | name: Verify Dependencies Install
2 | on: pull_request
3 | jobs:
4 | test:
5 | runs-on: ubuntu-latest
6 | steps:
7 | - uses: actions/checkout@v3
8 | - uses: shivammathur/setup-php@v2
9 | - name: Install Dependencies
10 | run: |
11 | composer install
12 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 | dist/
3 | dist/blocks.build.js
4 | vendor/
5 | build/
6 | package-lock.json
7 | composer.lock
8 | .DS_Store
9 | *.bak
10 | *.bak.js
11 | report*.txt
12 | .vscode/
13 |
--------------------------------------------------------------------------------
/.phpcs.xml.dist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Coding standards, based on the WordPress Coding Standards, to improve security and performance on the WP Engine farm.
5 |
6 | .
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 | */dev-lib/*
18 | */node_modules/*
19 | */vendor/*
20 | */tests/*
21 |
22 |
23 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Instructions For Logging Issues
2 |
3 | ## 1. Search For Duplicates
4 |
5 | [Search the existing issues](https://github.com/wpengine/wpengine-coding-standards/search?type=Issues) before logging a new one.
6 |
7 | ## 2. Did You Find A Bug?
8 |
9 | When logging a bug, please be sure to include the following:
10 |
11 | - What version of the package/plugin are you using
12 | - If at all possible, an _isolated_ way to reproduce the behavior
13 | - The behavior you expect to see, and the actual behavior
14 |
15 | ## 3. Do You Have A Suggestion?
16 |
17 | We also accept suggestions in the issue tracker. Be sure to [search](https://github.com/wpengine/wpengine-coding-standards/search?type=Issues) first.
18 |
19 | # Instructions For Contributing Code
20 |
21 | ## What You'll Need
22 |
23 | 0. [A bug or feature you want to work on](https://github.com/wpengine/wpengine-coding-standards/labels/help%20wanted)! If you have found a new bug or want to propose a feature, please [create an issue](https://github.com/wpengine/wpengine-coding-standards/issues/new/choose) before starting a pull request.
24 | 1. [A GitHub account](https://github.com/join).
25 | 2. The latest working copy of the code.
26 |
27 | ## Housekeeping
28 |
29 | Your pull request should:
30 |
31 | - Include a description of what your change intends to do
32 | - Reference any open issues that the PR addresses
33 | - Be based on reasonably recent commit in the **master** branch
34 | - Contain proper [semantic commit messages](https://gist.github.com/joshbuchea/6f47e86d2510bce28f8e7f42ae84c716#gistcomment-3711094) as follows:
35 |
36 | ```
37 | []: ()
38 | │ │ | │
39 | | | | └─> Summary in present tense. Not capitalized. No period at the end.
40 | | | |
41 | │ │ └─> Issue # (optional): Issue number if related to bug database.
42 | │ │
43 | │ └─> Scope (optional): eg. common, compiler, authentication, core
44 | │
45 | └─> Type: chore, docs, feat, fix, refactor, style, or test.
46 | ```
47 |
48 | - To avoid line ending issues, set `autocrlf = input` and `whitespace = cr-at-eol` in your git configuration
49 |
--------------------------------------------------------------------------------
/DEVELOPMENT.md:
--------------------------------------------------------------------------------
1 | # Development
2 |
3 | ## Releasing
4 |
5 | This project uses GitHub Releases for its release process. Once a release occurs on GitHub, Packagist is automatically notified of the release via a webhook.
6 |
7 | Each release should have a title that corresponds to the semantic version. The tag should also correspond to the semantic version, for example "1.0.0". The body should include the release's relevant changes.
8 |
9 | For more info on GitHub releases, visit the [Managing releases in a repository](https://docs.github.com/en/repositories/releasing-projects-on-github/managing-releases-in-a-repository) help doc.
10 |
11 | ## Versioning
12 |
13 | This project follows [Semantic Versioning](https://semver.org/).
14 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | VENDOR_BIN := ./vendor/bin
2 |
3 | install:
4 | composer install
5 | $(VENDOR_BIN)/phpcs --config-set default_standard WP-Engine
6 | $(VENDOR_BIN)/phpcs --config-set show_progress 1 > /dev/null 2>&1
7 | $(VENDOR_BIN)/phpcs --config-set colors 1 > /dev/null 2>&1
8 | chmod +x ${CURDIR}/bin/wpecs
9 | chmod +x ${CURDIR}/bin/wpecbf
10 | rm /usr/local/bin/wpecs || true
11 | rm /usr/local/bin/wpecbf || true
12 | ln -s ${CURDIR}/bin/wpecs /usr/local/bin/wpecs
13 | ln -s ${CURDIR}/bin/wpecbf /usr/local/bin/wpecbf
14 | $(VENDOR_BIN)/phpcs -i; echo "\n"
15 | echo "USAGE: wpecs [--strict] [phpcs-options] \n"
16 | echo "For assistance getting started try 'wpecs -h'\n"
17 | update:
18 | git pull origin master
19 | $(MAKE) install
20 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## Deprecation Notice
2 |
3 | This project is no longer actively maintained. We recommend using the [WordPress Coding Standards](https://github.com/WordPress/WordPress-Coding-Standards) and use their [recommended configuration](https://github.com/WordPress/WordPress-Coding-Standards/blob/develop/phpcs.xml.dist.sample) for your project.
4 |
5 | ## About
6 |
7 | WP Engine Coding Standards for WordPress
8 |
9 | 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:
10 |
11 | - help developers achieve greater consistency within their themes and plugins
12 | - assist developers in meeting the requirements of a WP Engine Solution Partner
13 | - ensure that all software listed in the WP Engine Solution Center is of the highest quality
14 | - offer users maximum performance and security benefits when using those themes and plugins in a modern hosting environment (PHP 7+)
15 |
16 | The information included here walks you through the process of installing and using WP Engine Coding Standards to lint your code.
17 |
18 | ## Requirements
19 |
20 | WP Engine Coding Standards (WPECS) uses [Composer](https://getcomposer.org/) to install these main dependencies:
21 |
22 | * [PHP_Codesniffer (PHPCS)](https://github.com/squizlabs/PHP_CodeSniffer)
23 | * [WordPress Coding Standards](https://github.com/WordPress/WordPress-Coding-Standards)
24 | * [PHPCompatibilityWP](https://github.com/PHPCompatibility/PHPCompatibilityWP).
25 |
26 | If you're using Homebrew on Mac, you can install Composer with: `brew install composer`. Otherwise, follow the official installation instructions for Composer.
27 |
28 | ## Installation
29 |
30 | ### Global installation
31 |
32 | 1. Clone the repository and install the dependencies:
33 |
34 | ```bash
35 | git clone git@github.com:wpengine/wpengine-coding-standards.git
36 | cd wpengine-coding-standards
37 | composer install
38 | ```
39 |
40 | 2. Link your coding standards to your `phpcs` installation:
41 |
42 | ```bash
43 | phpcs --config-set installed_paths /path/to/wp-engine-coding-standards
44 | ```
45 |
46 | ### Install as a dependency
47 |
48 | You can also install the coding standards as a dependency in your local project. Here's how
49 |
50 | 1. Add the following repository to your composer.json
51 |
52 | ```json
53 | "repositories": [
54 | {
55 | "type": "git",
56 | "url": "https://github.com/wpengine/wpengine-coding-standards.git"
57 | }
58 | ]
59 | ```
60 |
61 | 2. Manually add the following to `require-dev` in composer.json
62 |
63 | ```json
64 | "wpengine/wpengine-coding-standards": "dev-master"
65 | ```
66 |
67 | 3. Run `composer install` or `composer update` to ensure your project is configured.
68 |
69 | 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:
70 |
71 | ```xml
72 |
73 | ```
74 |
75 | ### Alternative Install (wpecs command)
76 |
77 | Clone or download this repository. From terminal, navigate to the download location and install WPECS globally with the following command:
78 |
79 | make install
80 |
81 | You will then be able to run WPECS from any directory.
82 |
83 | Running `make install` will install WPECS dependencies and register coding standards with PHPCS.
84 |
85 | * Note you might need to manually move the binaries to your path, or properly set path, if make fails.
86 |
87 | ## Usage
88 |
89 | ### Command line
90 |
91 | Run the `phpcs` command line tool on a given file or directory, for example:
92 |
93 | ```bash
94 | phpcs --standard=WP-Engine wp-load.php
95 | ```
96 |
97 | **WP-Engine Coding Standard**
98 |
99 | _The required standard for secure WordPress development._
100 |
101 | `wpecs .`
102 |
103 | **WP-Engine-Strict Coding Standard**
104 |
105 | _The recommend standard for WP Engine authored plugins._
106 |
107 | `wpecs --standard="WP-Engine-Strict" .`
108 |
109 | ### Using PHPCS and WP Engine Coding Standards from within your IDE
110 |
111 | 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.
112 |
113 | * **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.
114 | * **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.
115 | * **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.
116 | * **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.
117 | * **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.
118 |
119 | ### Alternative usage (wpecs)
120 |
121 | USAGE: wpecs [--strict] [phpcs-options]
122 | Run the specified path against the WP Engine Coding Standards
123 | Attempt to fix sniffs against the WP Engine Strict Coding Standards
124 |
125 | ## Results
126 |
127 | 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).
128 |
129 | ### Contributor License Agreement
130 |
131 | All external contributors to WP Engine products must have a signed Contributor License Agreement (CLA) in place before the contribution may be accepted into any WP Engine codebase.
132 |
133 | 1. [Submit your name and email](https://wpeng.in/cla/)
134 | 2. 📝 Sign the CLA emailed to you
135 | 3. 📥 Receive copy of signed CLA
136 |
137 | ❤️ Thank you for helping us fulfill our legal obligations in order to continue empowering builders through headless WordPress.
--------------------------------------------------------------------------------
/WP-Engine-Strict/ruleset.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | WP Engine Coding Standards - Strict
4 |
5 |
6 | 10
7 |
8 |
9 |
10 | 10
11 |
12 |
13 |
14 | 10
15 |
16 |
17 |
18 | 8
19 |
20 |
21 |
22 | 8
23 |
24 |
25 |
26 | 8
27 |
28 |
29 | -->
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/WP-Engine/ruleset.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | WP Engine Coding Standards
4 |
5 |
6 | 10
7 |
8 |
9 |
10 | 10
11 |
12 |
13 |
14 | 10
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/bin/wpecbf:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | echo -e "WP Engine Coding Standards\nVersion 1.0.0\n"
3 |
4 | SOURCE_DIR=$(readlink "${BASH_SOURCE[0]}")
5 | VENDOR_DIR="$(dirname "$(dirname "$SOURCE_DIR" )" )"
6 | PHPCS_STANDARD="WP-Engine"
7 | PHPCS_ARGS=${@}
8 | NEEDS_HELP="false"
9 |
10 | if [[ $# = 0 ]]; then
11 | NEEDS_HELP="true"
12 | fi
13 |
14 | if [ "${1}" = "-h" ] || [ "${1}" = "--h" ] || [ "${NEEDS_HELP}" = "true" ]
15 | then
16 | echo -e "WP Engine Coding Standards\n"
17 | echo -e "USAGE: wpecbf [--strict] [phpcbf-options] \n"
18 | echo -e " Run the WP Engine Coding Standards\n"
19 | echo -e " Attempt to fix sniffs against the WP Engine Strict Coding Standards\n"
20 | echo -e "[phpcs-options] Any argument that can be passed to PHP CodeSniffer\n"
21 | exit 0
22 | fi
23 |
24 | if [ "${1}" = "--strict" ]; then
25 | PHPCS_STANDARD="WP-Engine-Strict"
26 | PHPCS_ARGS=${@:2}
27 | fi
28 |
29 | echo -e "Attempting to beautify against WP Engine Coding Standards\n"
30 |
31 | ${VENDOR_DIR}/vendor/bin/phpcbf --standard="${PHPCS_STANDARD}" --basepath=. --ignore=*build*,*node_modules*,*vendor* ${PHPCS_ARGS}
32 |
--------------------------------------------------------------------------------
/bin/wpecs:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | echo -e "WP Engine Coding Standards\nVersion 1.0.0\n"
3 |
4 | SOURCE_DIR=$(readlink "${BASH_SOURCE[0]}")
5 | VENDOR_DIR="$(dirname "$(dirname "$SOURCE_DIR" )" )"
6 | PHPCS_STANDARD="WP-Engine"
7 | PHPCS_ARGS=${@}
8 | NEEDS_HELP="false"
9 |
10 | if [[ $# = 0 ]]; then
11 | NEEDS_HELP="true"
12 | fi
13 |
14 | if [ "${1}" = "-h" ] || [ "${1}" = "--h" ] || [ "${NEEDS_HELP}" = "true" ]
15 | then
16 | echo -e "WP Engine Coding Standards\n"
17 | echo -e "USAGE: wpecs [--strict] [phpcs-options] \n"
18 | echo -e " Run the WP Engine Coding Standards\n"
19 | echo -e " Attempt to fix sniffs against the WP Engine Strict Coding Standards\n"
20 | echo -e "[phpcs-options] Any argument that can be passed to PHP CodeSniffer\n"
21 | exit 0
22 | fi
23 |
24 | if [ "${1}" = "--strict" ]; then
25 | PHPCS_STANDARD="WP-Engine-Strict"
26 | PHPCS_ARGS=${@:2}
27 | fi
28 |
29 | ${VENDOR_DIR}/vendor/bin/phpcs --standard="${PHPCS_STANDARD}" --basepath=../ --ignore=*build*,*node_modules*,*vendor* --report-full=report-full.txt --report-summary=report-summary.txt --report-source ${PHPCS_ARGS}
30 |
31 | echo -e "Reports can be found in the target directory as 'report-full.txt' and 'report-source.txt'\n"
32 | echo -e "Try using 'wpecbf' to attempt fix the sniff violations automatically.\n"
33 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "wpengine/wpengine-coding-standards",
3 | "type": "phpcodesniffer-standard",
4 | "description": "PHP_CodeSniffer rules (sniffs) to enforce WP Engine coding conventions",
5 | "keywords": [
6 | "wpecs",
7 | "phpcs",
8 | "standards",
9 | "WordPress",
10 | "WP-Engine"
11 | ],
12 | "license": "MIT",
13 | "authors": [
14 | {
15 | "name": "Contributors",
16 | "homepage": "https://github.com/wpengine/wpengine-coding-standards/graphs/contributors"
17 | }
18 | ],
19 | "require": {
20 | "php": ">=5.4",
21 | "squizlabs/php_codesniffer": "^3.5",
22 | "dealerdirect/phpcodesniffer-composer-installer": "^0.7.0",
23 | "wp-coding-standards/wpcs": "^2.3.0",
24 | "phpcompatibility/phpcompatibility-wp": "^2.1.3"
25 | },
26 | "config": {
27 | "allow-plugins": {
28 | "dealerdirect/phpcodesniffer-composer-installer": true
29 | }
30 | },
31 | "minimum-stability": "dev",
32 | "prefer-stable" : true,
33 | "support": {
34 | "issues": "https://github.com/wpengine/wpengine-coding-standards/issues",
35 | "source": "https://github.com/wpengine/wpengine-coding-standards"
36 | },
37 | "bin": [
38 | "bin/wpecs",
39 | "bin/wpecbf"
40 | ],
41 | "scripts": {
42 | "check-cs": [
43 | "@php ./vendor/squizlabs/php_codesniffer/bin/phpcs"
44 | ],
45 | "fix-cs": [
46 | "@php ./vendor/squizlabs/php_codesniffer/bin/phpcbf"
47 | ],
48 | "install-codestandards": [
49 | "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin::run"
50 | ],
51 | "check-complete": [
52 | "@php ./vendor/phpcsstandards/phpcsdevtools/bin/phpcs-check-feature-completeness -q ./WP-Engine"
53 | ],
54 | "check-complete-strict": [
55 | "@php ./vendor/phpcsstandards/phpcsdevtools/bin/phpcs-check-feature-completeness ./WP-Engine"
56 | ]
57 | }
58 | }
59 |
--------------------------------------------------------------------------------