diff --git a/.github/workflows/deploy-to-wp-org.yml b/.github/workflows/deploy-to-wp-org.yml
index ae6f22f1..b8c779a9 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: Remove scoped packages
- run: rm -rf vendors/*
-
- name: Install dependencies with caching
uses: kagg-design/composer-install@v2
with:
diff --git a/.php-scoper/hcaptcha-wordpress-plugin-scoper.php b/.php-scoper/hcaptcha-wordpress-plugin-scoper.php
index cb10e3ea..39ca0a6b 100644
--- a/.php-scoper/hcaptcha-wordpress-plugin-scoper.php
+++ b/.php-scoper/hcaptcha-wordpress-plugin-scoper.php
@@ -15,7 +15,7 @@
use HCaptcha\Scoper\Scoper;
-require_once __DIR__ . '/Scoper.php';
+require_once __DIR__ . '/src/Scoper.php';
$finders = Scoper::get_finders();
diff --git a/.php-scoper/Scoper.php b/.php-scoper/src/Scoper.php
similarity index 84%
rename from .php-scoper/Scoper.php
rename to .php-scoper/src/Scoper.php
index 9b1b338f..4f7abd85 100644
--- a/.php-scoper/Scoper.php
+++ b/.php-scoper/src/Scoper.php
@@ -16,8 +16,8 @@
use Composer\DependencyResolver\Operation\UninstallOperation;
use Composer\DependencyResolver\Operation\UpdateOperation;
use Composer\EventDispatcher\Event as BaseEvent;
-use Composer\Script\Event;
use Composer\Installer\PackageEvent;
+use Composer\Script\Event;
use Isolated\Symfony\Component\Finder\Finder;
use Seld\JsonLint\ParsingException;
@@ -76,13 +76,16 @@ static function ( $package ) {
);
$removed_packages = array_diff( $packages, $locked_packages );
- $vendor_prefixed = self::get_vendor_prefixed();
+ $vendor_prefixed = self::get_vendor_prefixed_dir();
foreach ( $removed_packages as $removed_package ) {
self::delete_package( $vendor_prefixed, $removed_package );
}
}
+ // Always delete scoped packages from vendor.
+ self::cleanup_scope( $event );
+
if ( self::$do_dump ) {
self::dump( $event );
}
@@ -111,10 +114,8 @@ public static function post_package_install( PackageEvent $package_event ): void
return;
}
- $vendor_prefixed = self::get_vendor_prefixed();
-
// Do not run scoper after installation if we already have package scoped.
- self::$do_scope = self::$do_scope || ! self::is_not_empty_dir( $vendor_prefixed . '/' . $package );
+ self::$do_scope = self::$do_scope || ! self::is_not_empty_dir( self::get_vendor_prefixed_dir( $package ) );
}
/**
@@ -166,7 +167,7 @@ public static function post_package_uninstall( PackageEvent $event ): void {
return;
}
- self::delete_package( self::get_vendor_prefixed(), $package );
+ self::delete_package( self::get_vendor_prefixed_dir(), $package );
self::$do_dump = true;
}
@@ -178,6 +179,7 @@ public static function post_package_uninstall( PackageEvent $event ): void {
* @param Event $event Composer event.
*
* @return void
+ * @noinspection MkdirRaceConditionInspection
*/
private static function prepare_scope( Event $event ): void {
$packages = $event->getComposer()->getPackage()->getExtra()['scope-packages'] ?? [];
@@ -187,19 +189,18 @@ private static function prepare_scope( Event $event ): void {
}
// Bail if .php-scoper/vendor dir already exists and not empty.
- if ( self::is_not_empty_dir( __DIR__ . self::VENDOR ) ) {
+ if ( self::is_not_empty_dir( self::get_scoper_dir( self::VENDOR ) ) ) {
return;
}
- $vendor_prefixed = self::get_vendor_prefixed();
+ $vendor_prefixed = self::get_vendor_prefixed_dir();
if ( ! is_dir( $vendor_prefixed ) ) {
- // phpcs:disable WordPress.WP.AlternativeFunctions.file_system_operations_mkdir, Generic.Commenting.DocComment.MissingShort
+ // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_mkdir
mkdir( $vendor_prefixed );
- // phpcs:enable WordPress.WP.AlternativeFunctions.file_system_operations_mkdir, Generic.Commenting.DocComment.MissingShort
}
- $composer_cmd = 'composer --working-dir="' . __DIR__ . '" --no-plugins --no-scripts --no-dev install';
+ $composer_cmd = 'composer --working-dir="' . self::get_scoper_dir() . '" --no-plugins --no-scripts --no-dev install';
// phpcs:disable WordPress.PHP.DiscouragedPHPFunctions.system_calls_shell_exec, WordPress.Security.EscapeOutput.OutputNotEscaped
echo shell_exec( $composer_cmd );
@@ -221,8 +222,7 @@ private static function scope( Event $event ): void {
}
$slug = basename( getcwd() );
- $vendor = self::get_vendor();
- $output_dir = self::get_vendor_prefixed();
+ $output_dir = self::get_vendor_prefixed_dir();
$vendors = array_unique(
array_map(
@@ -246,7 +246,7 @@ static function ( $scope_package ) {
self::fix_logo_on_windows();
- $scoper_file = __DIR__ . self::VENDOR . '/humbug/php-scoper/bin/php-scoper';
+ $scoper_file = self::get_scoper_dir( self::VENDOR . '/humbug/php-scoper/bin/php-scoper' );
$scoper_args =
'" add-prefix' .
' --config=.php-scoper/' . $slug . '-scoper.php' .
@@ -257,12 +257,29 @@ static function ( $scope_package ) {
// phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.system_calls_shell_exec, WordPress.Security.EscapeOutput.OutputNotEscaped
echo shell_exec( $scoper_cmd );
+ self::$do_dump = true;
+ }
+
+ /**
+ * Cleanup scoped libraries.
+ *
+ * @param Event $event Composer event.
+ *
+ * @return void
+ */
+ private static function cleanup_scope( Event $event ): void {
+ $scope_packages = $event->getComposer()->getPackage()->getExtra()['scope-packages'] ?? [];
+
+ if ( ! $scope_packages ) {
+ return;
+ }
+
+ $vendor = self::get_vendor_dir();
+
// Loop through the list of packages and delete relevant dirs in vendor.
foreach ( $scope_packages as $package ) {
self::delete_package( $vendor, $package );
}
-
- self::$do_dump = true;
}
/**
@@ -341,7 +358,7 @@ public static function get_finders(): array {
// phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
$composer_json = json_decode( file_get_contents( getcwd() . '/composer.json' ), true );
$packages = $composer_json['extra']['scope-packages'] ?? [];
- $vendor_dir = self::get_vendor();
+ $vendor_dir = self::get_vendor_dir();
$filenames = [ '*.php', 'LICENSE', 'CHANGELOG.md', 'README.md' ];
$finders = [];
@@ -384,7 +401,7 @@ private static function fix_logo_on_windows(): void {
return;
}
- $file = __DIR__ . self::VENDOR . '/humbug/php-scoper/src/Console/Application.php';
+ $file = self::get_scoper_dir( self::VENDOR . '/humbug/php-scoper/src/Console/Application.php' );
// phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
$contents = file_get_contents( $file );
@@ -473,18 +490,49 @@ private static function is_not_empty_dir( string $filename ): bool {
/**
* Get vendor dir.
*
+ * @param string $path Path relative to the vendor prefixed dir.
+ *
* @return string
+ * @noinspection PhpSameParameterValueInspection
*/
- private static function get_vendor(): string {
- return getcwd() . self::VENDOR;
+ private static function get_vendor_dir( string $path = '' ): string {
+ return self::add_path_to_dir( getcwd() . self::VENDOR, $path );
}
/**
* Get vendor prefixed dir.
*
+ * @param string $path Path relative to the vendor prefixed dir.
+ *
* @return string
*/
- private static function get_vendor_prefixed(): string {
- return getcwd() . self::VENDOR_PREFIXED;
+ private static function get_vendor_prefixed_dir( string $path = '' ): string {
+ return self::add_path_to_dir( getcwd() . self::VENDOR_PREFIXED, $path );
+ }
+
+ /**
+ * Get scoper dir.
+ *
+ * @param string $path Path relative to the scoper dir.
+ *
+ * @return string
+ */
+ private static function get_scoper_dir( string $path = '' ): string {
+ return self::add_path_to_dir( dirname( __DIR__ ), $path );
+ }
+
+ /**
+ * Add a path to dir.
+ *
+ * @param string $dir Dir.
+ * @param string $path Path.
+ *
+ * @return string
+ */
+ private static function add_path_to_dir( string $dir, string $path ): string {
+ $dir = rtrim( $dir, '/' );
+ $path = ltrim( $path, '/' );
+
+ return rtrim( $dir . '/' . $path, '/' );
}
}
diff --git a/.tests/php/integration/CF7/AdminTest.php b/.tests/php/integration/CF7/AdminTest.php
index c622bb12..2ba5cbe2 100644
--- a/.tests/php/integration/CF7/AdminTest.php
+++ b/.tests/php/integration/CF7/AdminTest.php
@@ -38,7 +38,7 @@ class AdminTest extends HCaptchaPluginWPTestCase {
* Tear down the test.
*/
public function tearDown(): void { // phpcs:ignore PHPCompatibility.FunctionDeclarations.NewReturnTypeDeclarations.voidFound
- unset( $GLOBALS['current_screen'] );
+ unset( $GLOBALS['current_screen'], $_GET['post'], $_GET['page'] );
parent::tearDown();
}
@@ -57,6 +57,9 @@ public function test_init_hooks( bool $mode_auto, bool $mode_embed, bool $is_adm
$cf7_status = array_filter( [ $mode_auto ? 'form' : '', $mode_embed ? 'embed' : '' ] );
if ( $is_admin ) {
+ $_GET['page'] = 'wpcf7';
+ $_GET['post'] = 177;
+
set_current_screen( 'some' );
}
@@ -71,6 +74,10 @@ public function test_init_hooks( bool $mode_auto, bool $mode_embed, bool $is_adm
$subject = new Admin();
+ if ( $is_admin && $cf7_status ) {
+ set_current_screen( 'toplevel_page_wpcf7' );
+ }
+
if ( $expected ) {
self::assertSame(
54,
@@ -185,7 +192,6 @@ public function test_toplevel_page_wpcf7() {
-
HTML;
diff --git a/changelog.txt b/changelog.txt
index 9c06a033..a51215d0 100644
--- a/changelog.txt
+++ b/changelog.txt
@@ -1,3 +1,9 @@
+= 4.3.1 =
+* Added a live form in the Contact Form 7 admin form view.
+* Fixed warnings and deprecation messages in admin when Contact Form 7 is active.
+* Fixed tag generator with the live form for Contact Form 7.
+* Fixed fatal error with Gravity Forms.
+
= 4.3.0 =
* NOTE: the plugin has been renamed from "hCaptcha for WordPress" to "hCaptcha for WP"
* Dropped support for PHP 7.0 and 7.1. The minimum required PHP version is now 7.2.
diff --git a/composer.json b/composer.json
index 709bca45..3f8ac607 100644
--- a/composer.json
+++ b/composer.json
@@ -49,11 +49,14 @@
"autoload": {
"psr-4": {
"HCaptcha\\": "src/php",
- "HCaptcha\\Scoper\\": ".php-scoper",
+ "HCaptcha\\Scoper\\": ".php-scoper/src",
"KAGG\\Settings\\Abstracts\\": "src/php/Settings/Abstracts"
},
"classmap": [
"vendors"
+ ],
+ "exclude-from-classmap": [
+ "src/php/Divi/WPTestCaseStub.php"
]
},
"autoload-dev": {
diff --git a/hcaptcha.php b/hcaptcha.php
index 3715f0b8..68482a8e 100644
--- a/hcaptcha.php
+++ b/hcaptcha.php
@@ -10,7 +10,7 @@
* Plugin Name: hCaptcha for WP
* Plugin URI: https://www.hcaptcha.com/
* Description: hCaptcha keeps out bots and spam while putting privacy first. It is a drop-in replacement for reCAPTCHA.
- * Version: 4.3.0
+ * Version: 4.3.1
* Requires at least: 5.3
* Requires PHP: 7.2
* Author: hCaptcha
@@ -39,7 +39,7 @@
/**
* Plugin version.
*/
-const HCAPTCHA_VERSION = '4.3.0';
+const HCAPTCHA_VERSION = '4.3.1';
/**
* Path to the plugin dir.
diff --git a/phpcs.xml b/phpcs.xml
index 522d91b4..ccd4f875 100644
--- a/phpcs.xml
+++ b/phpcs.xml
@@ -10,7 +10,6 @@