diff --git a/.tests/php/integration/CF7/AdminTest.php b/.tests/php/integration/CF7/AdminTest.php index af5e5102..d2fd9820 100644 --- a/.tests/php/integration/CF7/AdminTest.php +++ b/.tests/php/integration/CF7/AdminTest.php @@ -15,7 +15,6 @@ use HCaptcha\CF7\Admin; use HCaptcha\Tests\Integration\HCaptchaPluginWPTestCase; -use Mockery; use WPCF7_TagGenerator; /** @@ -503,16 +502,16 @@ public function test_enqueue_admin_scripts(): void { wpcf7_admin_enqueue_scripts( 'wpcf7' ); - $data = $wp_scripts->registered['wpcf7-admin']->extra['data']; - preg_match( '/var wpcf7 = ({.+});/', $data, $m ); + $data = $wp_scripts->registered['wpcf7-admin']->extra['before'][1]; + preg_match( '/var wpcf7 = ({.+});/s', $data, $m ); $wpcf7 = json_decode( $m[1], true ); self::assertArrayNotHasKey( 'api', $wpcf7 ); $subject->enqueue_admin_scripts_after_cf7(); - $data = $wp_scripts->registered['wpcf7-admin']->extra['data']; - preg_match( '/var wpcf7 = ({.+});/', $data, $m ); + $data = $wp_scripts->registered['wpcf7-admin']->extra['before'][1]; + preg_match( '/var wpcf7 = ({.+});/s', $data, $m ); $wpcf7 = json_decode( $m[1], true ); self::assertArrayHasKey( 'api', $wpcf7 ); diff --git a/src/php/CF7/Admin.php b/src/php/CF7/Admin.php index d2285def..db94151b 100644 --- a/src/php/CF7/Admin.php +++ b/src/php/CF7/Admin.php @@ -287,12 +287,12 @@ public function enqueue_admin_scripts_after_cf7(): void { ], ]; - $data = $wp_scripts->registered['wpcf7-admin']->extra['data']; + $data = $wp_scripts->registered['wpcf7-admin']->extra['before'][1]; - if ( preg_match( '/var wpcf7 = ({.+});/', $data, $m ) ) { + if ( preg_match( '/var wpcf7 = ({.+});/s', $data, $m ) ) { $wpcf7 = array_merge( $wpcf7, json_decode( $m[1], true ) ); - $wp_scripts->registered['wpcf7-admin']->extra['data'] = 'var wpcf7 = ' . wp_json_encode( $wpcf7 ) . ';'; + $wp_scripts->registered['wpcf7-admin']->extra['before'][1] = 'var wpcf7 = ' . wp_json_encode( $wpcf7 ) . ';'; } } }