diff --git a/.phpcs.xml.dist b/.phpcs.xml.dist index 4e8fd21d0086e..4ceff1da3caeb 100644 --- a/.phpcs.xml.dist +++ b/.phpcs.xml.dist @@ -21,6 +21,26 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/composer.json b/composer.json index 31ae19222b875..f2f92c8551bdb 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ "php-parallel-lint/php-parallel-lint": "1.3.2", "sirbrillig/phpcs-changed": "2.10.0", "squizlabs/php_codesniffer": "^3.6.2", - "wp-coding-standards/wpcs": "2022-02-07 as 2.3.1" + "wp-coding-standards/wpcs": "2023-01-04 as 2.3.1" }, "scripts": { "php:lint": [ diff --git a/composer.lock b/composer.lock index 4165583366c18..e436e06825eca 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "46da96c828bcd14148151510d66e04a2", + "content-hash": "184fb6765b72e0f2538a2680d510e794", "packages": [], "packages-dev": [ { @@ -61,7 +61,7 @@ "dist": { "type": "path", "url": "projects/packages/codesniffer", - "reference": "c8726443864676c10b023bf28d894b2003cfebff" + "reference": "fa645eb94c212a4b8b636ecc6c7a9503b4c1a521" }, "require": { "automattic/vipwpcs": "^2.3", @@ -73,9 +73,7 @@ }, "require-dev": { "automattic/jetpack-changelogger": "@dev", - "phpcsstandards/phpcsextra": "1.0.0-alpha3", - "phpcsstandards/phpcsutils": "1.0.0-alpha3", - "wp-coding-standards/wpcs": "2022-02-07 as 2.3.1", + "wp-coding-standards/wpcs": "2023-01-04 as 2.3.1", "yoast/phpunit-polyfills": "1.0.4" }, "type": "phpcodesniffer-standard", @@ -738,22 +736,21 @@ }, { "name": "phpcsstandards/phpcsextra", - "version": "1.0.0-rc1", + "version": "1.0.1", "source": { "type": "git", "url": "https://github.com/PHPCSStandards/PHPCSExtra.git", - "reference": "e0e58d3d807b08aaa26b3df1a4a04a01a1d4ffa0" + "reference": "0f55c12dc6a81c7728794b01a4aea44f11c83991" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHPCSStandards/PHPCSExtra/zipball/e0e58d3d807b08aaa26b3df1a4a04a01a1d4ffa0", - "reference": "e0e58d3d807b08aaa26b3df1a4a04a01a1d4ffa0", + "url": "https://api.github.com/repos/PHPCSStandards/PHPCSExtra/zipball/0f55c12dc6a81c7728794b01a4aea44f11c83991", + "reference": "0f55c12dc6a81c7728794b01a4aea44f11c83991", "shasum": "" }, "require": { - "dealerdirect/phpcodesniffer-composer-installer": "^0.4.1 || ^0.5 || ^0.6.2 || ^0.7", "php": ">=5.4", - "phpcsstandards/phpcsutils": "^1.0 || dev-develop", + "phpcsstandards/phpcsutils": "^1.0", "squizlabs/php_codesniffer": "^3.7.1" }, "require-dev": { @@ -798,24 +795,24 @@ "issues": "https://github.com/PHPCSStandards/PHPCSExtra/issues", "source": "https://github.com/PHPCSStandards/PHPCSExtra" }, - "time": "2022-12-07T08:22:01+00:00" + "time": "2023-01-05T12:35:58+00:00" }, { "name": "phpcsstandards/phpcsutils", - "version": "1.0.0-alpha4", + "version": "1.0.1", "source": { "type": "git", "url": "https://github.com/PHPCSStandards/PHPCSUtils.git", - "reference": "37c6da9a0aede973974ae02ef1af2dd641355e86" + "reference": "4fd2e30c7465112ca2e3646037bfb9e6f0f4d4f3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHPCSStandards/PHPCSUtils/zipball/37c6da9a0aede973974ae02ef1af2dd641355e86", - "reference": "37c6da9a0aede973974ae02ef1af2dd641355e86", + "url": "https://api.github.com/repos/PHPCSStandards/PHPCSUtils/zipball/4fd2e30c7465112ca2e3646037bfb9e6f0f4d4f3", + "reference": "4fd2e30c7465112ca2e3646037bfb9e6f0f4d4f3", "shasum": "" }, "require": { - "dealerdirect/phpcodesniffer-composer-installer": "^0.4.1 || ^0.5 || ^0.6.2 || ^0.7", + "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" }, @@ -872,7 +869,7 @@ "issues": "https://github.com/PHPCSStandards/PHPCSUtils/issues", "source": "https://github.com/PHPCSStandards/PHPCSUtils" }, - "time": "2022-10-25T13:57:45+00:00" + "time": "2023-01-05T12:08:37+00:00" }, { "name": "sirbrillig/phpcs-changed", @@ -1129,38 +1126,35 @@ }, { "name": "wp-coding-standards/wpcs", - "version": "2022-02-07", + "version": "2023-01-04", "source": { "type": "git", "url": "https://github.com/Automattic/WordPress-Coding-Standards", - "reference": "7b39722c38cbf2fe64c55be7154ee6f1807d304c" + "reference": "dcbb3ec50911a554c9a4a7876dccb11419dda4e9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Automattic/WordPress-Coding-Standards/zipball/7b39722c38cbf2fe64c55be7154ee6f1807d304c", - "reference": "7b39722c38cbf2fe64c55be7154ee6f1807d304c", + "url": "https://api.github.com/repos/Automattic/WordPress-Coding-Standards/zipball/dcbb3ec50911a554c9a4a7876dccb11419dda4e9", + "reference": "dcbb3ec50911a554c9a4a7876dccb11419dda4e9", "shasum": "" }, "require": { "php": ">=5.4", "phpcsstandards/phpcsextra": "^1.0", "phpcsstandards/phpcsutils": "^1.0", - "squizlabs/php_codesniffer": "^3.5.0" + "squizlabs/php_codesniffer": "^3.7.1" }, "require-dev": { - "php-parallel-lint/php-console-highlighter": "^0.5", - "php-parallel-lint/php-parallel-lint": "^1.0", + "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.0", + "phpcsstandards/phpcsdevtools": "^1.2.0", "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" }, "type": "phpcodesniffer-standard", "scripts": { "lint": [ - "@php ./vendor/php-parallel-lint/php-parallel-lint/parallel-lint . -e php --exclude vendor --exclude .git" - ], - "lint-ci": [ - "@php ./vendor/php-parallel-lint/php-parallel-lint/parallel-lint . -e php --exclude vendor --exclude .git --checkstyle" + "@php ./vendor/php-parallel-lint/php-parallel-lint/parallel-lint . -e php --show-deprecated --exclude vendor --exclude .git" ], "check-cs": [ "@php ./vendor/squizlabs/php_codesniffer/bin/phpcs" @@ -1168,9 +1162,6 @@ "fix-cs": [ "@php ./vendor/squizlabs/php_codesniffer/bin/phpcbf" ], - "install-codestandards": [ - "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin::run" - ], "run-tests": [ "@php ./vendor/phpunit/phpunit/phpunit --filter WordPress ./vendor/squizlabs/php_codesniffer/tests/AllTests.php" ], @@ -1179,6 +1170,12 @@ ], "check-complete-strict": [ "@php ./vendor/phpcsstandards/phpcsdevtools/bin/phpcs-check-feature-completeness ./WordPress" + ], + "check-all": [ + "@lint", + "@check-cs", + "@run-tests", + "@check-complete-strict" ] }, "license": [ @@ -1194,20 +1191,21 @@ "keywords": [ "WordPress", "phpcs", - "standards" + "standards", + "static analysis" ], "support": { "issues": "https://github.com/WordPress/WordPress-Coding-Standards/issues", "wiki": "https://github.com/WordPress/WordPress-Coding-Standards/wiki", "source": "https://github.com/WordPress/WordPress-Coding-Standards" }, - "time": "2022-02-07T09:38:48+00:00" + "time": "2023-01-04T10:26:16+00:00" } ], "aliases": [ { "package": "wp-coding-standards/wpcs", - "version": "2022.02.07", + "version": "2023.01.04", "alias": "2.3.1", "alias_normalized": "2.3.1.0" } diff --git a/projects/packages/autoloader/changelog/update-wpcs b/projects/packages/autoloader/changelog/update-wpcs new file mode 100644 index 0000000000000..211a1cc7d9e1d --- /dev/null +++ b/projects/packages/autoloader/changelog/update-wpcs @@ -0,0 +1,5 @@ +Significance: patch +Type: fixed +Comment: PHPCS fixes for new WPCS sniffs. Should be no user-visible changes. + + diff --git a/projects/packages/autoloader/tests/php/lib/functions.php b/projects/packages/autoloader/tests/php/lib/functions.php index 52ecea0b747b1..eab2660cd77ff 100644 --- a/projects/packages/autoloader/tests/php/lib/functions.php +++ b/projects/packages/autoloader/tests/php/lib/functions.php @@ -5,6 +5,8 @@ * @package automattic/jetpack-autoloader */ +// phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed + /** * Since PHP8 added a warning for setting `$throw` to `false` in `spl_autoload_register()`, * we need to define the autoload functions in order for them to be registered. diff --git a/projects/packages/codesniffer/Jetpack/ruleset.xml b/projects/packages/codesniffer/Jetpack/ruleset.xml index 8baf4fb29f354..12be7aa4be940 100644 --- a/projects/packages/codesniffer/Jetpack/ruleset.xml +++ b/projects/packages/codesniffer/Jetpack/ruleset.xml @@ -15,7 +15,6 @@ - @@ -41,6 +40,11 @@ + + + + + @@ -75,4 +79,9 @@ + + + + + diff --git a/projects/packages/codesniffer/changelog/update-wpcs b/projects/packages/codesniffer/changelog/update-wpcs new file mode 100644 index 0000000000000..444c0a63a341c --- /dev/null +++ b/projects/packages/codesniffer/changelog/update-wpcs @@ -0,0 +1,4 @@ +Significance: minor +Type: changed + +Updated to a newer snapshot of WordPress-Coding-Standards, which adds a number of new sniffs. diff --git a/projects/packages/codesniffer/composer.json b/projects/packages/codesniffer/composer.json index edce71808cf28..22fcd84fce577 100644 --- a/projects/packages/codesniffer/composer.json +++ b/projects/packages/codesniffer/composer.json @@ -13,9 +13,7 @@ }, "require-dev": { "automattic/jetpack-changelogger": "@dev", - "wp-coding-standards/wpcs": "2022-02-07 as 2.3.1", - "phpcsstandards/phpcsutils": "1.0.0-alpha3", - "phpcsstandards/phpcsextra": "1.0.0-alpha3", + "wp-coding-standards/wpcs": "2023-01-04 as 2.3.1", "yoast/phpunit-polyfills": "1.0.4" }, "autoload": { diff --git a/projects/packages/codesniffer/tests/php/tests/files/mediawiki-imports.php.fixed b/projects/packages/codesniffer/tests/php/tests/files/mediawiki-imports.php.fixed index b0a7f2541767d..e89dc60aad8b3 100644 --- a/projects/packages/codesniffer/tests/php/tests/files/mediawiki-imports.php.fixed +++ b/projects/packages/codesniffer/tests/php/tests/files/mediawiki-imports.php.fixed @@ -38,9 +38,6 @@ class Dummy_Class { require_once 'bar.php'; $u->clone = clone $x; - // MediaWiki.Usage.DirUsage. - $u->dir = __DIR__; - // MediaWiki.Usage.DoubleNotOperator. $u->bool = (bool) $u->bool; diff --git a/projects/packages/codesniffer/tests/php/tests/files/mediawiki-imports.php.report b/projects/packages/codesniffer/tests/php/tests/files/mediawiki-imports.php.report index 895af290a89b9..a848bd0522a29 100644 --- a/projects/packages/codesniffer/tests/php/tests/files/mediawiki-imports.php.report +++ b/projects/packages/codesniffer/tests/php/tests/files/mediawiki-imports.php.report @@ -7,16 +7,15 @@ 41 | ERROR | [ ] Absolute include path must be used. Use `get_template_directory()`, `get_stylesheet_directory()` or `plugin_dir_path()`. | | (WordPressVIPMinimum.Files.IncludingFile.NotAbsolutePath) 42 | WARNING | [x] clone keyword must not be used as a function. (MediaWiki.ExtraCharacters.ParenthesesAroundKeyword.ParenthesesAroundKeywords) - 45 | ERROR | [x] Use __DIR__ constant instead of calling dirname(__FILE__) (MediaWiki.Usage.DirUsage.FunctionFound) - 48 | WARNING | [x] Use (bool) instead of !! (MediaWiki.Usage.DoubleNotOperator.DoubleNotOperator) - 52 | ERROR | [ ] Found slow in_array( …, array_keys() ), should be array_key_exists() or isset() (MediaWiki.Usage.InArrayUsage.Found) - 53 | ERROR | [ ] Found slow in_array( …, array_flip() ), should be array_key_exists() or isset() (MediaWiki.Usage.InArrayUsage.Found) - 60 | WARNING | [ ] Avoid use of __METHOD__ magic constant in closure (MediaWiki.Usage.MagicConstantClosure.FoundConstantMethod) - 60 | WARNING | [ ] Avoid use of __FUNCTION__ magic constant in closure (MediaWiki.Usage.MagicConstantClosure.FoundConstantFunction) - 66 | ERROR | [ ] Function nested is nested inside of another function or closure (MediaWiki.Usage.NestedFunctions.NestedFunction) - 70 | ERROR | [ ] Use "." for string concat (MediaWiki.Usage.PlusStringConcat.Found) - 71 | ERROR | [ ] Use ".=" for string concat (MediaWiki.Usage.PlusStringConcat.Found) - 74 | ERROR | [ ] The ampersand in "&$this" must be removed. If you plan to get back another instance of this class, assign $this to a temporary variable. (MediaWiki.Usage.ReferenceThis.Found) - 77 | ERROR | [x] Multiple empty lines should not exist in a row; found 2 consecutive empty lines (MediaWiki.WhiteSpace.MultipleEmptyLines.MultipleEmptyLines) - 80 | ERROR | [x] A single space should be after the function keyword in closures (MediaWiki.WhiteSpace.SpaceAfterClosure.NoWhitespaceAfterClosure) - 87 | ERROR | [x] Multiple empty lines should not exist in a row; found 2 consecutive empty lines (MediaWiki.WhiteSpace.MultipleEmptyLines.MultipleEmptyLines) + 45 | WARNING | [x] Use (bool) instead of !! (MediaWiki.Usage.DoubleNotOperator.DoubleNotOperator) + 49 | ERROR | [ ] Found slow in_array( …, array_keys() ), should be array_key_exists() or isset() (MediaWiki.Usage.InArrayUsage.Found) + 50 | ERROR | [ ] Found slow in_array( …, array_flip() ), should be array_key_exists() or isset() (MediaWiki.Usage.InArrayUsage.Found) + 57 | WARNING | [ ] Avoid use of __METHOD__ magic constant in closure (MediaWiki.Usage.MagicConstantClosure.FoundConstantMethod) + 57 | WARNING | [ ] Avoid use of __FUNCTION__ magic constant in closure (MediaWiki.Usage.MagicConstantClosure.FoundConstantFunction) + 63 | ERROR | [ ] Function nested is nested inside of another function or closure (MediaWiki.Usage.NestedFunctions.NestedFunction) + 67 | ERROR | [ ] Use "." for string concat (MediaWiki.Usage.PlusStringConcat.Found) + 68 | ERROR | [ ] Use ".=" for string concat (MediaWiki.Usage.PlusStringConcat.Found) + 71 | ERROR | [ ] The ampersand in "&$this" must be removed. If you plan to get back another instance of this class, assign $this to a temporary variable. (MediaWiki.Usage.ReferenceThis.Found) + 74 | ERROR | [x] Multiple empty lines should not exist in a row; found 2 consecutive empty lines (MediaWiki.WhiteSpace.MultipleEmptyLines.MultipleEmptyLines) + 77 | ERROR | [x] A single space should be after the function keyword in closures (MediaWiki.WhiteSpace.SpaceAfterClosure.NoWhitespaceAfterClosure) + 84 | ERROR | [x] Multiple empty lines should not exist in a row; found 2 consecutive empty lines (MediaWiki.WhiteSpace.MultipleEmptyLines.MultipleEmptyLines) diff --git a/projects/packages/codesniffer/tests/php/tests/files/mediawiki-imports.php.tolint b/projects/packages/codesniffer/tests/php/tests/files/mediawiki-imports.php.tolint index d9023800b1469..81bf580a72e71 100644 --- a/projects/packages/codesniffer/tests/php/tests/files/mediawiki-imports.php.tolint +++ b/projects/packages/codesniffer/tests/php/tests/files/mediawiki-imports.php.tolint @@ -41,9 +41,6 @@ class Dummy_Class { require_once( 'bar.php' ); $u->clone = clone( $x ); - // MediaWiki.Usage.DirUsage. - $u->dir = dirname( __FILE__ ); - // MediaWiki.Usage.DoubleNotOperator. $u->bool = ! ! $u->bool; diff --git a/projects/packages/connection/changelog/update-wpcs b/projects/packages/connection/changelog/update-wpcs new file mode 100644 index 0000000000000..211a1cc7d9e1d --- /dev/null +++ b/projects/packages/connection/changelog/update-wpcs @@ -0,0 +1,5 @@ +Significance: patch +Type: fixed +Comment: PHPCS fixes for new WPCS sniffs. Should be no user-visible changes. + + diff --git a/projects/packages/connection/src/class-manager.php b/projects/packages/connection/src/class-manager.php index b40b665944233..0fed1140b4b54 100644 --- a/projects/packages/connection/src/class-manager.php +++ b/projects/packages/connection/src/class-manager.php @@ -914,7 +914,8 @@ public function unlink_user_from_wpcom( $user_id ) { * @return true|WP_Error True if owner successfully changed, WP_Error otherwise. */ public function update_connection_owner( $new_owner_id ) { - if ( ! user_can( $new_owner_id, 'administrator' ) ) { + $roles = new Roles(); + if ( ! user_can( $new_owner_id, $roles->translate_role_to_cap( 'administrator' ) ) ) { return new WP_Error( 'new_owner_not_admin', __( 'New owner is not admin', 'jetpack-connection' ), diff --git a/projects/packages/connection/tests/php/test_Manager_integration.php b/projects/packages/connection/tests/php/test_Manager_integration.php index 4c35cc170b981..4c3515930a6de 100644 --- a/projects/packages/connection/tests/php/test_Manager_integration.php +++ b/projects/packages/connection/tests/php/test_Manager_integration.php @@ -309,7 +309,7 @@ public function get_access_token_data_provider() { 'no_possible_tokens', // expected error code. false, // expected token. ), - 'no tokens' => array( + 'no tokens, has user_id' => array( false, // blog token. false, // user tokens. false, // master_user. diff --git a/projects/packages/publicize/changelog/update-wpcs b/projects/packages/publicize/changelog/update-wpcs new file mode 100644 index 0000000000000..211a1cc7d9e1d --- /dev/null +++ b/projects/packages/publicize/changelog/update-wpcs @@ -0,0 +1,5 @@ +Significance: patch +Type: fixed +Comment: PHPCS fixes for new WPCS sniffs. Should be no user-visible changes. + + diff --git a/projects/packages/publicize/src/class-publicize-base.php b/projects/packages/publicize/src/class-publicize-base.php index 38f1ef5b09e97..b7abd570f9a70 100644 --- a/projects/packages/publicize/src/class-publicize-base.php +++ b/projects/packages/publicize/src/class-publicize-base.php @@ -1603,6 +1603,8 @@ public function has_paid_plan( $refresh_from_wpcom = false ) { } } +// phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move these functions to some other file. + /** * Get Calypso URL for Publicize connections. * diff --git a/projects/packages/roles/changelog/update-wpcs b/projects/packages/roles/changelog/update-wpcs new file mode 100644 index 0000000000000..211a1cc7d9e1d --- /dev/null +++ b/projects/packages/roles/changelog/update-wpcs @@ -0,0 +1,5 @@ +Significance: patch +Type: fixed +Comment: PHPCS fixes for new WPCS sniffs. Should be no user-visible changes. + + diff --git a/projects/packages/roles/tests/php/test-roles.php b/projects/packages/roles/tests/php/test-roles.php index 0aa5b62c922f9..4372ab9cfa5ba 100644 --- a/projects/packages/roles/tests/php/test-roles.php +++ b/projects/packages/roles/tests/php/test-roles.php @@ -74,7 +74,9 @@ function ( $cap ) { ); $this->assertTrue( current_user_can( 'edit_others_posts' ) ); + // phpcs:ignore WordPress.WP.Capabilities.Unknown $this->assertFalse( current_user_can( 'foobar' ) ); + // phpcs:ignore WordPress.WP.Capabilities.RoleFound $this->assertFalse( current_user_can( 'administrator' ) ); $this->assertEquals( 'editor', $this->roles->translate_current_user_to_role() ); diff --git a/projects/packages/status/changelog/update-wpcs b/projects/packages/status/changelog/update-wpcs new file mode 100644 index 0000000000000..211a1cc7d9e1d --- /dev/null +++ b/projects/packages/status/changelog/update-wpcs @@ -0,0 +1,5 @@ +Significance: patch +Type: fixed +Comment: PHPCS fixes for new WPCS sniffs. Should be no user-visible changes. + + diff --git a/projects/packages/status/src/class-errors.php b/projects/packages/status/src/class-errors.php index 99751fd19641d..342f1759f3493 100644 --- a/projects/packages/status/src/class-errors.php +++ b/projects/packages/status/src/class-errors.php @@ -5,7 +5,7 @@ * @package automattic/jetpack-status */ -// phpcs:disable WordPress.PHP.IniSet.display_errors_Blacklisted +// phpcs:disable WordPress.PHP.IniSet.display_errors_Disallowed // phpcs:disable WordPress.PHP.NoSilencedErrors.Discouraged // phpcs:disable WordPress.PHP.DevelopmentFunctions.prevent_path_disclosure_error_reporting // phpcs:disable WordPress.PHP.DiscouragedPHPFunctions.runtime_configuration_error_reporting diff --git a/projects/packages/sync/changelog/update-wpcs b/projects/packages/sync/changelog/update-wpcs new file mode 100644 index 0000000000000..211a1cc7d9e1d --- /dev/null +++ b/projects/packages/sync/changelog/update-wpcs @@ -0,0 +1,5 @@ +Significance: patch +Type: fixed +Comment: PHPCS fixes for new WPCS sniffs. Should be no user-visible changes. + + diff --git a/projects/packages/sync/src/modules/class-plugins.php b/projects/packages/sync/src/modules/class-plugins.php index 06c06ab00b4df..1ba86a2882d74 100644 --- a/projects/packages/sync/src/modules/class-plugins.php +++ b/projects/packages/sync/src/modules/class-plugins.php @@ -332,16 +332,17 @@ public function plugin_edit_ajax() { $real_file = WP_PLUGIN_DIR . '/' . $file; + // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_is_writeable if ( ! is_writeable( $real_file ) ) { return; } - // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_fopen + // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fopen $file_pointer = fopen( $real_file, 'w+' ); if ( false === $file_pointer ) { return; } - // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_fclose + // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fclose fclose( $file_pointer ); /** * This action is documented already in this file diff --git a/projects/packages/sync/src/modules/class-search.php b/projects/packages/sync/src/modules/class-search.php index 347a7d4f16ad0..6890b05b4b140 100644 --- a/projects/packages/sync/src/modules/class-search.php +++ b/projects/packages/sync/src/modules/class-search.php @@ -81,7 +81,6 @@ public function __construct() { 'jetpack-search-meta9' => array( 'searchable_in_all_content' => true ), // woocommerce. - 'entity_types' => array(), 'exclude_product_categories' => array(), 'exclude_product_ids' => array(), 'free_shipping' => array(), @@ -468,7 +467,6 @@ public function __construct() { '_manage_stock' => array(), '_product_image_gallery' => array(), '_purchase_note' => array(), - '_recorded_coupon_usage_counts' => array(), '_recorded_sales' => array(), '_sold_individually' => array(), '_stock' => array(), @@ -656,7 +654,6 @@ public function __construct() { '_VenueVenue' => array(), '_VenueVenueID' => array(), '_VenueZip' => array(), - '_default_attributes' => array(), '_description' => array(), '_edit_last' => array(), '_feedback_all_fields' => array(), @@ -666,7 +663,6 @@ public function __construct() { '_feedback_contact_form_url' => array(), '_feedback_ip' => array(), '_feedback_subject' => array(), - '_file_paths' => array(), '_layout' => array(), '_links_to' => array(), '_links_to_target' => array(), diff --git a/projects/packages/sync/src/modules/class-themes.php b/projects/packages/sync/src/modules/class-themes.php index 5b90bfac6dadb..7218e55d043c4 100644 --- a/projects/packages/sync/src/modules/class-themes.php +++ b/projects/packages/sync/src/modules/class-themes.php @@ -307,16 +307,17 @@ public function theme_edit_ajax() { } } + // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_is_writeable if ( ! is_writeable( $real_file ) ) { return; } - // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_fopen + // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fopen $file_pointer = fopen( $real_file, 'w+' ); if ( false === $file_pointer ) { return; } - // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_fclose + // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fclose fclose( $file_pointer ); $theme_data = array( diff --git a/projects/packages/videopress/changelog/update-wpcs b/projects/packages/videopress/changelog/update-wpcs new file mode 100644 index 0000000000000..211a1cc7d9e1d --- /dev/null +++ b/projects/packages/videopress/changelog/update-wpcs @@ -0,0 +1,5 @@ +Significance: patch +Type: fixed +Comment: PHPCS fixes for new WPCS sniffs. Should be no user-visible changes. + + diff --git a/projects/packages/videopress/src/tus/class-tus-file.php b/projects/packages/videopress/src/tus/class-tus-file.php index 1d5debcb6d29e..41f73c0d82d47 100644 --- a/projects/packages/videopress/src/tus/class-tus-file.php +++ b/projects/packages/videopress/src/tus/class-tus-file.php @@ -452,8 +452,7 @@ public function open( $file_path, $mode ) { } $this->exists( $file_path, $mode ); - // phpcs:disable WordPress.WP.AlternativeFunctions.file_system_read_fopen - // phpcs:disable WordPress.PHP.NoSilencedErrors.Discouraged + // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fopen, WordPress.PHP.NoSilencedErrors.Discouraged $ptr = @fopen( $file_path, $mode ); if ( false === $ptr ) { @@ -522,7 +521,7 @@ public function seek( $handle, $offset, $whence = SEEK_SET ) { */ public function read( $handle, $chunk_size ) { $chunk_size = $this->ensure_integer( $chunk_size ); - // phpcs:disable WordPress.WP.AlternativeFunctions.file_system_read_fread + // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fread $data = fread( $handle, $chunk_size ); if ( false === $data ) { @@ -544,8 +543,7 @@ public function read( $handle, $chunk_size ) { * @return int */ public function write( $handle, $data, $length = null ) { - // phpcs:disable WordPress.WP.AlternativeFunctions.file_system_read_fclose - // phpcs:disable WordPress.WP.AlternativeFunctions.file_system_read_fwrite + // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fwrite $bytes_written = \is_numeric( $length ) ? fwrite( $handle, $data, intval( $length ) ) : fwrite( $handle, $data ); if ( false === $bytes_written ) { @@ -644,7 +642,7 @@ public function delete_files( array $files ) { foreach ( $files as $file ) { if ( $this->get_wp_filesystem()->exists( $file ) ) { - $r = unlink( $file ); + $r = $this->get_wp_filesystem()->delete( $file ); $status = $status && $r; } } @@ -660,6 +658,7 @@ public function delete_files( array $files ) { * @return bool */ public function close( $handle ) { + // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fclose return fclose( $handle ); } diff --git a/projects/packages/videopress/src/utility-functions.php b/projects/packages/videopress/src/utility-functions.php index 45a56107f2c3f..395eb5e78b372 100644 --- a/projects/packages/videopress/src/utility-functions.php +++ b/projects/packages/videopress/src/utility-functions.php @@ -5,6 +5,8 @@ defined( 'VIDEOPRESS_MIN_WIDTH' ) || define( 'VIDEOPRESS_MIN_WIDTH', 60 ); defined( 'VIDEOPRESS_DEFAULT_WIDTH' ) || define( 'VIDEOPRESS_DEFAULT_WIDTH', 640 ); +// phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move classes to appropriately-named class files. + /** * VideoPress Privacy constants. */ diff --git a/projects/packages/waf/changelog/update-wpcs b/projects/packages/waf/changelog/update-wpcs new file mode 100644 index 0000000000000..211a1cc7d9e1d --- /dev/null +++ b/projects/packages/waf/changelog/update-wpcs @@ -0,0 +1,5 @@ +Significance: patch +Type: fixed +Comment: PHPCS fixes for new WPCS sniffs. Should be no user-visible changes. + + diff --git a/projects/packages/waf/tests/php/test-waf-transforms.php b/projects/packages/waf/tests/php/test-waf-transforms.php index 5dc6481f69a3b..4d67dfdfa8d90 100644 --- a/projects/packages/waf/tests/php/test-waf-transforms.php +++ b/projects/packages/waf/tests/php/test-waf-transforms.php @@ -258,16 +258,11 @@ public function transformDataProvider() { '/*TestCase */' => ' ', 'Before/* TestCase */After' => 'Before After', 'Before /* TestCase */ After' => 'Before After', - "/* Test\nCase */" => ' ', "/* Test\x0d\x0aCase */" => ' ', "/* Test\x0aCase */" => ' ', "/* Test\x0dCase */" => ' ', "Before/* Test\x0d\x0aCase " => 'Before ', "Before /* Test\x0aCase " => 'Before ', - "Before/* Test\x0d\x0aCase " => 'Before ', - "Before /* Test\x0aCase " => 'Before ', - "Test\x0d\x0aCase */After" => "Test\x0d\x0aCase */After", - "Test\x0aCase */ After" => "Test\x0aCase */ After", "Test\x0d\x0aCase */After" => "Test\x0d\x0aCase */After", "Test\x0aCase */ After" => "Test\x0aCase */ After", ), diff --git a/projects/plugins/boost/app/lib/critical-css/Display_Critical_CSS.php b/projects/plugins/boost/app/lib/critical-css/Display_Critical_CSS.php index 19482350d1c59..23c0080a9f8c3 100644 --- a/projects/plugins/boost/app/lib/critical-css/Display_Critical_CSS.php +++ b/projects/plugins/boost/app/lib/critical-css/Display_Critical_CSS.php @@ -91,6 +91,7 @@ public function display_critical_css() { $critical_css = $this->css; if ( false === $critical_css ) { + // phpcs:ignore Universal.CodeAnalysis.ConstructorDestructorReturn.ReturnValueFound -- This is not a PHP 4 constructor, that only applies to non-namespaced classes. return false; } diff --git a/projects/plugins/boost/changelog/update-wpcs b/projects/plugins/boost/changelog/update-wpcs new file mode 100644 index 0000000000000..211a1cc7d9e1d --- /dev/null +++ b/projects/plugins/boost/changelog/update-wpcs @@ -0,0 +1,5 @@ +Significance: patch +Type: fixed +Comment: PHPCS fixes for new WPCS sniffs. Should be no user-visible changes. + + diff --git a/projects/plugins/debug-helper/changelog/update-wpcs b/projects/plugins/debug-helper/changelog/update-wpcs new file mode 100644 index 0000000000000..211a1cc7d9e1d --- /dev/null +++ b/projects/plugins/debug-helper/changelog/update-wpcs @@ -0,0 +1,5 @@ +Significance: patch +Type: fixed +Comment: PHPCS fixes for new WPCS sniffs. Should be no user-visible changes. + + diff --git a/projects/plugins/debug-helper/modules/class-autoloader-debug-helper.php b/projects/plugins/debug-helper/modules/class-autoloader-debug-helper.php index 1618bb25eebee..e2509d089ffe1 100644 --- a/projects/plugins/debug-helper/modules/class-autoloader-debug-helper.php +++ b/projects/plugins/debug-helper/modules/class-autoloader-debug-helper.php @@ -268,6 +268,8 @@ public function display_notice() { } } +// phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move these functions to some other file. + add_action( 'plugins_loaded', 'register_autoloader_debug_helper', 1000 ); /** diff --git a/projects/plugins/debug-helper/modules/class-broken-token.php b/projects/plugins/debug-helper/modules/class-broken-token.php index a235439949c35..b62ae50f8b699 100644 --- a/projects/plugins/debug-helper/modules/class-broken-token.php +++ b/projects/plugins/debug-helper/modules/class-broken-token.php @@ -580,6 +580,8 @@ public function clear_tos() { } } +// phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move these functions to some other file. + add_action( 'plugins_loaded', 'register_broken_token', 1000 ); /** diff --git a/projects/plugins/debug-helper/modules/class-idc-simulator.php b/projects/plugins/debug-helper/modules/class-idc-simulator.php index a548df9cd972b..d360f1d942605 100644 --- a/projects/plugins/debug-helper/modules/class-idc-simulator.php +++ b/projects/plugins/debug-helper/modules/class-idc-simulator.php @@ -514,6 +514,8 @@ public function admin_post_redirect_referrer() { } } +// phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move these functions to some other file. + add_action( 'plugins_loaded', 'register_idc_simulator', 1000 ); /** diff --git a/projects/plugins/jetpack/3rd-party/class-jetpack-bbpress-rest-api.php b/projects/plugins/jetpack/3rd-party/class-jetpack-bbpress-rest-api.php index 4943bcd5d46c4..5f03139856715 100644 --- a/projects/plugins/jetpack/3rd-party/class-jetpack-bbpress-rest-api.php +++ b/projects/plugins/jetpack/3rd-party/class-jetpack-bbpress-rest-api.php @@ -124,7 +124,7 @@ public function adjust_meta_caps( $caps, $cap, $user_id, $args ) { $caps[] = 'do_not_allow'; // Moderators can always edit meta. - } elseif ( user_can( $user_id, 'moderate' ) ) { + } elseif ( user_can( $user_id, 'moderate' ) ) { // phpcs:ignore WordPress.WP.Capabilities.Unknown $caps[] = 'moderate'; // Unknown so map to edit_posts. diff --git a/projects/plugins/jetpack/3rd-party/class-jetpack-crm-data.php b/projects/plugins/jetpack/3rd-party/class-jetpack-crm-data.php index 85de4a1e54e18..0bfdeaf40c984 100644 --- a/projects/plugins/jetpack/3rd-party/class-jetpack-crm-data.php +++ b/projects/plugins/jetpack/3rd-party/class-jetpack-crm-data.php @@ -54,6 +54,7 @@ public function get_crm_data() { $response['can_activate_crm'] = $response['crm_active'] ? false : current_user_can( 'activate_plugins' ); if ( $response['crm_active'] && function_exists( 'zeroBSCRM_extension_install_jetpackforms' ) ) { + // phpcs:ignore WordPress.WP.Capabilities.Unknown $response['can_activate_extension'] = current_user_can( 'admin_zerobs_manage_options' ); } diff --git a/projects/plugins/jetpack/_inc/lib/admin-pages/class-jetpack-redux-state-helper.php b/projects/plugins/jetpack/_inc/lib/admin-pages/class-jetpack-redux-state-helper.php index b953247414ebf..cce110a8f400c 100644 --- a/projects/plugins/jetpack/_inc/lib/admin-pages/class-jetpack-redux-state-helper.php +++ b/projects/plugins/jetpack/_inc/lib/admin-pages/class-jetpack-redux-state-helper.php @@ -402,6 +402,8 @@ public static function generate_purchase_token() { } } +// phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move these functions to some other file. + /** * Gather data about the current user. * diff --git a/projects/plugins/jetpack/_inc/lib/class-jetpack-tweetstorm-helper.php b/projects/plugins/jetpack/_inc/lib/class-jetpack-tweetstorm-helper.php index 105b216a16d10..b80751d06ef97 100644 --- a/projects/plugins/jetpack/_inc/lib/class-jetpack-tweetstorm-helper.php +++ b/projects/plugins/jetpack/_inc/lib/class-jetpack-tweetstorm-helper.php @@ -1674,7 +1674,6 @@ function ( $url ) use ( $validator ) { ), 'image' => array( 'name' => 'twitter:image', - 'property' => 'og:image:secure', 'property' => 'og:image', ), 'title' => array( diff --git a/projects/plugins/jetpack/_inc/lib/class.core-rest-api-endpoints.php b/projects/plugins/jetpack/_inc/lib/class.core-rest-api-endpoints.php index 80a632fd0d780..103b20837bdda 100644 --- a/projects/plugins/jetpack/_inc/lib/class.core-rest-api-endpoints.php +++ b/projects/plugins/jetpack/_inc/lib/class.core-rest-api-endpoints.php @@ -4119,6 +4119,7 @@ public static function jetpack_crm_data_permission_check() { * @return true|WP_Error Returns true if the user has the required capability, else a WP_Error object. */ public static function activate_crm_extensions_permission_check() { + // phpcs:ignore WordPress.WP.Capabilities.Unknown if ( current_user_can( 'admin_zerobs_manage_options' ) ) { return true; } diff --git a/projects/plugins/jetpack/_inc/lib/class.media.php b/projects/plugins/jetpack/_inc/lib/class.media.php index 484cfe2574cc6..86deb7ef17c2e 100644 --- a/projects/plugins/jetpack/_inc/lib/class.media.php +++ b/projects/plugins/jetpack/_inc/lib/class.media.php @@ -148,14 +148,11 @@ protected static function is_file_supported_for_sideloading( $file ) { * Try to remove the temporal file from the given file array. * * @param array $file_array Array with data about the temporal file. - * - * @return bool `true` if the file has been removed. `false` either the file doesn't exist or it couldn't be removed. */ private static function remove_tmp_file( $file_array ) { - if ( ! file_exists( $file_array['tmp_name'] ) ) { - return false; + if ( file_exists( $file_array['tmp_name'] ) ) { + wp_delete_file( $file_array['tmp_name'] ); } - return @unlink( $file_array['tmp_name'] ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged } /** @@ -186,7 +183,7 @@ public static function save_temporary_file( $file_array, $media_id ) { ! self::is_file_supported_for_sideloading( $tmp_filename ) && ! file_is_displayable_image( $tmp_filename ) ) { - @unlink( $tmp_filename ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged + wp_delete_file( $tmp_filename ); return new WP_Error( 'invalid_input', 'Invalid file type.', 403 ); } remove_filter( 'jetpack_supported_media_sideload_types', $mime_type_static_filter ); @@ -278,7 +275,7 @@ public static function get_original_media( $media_id ) { public static function delete_file( $pathname ) { if ( ! file_exists( $pathname ) || ! is_file( $pathname ) ) { // let's touch a fake file to try to `really` remove the media file. - touch( $pathname ); + touch( $pathname ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_touch } return wp_delete_file( $pathname ); @@ -503,6 +500,8 @@ public static function edit_media_file( $media_id, $file_array ) { } } +// phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move these functions to some other file. + /** * Clean revision history when the media item is deleted. * diff --git a/projects/plugins/jetpack/_inc/lib/core-api/class.jetpack-core-api-module-endpoints.php b/projects/plugins/jetpack/_inc/lib/core-api/class.jetpack-core-api-module-endpoints.php index b8b9c170d2c26..119cf420dc308 100644 --- a/projects/plugins/jetpack/_inc/lib/core-api/class.jetpack-core-api-module-endpoints.php +++ b/projects/plugins/jetpack/_inc/lib/core-api/class.jetpack-core-api-module-endpoints.php @@ -1816,6 +1816,8 @@ public function can_request() { } } +// phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move these functions to some other file. + /** * Actions performed only when Gravatar Hovercards is activated through the endpoint call. * diff --git a/projects/plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/class-wpcom-rest-api-v2-endpoint-external-media.php b/projects/plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/class-wpcom-rest-api-v2-endpoint-external-media.php index 231f9f43bb76f..df2333ef73667 100644 --- a/projects/plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/class-wpcom-rest-api-v2-endpoint-external-media.php +++ b/projects/plugins/jetpack/_inc/lib/core-api/wpcom-endpoints/class-wpcom-rest-api-v2-endpoint-external-media.php @@ -394,7 +394,7 @@ public function delete_connection( WP_REST_Request $request ) { $wpcom_path = sprintf( '/meta/external-media/connection/%s', $service ); if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { - $internal_request = new WP_REST_Request( REQUESTS::DELETE, '/' . $this->namespace . $wpcom_path ); + $internal_request = new WP_REST_Request( Requests::DELETE, '/' . $this->namespace . $wpcom_path ); $internal_request->set_query_params( $request->get_params() ); return rest_do_request( $internal_request ); @@ -404,7 +404,7 @@ public function delete_connection( WP_REST_Request $request ) { $wpcom_path, '2', array( - 'method' => REQUESTS::DELETE, + 'method' => Requests::DELETE, ) ); @@ -456,7 +456,7 @@ public function sideload_media( $file_name, $download_url, $post_id = 0 ) { $id = media_handle_sideload( $file, $post_id, null ); if ( is_wp_error( $id ) ) { - @unlink( $file['tmp_name'] ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged + wp_delete_file( $file['tmp_name'] ); $id->add_data( array( 'status' => 400 ) ); } diff --git a/projects/plugins/jetpack/_inc/lib/icalendar-reader.php b/projects/plugins/jetpack/_inc/lib/icalendar-reader.php index 4eecedd6d1557..8871f7077ad10 100644 --- a/projects/plugins/jetpack/_inc/lib/icalendar-reader.php +++ b/projects/plugins/jetpack/_inc/lib/icalendar-reader.php @@ -6,6 +6,8 @@ * @package automattic/jetpack */ +// phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move classes to appropriately-named class files. + /** * Calendar utilities class. * diff --git a/projects/plugins/jetpack/changelog/update-wpcs b/projects/plugins/jetpack/changelog/update-wpcs new file mode 100644 index 0000000000000..95919879cb565 --- /dev/null +++ b/projects/plugins/jetpack/changelog/update-wpcs @@ -0,0 +1,5 @@ +Significance: patch +Type: other +Comment: PHPCS fixes for new WPCS sniffs. Should be no user-visible changes. + + diff --git a/projects/plugins/jetpack/class.jetpack-cli.php b/projects/plugins/jetpack/class.jetpack-cli.php index 6434785e4e015..e367879a34d9b 100644 --- a/projects/plugins/jetpack/class.jetpack-cli.php +++ b/projects/plugins/jetpack/class.jetpack-cli.php @@ -2141,6 +2141,8 @@ private static function render_block_file( $template, $data = array() ) { } } +// phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move these functions to some other file. + /** * Standard "ask for permission to continue" function. * If action cancelled, ask if they need help. diff --git a/projects/plugins/jetpack/class.jetpack-gutenberg.php b/projects/plugins/jetpack/class.jetpack-gutenberg.php index 3089f1a0bbdf7..a505ac4f741e5 100644 --- a/projects/plugins/jetpack/class.jetpack-gutenberg.php +++ b/projects/plugins/jetpack/class.jetpack-gutenberg.php @@ -14,6 +14,8 @@ use Automattic\Jetpack\Status; use Automattic\Jetpack\Status\Host; +// phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move the functions and such to some other file. + /** * Wrapper function to safely register a gutenberg block type * diff --git a/projects/plugins/jetpack/json-endpoints/class.wpcom-json-api-edit-media-v1-2-endpoint.php b/projects/plugins/jetpack/json-endpoints/class.wpcom-json-api-edit-media-v1-2-endpoint.php index 1e08d5365aef9..61373213186fa 100644 --- a/projects/plugins/jetpack/json-endpoints/class.wpcom-json-api-edit-media-v1-2-endpoint.php +++ b/projects/plugins/jetpack/json-endpoints/class.wpcom-json-api-edit-media-v1-2-endpoint.php @@ -199,16 +199,11 @@ private function get_snapshot( $media_item ) { * Try to remove the temporal file from the given file array. * * @param {Array} $file_array - Array with data about the temporal file. - * @return {Boolean} `true` if the file has been removed. - * `false` either the file doesn't exist or it couldn't be removed. */ private function remove_tmp_file( $file_array ) { - if ( ! file_exists( $file_array['tmp_name'] ) ) { - return false; + if ( file_exists( $file_array['tmp_name'] ) ) { + wp_delete_file( $file_array['tmp_name'] ); } - // @todo - see if we can more permanently fix this NoSilencedError. - // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged - return @unlink( $file_array['tmp_name'] ); } /** @@ -236,9 +231,7 @@ private function save_temporary_file( $file_array, $media_id ) { ! $this->is_file_supported_for_sideloading( $tmp_filename ) && ! file_is_displayable_image( $tmp_filename ) ) { - // @todo - see if we can more permanently fix this NoSilencedError. - // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged - @unlink( $tmp_filename ); + wp_delete_file( $tmp_filename ); return new WP_Error( 'invalid_input', 'Invalid file type.', 403 ); } remove_filter( 'jetpack_supported_media_sideload_types', $mime_type_static_filter ); diff --git a/projects/plugins/jetpack/json-endpoints/class.wpcom-json-api-sharing-buttons-endpoint.php b/projects/plugins/jetpack/json-endpoints/class.wpcom-json-api-sharing-buttons-endpoint.php index 08059462ce2c5..6faf1b8ef0d25 100644 --- a/projects/plugins/jetpack/json-endpoints/class.wpcom-json-api-sharing-buttons-endpoint.php +++ b/projects/plugins/jetpack/json-endpoints/class.wpcom-json-api-sharing-buttons-endpoint.php @@ -779,7 +779,7 @@ public function callback( $path = '', $blog_id = 0, $button_id = 0 ) { // Verify button is custom if ( ! is_a( $all_buttons[ $button_id ], 'Share_Custom' ) ) { - return new WP_error( 'invalid_request', 'Only custom sharing buttons can be deleted', 400 ); + return new WP_Error( 'invalid_request', 'Only custom sharing buttons can be deleted', 400 ); } $success = $this->sharing_service->delete_service( $button_id ); diff --git a/projects/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-themes-install-endpoint.php b/projects/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-themes-install-endpoint.php index 8c6548e29959d..941ead4224fff 100644 --- a/projects/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-themes-install-endpoint.php +++ b/projects/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-themes-install-endpoint.php @@ -76,7 +76,7 @@ protected function install() { if ( file_exists( $link ) ) { // Delete if link was tmp local file - unlink( $link ); + wp_delete_file( $link ); } if ( ! $this->bulk && is_wp_error( $result ) ) { @@ -211,7 +211,7 @@ protected static function download_wpcom_theme_to_file( $theme ) { $response = $result['response']; if ( $response['code'] !== 200 ) { - unlink( $file ); + wp_delete_file( $file ); return new WP_Error( 'problem_fetching_theme', __( 'Problem downloading theme', 'jetpack' ) ); } diff --git a/projects/plugins/jetpack/modules/contact-form/admin.php b/projects/plugins/jetpack/modules/contact-form/admin.php index fa909c08ca198..8718ea4940416 100644 --- a/projects/plugins/jetpack/modules/contact-form/admin.php +++ b/projects/plugins/jetpack/modules/contact-form/admin.php @@ -5,6 +5,8 @@ * @package automattic/jetpack */ +// phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move classes to appropriately-named class files. + use Automattic\Jetpack\Assets; use Automattic\Jetpack\Assets\Logo; use Automattic\Jetpack\Connection\Manager as Connection_Manager; diff --git a/projects/plugins/jetpack/modules/contact-form/grunion-contact-form.php b/projects/plugins/jetpack/modules/contact-form/grunion-contact-form.php index b94808f3fe7dc..df992696bf251 100644 --- a/projects/plugins/jetpack/modules/contact-form/grunion-contact-form.php +++ b/projects/plugins/jetpack/modules/contact-form/grunion-contact-form.php @@ -7,6 +7,8 @@ * @package automattic/jetpack */ +// phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move classes to appropriately-named class files. + use Automattic\Jetpack\Assets; use Automattic\Jetpack\Blocks; use Automattic\Jetpack\Sync\Settings; diff --git a/projects/plugins/jetpack/modules/contact-form/grunion-form-view.php b/projects/plugins/jetpack/modules/contact-form/grunion-form-view.php index 55d1e2aeb403a..259f47fc7893c 100644 --- a/projects/plugins/jetpack/modules/contact-form/grunion-form-view.php +++ b/projects/plugins/jetpack/modules/contact-form/grunion-form-view.php @@ -38,7 +38,7 @@ 'commentLabel' => esc_attr( _x( 'Comment', 'noun', 'jetpack' ) ), 'newLabel' => esc_attr( _x( 'New Field', 'Default label for new HTML form field in contact form builder', 'jetpack' ) ), 'optionsLabel' => esc_attr( _x( 'Options', 'Label for the set of options to be included in a user-created dropdown in contact form builder', 'jetpack' ) ), - 'optionsLabel' => esc_attr( _x( 'Option', 'Label for an option to be included in a user-created dropdown in contact form builder', 'jetpack' ) ), + 'optionLabel' => esc_attr( _x( 'Option', 'Label for an option to be included in a user-created dropdown in contact form builder', 'jetpack' ) ), 'firstOptionLabel' => esc_attr( _x( 'First option', 'Default label for the first option to be included in a user-created dropdown in contact form builder', 'jetpack' ) ), 'problemGeneratingForm' => esc_attr( _x( "Oops, there was a problem generating your form. You'll likely need to try again.", 'error message in contact form builder', 'jetpack' ) ), 'moveInstructions' => esc_attr__( "Drag up or down\nto re-arrange", 'jetpack' ), diff --git a/projects/plugins/jetpack/modules/copy-post.php b/projects/plugins/jetpack/modules/copy-post.php index 676845a1bcbf9..c34c7b5576705 100644 --- a/projects/plugins/jetpack/modules/copy-post.php +++ b/projects/plugins/jetpack/modules/copy-post.php @@ -13,6 +13,8 @@ * @package automattic/jetpack */ +// phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move classes to appropriately-named class files. + /** * Copy Post class. */ diff --git a/projects/plugins/jetpack/modules/custom-css/csstidy/class.csstidy.php b/projects/plugins/jetpack/modules/custom-css/csstidy/class.csstidy.php index 78b65be4be39b..737ed61918e07 100644 --- a/projects/plugins/jetpack/modules/custom-css/csstidy/class.csstidy.php +++ b/projects/plugins/jetpack/modules/custom-css/csstidy/class.csstidy.php @@ -523,21 +523,21 @@ public function write( $filename, $formatted = false, $doctype = 'xhtml1.1', $ex $filename .= ( $formatted ) ? '.xhtml' : '.css'; if ( ! is_dir( 'temp' ) ) { - $madedir = mkdir( 'temp' ); + $madedir = mkdir( 'temp' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_mkdir if ( ! $madedir ) { print 'Could not make directory "temp" in ' . __DIR__; exit; } } - $handle = fopen( 'temp/' . $filename, 'w' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_fopen + $handle = fopen( 'temp/' . $filename, 'w' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fopen if ( $handle ) { if ( ! $formatted ) { - fwrite( $handle, $this->print->plain() ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_fwrite + fwrite( $handle, $this->print->plain() ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fwrite } else { - fwrite( $handle, $this->print->formatted_page( $doctype, $externalcss, $title, $lang, $pre_code ) ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_fwrite + fwrite( $handle, $this->print->formatted_page( $doctype, $externalcss, $title, $lang, $pre_code ) ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fwrite } } - fclose( $handle ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_fclose + fclose( $handle ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fclose } /** diff --git a/projects/plugins/jetpack/modules/custom-css/custom-css.php b/projects/plugins/jetpack/modules/custom-css/custom-css.php index f3c48f1e74c5d..acd41da74c685 100644 --- a/projects/plugins/jetpack/modules/custom-css/custom-css.php +++ b/projects/plugins/jetpack/modules/custom-css/custom-css.php @@ -1,5 +1,7 @@ translate_role_to_cap( 'administrator' ) ) ) { $number_menu_items_published = sprintf( '%2$s', esc_url( diff --git a/projects/plugins/jetpack/modules/custom-post-types/testimonial.php b/projects/plugins/jetpack/modules/custom-post-types/testimonial.php index 79f1ed10fb3ad..b5ad16f3f6221 100644 --- a/projects/plugins/jetpack/modules/custom-post-types/testimonial.php +++ b/projects/plugins/jetpack/modules/custom-post-types/testimonial.php @@ -7,6 +7,8 @@ * @phpcs:disable MediaWiki.Usage.NestedFunctions.NestedFunction */ +// phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move classes to appropriately-named class files. + /** * Add a Testimonial CPT, and display it with a shortcode */ diff --git a/projects/plugins/jetpack/modules/infinite-scroll/infinity.php b/projects/plugins/jetpack/modules/infinite-scroll/infinity.php index aab990dbe2ce9..34a20acb55fae 100644 --- a/projects/plugins/jetpack/modules/infinite-scroll/infinity.php +++ b/projects/plugins/jetpack/modules/infinite-scroll/infinity.php @@ -1,5 +1,7 @@ 'mb-icon', - 'class' => 'inline-action', + 'class' => 'mb-icon inline-action', ); $href = false; diff --git a/projects/plugins/jetpack/modules/plugin-search.php b/projects/plugins/jetpack/modules/plugin-search.php index 25267aab50f6e..93c682cfe8f44 100644 --- a/projects/plugins/jetpack/modules/plugin-search.php +++ b/projects/plugins/jetpack/modules/plugin-search.php @@ -5,6 +5,8 @@ * @package automattic/jetpack */ +// phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move classes to appropriately-named class files. + use Automattic\Jetpack\Constants; use Automattic\Jetpack\Redirect; use Automattic\Jetpack\Tracking; diff --git a/projects/plugins/jetpack/modules/publicize.php b/projects/plugins/jetpack/modules/publicize.php index cb596f8d41a62..c941d266d17f3 100644 --- a/projects/plugins/jetpack/modules/publicize.php +++ b/projects/plugins/jetpack/modules/publicize.php @@ -15,6 +15,8 @@ * @package automattic/jetpack */ +// phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move classes to appropriately-named class files. + /** * Class Jetpack_Publicize */ diff --git a/projects/plugins/jetpack/modules/sharedaddy/sharing-service.php b/projects/plugins/jetpack/modules/sharedaddy/sharing-service.php index fcc36b5f58c0c..de677edb13b98 100644 --- a/projects/plugins/jetpack/modules/sharedaddy/sharing-service.php +++ b/projects/plugins/jetpack/modules/sharedaddy/sharing-service.php @@ -10,6 +10,8 @@ * phpcs:disable Generic.Files.OneObjectStructurePerFile.MultipleFound */ +// phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move classes to appropriately-named class files. + use Automattic\Jetpack\Assets; use Automattic\Jetpack\Redirect; use Automattic\Jetpack\Status; @@ -581,8 +583,8 @@ public function get_total( $service_name = false, $post_id = false, $_blog_id = $ret = wp_cache_get( $cache_key, 'sharing' ); if ( $ret === false ) { - // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- Prepared above. - $ret = (int) $wpdb->get_var( $sql ); // db call ok + // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery -- Prepared above. + $ret = (int) $wpdb->get_var( $sql ); wp_cache_set( $cache_key, $ret, 'sharing', 5 * MINUTE_IN_SECONDS ); } return $ret; @@ -621,7 +623,7 @@ public function get_posts_total() { $cache_key = "sharing_service_get_posts_total_{$blog_id}"; $my_data = wp_cache_get( $cache_key, 'sharing' ); if ( $my_data === false ) { - $my_data = $wpdb->get_results( $wpdb->prepare( 'SELECT post_id as id, SUM( count ) as total FROM sharing_stats WHERE blog_id = %d GROUP BY post_id ORDER BY count DESC ', $blog_id ) ); // db call ok + $my_data = $wpdb->get_results( $wpdb->prepare( 'SELECT post_id as id, SUM( count ) as total FROM sharing_stats WHERE blog_id = %d GROUP BY post_id ORDER BY count DESC ', $blog_id ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery wp_cache_set( $cache_key, $my_data, 'sharing', 5 * MINUTE_IN_SECONDS ); } diff --git a/projects/plugins/jetpack/modules/sharedaddy/sharing.php b/projects/plugins/jetpack/modules/sharedaddy/sharing.php index f61472f989a29..49f85f3149cc1 100644 --- a/projects/plugins/jetpack/modules/sharedaddy/sharing.php +++ b/projects/plugins/jetpack/modules/sharedaddy/sharing.php @@ -5,6 +5,8 @@ * @package automattic/jetpack */ +// phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move classes to appropriately-named class files. + use Automattic\Jetpack\Assets; if ( ! defined( 'WP_SHARING_PLUGIN_URL' ) ) { diff --git a/projects/plugins/jetpack/modules/shortcodes/crowdsignal.php b/projects/plugins/jetpack/modules/shortcodes/crowdsignal.php index 0317119177908..63f03d8f65e86 100644 --- a/projects/plugins/jetpack/modules/shortcodes/crowdsignal.php +++ b/projects/plugins/jetpack/modules/shortcodes/crowdsignal.php @@ -18,6 +18,8 @@ * @package automattic/jetpack */ +// phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move classes to appropriately-named class files. + use Automattic\Jetpack\Assets; use Automattic\Jetpack\Constants; diff --git a/projects/plugins/jetpack/modules/shortcodes/mailchimp.php b/projects/plugins/jetpack/modules/shortcodes/mailchimp.php index 15766649143cf..edb74550f6e70 100644 --- a/projects/plugins/jetpack/modules/shortcodes/mailchimp.php +++ b/projects/plugins/jetpack/modules/shortcodes/mailchimp.php @@ -9,6 +9,8 @@ * */ +// phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move classes to appropriately-named class files. + /** * Register [mailchimp_subscriber_popup] shortcode and add a filter to 'pre_kses' queue to reverse MailChimp embed to shortcode. * diff --git a/projects/plugins/jetpack/modules/shortcodes/unavailable.php b/projects/plugins/jetpack/modules/shortcodes/unavailable.php index 8327e9341f187..45fb881052b22 100644 --- a/projects/plugins/jetpack/modules/shortcodes/unavailable.php +++ b/projects/plugins/jetpack/modules/shortcodes/unavailable.php @@ -6,6 +6,8 @@ * @package automattic/jetpack */ +// phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move classes to appropriately-named class files. + /** * Class Jetpack_Shortcode_Unavailable */ diff --git a/projects/plugins/jetpack/modules/simple-payments/simple-payments.php b/projects/plugins/jetpack/modules/simple-payments/simple-payments.php index 587ec65ae3662..9485e95db1655 100644 --- a/projects/plugins/jetpack/modules/simple-payments/simple-payments.php +++ b/projects/plugins/jetpack/modules/simple-payments/simple-payments.php @@ -93,11 +93,11 @@ private function register_scripts_and_styles() { * * @see https://developer.paypal.com/docs/integration/direct/express-checkout/integration-jsv4/add-paypal-button/ */ - wp_register_script( // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion + wp_register_script( 'paypal-checkout-js', 'https://www.paypalobjects.com/api/checkout.js', array(), - null, + null, // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion true ); wp_register_script( diff --git a/projects/plugins/jetpack/modules/sitemaps/sitemaps.php b/projects/plugins/jetpack/modules/sitemaps/sitemaps.php index 70d96c5f3e931..974c6607d4cef 100644 --- a/projects/plugins/jetpack/modules/sitemaps/sitemaps.php +++ b/projects/plugins/jetpack/modules/sitemaps/sitemaps.php @@ -43,6 +43,8 @@ require_once __DIR__ . '/sitemap-logger.php'; } +// phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move classes to appropriately-named class files. + /** * Governs the generation, storage, and serving of sitemaps. * diff --git a/projects/plugins/jetpack/modules/subscriptions.php b/projects/plugins/jetpack/modules/subscriptions.php index 75f1940c34e98..605f6edd39ba8 100644 --- a/projects/plugins/jetpack/modules/subscriptions.php +++ b/projects/plugins/jetpack/modules/subscriptions.php @@ -13,6 +13,8 @@ * Additional Search Queries: subscriptions, subscription, email, follow, followers, subscribers, signup */ +// phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move classes to appropriately-named class files. + use Automattic\Jetpack\Connection\XMLRPC_Async_Call; add_action( 'jetpack_modules_loaded', 'jetpack_subscriptions_load' ); diff --git a/projects/plugins/jetpack/modules/subscriptions/views.php b/projects/plugins/jetpack/modules/subscriptions/views.php index 4b3ba2d70ca0f..bfec991404824 100644 --- a/projects/plugins/jetpack/modules/subscriptions/views.php +++ b/projects/plugins/jetpack/modules/subscriptions/views.php @@ -1,5 +1,7 @@ Widgets diff --git a/projects/plugins/jetpack/modules/widgets/flickr.php b/projects/plugins/jetpack/modules/widgets/flickr.php index fe9631d4c7759..18a881485294d 100644 --- a/projects/plugins/jetpack/modules/widgets/flickr.php +++ b/projects/plugins/jetpack/modules/widgets/flickr.php @@ -1,4 +1,7 @@ Widgets diff --git a/projects/plugins/jetpack/modules/widgets/google-translate.php b/projects/plugins/jetpack/modules/widgets/google-translate.php index d6f0e88d9cf06..155f1d3c933f7 100644 --- a/projects/plugins/jetpack/modules/widgets/google-translate.php +++ b/projects/plugins/jetpack/modules/widgets/google-translate.php @@ -1,5 +1,7 @@ Widgets @@ -186,7 +188,7 @@ public function update( $new_instance, $old_instance ) { $height = $size[1]; $instance['img_height'] = absint( $height ); - unlink( $tmp_file ); + wp_delete_file( $tmp_file ); } else { $instance['img_width'] = $new_img_width; $instance['img_height'] = $new_img_height; diff --git a/projects/plugins/jetpack/modules/widgets/internet-defense-league.php b/projects/plugins/jetpack/modules/widgets/internet-defense-league.php index bb0404ca5b134..68715f90198d9 100644 --- a/projects/plugins/jetpack/modules/widgets/internet-defense-league.php +++ b/projects/plugins/jetpack/modules/widgets/internet-defense-league.php @@ -1,5 +1,7 @@ \WP_REST_SERVER::EDITABLE, + 'methods' => \WP_REST_Server::EDITABLE, 'callback' => __CLASS__ . '::api_clear_scan_cache', 'permission_callback' => function () { return current_user_can( 'manage_options' ); @@ -318,7 +318,7 @@ public static function register_rest_endpoints() { 'jetpack-protect/v1', 'ignore-threat', array( - 'methods' => \WP_REST_SERVER::EDITABLE, + 'methods' => \WP_REST_Server::EDITABLE, 'callback' => __CLASS__ . '::api_ignore_threat', 'permission_callback' => function () { return current_user_can( 'manage_options' ); @@ -330,7 +330,7 @@ public static function register_rest_endpoints() { 'jetpack-protect/v1', 'fix-threats', array( - 'methods' => \WP_REST_SERVER::EDITABLE, + 'methods' => \WP_REST_Server::EDITABLE, 'callback' => __CLASS__ . '::api_fix_threats', 'permission_callback' => function () { return current_user_can( 'manage_options' ); @@ -342,7 +342,7 @@ public static function register_rest_endpoints() { 'jetpack-protect/v1', 'fix-threats-status', array( - 'methods' => \WP_REST_SERVER::READABLE, + 'methods' => \WP_REST_Server::READABLE, 'callback' => __CLASS__ . '::api_fix_threats_status', 'permission_callback' => function () { return current_user_can( 'manage_options' ); @@ -366,7 +366,7 @@ public static function register_rest_endpoints() { 'jetpack-protect/v1', 'scan', array( - 'methods' => \WP_REST_SERVER::EDITABLE, + 'methods' => \WP_REST_Server::EDITABLE, 'callback' => __CLASS__ . '::api_scan', 'permission_callback' => function () { return current_user_can( 'manage_options' ); @@ -378,7 +378,7 @@ public static function register_rest_endpoints() { 'jetpack-protect/v1', 'toggle-waf', array( - 'methods' => \WP_REST_SERVER::EDITABLE, + 'methods' => \WP_REST_Server::EDITABLE, 'callback' => __CLASS__ . '::api_toggle_waf', 'permission_callback' => function () { return current_user_can( 'manage_options' ); @@ -390,7 +390,7 @@ public static function register_rest_endpoints() { 'jetpack-protect/v1', 'waf', array( - 'methods' => \WP_REST_SERVER::READABLE, + 'methods' => \WP_REST_Server::READABLE, 'callback' => __CLASS__ . '::api_get_waf', 'permission_callback' => function () { return current_user_can( 'manage_options' ); @@ -402,7 +402,7 @@ public static function register_rest_endpoints() { 'jetpack-protect/v1', 'waf-seen', array( - 'methods' => \WP_REST_SERVER::READABLE, + 'methods' => \WP_REST_Server::READABLE, 'callback' => __CLASS__ . '::get_waf_seen_status', 'permission_callback' => function () { return current_user_can( 'manage_options' ); @@ -414,7 +414,7 @@ public static function register_rest_endpoints() { 'jetpack-protect/v1', 'waf-seen', array( - 'methods' => \WP_REST_SERVER::EDITABLE, + 'methods' => \WP_REST_Server::EDITABLE, 'callback' => __CLASS__ . '::set_waf_seen_status', 'permission_callback' => function () { return current_user_can( 'manage_options' ); @@ -470,7 +470,7 @@ public static function api_clear_scan_cache() { */ public static function api_ignore_threat( $request ) { if ( ! $request['threat_id'] ) { - return new WP_REST_RESPONSE( 'Missing threat ID.', 400 ); + return new WP_REST_Response( 'Missing threat ID.', 400 ); } $threat_ignored = Threats::ignore_threat( $request['threat_id'] ); @@ -491,7 +491,7 @@ public static function api_ignore_threat( $request ) { */ public static function api_fix_threats( $request ) { if ( empty( $request['threat_ids'] ) ) { - return new WP_REST_RESPONSE( 'Missing threat IDs.', 400 ); + return new WP_REST_Response( 'Missing threat IDs.', 400 ); } $threats_fixed = Threats::fix_threats( $request['threat_ids'] ); @@ -512,7 +512,7 @@ public static function api_fix_threats( $request ) { */ public static function api_fix_threats_status( $request ) { if ( empty( $request['threat_ids'] ) ) { - return new WP_REST_RESPONSE( 'Missing threat IDs.', 400 ); + return new WP_REST_Response( 'Missing threat IDs.', 400 ); } $threats_fixed = Threats::fix_threats_status( $request['threat_ids'] );