Install WordPress Coding Standards on PHPStorm easily

WordPress, as all development frameworks, has its own rules to follow so that each developer can easily read and understand a colleague’s code.

This is what we call “Coding Standards”. For WordPress, we have the WordPress Coding Standards better known as WPCS!

These developments rules can be read here: Discover the WordPress Coding StandardsOK, we’ve got a thousand pages of docs… but I’m not gonna read all those docs while developing… couldn’t you make it easier?

Well you’re lucky because we can integrate these rules directly into our IDEs or text editors! So your code will be automatically checked during your development.

I use PHPStorm from Jetbrains every day but you should know that these rules can be used on almost any code editor.

Where do I find the WPCS?

WPCS are available on Github. I will detail how I do it but there are several methods. Take your pick!

Séb method for installing WPCS

So it’s not really my method… in the sense that it’s not me who developed it… but it’s the one I’m using and that I’m going to detail!

Before installing WPCS, you need to install PHPCS… and yes, WordPress is developed in PHP and to make it simple, WPCS adds rules or modify a little the rules of the PHP Codings Standards.

Keep in mind that, as in all the WordPress ecosystem, the goal is to make development accessible and easy.

Install PHPCS

Personally, I have a partition on my Ubuntu Linux dedicated to my projects and next to the projects, I have a folder with the WPCS and one with the PHPCS.

PHPCS are also available on Github

Clone PHPCS Github repo

Go to the place where you want to download the rules then:

or

if you haven’t entered an SSH key in your GitHub account.

You should now have a folder named phpcs.

Clone WPCS Github repo

We’ll do almost the same command to clone the WPCS repository this time:

or

I reassure you, the hardest part is over…

Setting PHPStorm

Go to “File | Settings | Languages & Frameworks | PHP | Quality Tools”.

Programme d'ordinateur
PHPStorm settings

By clicking on the 3 points to the right of Configuration you can specify the path to the PHPCS. It will be necessary to navigate and select the file “phpcs” present in the directory “phpcs/bin” obtained thanks to the preceding cloning.

Capture d'écran

If everything is OK, at the bottom of the window will show the version of Code Sniffer installed.

Let’s move on to WPCS, because after all… they’re the reason we’re here!

The path to the settings is File | Settings | Editor | Inspections

Logiciel
I love arrows!

the goal here is to get to the “PHP Code Sniffer Validation” menu in order to check “Installed Standard Paths” and to search after clicking on the folder on the right for the directory to be cloned with WPCS.

If all goes well… by clicking on the 2 circular arrows, you should have the choice of several WPCS… personally, I choose WordPress-Extra. then we validate by clicking OK…

3 minutes to install WordPress!

We read everywhere that it takes 5 minutes to install WordPress… and it’s FALSE! We’ve been lied to! We can install it much faster than that…

The proof in video!

Those of you who have already installed a multisite know that after installing WordPress, you have to enter constants in the wp-config.php to activate this mode, go to the Back-Office, configure the network and return to the wp-config.php to paste a pad of constants as well as in the .htaccess … in short much more than with the script I have concocted!

How does it work ?

I’ve created a bash script that, when you run it, asks you a few questions.

Nothing nasty, it’s the information you would enter during the routine of installing a WordPress via your favorite browser.

Once the answers are recorded, the script launches the installation and the multisite is ready … in 3 minutes!

Of course this script will need wp-cli to work.

Command line interface for WordPress | WP-CLI

Command line interface for WordPress | WP-CLI

WP-CLI is the command-line interface for WordPress. You can update plugins, configure multisite installs and much more, without using a web browser.

https://wp-cli.org

I’d like to have the Seb Scripts!

Yeat get it on Github 😉

Publish your WordPress plugin thanks to Github Actions!

This article will surely speak to WordPress extension developers who publish to the WordPress repository… and those who don’t publish to it so they don’t have to use SVN.

Indeed SVN is in a way the ancestor of GIT and nowadays rare are the developers who have not switched to Git.

Github is a service hosting GIT repositories that devs like particularly and very much used in the Open-Source world.

A few weeks ago, GitHub released the Github actions.

OK, but what is Github actions?

Simply put, it’s a solution to automate tasks when an action occurs on a repository or a branch of a repository (pull / push…)

That’s where it gets interesting!

Previously, for my personal example, I would version my code on Github and then I would transfer my WordPress extension files by hand to the WordPress.org SVN.

It works… but it’s long and boring!

Thanks 10Up!

10Up is one of the big WordPress agencies in the world and they just published an action that allows you to publish on the WordPress repo when you push on a branch of a Git repo, a particular Tag.

This tag will be included in the WordPress repository in order to publish the new version of your work.

How do we do it?

I don’t know if it’s the way to do it the right way as they say… but it’s the way I use it… it will surely get better with time, experience, cough cough cough.

In my project, I create a .github folder, note the dot in front and then a workflows subfolder.

Create in this last folder a file named `main.yml`:

Commit, then push this file.

Github Settings

Go to your Github repository, in the “Actions” tab you should find the action created earlier.

Marque
Github Actions

We used a SVN_PASSWORD variable and a SVN_USERNAME corresponding to the SVN IDs needed to publish on the WordPress repo. We’ll need to pass them to Github so that it can connect securely.

Go to the “Settings” tab.

page Web
Github Actions Settings

Click on “Add a new secret”

Capture d'écran
Github Actions Secret

In the “Name” input, enter the 1st variable name “SVN_PASSWORD” and enter the password of your wp.org account in the “Value” textarea.

Repeat, adapting for the variable corresponding to your password.

Test!

If all went well, the next time you create and push a Git tag, your extension will automatically be published to the Official WordPress repository.