0% found this document useful (0 votes)
24 views15 pages

FWDP 3600 Wpcs Setup

This document provides steps to set up WordPress coding standards in Visual Studio Code. It instructs the user to install Composer, PHP CodeSniffer, download the WordPress coding standards from GitHub, configure PHP CodeSniffer to use the WordPress standards, install and configure the PHP CodeSniffer extension in VSCode, and then verify that code analysis is working by checking a PHP file. Following these steps allows developers to write PHP that complies with WordPress coding standards.

Uploaded by

tyler0327feng
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views15 pages

FWDP 3600 Wpcs Setup

This document provides steps to set up WordPress coding standards in Visual Studio Code. It instructs the user to install Composer, PHP CodeSniffer, download the WordPress coding standards from GitHub, configure PHP CodeSniffer to use the WordPress standards, install and configure the PHP CodeSniffer extension in VSCode, and then verify that code analysis is working by checking a PHP file. Following these steps allows developers to write PHP that complies with WordPress coding standards.

Uploaded by

tyler0327feng
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

1

WordPress Coding
Standards
2

WordPress Coding Standards


If you want to make sure you are writing good PHP for
WordPress, you can use the WordPress Coding Standards…

https://github.com/WordPress/WordPress-Coding-Standards

Follow the steps on the remaining slides to set this up in


Visual Studio Code.
3

Alternative Walkthrough
The steps in these slides are taken from this walkthrough…
https://www.edmundcwm.com/setting-up-wordpress-coding-standards-in-vs-code/

Mac users… follow the remaining slides or refer to that page.

Windows users… follow the remaining slides as they are a


modified version of that walkthrough.
4

Install Composer
Follow the steps here:

https://getcomposer.org/

If on Windows, during the installation wizard make sure to


select the PHP version file you are running in MAMP or
WAMP.
5

MacOS – Monterey or higher


If you are running MacOS version 12 or higher, you need to
follow these additional steps:
https://wpbeaches.com/updating-to-php-versions-7-4-and-8-on-macos-12-monterey/
6

Install PHP CodeSniffer (phpcs)


In your Terminal, run the following command:

composer global require "squizlabs/php_codesniffer=*"

This will install phpcs:

https://github.com/squizlabs/PHP_CodeSniffer
7

Download Coding Standards


Go to this GitHub repo and switch to the “master” branch:

https://github.com/WordPress/WordPress-Coding-Standards

Click Code à Download ZIP

Extract the folder anywhere you


want to store it on your computer.
8

Add Coding Standards to phpcs


Mac Users... see the next slide.

Windows Users… run a command like this:


phpcs --config-set installed_paths C:\phpcs-stuff\wpcs

Note: the end of the command should


be the full path to the extracted folder
on your computer.
9

Add Coding Standards to phpcs


Mac Users... run a command like this:
path/to/phpcs --config-set installed_paths /path/to/wpcs

Note: the highlighted parts will change depending on your


paths and user name. The first is the path to phpcs and the
second is the path to the extracted GitHub code folder. For
example:
/Users/jtleathers/.composer/vendor/bin/phpcs --config-set installed_paths
/Users/jtleathers/Documents/wpcs
10

Verify it Worked
On Windows, run the following command:
phpcs -i

On Mac, run a command like this:


/Users/your-username/.composer/vendor/bin/phpcs -i

You should see the WordPress coding standards listed with


some other standards.
11

Install phpcs in VSCode


Search for the phpcs extension in VSCode and install it…
12

Apply Standards
In VSCode go to Preferences à Settings.
To apply the standards to ALL Workspaces, click on User.
To apply the standards to only the current Workspace, click on
Workspace.
13

Apply Standards (cont’d)


Then click on PHP CodeSniffer under
Extensions.
Find the “Standard” section and click
“Edit in settings.json”.
Add the following code…
"phpcs.standard": "WordPress"
14

Apply Standards (cont’d)


If you are getting an error in VS Code for “phpcs”, then set
the Executable Path in the Settings for PHP CodeSniffer.
Below is an example path for Mac users. A Windows path will
include the drive number like C:\Users\...
15

Check PHP Files


Check one of your PHP files to see if it gives you any errors
or warnings like this…

Now you can keep your code clean and up to the standards!

You might also like