Skip to content

Commit

Permalink
V4.3.1 (#349)
Browse files Browse the repository at this point in the history
* Do not remove scoped packages before deploy.

* Always remove scoped packages from vendor.

* Fix warnings and deprecation messages in admin when CF7 is active.
Add a live form in the Contact Form 7 admin form view.

* Fix fatal error with Gravity Forms.

* Fix CF7 tests.

* Bump up version.

* Update phpcs.xml.

* Update readme.txt.

* Bump up version.

* Fix tag generator hCaptcha.

* Fix CF7 live form with tag generator.

* Fix CF7 live form with tag generator.

* Fix CF7 live form with tag generator.
  • Loading branch information
kagg-design authored Jul 9, 2024
1 parent a778058 commit 79902b1
Show file tree
Hide file tree
Showing 15 changed files with 175 additions and 50 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/deploy-to-wp-org.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion .php-scoper/hcaptcha-wordpress-plugin-scoper.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

use HCaptcha\Scoper\Scoper;

require_once __DIR__ . '/Scoper.php';
require_once __DIR__ . '/src/Scoper.php';

$finders = Scoper::get_finders();

Expand Down
92 changes: 70 additions & 22 deletions .php-scoper/Scoper.php → .php-scoper/src/Scoper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 );
}
Expand Down Expand Up @@ -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 ) );
}

/**
Expand Down Expand Up @@ -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;
}
Expand All @@ -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'] ?? [];
Expand All @@ -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 );
Expand All @@ -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(
Expand All @@ -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' .
Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -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 = [];

Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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, '/' );
}
}
10 changes: 8 additions & 2 deletions .tests/php/integration/CF7/AdminTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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' );
}

Expand All @@ -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,
Expand Down Expand Up @@ -185,7 +192,6 @@ public function test_toplevel_page_wpcf7() {
<br class="clear" />
</div><!-- #poststuff -->
</div><!-- .wrap -->
HTML;

Expand Down
6 changes: 6 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
4 changes: 2 additions & 2 deletions hcaptcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -39,7 +39,7 @@
/**
* Plugin version.
*/
const HCAPTCHA_VERSION = '4.3.0';
const HCAPTCHA_VERSION = '4.3.1';

/**
* Path to the plugin dir.
Expand Down
2 changes: 0 additions & 2 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
<exclude-pattern>*/\.wordpress-org/*</exclude-pattern>
<exclude-pattern>*/\.yarn/*</exclude-pattern>
<exclude-pattern>*/assets/*</exclude-pattern>
<exclude-pattern>*/bin/*</exclude-pattern>
<exclude-pattern>*/coverage/*</exclude-pattern>
<exclude-pattern>*/languages/*</exclude-pattern>
<exclude-pattern>*/node_modules/*</exclude-pattern>
Expand All @@ -22,7 +21,6 @@
<arg value="sp"/><!-- Show sniff and progress -->
<arg name="basepath" value="./"/><!-- Strip the file paths down to the relevant bit -->
<arg name="extensions" value="php"/>
<arg name="cache" value=".phpcs.cache"/>

<config name="installed_paths" value="vendor/phpcompatibility/php-compatibility,vendor/phpcompatibility/phpcompatibility-paragonie,vendor/phpcompatibility/phpcompatibility-wp,vendor/phpcsstandards/phpcsextra,vendor/phpcsstandards/phpcsutils,vendor/wp-coding-standards/wpcs"/>
<config name="testVersion" value="7.2-"/>
Expand Down
10 changes: 8 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ Tags: captcha, hcaptcha, antispam, abuse, protect form
Requires at least: 5.3
Tested up to: 6.6
Requires PHP: 7.2
Stable tag: 4.3.0
Stable tag: 4.3.1
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Enables hCaptcha integration with WordPress and popular plugins.

Expand Down Expand Up @@ -561,6 +561,12 @@ Instructions for popular native integrations are below:

== Changelog ==

= 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.
Expand Down
Loading

0 comments on commit 79902b1

Please sign in to comment.