From 3f3d675e6a0c12404a0a7aa20b4472b5d37ea88d Mon Sep 17 00:00:00 2001 From: Igor at KAGG Design Date: Sat, 1 Feb 2025 20:06:51 +0300 Subject: [PATCH] V4.10.0 (#382) * Fix fatal error with the WPForms plugin in rare cases. * Improve helper text for anonymous collection. * Improve helper text for anonymous collection. * Fix an error message at the first entry to the login page when Hide Login Errors in on. * Bump up the plugin version to 4.10.0-RC2. * Bump up the plugin version to 4.10.0-RC2. * Fix scrolling to the message on the General page. * Improve error messaging for hCaptcha verification. * Improve comments in Main. * Fix fatal error on install entity. * Fix the Integrations page when active plugin was deleted. * Fix error when hCaptcha is disabled for standard login but enabled for Tutor login. * Refactor CL login. * Fix error when hCaptcha is disabled for standard login but enabled for LearnPress login. * Refactor Profile Builder login. * Add support for hCaptcha in HTML Gravity Forms fields. * Update packages. * Fix default id in hCaptcha form. * Fix default id in hCaptcha form. * Add support for custom nonce action and name in the [hcaptcha] shortcode. * Tests for custom nonce in the [hcaptcha] shortcode. * Fix bug with changing shortcode args. * Tests for Autoverify and Gravity. * Fix bug in GF shortcode (via tests). * Add compatibility with Cookies and Content Security Policy * Add auto-verification of arbitrary forms in ajax. * Fix tests after adding auto-ajax. * Add support for wp_login_form() function and LoginOut block. * Bump up to RC4. * Fix IP detection in WP to sync with hCaptcha events info. * Add deletion of events on the Forms page. * Fix tests. * Add deletion of events on the Events page. * Fix tests. * Fix phpcs. * Fix phpcs. * Multiple layout fixes for Forms and Events pages on small screens. * Multiple layout fixes for Forms and Events pages on small screens. * Remove SVN from the deployment action as it is already included in the 10up action. * Cover Autoverify 100%. * Cover DB 100%. * Bump up to 4.10.0. * Apply suggestions from code review * Apply suggestions from code review --------- Co-authored-by: e271828- --- .../deploy-readme-assets-to-wp-org.yml | 3 - .github/workflows/deploy-to-wp-org.yml | 3 - .../js/assets-js-files/integrations.test.js | 1 + .tests/php/integration/AAAMainTest.php | 3 +- .../integration/Admin/Events/EventsTest.php | 1 + .../integration/AutoVerify/AutoVerifyTest.php | 122 +- .tests/php/integration/CF7/CF7Test.php | 1 + .../php/integration/GravityForms/FormTest.php | 29 +- .tests/php/integration/HCaptchaWPTestCase.php | 3 + .tests/php/integration/Helpers/DBTest.php | 55 + .tests/php/integration/NF/NFTest.php | 1 + .tests/php/integration/WP/CommentTest.php | 10 +- .tests/php/unit/AutoVerify/AutoVerifyTest.php | 411 +++++-- .tests/php/unit/HCaptchaTestCase.php | 2 +- .tests/php/unit/Settings/EventsPageTest.php | 11 + .tests/php/unit/Settings/FormsPageTest.php | 11 + .tests/php/unit/Settings/ListPageBaseTest.php | 12 +- .tests/php/unit/includes/FunctionsTest.php | 5 + assets/css/events.css | 3 +- assets/css/forms.css | 3 +- assets/css/settings-base.css | 55 +- assets/css/settings-list-page-base.css | 1 - assets/js/events.js | 166 ++- assets/js/forms.js | 169 ++- assets/js/general.js | 9 +- assets/js/hcaptcha-auto-verify.js | 65 ++ assets/js/integrations.js | 29 +- assets/js/settings-base.js | 93 +- assets/js/settings-list-page-base.js | 6 +- changelog.txt | 19 + composer.json | 2 +- hcaptcha.php | 6 +- package.json | 9 +- readme.txt | 30 +- src/js/hcaptcha/hcaptcha.js | 54 +- src/php/Abstracts/LoginBase.php | 6 + src/php/Admin/Events/Events.php | 2 +- src/php/Admin/Events/EventsTable.php | 182 +-- src/php/Admin/Events/FormsTable.php | 178 +-- src/php/Admin/Events/TableBase.php | 227 ++++ src/php/AutoVerify/AutoVerify.php | 195 +++- src/php/CACSP/Compatibility.php | 85 ++ src/php/ClassifiedListing/Login.php | 18 +- src/php/GravityForms/Base.php | 4 +- src/php/GravityForms/Form.php | 96 +- src/php/Helpers/DB.php | 46 + src/php/Helpers/HCaptcha.php | 48 +- src/php/LearnPress/Login.php | 31 +- src/php/LearnPress/Register.php | 1 + src/php/Main.php | 14 +- src/php/ProfileBuilder/Login.php | 17 +- src/php/Sendinblue/Sendinblue.php | 4 +- src/php/Settings/EventsPage.php | 87 +- src/php/Settings/FormsPage.php | 95 +- src/php/Settings/General.php | 5 +- src/php/Settings/Integrations.php | 21 +- src/php/Settings/ListPageBase.php | 39 +- src/php/Tutor/Login.php | 31 +- src/php/WP/Comment.php | 3 + src/php/WP/Login.php | 6 - src/php/WP/LoginOut.php | 60 + src/php/WPForms/Form.php | 4 + src/php/includes/functions.php | 2 + src/php/includes/request.php | 16 +- yarn.lock | 1039 +++++++++-------- 65 files changed, 2613 insertions(+), 1352 deletions(-) create mode 100644 .tests/php/integration/Helpers/DBTest.php create mode 100644 assets/js/hcaptcha-auto-verify.js create mode 100644 src/php/Admin/Events/TableBase.php create mode 100644 src/php/CACSP/Compatibility.php create mode 100644 src/php/Helpers/DB.php create mode 100644 src/php/WP/LoginOut.php diff --git a/.github/workflows/deploy-readme-assets-to-wp-org.yml b/.github/workflows/deploy-readme-assets-to-wp-org.yml index bb90c54a..d089e7df 100644 --- a/.github/workflows/deploy-readme-assets-to-wp-org.yml +++ b/.github/workflows/deploy-readme-assets-to-wp-org.yml @@ -11,9 +11,6 @@ jobs: - name: Checkout code uses: actions/checkout@v4 - - name: Install SVN - run: sudo apt-get update && sudo apt-get install -y subversion - - name: WordPress.org plugin asset/readme update uses: 10up/action-wordpress-plugin-asset-update@stable env: diff --git a/.github/workflows/deploy-to-wp-org.yml b/.github/workflows/deploy-to-wp-org.yml index c916e4b1..0431f99d 100644 --- a/.github/workflows/deploy-to-wp-org.yml +++ b/.github/workflows/deploy-to-wp-org.yml @@ -15,9 +15,6 @@ jobs: - name: Checkout code uses: actions/checkout@v4 - - name: Install SVN - run: sudo apt-get update && sudo apt-get install -y subversion - - name: Install dependencies with caching uses: ramsey/composer-install@v3 with: diff --git a/.tests/js/assets-js-files/integrations.test.js b/.tests/js/assets-js-files/integrations.test.js index b8a331ed..a80285b3 100644 --- a/.tests/js/assets-js-files/integrations.test.js +++ b/.tests/js/assets-js-files/integrations.test.js @@ -5,6 +5,7 @@ import $ from 'jquery'; global.jQuery = $; global.$ = $; +require( '../../../assets/js/settings-base.js' ); require( '../../../assets/js/integrations.js' ); // Mock HCaptchaIntegrationsObject diff --git a/.tests/php/integration/AAAMainTest.php b/.tests/php/integration/AAAMainTest.php index 9cd812fa..38f9d1b7 100644 --- a/.tests/php/integration/AAAMainTest.php +++ b/.tests/php/integration/AAAMainTest.php @@ -34,6 +34,7 @@ use HCaptcha\WCWishlists\CreateList; use HCaptcha\WP\Comment; use HCaptcha\WP\Login; +use HCaptcha\WP\LoginOut; use HCaptcha\WP\LostPassword; use HCaptcha\WP\PasswordProtected; use HCaptcha\WP\Register; @@ -1295,7 +1296,7 @@ public function dp_test_load_modules(): array { 'Login Form' => [ [ 'wp_status', 'login' ], '', - Login::class, + [ Login::class, LoginOut::class ], ], 'Lost Password Form' => [ [ 'wp_status', 'lost_pass' ], diff --git a/.tests/php/integration/Admin/Events/EventsTest.php b/.tests/php/integration/Admin/Events/EventsTest.php index e9833f8a..af9dce1c 100644 --- a/.tests/php/integration/Admin/Events/EventsTest.php +++ b/.tests/php/integration/Admin/Events/EventsTest.php @@ -241,6 +241,7 @@ public function test_get_forms(): void { 'source' => '[]', 'form_id' => '0', 'served' => '2', + 'id' => '1', ], ], 'total' => 1, diff --git a/.tests/php/integration/AutoVerify/AutoVerifyTest.php b/.tests/php/integration/AutoVerify/AutoVerifyTest.php index 07e1b05d..61ca131d 100644 --- a/.tests/php/integration/AutoVerify/AutoVerifyTest.php +++ b/.tests/php/integration/AutoVerify/AutoVerifyTest.php @@ -40,7 +40,7 @@ public function test_init_and_init_hooks(): void { $subject = new AutoVerify(); $subject->init(); - self::assertSame( -PHP_INT_MAX, has_action( 'init', [ $subject, 'verify_form' ] ) ); + self::assertSame( -PHP_INT_MAX, has_action( 'init', [ $subject, 'verify' ] ) ); self::assertSame( PHP_INT_MAX, has_filter( 'the_content', [ $subject, 'content_filter' ] ) ); self::assertSame( PHP_INT_MAX, @@ -62,8 +62,10 @@ public function test_content_filter(): void { $subject = new AutoVerify(); + $subject->init(); + self::assertFalse( get_transient( $subject::TRANSIENT ) ); - self::assertSame( $content, $subject->content_filter( $content ) ); + apply_filters( 'the_content', $content ); self::assertSame( $expected, get_transient( $subject::TRANSIENT ) ); } @@ -82,8 +84,10 @@ public function test_widget_block_content_filter(): void { $subject = new AutoVerify(); + $subject->init(); + self::assertFalse( get_transient( $subject::TRANSIENT ) ); - self::assertSame( $content, $subject->widget_block_content_filter( $content, [], $wp_widget_block ) ); + apply_filters( 'widget_block_content', $content, [], $wp_widget_block ); self::assertSame( $expected, get_transient( $subject::TRANSIENT ) ); } @@ -99,14 +103,16 @@ public function test_content_filter_with_action(): void { $content ); - unset( $_SERVER['REQUEST_URI'] ); + $_SERVER['REQUEST_URI'] = 'some-uri'; $expected = $this->get_test_registered_forms(); $subject = new AutoVerify(); + $subject->init(); + self::assertFalse( get_transient( $subject::TRANSIENT ) ); - self::assertSame( $content, $subject->content_filter( $content ) ); + apply_filters( 'the_content', $content ); self::assertSame( $expected, get_transient( $subject::TRANSIENT ) ); } @@ -116,64 +122,15 @@ public function test_content_filter_with_action(): void { public function test_content_filter_without_form_action(): void { $content = $this->get_test_content(); - unset( $_SERVER['REQUEST_URI'] ); - - $subject = new AutoVerify(); - - self::assertFalse( get_transient( $subject::TRANSIENT ) ); - self::assertSame( $content, $subject->content_filter( $content ) ); - self::assertSame( [], get_transient( $subject::TRANSIENT ) ); - } - - /** - * Test content_filter() when no input in form (really?). - */ - public function test_content_filter_without_form_inputs(): void { - $request_uri = wp_parse_url( $this->get_test_request_uri(), PHP_URL_PATH ); - $content = $this->get_test_content(); - $content = preg_replace( '##', '', $content ); - $expected = $this->get_test_registered_forms(); - - $expected[ untrailingslashit( $request_uri ) ][0] = []; - - $_SERVER['REQUEST_URI'] = $request_uri; + $_SERVER['REQUEST_URI'] = ''; $subject = new AutoVerify(); - self::assertFalse( get_transient( $subject::TRANSIENT ) ); - self::assertSame( $content, $subject->content_filter( $content ) ); - self::assertSame( $expected, get_transient( $subject::TRANSIENT ) ); - - // Test update existing transient. - self::assertSame( $content, $subject->content_filter( $content ) ); - self::assertSame( $expected, get_transient( $subject::TRANSIENT ) ); - } - - /** - * Test content_filter() when no data-auto in form (really?). - */ - public function test_content_filter_without_form_data_auto(): void { - $request_uri = $this->get_test_request_uri(); - $content = $this->get_test_content(); - $content = preg_replace( '#data-auto=".*?">#', '', $content ); - - $_SERVER['REQUEST_URI'] = $request_uri; - - $subject = new AutoVerify(); + $subject->init(); self::assertFalse( get_transient( $subject::TRANSIENT ) ); - self::assertSame( $content, $subject->content_filter( $content ) ); + apply_filters( 'the_content', $content ); self::assertSame( [], get_transient( $subject::TRANSIENT ) ); - - $registered_forms = $this->get_test_registered_forms(); - $expected = $registered_forms; - - $expected[ untrailingslashit( wp_parse_url( $request_uri, PHP_URL_PATH ) ) ] = []; - - // Test update existing transient. - set_transient( AutoVerify::TRANSIENT, $registered_forms ); - self::assertSame( $content, $subject->content_filter( $content ) ); - self::assertSame( $expected, get_transient( $subject::TRANSIENT ) ); } /** @@ -216,10 +173,10 @@ static function () { */ public function test_verify_form_when_not_post(): void { $subject = new AutoVerify(); - $subject->verify_form(); + $subject->verify(); $_SERVER['REQUEST_METHOD'] = 'GET'; - $subject->verify_form(); + $subject->verify(); } /** @@ -231,7 +188,7 @@ public function test_verify_form_when_no_request_uri(): void { unset( $_SERVER['REQUEST_URI'] ); $subject = new AutoVerify(); - $subject->verify_form(); + $subject->verify(); } /** @@ -244,7 +201,7 @@ public function test_verify_form_when_no_forms_are_registered(): void { $_SERVER['REQUEST_URI'] = $request_uri; $subject = new AutoVerify(); - $subject->verify_form(); + $subject->verify(); } /** @@ -263,7 +220,7 @@ public function test_verify_form_when_forms_on_another_uri_are_registered(): voi set_transient( AutoVerify::TRANSIENT, $registered_forms ); $subject = new AutoVerify(); - $subject->verify_form(); + $subject->verify(); } /** @@ -282,7 +239,7 @@ public function test_verify_form_when_other_forms_on_the_same_uri_are_registered set_transient( AutoVerify::TRANSIENT, $registered_forms ); $subject = new AutoVerify(); - $subject->verify_form(); + $subject->verify(); } /** @@ -319,7 +276,7 @@ static function ( $name ) use ( &$die_arr ) { ); $subject = new AutoVerify(); - $subject->verify_form(); + $subject->verify(); // phpcs:ignore WordPress.Security.NonceVerification.Missing self::assertSame( [], $_POST ); @@ -349,7 +306,7 @@ public function test_verify_form_when_success(): void { $this->prepare_hcaptcha_request_verify( $hcaptcha_response ); $subject = new AutoVerify(); - $subject->verify_form(); + $subject->verify(); $_POST[ HCAPTCHA_NONCE ] = $this->get_test_nonce(); @@ -364,7 +321,7 @@ public function test_verify_form_in_admin(): void { set_current_screen( 'some-screen' ); $subject = new AutoVerify(); - $subject->verify_form(); + $subject->verify(); } /** @@ -379,7 +336,7 @@ static function () { ); $subject = new AutoVerify(); - $subject->verify_form(); + $subject->verify(); } /** @@ -394,7 +351,7 @@ public function test_verify_form_in_rest_case_3_and_4(): void { $_SERVER['REQUEST_URI'] = rest_url(); $subject = new AutoVerify(); - $subject->verify_form(); + $subject->verify(); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited $GLOBALS['wp_rewrite'] = $old_wp_rewrite; @@ -431,15 +388,7 @@ private function get_test_content(): string {
-
-
- - + [hcaptcha auto="true"]