WordPress is a free and open-source web content management software (CMS) that can be downloaded and installed on one’s own server.
VSCode Extensions
- Eslint
- Code runner
- CSS flexbox cheatsheet
- Beautify
Applications
LocalWP
brew install composer wget php node
Install PHPCS
composer global require "squizlabs/php_codesniffer=*"
export PATH="$HOME/.composer/vendor/bin:$PATH"
- Install rules
composer global require dealerdirect/phpcodesniffer-composer-installer \
automattic/vipwpcs \
"phpcompatibility/phpcompatibility-wp:*" \
--update-no-dev -W
- Update
composer global update automattic/vipwpcs phpcompatibility/phpcompatibility-wp -W
a “Sniff” is a single PHP class that checks one specific coding rule.
function hello_world() {
echo "Hi"; // Sniff error: Line indented incorrectly; expected 4 spaces, found 0.
}
- File named
phpcs.xmlorphpcs.xml.distis used for custom coding standards. - This file lives in your project’s root directory. phpcs automatically looks for it.
<?xml version="1.0"?>
<ruleset name="MyProjectStandard">
<description>My custom ruleset.</description>
<rule ref="WordPress-VIP"/>
<rule ref="PHPCompatibilityWP"/>
<config name="testVersion" value="8.2"/>
<exclude-pattern>*/vendor/*</exclude-pattern>
</ruleset>
To ignore specific error codes or standards:
- In the
phpcs.xmlfile: You can tell PHPCS to use a standard but “exclude” a specific sniff that you don’t like. - In the Code (Inline): If you have a specific line of code that must break a rule for a good reason, you use comments:
// phpcs:ignore Standard.Category.SniffName -- reason for ignoring $variable = 'this line will be ignored'; // phpcs:disable -- disables everything until the enable tag $some_bad_code = true; // phpcs:enable- In the
PHPCBF (PHP Code Beautifier and Fixer) installs automatically and fixes violations. Command:
phpcbf /path/to/code
phpcs -i shows which rulesets currently being used
To check a file using a standard phpcs --standard=WordPress-VIP path/to/file.php