Skip to content

Instantly share code, notes, and snippets.

@sarahcssiqueira
Created October 15, 2024 18:38
Show Gist options
  • Save sarahcssiqueira/3799fb5c09e086722ba80eff34830d3f to your computer and use it in GitHub Desktop.
Save sarahcssiqueira/3799fb5c09e086722ba80eff34830d3f to your computer and use it in GitHub Desktop.
This patch fixes an issue in the WordPress Coding Standards (WPCS) package where null values are passed to `trim()`, causing errors in PHP 8.x. It modifies the following files: - PrefixAllGlobalsSniff.php (line 280) - I18nSniff.php (line 194) - Sniff.php (line 1144)
"extra": {
"patches": {
"wp-coding-standards/wpcs": {
"Fix null trim() issue in multiple files": "patches/fix-null-trim-multi.patch"
}
}
}
--- a/vendor/wp-coding-standards/wpcs/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php
+++ b/vendor/wp-coding-standards/wpcs/WordPress/Sniffs/NamingConventions/PrefixAllGlobalsSniff.php
@@ -280,7 +280,7 @@
// Original code with `trim()`
// Update this line:
- $cl_prefixes = trim( PHPCSHelper::get_config_data( 'prefixes' ) );
+ $cl_prefixes = is_null( PHPCSHelper::get_config_data( 'prefixes' ) ) ? '' : trim( PHPCSHelper::get_config_data( 'prefixes' ) );
--- a/vendor/wp-coding-standards/wpcs/WordPress/Sniffs/WP/I18nSniff.php
+++ b/vendor/wp-coding-standards/wpcs/WordPress/Sniffs/WP/I18nSniff.php
@@ -194,7 +194,7 @@
// Original code with `trim()`
// Update this line:
- $cl_text_domain = trim( PHPCSHelper::get_config_data( 'text_domain' ) );
+ $cl_text_domain = is_null(PHPCSHelper::get_config_data( 'text_domain' )) ? '' : trim( PHPCSHelper::get_config_data( 'text_domain' ) );
--- a/vendor/wp-coding-standards/wpcs/WordPress/Sniffs/Sniff.php
+++ b/vendor/wp-coding-standards/wpcs/WordPress/Sniffs/Sniff.php
@@ -1144,7 +1144,7 @@
// Original code with `trim()`
// Update this line:
- $cl_supported_version = trim( PHPCSHelper::get_config_data( 'minimum_supported_wp_version' ) );
+ $cl_supported_version = is_null(PHPCSHelper::get_config_data( 'minimum_supported_wp_version' )) ? '' : trim( PHPCSHelper::get_config_data( 'minimum_supported_wp_version' ) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment