From aa5867f4abda5e7a7c621ec6a4d71bd01e752d68 Mon Sep 17 00:00:00 2001 From: Slava Abakumov <282234+slaFFik@users.noreply.github.com> Date: Wed, 1 Oct 2025 21:22:45 +0200 Subject: [PATCH 1/6] Refactor domain validation logic in ValidateDomainSniff Do not allow current domain name to be empty. Notify the user with an error --- WPForms/Sniffs/PHP/ValidateDomainSniff.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/WPForms/Sniffs/PHP/ValidateDomainSniff.php b/WPForms/Sniffs/PHP/ValidateDomainSniff.php index c9692f6..73093d8 100644 --- a/WPForms/Sniffs/PHP/ValidateDomainSniff.php +++ b/WPForms/Sniffs/PHP/ValidateDomainSniff.php @@ -113,7 +113,19 @@ public function process( File $phpcsFile, $stackPtr ) { return; } - if ( ! $currentDomain || ! $expectedDomain ) { + if ( ! $currentDomain ) { + $phpcsFile->addError( + sprintf( + "Domain name is not set. You should be using '%s'.", + $expectedDomain + ), + $stackPtr, + 'InvalidDomain' + ); + return; + } + + if ( ! $expectedDomain ) { return; } From 8e7fa93ac929f4b7aab461c8f059120d73fcc199 Mon Sep 17 00:00:00 2001 From: Slava Abakumov <282234+slaFFik@users.noreply.github.com> Date: Wed, 1 Oct 2025 21:25:17 +0200 Subject: [PATCH 2/6] Fix formatting issue in ValidateDomainSniff.php --- WPForms/Sniffs/PHP/ValidateDomainSniff.php | 1 + 1 file changed, 1 insertion(+) diff --git a/WPForms/Sniffs/PHP/ValidateDomainSniff.php b/WPForms/Sniffs/PHP/ValidateDomainSniff.php index 73093d8..03c1824 100644 --- a/WPForms/Sniffs/PHP/ValidateDomainSniff.php +++ b/WPForms/Sniffs/PHP/ValidateDomainSniff.php @@ -122,6 +122,7 @@ public function process( File $phpcsFile, $stackPtr ) { $stackPtr, 'InvalidDomain' ); + return; } From f3fff76bc651bdf2797bc8b52b5e8250b03dd00b Mon Sep 17 00:00:00 2001 From: Slava Abakumov <282234+slaFFik@users.noreply.github.com> Date: Wed, 1 Oct 2025 21:31:20 +0200 Subject: [PATCH 3/6] Fix comment on esc_html__ usage in ValidateDomain.php Updated comment to reflect the change in syntax validity. --- WPForms/Tests/TestFiles/PHP/ValidateDomain.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WPForms/Tests/TestFiles/PHP/ValidateDomain.php b/WPForms/Tests/TestFiles/PHP/ValidateDomain.php index 8c8ce8f..d646ae4 100644 --- a/WPForms/Tests/TestFiles/PHP/ValidateDomain.php +++ b/WPForms/Tests/TestFiles/PHP/ValidateDomain.php @@ -30,8 +30,8 @@ _nx( 'Invalid', 'Invalid', 10, 'Invalid', 'wpforms' ); -// Valid syntax when the text domain is not specified. -esc_html__( 'Valid' ); +// Invalid syntax when the text domain is not specified. +esc_html__( 'Invalid' ); // Invalid - not a string as the last argument. $bulk_counts['read'] = 25; From b321ff049cb4b2122dc7d34d71f6a19f6bef624a Mon Sep 17 00:00:00 2001 From: Slava Abakumov <282234+slaFFik@users.noreply.github.com> Date: Wed, 1 Oct 2025 21:31:37 +0200 Subject: [PATCH 4/6] Update test cases for ValidateDomainSniff --- WPForms/Tests/Tests/PHP/ValidateDomainTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WPForms/Tests/Tests/PHP/ValidateDomainTest.php b/WPForms/Tests/Tests/PHP/ValidateDomainTest.php index 20ab89c..543ae72 100644 --- a/WPForms/Tests/Tests/PHP/ValidateDomainTest.php +++ b/WPForms/Tests/Tests/PHP/ValidateDomainTest.php @@ -21,7 +21,7 @@ public function testProcess() { $phpcsFile = $this->process( new ValidateDomainSniff() ); - $this->fileHasErrors( $phpcsFile, 'InvalidDomain', [ 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 41 ] ); + $this->fileHasErrors( $phpcsFile, 'InvalidDomain', [ 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 34, 41 ] ); $this->fileHasErrors( $phpcsFile, 'NotStringDomain', [ 38 ] ); } From 035ffea226e54f28a58c36b54b31b5163e15b66e Mon Sep 17 00:00:00 2001 From: Slava Abakumov <282234+slaFFik@users.noreply.github.com> Date: Wed, 1 Oct 2025 21:33:17 +0200 Subject: [PATCH 5/6] Update ValidateDomainTest.php --- WPForms/Tests/Tests/PHP/ValidateDomainTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WPForms/Tests/Tests/PHP/ValidateDomainTest.php b/WPForms/Tests/Tests/PHP/ValidateDomainTest.php index 543ae72..0c9f5e8 100644 --- a/WPForms/Tests/Tests/PHP/ValidateDomainTest.php +++ b/WPForms/Tests/Tests/PHP/ValidateDomainTest.php @@ -46,6 +46,6 @@ public function testProcessWithRewrittenPaths() { $phpcsFile = $this->process( new ValidateDomainSniff(), 'ValidateDomainWithRewrites' ); - $this->fileHasErrors( $phpcsFile, 'InvalidDomain', [ 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 19, 20, 27, 28, 29, 30, 41 ] ); + $this->fileHasErrors( $phpcsFile, 'InvalidDomain', [ 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 19, 20, 27, 28, 29, 30, 34, 41 ] ); } } From 876e19d6294d196abc1108198b63f996d91d67f1 Mon Sep 17 00:00:00 2001 From: Slava Abakumov <282234+slaFFik@users.noreply.github.com> Date: Wed, 1 Oct 2025 21:34:25 +0200 Subject: [PATCH 6/6] Update test for multi-domain validation errors --- WPForms/Tests/Tests/PHP/ValidateDomainTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WPForms/Tests/Tests/PHP/ValidateDomainTest.php b/WPForms/Tests/Tests/PHP/ValidateDomainTest.php index 0c9f5e8..527fbb8 100644 --- a/WPForms/Tests/Tests/PHP/ValidateDomainTest.php +++ b/WPForms/Tests/Tests/PHP/ValidateDomainTest.php @@ -34,7 +34,7 @@ public function testProcessWithMultiDomains() { $phpcsFile = $this->process( new ValidateDomainSniff(), 'MultiDomains' ); - $this->fileHasErrors( $phpcsFile, 'InvalidDomain', [ 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 20, 21, 22, 23, 24, 25, 26 ] ); + $this->fileHasErrors( $phpcsFile, 'InvalidDomain', [ 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 20, 21, 22, 23, 24, 25, 26, 34 ] ); } /**