diff --git a/.github/contributing.md b/.github/contributing.md new file mode 100644 index 0000000..ef0b6cb --- /dev/null +++ b/.github/contributing.md @@ -0,0 +1,35 @@ +# Contributing + +[![PHPCS](https://github.com/cssllc/mu-plugins/actions/workflows/phpcs.yml/badge.svg)](https://github.com/cssllc/mu-plugins/actions/workflows/phpcs.yml) +[![PHPStan](https://github.com/cssllc/mu-plugins/actions/workflows/phpstan.yml/badge.svg)](https://github.com/cssllc/mu-plugins/actions/workflows/phpstan.yml) + +## Checks + +There are two checks run on pull requests: + +1. PHPCS +1. PHPStan + +PHPCS and PHPStan are managed via Composer. + +### Setup + +To setup the checks locally, run the install command with the root of the WordPress install (directory with `composer.json`): + +``` +composer install +``` + +### Run + +#### PHPCS + +``` +vendor/bin/phpcs +``` + +#### PHPStan + +``` +vendor/bin/phpstan --memory-limit=-1 +``` \ No newline at end of file diff --git a/.github/readme.md b/.github/readme.md new file mode 100644 index 0000000..8883695 --- /dev/null +++ b/.github/readme.md @@ -0,0 +1,7 @@ +# MU-Plugins + +Collection of WordPress mu-plugins to enhance and customize a WordPress install. + +## Contributing + +Please read the [Contributing doc](contributing.md). \ No newline at end of file diff --git a/.github/workflows/phpcs.yml b/.github/workflows/phpcs.yml new file mode 100644 index 0000000..888db4b --- /dev/null +++ b/.github/workflows/phpcs.yml @@ -0,0 +1,50 @@ +name: PHPCS +run-name: Run PHPCS on `${{ github.head_ref }}` + +on: + pull_request: + paths: + - 'src/*.php' + - '.github/workflows/phpcs.yml' + - 'phpcs.xml' + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + phpcs: + runs-on: ubuntu-latest + steps: + + - uses: actions/checkout@v3 + + - name: Detect File Changes + uses: dorny/paths-filter@v2 + id: filter + with: + list-files: shell + filters: | + wpcontent: + - added|modified: 'src/**/*.php' + + - name: Setup PHP + if: ${{ steps.filter.outputs.wpcontent == 'true' }} + uses: "shivammathur/setup-php@v2" + with: + php-version: "8.2" + ini-values: "memory_limit=1G" + coverage: none + + - name: Validate composer.json and composer.lock + if: ${{ steps.filter.outputs.wpcontent == 'true' }} + run: composer validate --no-check-publish + + - name: Install Composer dependencies + if: ${{ steps.filter.outputs.wpcontent == 'true' }} + run: | + composer install --prefer-dist --no-progress --no-suggest --optimize-autoloader + + - name: Run PHPCS checks + if: ${{ steps.filter.outputs.wpcontent == 'true' }} + run: ./vendor/bin/phpcs ${{ steps.filter.outputs.wpcontent_files }} \ No newline at end of file diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml new file mode 100644 index 0000000..0630705 --- /dev/null +++ b/.github/workflows/phpstan.yml @@ -0,0 +1,54 @@ +name: PHPStan +run-name: Run PHPStan on `${{ github.head_ref }}` + +on: + pull_request: + paths: + - 'dev/phpstan-bootstrap.php' + - 'dev/wordpress-overrides.stub' + - 'dev/patches/**/*.patch' + - 'src/**/*.php' + - '.github/workflows/phpstan.yml' + - 'phpstan-baseline.neon' + - 'phpstan.neon' + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + phpstan: + runs-on: ubuntu-latest + steps: + + - uses: actions/checkout@v3 + + - name: Detect File Changes + uses: dorny/paths-filter@v2 + id: filter + with: + list-files: shell + filters: | + wpcontent: + - added|modified: 'src/**/*.php' + + - name: Setup PHP + if: ${{ steps.filter.outputs.wpcontent == 'true' }} + uses: "shivammathur/setup-php@v2" + with: + php-version: "8.2" + ini-values: "memory_limit=1G" + coverage: none + + - name: Validate composer.json and composer.lock + if: ${{ steps.filter.outputs.wpcontent == 'true' }} + run: composer validate --no-check-publish + + - name: Install Composer dependencies + if: ${{ steps.filter.outputs.wpcontent == 'true' }} + run: | + composer install --prefer-dist --no-progress --no-suggest --optimize-autoloader + + - name: Run PHPStan checks + if: ${{ steps.filter.outputs.wpcontent == 'true' }} + run: ./vendor/bin/phpstan analyse ${{ steps.filter.outputs.wpcontent_files }} \ No newline at end of file diff --git a/.gitignore b/.gitignore index fbf16a6..5d087f8 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ -/acf-json \ No newline at end of file +/.phpstan-cache +/acf-json +/vendor \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..79e590e --- /dev/null +++ b/composer.json @@ -0,0 +1,29 @@ +{ + "name": "cssllc/mu-plugins", + "description": "CSSLLC MU-Plugins", + "require-dev": { + "automattic/vipwpcs": "^3.0", + "szepeviktor/phpstan-wordpress": "^1.1", + "phpstan/extension-installer": "^1.1", + "php-stubs/acf-pro-stubs": "^6.0", + "php-stubs/wordpress-stubs": "^6.0", + "squizlabs/php_codesniffer": "^3.7", + "mediawiki/mediawiki-codesniffer": "^41.0", + "cweagans/composer-patches": "~1.0" + }, + "config": { + "allow-plugins": { + "dealerdirect/phpcodesniffer-composer-installer": true, + "phpstan/extension-installer": true, + "cweagans/composer-patches": true + } + }, + "license": "proprietary", + "extra": { + "patches": { + "php-stubs/acf-pro-stubs": { + "PHPStan return types": "dev/patches/acf-pro-stubs.patch" + } + } + } +} diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..5dcf46b --- /dev/null +++ b/composer.lock @@ -0,0 +1,1144 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "316153258ea6cfb86b17e0d6c8b420e5", + "packages": [], + "packages-dev": [ + { + "name": "automattic/vipwpcs", + "version": "3.0.0", + "source": { + "type": "git", + "url": "https://github.com/Automattic/VIP-Coding-Standards.git", + "reference": "1b8960ebff9ea3eb482258a906ece4d1ee1e25fd" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Automattic/VIP-Coding-Standards/zipball/1b8960ebff9ea3eb482258a906ece4d1ee1e25fd", + "reference": "1b8960ebff9ea3eb482258a906ece4d1ee1e25fd", + "shasum": "" + }, + "require": { + "php": ">=5.4", + "phpcsstandards/phpcsextra": "^1.1.0", + "phpcsstandards/phpcsutils": "^1.0.8", + "sirbrillig/phpcs-variable-analysis": "^2.11.17", + "squizlabs/php_codesniffer": "^3.7.2", + "wp-coding-standards/wpcs": "^3.0" + }, + "require-dev": { + "php-parallel-lint/php-console-highlighter": "^1.0.0", + "php-parallel-lint/php-parallel-lint": "^1.3.2", + "phpcompatibility/php-compatibility": "^9", + "phpcsstandards/phpcsdevtools": "^1.0", + "phpunit/phpunit": "^4 || ^5 || ^6 || ^7" + }, + "type": "phpcodesniffer-standard", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Contributors", + "homepage": "https://github.com/Automattic/VIP-Coding-Standards/graphs/contributors" + } + ], + "description": "PHP_CodeSniffer rules (sniffs) to enforce WordPress VIP minimum coding conventions", + "keywords": [ + "phpcs", + "standards", + "static analysis", + "wordpress" + ], + "support": { + "issues": "https://github.com/Automattic/VIP-Coding-Standards/issues", + "source": "https://github.com/Automattic/VIP-Coding-Standards", + "wiki": "https://github.com/Automattic/VIP-Coding-Standards/wiki" + }, + "time": "2023-09-05T11:01:05+00:00" + }, + { + "name": "composer/semver", + "version": "3.3.2", + "source": { + "type": "git", + "url": "https://github.com/composer/semver.git", + "reference": "3953f23262f2bff1919fc82183ad9acb13ff62c9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/composer/semver/zipball/3953f23262f2bff1919fc82183ad9acb13ff62c9", + "reference": "3953f23262f2bff1919fc82183ad9acb13ff62c9", + "shasum": "" + }, + "require": { + "php": "^5.3.2 || ^7.0 || ^8.0" + }, + "require-dev": { + "phpstan/phpstan": "^1.4", + "symfony/phpunit-bridge": "^4.2 || ^5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "3.x-dev" + } + }, + "autoload": { + "psr-4": { + "Composer\\Semver\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nils Adermann", + "email": "naderman@naderman.de", + "homepage": "http://www.naderman.de" + }, + { + "name": "Jordi Boggiano", + "email": "j.boggiano@seld.be", + "homepage": "http://seld.be" + }, + { + "name": "Rob Bast", + "email": "rob.bast@gmail.com", + "homepage": "http://robbast.nl" + } + ], + "description": "Semver library that offers utilities, version constraint parsing and validation.", + "keywords": [ + "semantic", + "semver", + "validation", + "versioning" + ], + "support": { + "irc": "irc://irc.freenode.org/composer", + "issues": "https://github.com/composer/semver/issues", + "source": "https://github.com/composer/semver/tree/3.3.2" + }, + "funding": [ + { + "url": "https://packagist.com", + "type": "custom" + }, + { + "url": "https://github.com/composer", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/composer/composer", + "type": "tidelift" + } + ], + "time": "2022-04-01T19:23:25+00:00" + }, + { + "name": "composer/spdx-licenses", + "version": "1.5.7", + "source": { + "type": "git", + "url": "https://github.com/composer/spdx-licenses.git", + "reference": "c848241796da2abf65837d51dce1fae55a960149" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/composer/spdx-licenses/zipball/c848241796da2abf65837d51dce1fae55a960149", + "reference": "c848241796da2abf65837d51dce1fae55a960149", + "shasum": "" + }, + "require": { + "php": "^5.3.2 || ^7.0 || ^8.0" + }, + "require-dev": { + "phpstan/phpstan": "^0.12.55", + "symfony/phpunit-bridge": "^4.2 || ^5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.x-dev" + } + }, + "autoload": { + "psr-4": { + "Composer\\Spdx\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nils Adermann", + "email": "naderman@naderman.de", + "homepage": "http://www.naderman.de" + }, + { + "name": "Jordi Boggiano", + "email": "j.boggiano@seld.be", + "homepage": "http://seld.be" + }, + { + "name": "Rob Bast", + "email": "rob.bast@gmail.com", + "homepage": "http://robbast.nl" + } + ], + "description": "SPDX licenses list and validation library.", + "keywords": [ + "license", + "spdx", + "validator" + ], + "support": { + "irc": "irc://irc.freenode.org/composer", + "issues": "https://github.com/composer/spdx-licenses/issues", + "source": "https://github.com/composer/spdx-licenses/tree/1.5.7" + }, + "funding": [ + { + "url": "https://packagist.com", + "type": "custom" + }, + { + "url": "https://github.com/composer", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/composer/composer", + "type": "tidelift" + } + ], + "time": "2022-05-23T07:37:50+00:00" + }, + { + "name": "cweagans/composer-patches", + "version": "1.7.3", + "source": { + "type": "git", + "url": "https://github.com/cweagans/composer-patches.git", + "reference": "e190d4466fe2b103a55467dfa83fc2fecfcaf2db" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/cweagans/composer-patches/zipball/e190d4466fe2b103a55467dfa83fc2fecfcaf2db", + "reference": "e190d4466fe2b103a55467dfa83fc2fecfcaf2db", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^1.0 || ^2.0", + "php": ">=5.3.0" + }, + "require-dev": { + "composer/composer": "~1.0 || ~2.0", + "phpunit/phpunit": "~4.6" + }, + "type": "composer-plugin", + "extra": { + "class": "cweagans\\Composer\\Patches" + }, + "autoload": { + "psr-4": { + "cweagans\\Composer\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Cameron Eagans", + "email": "me@cweagans.net" + } + ], + "description": "Provides a way to patch Composer packages.", + "support": { + "issues": "https://github.com/cweagans/composer-patches/issues", + "source": "https://github.com/cweagans/composer-patches/tree/1.7.3" + }, + "time": "2022-12-20T22:53:13+00:00" + }, + { + "name": "dealerdirect/phpcodesniffer-composer-installer", + "version": "v1.0.0", + "source": { + "type": "git", + "url": "https://github.com/PHPCSStandards/composer-installer.git", + "reference": "4be43904336affa5c2f70744a348312336afd0da" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCSStandards/composer-installer/zipball/4be43904336affa5c2f70744a348312336afd0da", + "reference": "4be43904336affa5c2f70744a348312336afd0da", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^1.0 || ^2.0", + "php": ">=5.4", + "squizlabs/php_codesniffer": "^2.0 || ^3.1.0 || ^4.0" + }, + "require-dev": { + "composer/composer": "*", + "ext-json": "*", + "ext-zip": "*", + "php-parallel-lint/php-parallel-lint": "^1.3.1", + "phpcompatibility/php-compatibility": "^9.0", + "yoast/phpunit-polyfills": "^1.0" + }, + "type": "composer-plugin", + "extra": { + "class": "PHPCSStandards\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin" + }, + "autoload": { + "psr-4": { + "PHPCSStandards\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Franck Nijhof", + "email": "franck.nijhof@dealerdirect.com", + "homepage": "http://www.frenck.nl", + "role": "Developer / IT Manager" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCSStandards/composer-installer/graphs/contributors" + } + ], + "description": "PHP_CodeSniffer Standards Composer Installer Plugin", + "homepage": "http://www.dealerdirect.com", + "keywords": [ + "PHPCodeSniffer", + "PHP_CodeSniffer", + "code quality", + "codesniffer", + "composer", + "installer", + "phpcbf", + "phpcs", + "plugin", + "qa", + "quality", + "standard", + "standards", + "style guide", + "stylecheck", + "tests" + ], + "support": { + "issues": "https://github.com/PHPCSStandards/composer-installer/issues", + "source": "https://github.com/PHPCSStandards/composer-installer" + }, + "time": "2023-01-05T11:28:13+00:00" + }, + { + "name": "mediawiki/mediawiki-codesniffer", + "version": "v41.0.0", + "source": { + "type": "git", + "url": "https://github.com/wikimedia/mediawiki-tools-codesniffer.git", + "reference": "0ccdbc10ad819e86d7872175e1649037a3352000" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/wikimedia/mediawiki-tools-codesniffer/zipball/0ccdbc10ad819e86d7872175e1649037a3352000", + "reference": "0ccdbc10ad819e86d7872175e1649037a3352000", + "shasum": "" + }, + "require": { + "composer/semver": "3.3.2", + "composer/spdx-licenses": "~1.5.2", + "ext-json": "*", + "ext-mbstring": "*", + "php": ">=7.4.0", + "squizlabs/php_codesniffer": "3.7.2", + "symfony/polyfill-php80": "^1.26.0" + }, + "require-dev": { + "mediawiki/mediawiki-phan-config": "0.12.0", + "mediawiki/minus-x": "1.1.1", + "php-parallel-lint/php-console-highlighter": "1.0.0", + "php-parallel-lint/php-parallel-lint": "1.3.2", + "phpunit/phpunit": "9.5.28" + }, + "type": "phpcodesniffer-standard", + "autoload": { + "psr-4": { + "MediaWiki\\Sniffs\\": "MediaWiki/Sniffs/", + "MediaWiki\\Sniffs\\Tests\\": "MediaWiki/Tests/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "GPL-2.0-or-later" + ], + "description": "MediaWiki CodeSniffer Standards", + "homepage": "https://www.mediawiki.org/wiki/Manual:Coding_conventions/PHP", + "keywords": [ + "codesniffer", + "mediawiki" + ], + "support": { + "source": "https://github.com/wikimedia/mediawiki-tools-codesniffer/tree/v41.0.0" + }, + "time": "2023-02-25T22:10:21+00:00" + }, + { + "name": "php-stubs/acf-pro-stubs", + "version": "v6.1.7", + "source": { + "type": "git", + "url": "https://github.com/php-stubs/acf-pro-stubs.git", + "reference": "0e6c6da1c581b7a6fa555da1ccd90260b5bbc495" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-stubs/acf-pro-stubs/zipball/0e6c6da1c581b7a6fa555da1ccd90260b5bbc495", + "reference": "0e6c6da1c581b7a6fa555da1ccd90260b5bbc495", + "shasum": "" + }, + "require": { + "php-stubs/wordpress-stubs": "^4.7 || ^5.0 || ^6.0" + }, + "require-dev": { + "php": "~7.1", + "php-stubs/generator": "^0.8" + }, + "suggest": { + "symfony/polyfill-php73": "Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions", + "szepeviktor/phpstan-wordpress": "WordPress extensions for PHPStan" + }, + "type": "library", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "GPL-2.0-or-later" + ], + "description": "Advanced Custom Fields PRO stubs for static analysis.", + "homepage": "https://github.com/php-stubs/acf-pro-stubs", + "keywords": [ + "PHPStan", + "acf", + "static analysis", + "wordpress" + ], + "support": { + "issues": "https://github.com/php-stubs/acf-pro-stubs/issues", + "source": "https://github.com/php-stubs/acf-pro-stubs/tree/v6.1.7" + }, + "time": "2023-07-21T09:18:17+00:00" + }, + { + "name": "php-stubs/wordpress-stubs", + "version": "v6.3.0", + "source": { + "type": "git", + "url": "https://github.com/php-stubs/wordpress-stubs.git", + "reference": "adda7609e71d5f4dc7b87c74f8ec9e3437d2e92c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-stubs/wordpress-stubs/zipball/adda7609e71d5f4dc7b87c74f8ec9e3437d2e92c", + "reference": "adda7609e71d5f4dc7b87c74f8ec9e3437d2e92c", + "shasum": "" + }, + "require-dev": { + "nikic/php-parser": "^4.13", + "php": "^7.4 || ~8.0.0", + "php-stubs/generator": "^0.8.3", + "phpdocumentor/reflection-docblock": "^5.3", + "phpstan/phpstan": "^1.10.12", + "phpunit/phpunit": "^9.5" + }, + "suggest": { + "paragonie/sodium_compat": "Pure PHP implementation of libsodium", + "szepeviktor/phpstan-wordpress": "WordPress extensions for PHPStan" + }, + "type": "library", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "WordPress function and class declaration stubs for static analysis.", + "homepage": "https://github.com/php-stubs/wordpress-stubs", + "keywords": [ + "PHPStan", + "static analysis", + "wordpress" + ], + "support": { + "issues": "https://github.com/php-stubs/wordpress-stubs/issues", + "source": "https://github.com/php-stubs/wordpress-stubs/tree/v6.3.0" + }, + "time": "2023-08-10T16:34:11+00:00" + }, + { + "name": "phpcsstandards/phpcsextra", + "version": "1.1.1", + "source": { + "type": "git", + "url": "https://github.com/PHPCSStandards/PHPCSExtra.git", + "reference": "98bcdbacbda14b1db85f710b1853125726795bbc" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCSStandards/PHPCSExtra/zipball/98bcdbacbda14b1db85f710b1853125726795bbc", + "reference": "98bcdbacbda14b1db85f710b1853125726795bbc", + "shasum": "" + }, + "require": { + "php": ">=5.4", + "phpcsstandards/phpcsutils": "^1.0.8", + "squizlabs/php_codesniffer": "^3.7.1" + }, + "require-dev": { + "php-parallel-lint/php-console-highlighter": "^1.0", + "php-parallel-lint/php-parallel-lint": "^1.3.2", + "phpcsstandards/phpcsdevcs": "^1.1.6", + "phpcsstandards/phpcsdevtools": "^1.2.1", + "phpunit/phpunit": "^4.5 || ^5.0 || ^6.0 || ^7.0" + }, + "type": "phpcodesniffer-standard", + "extra": { + "branch-alias": { + "dev-stable": "1.x-dev", + "dev-develop": "1.x-dev" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0-or-later" + ], + "authors": [ + { + "name": "Juliette Reinders Folmer", + "homepage": "https://github.com/jrfnl", + "role": "lead" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCSStandards/PHPCSExtra/graphs/contributors" + } + ], + "description": "A collection of sniffs and standards for use with PHP_CodeSniffer.", + "keywords": [ + "PHP_CodeSniffer", + "phpcbf", + "phpcodesniffer-standard", + "phpcs", + "standards", + "static analysis" + ], + "support": { + "issues": "https://github.com/PHPCSStandards/PHPCSExtra/issues", + "source": "https://github.com/PHPCSStandards/PHPCSExtra" + }, + "time": "2023-08-26T04:46:45+00:00" + }, + { + "name": "phpcsstandards/phpcsutils", + "version": "1.0.8", + "source": { + "type": "git", + "url": "https://github.com/PHPCSStandards/PHPCSUtils.git", + "reference": "69465cab9d12454e5e7767b9041af0cd8cd13be7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCSStandards/PHPCSUtils/zipball/69465cab9d12454e5e7767b9041af0cd8cd13be7", + "reference": "69465cab9d12454e5e7767b9041af0cd8cd13be7", + "shasum": "" + }, + "require": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.4.1 || ^0.5 || ^0.6.2 || ^0.7 || ^1.0", + "php": ">=5.4", + "squizlabs/php_codesniffer": "^3.7.1 || 4.0.x-dev@dev" + }, + "require-dev": { + "ext-filter": "*", + "php-parallel-lint/php-console-highlighter": "^1.0", + "php-parallel-lint/php-parallel-lint": "^1.3.2", + "phpcsstandards/phpcsdevcs": "^1.1.6", + "yoast/phpunit-polyfills": "^1.0.5 || ^2.0.0" + }, + "type": "phpcodesniffer-standard", + "extra": { + "branch-alias": { + "dev-stable": "1.x-dev", + "dev-develop": "1.x-dev" + } + }, + "autoload": { + "classmap": [ + "PHPCSUtils/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0-or-later" + ], + "authors": [ + { + "name": "Juliette Reinders Folmer", + "homepage": "https://github.com/jrfnl", + "role": "lead" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCSStandards/PHPCSUtils/graphs/contributors" + } + ], + "description": "A suite of utility functions for use with PHP_CodeSniffer", + "homepage": "https://phpcsutils.com/", + "keywords": [ + "PHP_CodeSniffer", + "phpcbf", + "phpcodesniffer-standard", + "phpcs", + "phpcs3", + "standards", + "static analysis", + "tokens", + "utility" + ], + "support": { + "docs": "https://phpcsutils.com/", + "issues": "https://github.com/PHPCSStandards/PHPCSUtils/issues", + "source": "https://github.com/PHPCSStandards/PHPCSUtils" + }, + "time": "2023-07-16T21:39:41+00:00" + }, + { + "name": "phpstan/extension-installer", + "version": "1.3.1", + "source": { + "type": "git", + "url": "https://github.com/phpstan/extension-installer.git", + "reference": "f45734bfb9984c6c56c4486b71230355f066a58a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/extension-installer/zipball/f45734bfb9984c6c56c4486b71230355f066a58a", + "reference": "f45734bfb9984c6c56c4486b71230355f066a58a", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^2.0", + "php": "^7.2 || ^8.0", + "phpstan/phpstan": "^1.9.0" + }, + "require-dev": { + "composer/composer": "^2.0", + "php-parallel-lint/php-parallel-lint": "^1.2.0", + "phpstan/phpstan-strict-rules": "^0.11 || ^0.12 || ^1.0" + }, + "type": "composer-plugin", + "extra": { + "class": "PHPStan\\ExtensionInstaller\\Plugin" + }, + "autoload": { + "psr-4": { + "PHPStan\\ExtensionInstaller\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Composer plugin for automatic installation of PHPStan extensions", + "support": { + "issues": "https://github.com/phpstan/extension-installer/issues", + "source": "https://github.com/phpstan/extension-installer/tree/1.3.1" + }, + "time": "2023-05-24T08:59:17+00:00" + }, + { + "name": "phpstan/phpstan", + "version": "1.10.34", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpstan.git", + "reference": "7f806b6f1403e6914c778140e2ba07c293cb4901" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/7f806b6f1403e6914c778140e2ba07c293cb4901", + "reference": "7f806b6f1403e6914c778140e2ba07c293cb4901", + "shasum": "" + }, + "require": { + "php": "^7.2|^8.0" + }, + "conflict": { + "phpstan/phpstan-shim": "*" + }, + "bin": [ + "phpstan", + "phpstan.phar" + ], + "type": "library", + "autoload": { + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPStan - PHP Static Analysis Tool", + "keywords": [ + "dev", + "static analysis" + ], + "support": { + "docs": "https://phpstan.org/user-guide/getting-started", + "forum": "https://github.com/phpstan/phpstan/discussions", + "issues": "https://github.com/phpstan/phpstan/issues", + "security": "https://github.com/phpstan/phpstan/security/policy", + "source": "https://github.com/phpstan/phpstan-src" + }, + "funding": [ + { + "url": "https://github.com/ondrejmirtes", + "type": "github" + }, + { + "url": "https://github.com/phpstan", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/phpstan/phpstan", + "type": "tidelift" + } + ], + "time": "2023-09-13T09:49:47+00:00" + }, + { + "name": "sirbrillig/phpcs-variable-analysis", + "version": "v2.11.17", + "source": { + "type": "git", + "url": "https://github.com/sirbrillig/phpcs-variable-analysis.git", + "reference": "3b71162a6bf0cde2bff1752e40a1788d8273d049" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sirbrillig/phpcs-variable-analysis/zipball/3b71162a6bf0cde2bff1752e40a1788d8273d049", + "reference": "3b71162a6bf0cde2bff1752e40a1788d8273d049", + "shasum": "" + }, + "require": { + "php": ">=5.4.0", + "squizlabs/php_codesniffer": "^3.5.6" + }, + "require-dev": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.7 || ^1.0", + "phpcsstandards/phpcsdevcs": "^1.1", + "phpstan/phpstan": "^1.7", + "phpunit/phpunit": "^4.8.36 || ^5.7.21 || ^6.5 || ^7.0 || ^8.0 || ^9.0", + "sirbrillig/phpcs-import-detection": "^1.1", + "vimeo/psalm": "^0.2 || ^0.3 || ^1.1 || ^4.24 || ^5.0@beta" + }, + "type": "phpcodesniffer-standard", + "autoload": { + "psr-4": { + "VariableAnalysis\\": "VariableAnalysis/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-2-Clause" + ], + "authors": [ + { + "name": "Sam Graham", + "email": "php-codesniffer-variableanalysis@illusori.co.uk" + }, + { + "name": "Payton Swick", + "email": "payton@foolord.com" + } + ], + "description": "A PHPCS sniff to detect problems with variables.", + "keywords": [ + "phpcs", + "static analysis" + ], + "support": { + "issues": "https://github.com/sirbrillig/phpcs-variable-analysis/issues", + "source": "https://github.com/sirbrillig/phpcs-variable-analysis", + "wiki": "https://github.com/sirbrillig/phpcs-variable-analysis/wiki" + }, + "time": "2023-08-05T23:46:11+00:00" + }, + { + "name": "squizlabs/php_codesniffer", + "version": "3.7.2", + "source": { + "type": "git", + "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", + "reference": "ed8e00df0a83aa96acf703f8c2979ff33341f879" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/ed8e00df0a83aa96acf703f8c2979ff33341f879", + "reference": "ed8e00df0a83aa96acf703f8c2979ff33341f879", + "shasum": "" + }, + "require": { + "ext-simplexml": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" + }, + "bin": [ + "bin/phpcs", + "bin/phpcbf" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.x-dev" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Greg Sherwood", + "role": "lead" + } + ], + "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", + "homepage": "https://github.com/squizlabs/PHP_CodeSniffer", + "keywords": [ + "phpcs", + "standards", + "static analysis" + ], + "support": { + "issues": "https://github.com/squizlabs/PHP_CodeSniffer/issues", + "source": "https://github.com/squizlabs/PHP_CodeSniffer", + "wiki": "https://github.com/squizlabs/PHP_CodeSniffer/wiki" + }, + "time": "2023-02-22T23:07:41+00:00" + }, + { + "name": "symfony/polyfill-php73", + "version": "v1.28.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-php73.git", + "reference": "fe2f306d1d9d346a7fee353d0d5012e401e984b5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-php73/zipball/fe2f306d1d9d346a7fee353d0d5012e401e984b5", + "reference": "fe2f306d1d9d346a7fee353d0d5012e401e984b5", + "shasum": "" + }, + "require": { + "php": ">=7.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.28-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "files": [ + "bootstrap.php" + ], + "psr-4": { + "Symfony\\Polyfill\\Php73\\": "" + }, + "classmap": [ + "Resources/stubs" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "polyfill", + "portable", + "shim" + ], + "support": { + "source": "https://github.com/symfony/polyfill-php73/tree/v1.28.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2023-01-26T09:26:14+00:00" + }, + { + "name": "symfony/polyfill-php80", + "version": "v1.28.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-php80.git", + "reference": "6caa57379c4aec19c0a12a38b59b26487dcfe4b5" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/6caa57379c4aec19c0a12a38b59b26487dcfe4b5", + "reference": "6caa57379c4aec19c0a12a38b59b26487dcfe4b5", + "shasum": "" + }, + "require": { + "php": ">=7.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.28-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "files": [ + "bootstrap.php" + ], + "psr-4": { + "Symfony\\Polyfill\\Php80\\": "" + }, + "classmap": [ + "Resources/stubs" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ion Bazan", + "email": "ion.bazan@gmail.com" + }, + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "polyfill", + "portable", + "shim" + ], + "support": { + "source": "https://github.com/symfony/polyfill-php80/tree/v1.28.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2023-01-26T09:26:14+00:00" + }, + { + "name": "szepeviktor/phpstan-wordpress", + "version": "v1.3.0", + "source": { + "type": "git", + "url": "https://github.com/szepeviktor/phpstan-wordpress.git", + "reference": "5b5cc77ed51fdaf64efe3f00b5aae4b709d2cfa9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/szepeviktor/phpstan-wordpress/zipball/5b5cc77ed51fdaf64efe3f00b5aae4b709d2cfa9", + "reference": "5b5cc77ed51fdaf64efe3f00b5aae4b709d2cfa9", + "shasum": "" + }, + "require": { + "php": "^7.2 || ^8.0", + "php-stubs/wordpress-stubs": "^4.7 || ^5.0 || ^6.0", + "phpstan/phpstan": "^1.10.0", + "symfony/polyfill-php73": "^1.12.0" + }, + "require-dev": { + "composer/composer": "^2.1.14", + "dealerdirect/phpcodesniffer-composer-installer": "^1.0", + "php-parallel-lint/php-parallel-lint": "^1.1", + "phpstan/phpstan-strict-rules": "^1.2", + "phpunit/phpunit": "^8.0 || ^9.0", + "szepeviktor/phpcs-psr-12-neutron-hybrid-ruleset": "^0.8" + }, + "type": "phpstan-extension", + "extra": { + "phpstan": { + "includes": [ + "extension.neon" + ] + } + }, + "autoload": { + "psr-4": { + "SzepeViktor\\PHPStan\\WordPress\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "WordPress extensions for PHPStan", + "keywords": [ + "PHPStan", + "code analyse", + "code analysis", + "static analysis", + "wordpress" + ], + "support": { + "issues": "https://github.com/szepeviktor/phpstan-wordpress/issues", + "source": "https://github.com/szepeviktor/phpstan-wordpress/tree/v1.3.0" + }, + "time": "2023-04-23T06:15:06+00:00" + }, + { + "name": "wp-coding-standards/wpcs", + "version": "3.0.1", + "source": { + "type": "git", + "url": "https://github.com/WordPress/WordPress-Coding-Standards.git", + "reference": "b4caf9689f1a0e4a4c632679a44e638c1c67aff1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/WordPress/WordPress-Coding-Standards/zipball/b4caf9689f1a0e4a4c632679a44e638c1c67aff1", + "reference": "b4caf9689f1a0e4a4c632679a44e638c1c67aff1", + "shasum": "" + }, + "require": { + "ext-filter": "*", + "ext-libxml": "*", + "ext-tokenizer": "*", + "ext-xmlreader": "*", + "php": ">=5.4", + "phpcsstandards/phpcsextra": "^1.1.0", + "phpcsstandards/phpcsutils": "^1.0.8", + "squizlabs/php_codesniffer": "^3.7.2" + }, + "require-dev": { + "php-parallel-lint/php-console-highlighter": "^1.0.0", + "php-parallel-lint/php-parallel-lint": "^1.3.2", + "phpcompatibility/php-compatibility": "^9.0", + "phpcsstandards/phpcsdevtools": "^1.2.0", + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" + }, + "suggest": { + "ext-iconv": "For improved results", + "ext-mbstring": "For improved results" + }, + "type": "phpcodesniffer-standard", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Contributors", + "homepage": "https://github.com/WordPress/WordPress-Coding-Standards/graphs/contributors" + } + ], + "description": "PHP_CodeSniffer rules (sniffs) to enforce WordPress coding conventions", + "keywords": [ + "phpcs", + "standards", + "static analysis", + "wordpress" + ], + "support": { + "issues": "https://github.com/WordPress/WordPress-Coding-Standards/issues", + "source": "https://github.com/WordPress/WordPress-Coding-Standards", + "wiki": "https://github.com/WordPress/WordPress-Coding-Standards/wiki" + }, + "funding": [ + { + "url": "https://opencollective.com/thewpcc/contribute/wp-php-63406", + "type": "custom" + } + ], + "time": "2023-09-14T07:06:09+00:00" + } + ], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [], + "plugin-api-version": "2.3.0" +} diff --git a/cssllc-acf--rule-page-slug.php b/cssllc-acf--rule-page-slug.php deleted file mode 100644 index b11fd20..0000000 --- a/cssllc-acf--rule-page-slug.php +++ /dev/null @@ -1,97 +0,0 @@ - 'page', - 'posts_per_page' => -1, - 'orderby' => 'title', - 'order' => 'asc', - ) ); - - $choices = array(); - - foreach ( $query->posts as $post ) - $choices[$post->post_name] = get_the_title( $post ); - - return $choices; - } - - function filter__acf_location_rule_match_slug( $match, $rule, $options, $field_group ) { - if ( - !isset( $options['post_type'] ) - || 'page' !== $options['post_type'] - ) - return $match; - - $page = get_post( $options['post_id'] ); - - switch ( $rule['operator'] ) { - - case '==': - return $page->post_name === $rule['value']; - - case '!=': - return $page->post_name !== $rule['value']; - - case 'contains': - return false !== stripos( $page->post_name, $rule['value'] ); - - case 'does not contain': - return false === stripos( $page->post_name, $rule['value'] ); - - } - - return $match; - } - -} - -add_action( 'init', array( 'CSSLLC_ACF__Rule_PageSlug', 'init' ), 5 ); - -?> \ No newline at end of file diff --git a/dev/patches/acf-pro-stubs.patch b/dev/patches/acf-pro-stubs.patch new file mode 100644 index 0000000..4fb457f --- /dev/null +++ b/dev/patches/acf-pro-stubs.patch @@ -0,0 +1,14 @@ +diff --git a/acf-pro-stubs.php b/acf-pro-stubs.php +--- dev/null ++++ b/acf-pro-stubs.php +@@ -21074,8 +21074,8 @@ function acf_register_field_type_info($info) + * @date 31/5/17 + * @since 5.6.0 + * +-* @param void +-* @return void ++* @param string $name ++* @return mixed + */ + function acf_get_field_type($name) + { diff --git a/dev/phpstan-bootstrap.php b/dev/phpstan-bootstrap.php new file mode 100644 index 0000000..b4436e7 --- /dev/null +++ b/dev/phpstan-bootstrap.php @@ -0,0 +1,16 @@ + + + OM Performance Marketers Coding Standards. + + src + + + + + + + + + + + + + + *-config.php + *assets/ + *vendor/ + *tests/* + extensions\/(?!twig).* + *webpack/ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + + + + + + + + + + + + + + 3 + + + + + + + + + + + \ No newline at end of file diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon new file mode 100644 index 0000000..5b9c3ba --- /dev/null +++ b/phpstan-baseline.neon @@ -0,0 +1,6 @@ +parameters: + ignoreErrors: + - + message: "#^Variable \\$dev_email_address in empty\\(\\) always exists and is always falsy\\.$#" + count: 1 + path: src/cssllc-environment.php diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..34145b5 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,40 @@ +includes: + - phpstan-baseline.neon + +parameters: + level: 9 + paths: + - src/ + bootstrapFiles: + - dev/phpstan-bootstrap.php + - vendor/php-stubs/wordpress-stubs/wordpress-stubs.php + - vendor/php-stubs/acf-pro-stubs/acf-pro-stubs.php + stubFiles: + - dev/wordpress-overrides.stub + dynamicConstantNames: + - CONCATENATE_SCRIPTS + - COMPRESS_SCRIPTS + - COMPRESS_CSS + tmpDir: .phpstan-cache/ + reportUnmatchedIgnoredErrors: false + ignoreErrors: + - '#^Function yoast_get_primary_term_id not found.$#' + # Uses func_get_args() + - '#^Function apply_filters invoked with [34567] parameters, 2 required\.$#' + - '#^Function do_action invoked with [3456] parameters, 1-2 required\.$#' + - '#^Function current_user_can invoked with 2 parameters, 1 required\.$#' + - '#^Function add_query_arg invoked with [123] parameters?, 0 required\.$#' + - '#^Function add_theme_support invoked with [2345] parameters, 1 required\.$#' + - '#^Function wp_sprintf invoked with [23456] parameters, 1 required\.$#' + # https://core.trac.wordpress.org/ticket/43304 + - '/^Parameter #2 \$deprecated of function load_plugin_textdomain expects string, false given\.$/' + # WP-CLI accepts a class as callable + - '/^Parameter #2 \$callable of static method WP_CLI::add_command\(\) expects callable\(\): mixed, \S+ given\.$/' + - '#PHPDoc tag @throws with type .*? is not subtype of Throwable#' + - '#Function gravity_form not found.#' + - '/^Parameter #1 \$args of function wp_nav_menu expects.* given\.$/' + + checkAlwaysTrueStrictComparison: true + + # Unfortunately, DocBlocks can't be relied upon in WordPress. + treatPhpDocTypesAsCertain: false \ No newline at end of file diff --git a/src/cssllc-acf--rule-page-slug.php b/src/cssllc-acf--rule-page-slug.php new file mode 100644 index 0000000..9665d9d --- /dev/null +++ b/src/cssllc-acf--rule-page-slug.php @@ -0,0 +1,131 @@ +> $choices + * @return array> + */ + public function filter__acf_location_rule_types( array $choices ) { + $choices['Page']['page'] = 'Page ID'; + $choices['Page']['slug'] = 'Page Slug'; + + return $choices; + } + + /** + * @param array $choices + * @return array + */ + public function filter__acf_location_rule_operators_slug( array $choices ) { + $choices['contains'] = 'contains'; + $choices['does not contain'] = 'does not contain'; + + return $choices; + } + + /** + * @param array $choices + * @return array + */ + public function filter__acf_location_rule_values_slug( array $choices ) { + $query = new WP_Query( array( + 'post_type' => 'page', + 'posts_per_page' => -1, + 'orderby' => 'title', + 'order' => 'asc', + ) ); + + $choices = array(); + + foreach ( $query->posts as $post ) { + if ( ! is_object( $post ) || ! is_a( $post, WP_Post::class ) ) { + continue; + } + + $choices[ $post->post_name ] = get_the_title( $post ); + } + + return $choices; + } + + /** + * @param bool $match + * @param array $rule + * @param array $options + * @return bool + */ + public function filter__acf_location_rule_match_slug( $match, $rule, $options ) { + if ( + ! isset( $options['post_type'] ) + || 'page' !== $options['post_type'] + ) { + return $match; + } + + $page = get_post( $options['post_id'] ); + + if ( is_null( $page ) || ! is_string( $rule['value'] ) ) { + return false; + } + + switch ( $rule['operator'] ) { + + case '==': + return $page->post_name === $rule['value']; + + case '!=': + return $page->post_name !== $rule['value']; + + case 'contains': + return false !== stripos( $page->post_name, $rule['value'] ); + + case 'does not contain': + return false === stripos( $page->post_name, $rule['value'] ); + + } + + return $match; + } + +} + +add_action( 'init', array( 'CSSLLC_ACF__Rule_PageSlug', 'init' ), 5 ); diff --git a/cssllc-acf.php b/src/cssllc-acf.php similarity index 85% rename from cssllc-acf.php rename to src/cssllc-acf.php index eb1b86f..d8ee13f 100644 --- a/cssllc-acf.php +++ b/src/cssllc-acf.php @@ -32,11 +32,12 @@ public static function init() { * * @return self */ - static function instance() { + public static function instance() { static $instance = null; - if ( is_null( $instance ) ) + if ( is_null( $instance ) ) { $instance = new self; + } return $instance; } @@ -56,7 +57,6 @@ protected function __construct() { add_filter( 'acf/settings/enable_post_types', '__return_false' ); add_filter( 'acf/settings/save_json', array( $this, 'filter__acf_settings_save_json' ) ); add_filter( 'acf/settings/load_json', array( $this, 'filter__acf_settings_load_json' ) ); - } /** @@ -67,7 +67,7 @@ protected function __construct() { protected function maybe_create_directory() { if ( ! file_exists( $this->directory ) - || ! is_dir( $this->directory ) + || ! is_dir( $this->directory ) ) { mkdir( $this->directory ); } @@ -88,7 +88,7 @@ protected function maybe_create_directory() { * * @return void */ - function action__acf_input_admin_head() : void { + public function action__acf_input_admin_head() : void { echo ''; } @@ -101,7 +101,7 @@ function action__acf_input_admin_head() : void { * @param string $path * @return string */ - function filter__acf_settings_save_json( $path = '' ) { + public function filter__acf_settings_save_json( $path = '' ) { return $this->directory; } @@ -113,9 +113,11 @@ function filter__acf_settings_save_json( $path = '' ) { * @param string[] $paths * @return string[] */ - function filter__acf_settings_load_json( $paths ) { - $pattern = trailingslashit( get_template_directory() ) . 'template-*/'; - $paths = glob( $pattern, GLOB_ONLYDIR ); + public function filter__acf_settings_load_json( $paths ) { + if ( ! is_array( $paths ) ) { + $paths = array(); + } + $paths[] = $this->directory; return $paths; @@ -124,5 +126,3 @@ function filter__acf_settings_load_json( $paths ) { } add_action( 'init', array( 'CSSLLC_ACF', 'init' ), 0 ); - -?> diff --git a/cssllc-cpt.php b/src/cssllc-cpt.php similarity index 76% rename from cssllc-cpt.php rename to src/cssllc-cpt.php index b960396..19f0675 100644 --- a/cssllc-cpt.php +++ b/src/cssllc-cpt.php @@ -12,6 +12,8 @@ /** * Abstract class for custom post types. + * + * @phpstan-consistent-constructor */ abstract class CSSLLC_CPT { @@ -49,7 +51,7 @@ abstract class CSSLLC_CPT { 'has_archive' => true, 'hierarchical' => false, - 'rewrite' => array( + 'rewrite' => array( 'with_front' => false, ), @@ -57,14 +59,14 @@ abstract class CSSLLC_CPT { /* - ###### ######## ### ######## #### ###### - ## ## ## ## ## ## ## ## ## - ## ## ## ## ## ## ## - ###### ## ## ## ## ## ## - ## ## ######### ## ## ## - ## ## ## ## ## ## ## ## ## - ###### ## ## ## ## #### ###### - */ + * ###### ######## ### ######## #### ###### + * ## ## ## ## ## ## ## ## ## + * ## ## ## ## ## ## ## + * ###### ## ## ## ## ## ## + * ## ## ######### ## ## ## + * ## ## ## ## ## ## ## ## ## + * ###### ## ## ## ## #### ###### + */ /** * Initialize. @@ -72,11 +74,12 @@ abstract class CSSLLC_CPT { * @uses static::instance() * @return void */ - static function init() : void { + public static function init() : void { static $init = array(); - if ( in_array( static::class, $init ) ) + if ( in_array( static::class, $init ) ) { return; + } static::instance(); @@ -88,11 +91,12 @@ static function init() : void { * * @return CSSLLC_CPT */ - static function instance() : CSSLLC_CPT { + public static function instance() : CSSLLC_CPT { static $instances = array(); - if ( ! array_key_exists( static::class, $instances ) ) + if ( ! array_key_exists( static::class, $instances ) ) { $instances[ static::class ] = new static; + } return $instances[ static::class ]; } @@ -107,9 +111,9 @@ static function instance() : CSSLLC_CPT { */ protected static function register() : void { if ( - empty( static::TYPE ) + empty( static::TYPE ) || empty( static::SINGULAR ) - || empty( static::PLURAL ) + || empty( static::PLURAL ) ) { trigger_error( sprintf( 'Custom post type `%s` is not setup.', static::TYPE ), E_USER_WARNING ); return; @@ -161,11 +165,12 @@ protected static function default_labels() : array { * @uses get_post_type_object() * @return WP_Post_Type */ - static function object() : WP_Post_Type { + public static function object() : WP_Post_Type { $object = get_post_type_object( static::TYPE ); - if ( is_null( $object ) ) + if ( is_null( $object ) ) { return new WP_Post_Type( 'does_not_exist' ); + } return $object; } @@ -189,13 +194,12 @@ static function object() : WP_Post_Type { protected function __construct() { $this->setup(); - add_action( 'init', array( $this, 'action__init' ) ); + add_action( 'init', array( $this, 'action__init' ) ); add_action( 'admin_init', array( $this, 'action__admin_init' ) ); - add_filter( 'dashboard_glance_items', array( $this, 'filter__dashboard_glance_items' ) ); + add_filter( 'dashboard_glance_items', array( $this, 'filter__dashboard_glance_items' ) ); add_filter( 'bulk_post_updated_messages', array( $this, 'filter__bulk_post_updated_messages' ), 10, 2 ); - add_filter( 'post_updated_messages', array( $this, 'filter__post_updated_messages' ) ); - + add_filter( 'post_updated_messages', array( $this, 'filter__post_updated_messages' ) ); } /** @@ -205,14 +209,25 @@ protected function __construct() { * @return void */ protected function setup() : void { - if ( !array_key_exists( 'labels', $this->args ) ) $this->args['labels'] = array(); - if ( !array_key_exists( 'rewrite', $this->args ) ) $this->args['rewrite'] = array(); + if ( ! array_key_exists( 'labels', $this->args ) ) { + $this->args['labels'] = array(); + } - if ( is_array( $this->args['labels'] ) ) + if ( ! array_key_exists( 'rewrite', $this->args ) ) { + $this->args['rewrite'] = array(); + } + + if ( is_array( $this->args['labels'] ) ) { $this->args['labels'] = wp_parse_args( $this->args['labels'], static::default_labels() ); + } - if ( is_array( $this->args['rewrite'] ) ) + if ( ! is_array( static::$default_args['rewrite'] ) ) { + static::$default_args['rewrite'] = array(); + } + + if ( is_array( $this->args['rewrite'] ) ) { $this->args['rewrite'] = wp_parse_args( $this->args['rewrite'], static::$default_args['rewrite'] ); + } } @@ -234,9 +249,10 @@ protected function setup() : void { * @uses static::register() * @return void */ - function action__init() : void { - if ( 'init' !== current_action() ) + public function action__init() : void { + if ( 'init' !== current_action() ) { return; + } static::register(); } @@ -249,9 +265,10 @@ function action__init() : void { * @uses wp_add_inline_style() * @return void */ - function action__admin_init() : void { - if ( 'admin_init' !== current_action() ) + public function action__admin_init() : void { + if ( 'admin_init' !== current_action() ) { return; + } wp_add_inline_style( 'dashicons', '.icon-cpt-' . esc_attr( static::TYPE ) . ':before { content: "' . static::DASHICON_CODE . '" !important; }' ); } @@ -277,17 +294,20 @@ function action__admin_init() : void { * @param string[] $items * @return string[] */ - function filter__dashboard_glance_items( array $items ) : array { - if ( 'dashboard_glance_items' !== current_filter() ) + public function filter__dashboard_glance_items( array $items ) : array { + if ( 'dashboard_glance_items' !== current_filter() ) { return $items; + } - if ( !current_user_can( static::object()->cap->edit_posts ) ) + if ( ! current_user_can( static::object()->cap->edit_posts ) ) { return $items; + } $count = wp_count_posts( static::TYPE ); - if ( empty( $count->publish ) ) + if ( empty( $count->publish ) ) { $count->publish = 0; + } $url = add_query_arg( 'post_type', static::TYPE, 'edit.php' ); @@ -309,24 +329,25 @@ function filter__dashboard_glance_items( array $items ) : array { * @param mixed[] $bulk_counts * @return mixed[] */ - function filter__bulk_post_updated_messages( array $bulk_messages, array $bulk_counts ) : array { - if ( 'bulk_post_updated_messages' !== current_filter() ) + public function filter__bulk_post_updated_messages( array $bulk_messages, array $bulk_counts ) : array { + if ( 'bulk_post_updated_messages' !== current_filter() ) { return $bulk_messages; + } $singular = strtolower( static::SINGULAR ); - $plural = strtolower( static::PLURAL ); + $plural = strtolower( static::PLURAL ); - $bulk_messages[static::TYPE] = array( - 'updated' => _n( '%s ' . $singular . ' updated.', '%s ' . $plural . ' updated.', $bulk_counts['updated'] ), - 'deleted' => _n( '%s ' . $singular . ' permanently deleted.', '%s ' . $plural . ' permanently deleted.', $bulk_counts['deleted'] ), - 'trashed' => _n( '%s ' . $singular . ' moved to the Trash.', '%s ' . $plural . ' moved to the Trash.', $bulk_counts['trashed'] ), - 'untrashed' => _n( '%s ' . $singular . ' restored from the Trash.', '%s ' . $plural . ' restored from the Trash.', $bulk_counts['untrashed'] ), + $bulk_messages[ static::TYPE ] = array( + 'updated' => _n( '%s ' . $singular . ' updated.', '%s ' . $plural . ' updated.', absint( $bulk_counts['updated'] ) ), + 'deleted' => _n( '%s ' . $singular . ' permanently deleted.', '%s ' . $plural . ' permanently deleted.', absint( $bulk_counts['deleted'] ) ), + 'trashed' => _n( '%s ' . $singular . ' moved to the Trash.', '%s ' . $plural . ' moved to the Trash.', absint( $bulk_counts['trashed'] ) ), + 'untrashed' => _n( '%s ' . $singular . ' restored from the Trash.', '%s ' . $plural . ' restored from the Trash.', absint( $bulk_counts['untrashed'] ) ), ); - $bulk_messages[static::TYPE]['locked'] = _n( + $bulk_messages[ static::TYPE ]['locked'] = _n( '%s ' . $singular . ' not updated, somebody is editing it.', '%s ' . $plural . ' not updated, somebody is editing them.', - $bulk_counts['locked'] + absint( $bulk_counts['locked'] ) ); return $bulk_messages; @@ -340,14 +361,16 @@ function filter__bulk_post_updated_messages( array $bulk_messages, array $bulk_c * @param mixed[] $notices * @return mixed[] */ - function filter__post_updated_messages( array $notices ) : array { - if ( 'post_updated_messages' !== current_filter() ) + public function filter__post_updated_messages( array $notices ) : array { + if ( 'post_updated_messages' !== current_filter() ) { return $notices; + } global $post; - if ( get_post_type( $post ) !== static::TYPE ) + if ( get_post_type( $post ) !== static::TYPE ) { return $notices; + } $preview_link_html = ''; $scheduled_link_html = ''; @@ -383,10 +406,10 @@ function filter__post_updated_messages( array $notices ) : array { $scheduled_date = sprintf( __( '%1$s at %2$s' ), date_i18n( _x( 'M j, Y', 'publish box date format' ), strtotime( $post->post_date ) ), - date_i18n( _x( 'H:i', 'publish box time format' ), strtotime( $post->post_date ) ) + date_i18n( _x( 'H:i', 'publish box time format' ), strtotime( $post->post_date ) ) ); - $notices[static::TYPE] = array( + $notices[ static::TYPE ] = array( 0 => '', // Unused. Messages start at index 1. 1 => __( static::SINGULAR . ' updated.' ) . $view_link_html, 2 => __( 'Custom field updated.' ), diff --git a/cssllc-default-constants.php b/src/cssllc-default-constants.php similarity index 62% rename from cssllc-default-constants.php rename to src/cssllc-default-constants.php index 6730149..9b052eb 100644 --- a/cssllc-default-constants.php +++ b/src/cssllc-default-constants.php @@ -6,17 +6,20 @@ * Plugin URI: https://github.com/cssllc/mu-plugins */ -$is_production = ( 'production' === wp_get_environment_type() ); +// phpcs:disable PEAR.Functions.FunctionCallSignature.SpaceBeforeCloseBracket +// phpcs:disable Generic.Functions.FunctionCallArgumentSpacing.TooMuchSpaceAfterComma +// phpcs:disable WordPress.WhiteSpace.OperatorSpacing.SpacingBefore +// phpcs:disable PEAR.Functions.FunctionCallSignature.SpaceAfterOpenBracket -defined( 'WP_DEBUG' ) || define( 'WP_DEBUG', !$is_production ); -defined( 'WP_DEBUG_LOG' ) || define( 'WP_DEBUG_LOG', WP_DEBUG ); -defined( 'WP_DEBUG_DISPLAY' ) || define( 'WP_DEBUG_DISPLAY', false ); -defined( 'SCRIPT_DEBUG' ) || define( 'SCRIPT_DEBUG', !$is_production ); -defined( 'CONCATENATE_SCRIPTS' ) || define( 'CONCATENATE_SCRIPTS', !WP_DEBUG || !SCRIPT_DEBUG ); -defined( 'COMPRESS_SCRIPTS' ) || define( 'COMPRESS_SCRIPTS', !WP_DEBUG || !SCRIPT_DEBUG ); -defined( 'COMPRESS_CSS' ) || define( 'COMPRESS_CSS', !WP_DEBUG || !SCRIPT_DEBUG ); -defined( 'QM_DISABLED' ) || define( 'QM_DISABLED', !WP_DEBUG ); -defined( 'QMX_DISABLED' ) || define( 'QMX_DISABLED', QM_DISABLED ); -defined( 'ACF_LITE' ) || define( 'ACF_LITE', $is_production ); +$is_production = ( 'production' === wp_get_environment_type() ); -?> +defined( 'WP_DEBUG' ) || define( 'WP_DEBUG', ! $is_production ); +defined( 'WP_DEBUG_LOG' ) || define( 'WP_DEBUG_LOG', WP_DEBUG ); +defined( 'WP_DEBUG_DISPLAY' ) || define( 'WP_DEBUG_DISPLAY', false ); +defined( 'SCRIPT_DEBUG' ) || define( 'SCRIPT_DEBUG', ! $is_production ); +defined( 'CONCATENATE_SCRIPTS' ) || define( 'CONCATENATE_SCRIPTS', ! WP_DEBUG || ! SCRIPT_DEBUG ); +defined( 'COMPRESS_SCRIPTS' ) || define( 'COMPRESS_SCRIPTS', ! WP_DEBUG || ! SCRIPT_DEBUG ); +defined( 'COMPRESS_CSS' ) || define( 'COMPRESS_CSS', ! WP_DEBUG || ! SCRIPT_DEBUG ); +defined( 'QM_DISABLED' ) || define( 'QM_DISABLED', ! WP_DEBUG ); +defined( 'QMX_DISABLED' ) || define( 'QMX_DISABLED', QM_DISABLED ); +defined( 'ACF_LITE' ) || define( 'ACF_LITE', $is_production ); \ No newline at end of file diff --git a/cssllc-dynamicstyles.php b/src/cssllc-dynamicstyles.php similarity index 81% rename from cssllc-dynamicstyles.php rename to src/cssllc-dynamicstyles.php index 4849f61..84a963c 100644 --- a/cssllc-dynamicstyles.php +++ b/src/cssllc-dynamicstyles.php @@ -32,11 +32,12 @@ class DynamicStyles { * * @return self */ - static function instance() { + public static function instance() { static $instance = null; - if ( is_null( $instance ) ) + if ( is_null( $instance ) ) { $instance = new self; + } return $instance; } @@ -48,17 +49,18 @@ static function instance() { * @param null|string $key * @return string */ - static function add( string $style, string $key = null ) { + public static function add( string $style, string $key = null ) { if ( is_null( $key ) ) { $key = microtime( true ); - while ( isset( static::$todo[ ( string ) $key ] ) ) + while ( isset( static::$todo[ ( string ) $key ] ) ) { $key += 0.00001; + } } $key = ( string ) $key; - static::$todo[$key] = $style; + static::$todo[ $key ] = $style; return $key; } @@ -67,7 +69,7 @@ static function add( string $style, string $key = null ) { * * @return void */ - static function print() { + public static function print() { if ( empty( static::$todo ) ) { return; } @@ -90,13 +92,11 @@ static function print() { * Construct. */ protected function __construct() { - add_action( 'wp_print_scripts', array( __CLASS__, 'print' ) ); + add_action( 'wp_print_scripts', array( __CLASS__, 'print' ) ); add_action( 'wp_print_footer_scripts', array( __CLASS__, 'print' ) ); } } # Initialize. -DynamicStyles::instance(); - -?> \ No newline at end of file +DynamicStyles::instance(); \ No newline at end of file diff --git a/cssllc-enhancements.php b/src/cssllc-enhancements.php similarity index 79% rename from cssllc-enhancements.php rename to src/cssllc-enhancements.php index 7ab5ac8..e59b835 100644 --- a/cssllc-enhancements.php +++ b/src/cssllc-enhancements.php @@ -11,13 +11,13 @@ * * - prevent emoji scripts and styles */ -add_action( 'wp_enqueue_scripts', function() { - remove_action( 'wp_head', 'print_emoji_detection_script', 7 ); +add_action( 'wp_enqueue_scripts', function () { + remove_action( 'wp_head', 'print_emoji_detection_script', 7 ); remove_action( 'admin_print_scripts', 'print_emoji_detection_script' ); - remove_action( 'wp_print_styles', 'print_emoji_styles' ); - remove_action( 'admin_print_styles', 'print_emoji_styles' ); - remove_action( 'wp_enqueue_scripts', 'wp_enqueue_global_styles' ); - remove_action( 'wp_body_open', 'wp_global_styles_render_svg_filters' ); + remove_action( 'wp_print_styles', 'print_emoji_styles' ); + remove_action( 'admin_print_styles', 'print_emoji_styles' ); + remove_action( 'wp_enqueue_scripts', 'wp_enqueue_global_styles' ); + remove_action( 'wp_body_open', 'wp_global_styles_render_svg_filters' ); }, 0 ); /** @@ -30,7 +30,7 @@ * @uses get_post_thumbnail_id() * @return array */ -add_filter( 'body_class', function( $classes ) { +add_filter( 'body_class', function ( $classes ) { if ( is_singular() && has_post_thumbnail() ) { $classes[] = 'has-post-thumbnail'; $classes[] = 'post-thumbnail-' . get_post_thumbnail_id(); @@ -51,7 +51,7 @@ * @uses get_post_thumbnail_id() * @return array */ -add_filter( 'post_class', function( $classes, $class, $post_id ) { +add_filter( 'post_class', function ( $classes, $class, $post_id ) { if ( has_post_thumbnail( $post_id ) ) { $classes[] = 'has-post-thumbnail'; $classes[] = 'post-thumbnail-' . get_post_thumbnail_id( $post_id ); @@ -65,9 +65,10 @@ * * - add "Empty Link" badge to empty links */ -add_action( 'wp_print_footer_scripts', function() { - if ( !current_user_can( 'edit_post', get_queried_object_id() ) ) +add_action( 'wp_print_footer_scripts', function () { + if ( ! current_user_can( 'edit_post', get_queried_object_id() ) ) { return; + } ?>