Skip to content

Commit 80ea3fd

Browse files
vianaswclaudeenejb
authored
Forms: Enable Central Forms Management by default for all sites (#47826)
* Forms: Enable Central Forms Management by default for all sites Flip the jetpack_forms_alpha filter default from false to true and add the central-form-management editor feature flag from within the Forms package. This makes CFM available to all sites including self-hosted Jetpack installations, without requiring a feature flag. The wpcom flags file is updated to explicitly disable CFM for excluded sites (e2e test, disable sticker) rather than enabling for included ones, preserving the opt-out mechanism. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Fix forms e2e test: use explicit inner blocks to avoid synced form creation With CFM enabled by default, clicking the variation picker creates a synced form whose title comes from the variation (not the block's formTitle attribute). The test then fails looking for a form with the original title. Provide explicit innerBlocks when inserting the form block, matching the pattern already used by the second test. This keeps the form inline and preserves the formTitle attribute. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Add changelog for Jetpack plugin e2e test update Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Lets not introduce a new public method to enable the 'enable_central_form_management_flag' flag. --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Co-authored-by: Enej Bajgoric <enej.bajgoric@automattic.com>
1 parent feea51d commit 80ea3fd

9 files changed

Lines changed: 92 additions & 22 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: minor
2+
Type: changed
3+
4+
Enable Central Forms Management (wp-build dashboard and synced forms) by default for all sites, including self-hosted Jetpack installations.

projects/packages/forms/src/blocks/contact-form/class-contact-form-block.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ public static function register_feature( $features ) {
102102
$features['multistep-form'] = Current_Plan::supports( 'multistep-form' );
103103
$features['form-webhooks'] = Current_Plan::supports( 'form-webhooks' );
104104

105+
if ( ! isset( $features['central-form-management'] ) ) {
106+
$features['central-form-management'] = true;
107+
}
108+
105109
return $features;
106110
}
107111

projects/packages/forms/src/contact-form/class-contact-form-plugin.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,6 @@ public static function has_editor_feature_flag( $flag ) {
413413
$feature_flags = apply_filters( 'jetpack_block_editor_feature_flags', array() );
414414
return ! empty( $feature_flags[ $flag ] );
415415
}
416-
417416
/**
418417
* Remove feedback post type from the allowed post types for related posts.
419418
*
@@ -1566,7 +1565,8 @@ public function unread_count() {
15661565

15671566
// Jetpack submenu entries
15681567
foreach ( $submenu['jetpack'] as $index => $menu_item ) {
1569-
$admin_slug = apply_filters( 'jetpack_forms_alpha', false ) ? Dashboard::FORMS_WPBUILD_ADMIN_SLUG : Dashboard::ADMIN_SLUG;
1568+
/** This filter is documented in class-dashboard.php::init */
1569+
$admin_slug = apply_filters( 'jetpack_forms_alpha', true ) ? Dashboard::FORMS_WPBUILD_ADMIN_SLUG : Dashboard::ADMIN_SLUG;
15701570
if ( $admin_slug === $menu_item[2] ) {
15711571
// phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
15721572
$submenu['jetpack'][ $index ][0] .= $forms_unread_count_tag;

projects/packages/forms/src/dashboard/class-dashboard.php

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,17 @@ public function init() {
170170
add_action( 'admin_menu', array( $this, 'add_admin_submenu' ), self::MENU_PRIORITY );
171171
add_action( 'admin_menu', array( __CLASS__, 'redirect_dashboard_url_cross_variant' ), 1 );
172172

173-
// Flag to enable the wp-build-based dashboard.
174-
$is_wp_build_enabled = apply_filters( 'jetpack_forms_alpha', false );
173+
/**
174+
* Filter to enable or disable the wp-build-based Forms dashboard.
175+
*
176+
* Enabled by default since Central Forms Management is now available for all sites.
177+
* Can be disabled by returning false from this filter.
178+
*
179+
* @since $$next-version$$
180+
*
181+
* @param bool $enabled Whether the wp-build dashboard is enabled. Default true.
182+
*/
183+
$is_wp_build_enabled = apply_filters( 'jetpack_forms_alpha', true );
175184

176185
if ( $is_wp_build_enabled ) {
177186
self::load_wp_build();
@@ -200,7 +209,8 @@ public static function redirect_dashboard_url_cross_variant() {
200209
return;
201210
}
202211

203-
$is_wp_build_enabled = apply_filters( 'jetpack_forms_alpha', false );
212+
/** This filter is documented in class-dashboard.php::init */
213+
$is_wp_build_enabled = apply_filters( 'jetpack_forms_alpha', true );
204214

205215
// Legacy URL requested but wp-build is now active → redirect to wp-build.
206216
if ( $page === self::ADMIN_SLUG && $is_wp_build_enabled ) {
@@ -368,7 +378,8 @@ public function load_admin_scripts() {
368378
*/
369379
public function add_admin_submenu() {
370380

371-
if ( apply_filters( 'jetpack_forms_alpha', false ) ) {
381+
/** This filter is documented in class-dashboard.php::init */
382+
if ( apply_filters( 'jetpack_forms_alpha', true ) ) {
372383

373384
// `jetpack_forms_jetpack_forms_responses_wp_admin_render_page` is the callback generated by WP build script.
374385
$callback = function_exists( 'jetpack_forms_jetpack_forms_responses_wp_admin_render_page' )
@@ -553,7 +564,8 @@ public static function mark_classic_form_detected() {
553564
* @return string
554565
*/
555566
public static function get_forms_admin_url( $tab = null, $post_id = null ) {
556-
$is_wp_build_enabled = apply_filters( 'jetpack_forms_alpha', false );
567+
/** This filter is documented in class-dashboard.php::init */
568+
$is_wp_build_enabled = apply_filters( 'jetpack_forms_alpha', true );
557569
$url = admin_url( 'admin.php' );
558570

559571
$url .= $is_wp_build_enabled

projects/packages/forms/tests/php/dashboard/Dashboard_Test.php

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,21 @@ public function tear_down() {
2929
}
3030

3131
/**
32-
* Test get_forms_admin_url without tab parameter
32+
* Test get_forms_admin_url without tab parameter (legacy dashboard)
3333
*/
3434
public function test_get_forms_admin_url_without_tab() {
35+
add_filter( 'jetpack_forms_alpha', '__return_false' );
3536
$expected = get_admin_url() . 'admin.php?page=jetpack-forms-admin';
3637
$this->assertEquals( $expected, Dashboard::get_forms_admin_url() );
38+
remove_filter( 'jetpack_forms_alpha', '__return_false' );
3739
}
3840

3941
/**
40-
* Test get_forms_admin_url with valid tab parameter
42+
* Test get_forms_admin_url with valid tab parameter (legacy dashboard)
4143
*/
4244
public function test_get_forms_admin_url_with_valid_tab() {
45+
add_filter( 'jetpack_forms_alpha', '__return_false' );
46+
4347
$expected = get_admin_url() . 'admin.php?page=jetpack-forms-admin#/responses?status=inbox';
4448
$this->assertEquals( $expected, Dashboard::get_forms_admin_url( 'inbox' ) );
4549

@@ -48,29 +52,37 @@ public function test_get_forms_admin_url_with_valid_tab() {
4852

4953
$expected = get_admin_url() . 'admin.php?page=jetpack-forms-admin#/responses?status=trash';
5054
$this->assertEquals( $expected, Dashboard::get_forms_admin_url( 'trash' ) );
55+
56+
remove_filter( 'jetpack_forms_alpha', '__return_false' );
5157
}
5258

5359
/**
54-
* Test get_forms_admin_url with invalid tab parameter
60+
* Test get_forms_admin_url with invalid tab parameter (legacy dashboard)
5561
*/
5662
public function test_get_forms_admin_url_with_invalid_tab() {
63+
add_filter( 'jetpack_forms_alpha', '__return_false' );
5764
$expected = get_admin_url() . 'admin.php?page=jetpack-forms-admin';
5865
$this->assertEquals( $expected, Dashboard::get_forms_admin_url( 'invalid' ) );
66+
remove_filter( 'jetpack_forms_alpha', '__return_false' );
5967
}
6068

6169
/**
62-
* Test get_forms_admin_url with forms tab parameter
70+
* Test get_forms_admin_url with forms tab parameter (legacy dashboard)
6371
*/
6472
public function test_get_forms_admin_url_with_forms_tab() {
73+
add_filter( 'jetpack_forms_alpha', '__return_false' );
6574
$expected = get_admin_url() . 'admin.php?page=jetpack-forms-admin#/forms';
6675
$this->assertEquals( $expected, Dashboard::get_forms_admin_url( 'forms' ) );
76+
remove_filter( 'jetpack_forms_alpha', '__return_false' );
6777
}
6878

6979
/**
7080
* Test get_forms_admin_url with post_id parameter (legacy mode).
7181
* Verifies the r parameter is correctly appended in the hash fragment.
7282
*/
7383
public function test_get_forms_admin_url_with_post_id_legacy() {
84+
add_filter( 'jetpack_forms_alpha', '__return_false' );
85+
7486
// Tab + post_id: appends r and status in hash fragment (client-side handles redirect).
7587
$expected = get_admin_url() . 'admin.php?page=jetpack-forms-admin#/responses?status=inbox&r=123';
7688
$this->assertEquals( $expected, Dashboard::get_forms_admin_url( 'inbox', 123 ) );
@@ -81,6 +93,8 @@ public function test_get_forms_admin_url_with_post_id_legacy() {
8193
// post_id only (no tab): appends r and status=inbox in hash fragment.
8294
$expected = get_admin_url() . 'admin.php?page=jetpack-forms-admin#/responses?status=inbox&r=789';
8395
$this->assertEquals( $expected, Dashboard::get_forms_admin_url( null, 789 ) );
96+
97+
remove_filter( 'jetpack_forms_alpha', '__return_false' );
8498
}
8599

86100
/**
@@ -242,9 +256,11 @@ public function test_is_notes_enabled_with_filter() {
242256
}
243257

244258
/**
245-
* Test get_forms_admin_url with screen ID equivalents (edit-jetpack_form -> forms, edit-feedback -> base/inbox).
259+
* Test get_forms_admin_url with screen ID equivalents (legacy dashboard).
246260
*/
247261
public function test_get_forms_admin_url_with_screen_id_equivalents() {
262+
add_filter( 'jetpack_forms_alpha', '__return_false' );
263+
248264
$url_form = Dashboard::get_forms_admin_url( 'forms' );
249265
$this->assertStringContainsString( 'admin.php?page=' . Dashboard::ADMIN_SLUG, $url_form );
250266
$this->assertStringContainsString( '#/forms', $url_form );
@@ -253,18 +269,24 @@ public function test_get_forms_admin_url_with_screen_id_equivalents() {
253269
$url_feedback = Dashboard::get_forms_admin_url();
254270
$expected = get_admin_url() . 'admin.php?page=' . Dashboard::ADMIN_SLUG;
255271
$this->assertEquals( $expected, $url_feedback );
272+
273+
remove_filter( 'jetpack_forms_alpha', '__return_false' );
256274
}
257275

258276
/**
259-
* Test get_forms_admin_url with invalid tab returns base URL.
277+
* Test get_forms_admin_url with invalid tab returns base URL (legacy dashboard).
260278
*/
261279
public function test_get_forms_admin_url_with_invalid_tab_returns_base_url() {
280+
add_filter( 'jetpack_forms_alpha', '__return_false' );
281+
262282
$url = Dashboard::get_forms_admin_url( 'invalid-screen' );
263283
$this->assertStringContainsString( 'admin.php?page=' . Dashboard::ADMIN_SLUG, $url );
264284
$this->assertStringNotContainsString( '#/', $url );
265285

266286
$url = Dashboard::get_forms_admin_url( '' );
267287
$this->assertStringContainsString( 'admin.php?page=' . Dashboard::ADMIN_SLUG, $url );
288+
289+
remove_filter( 'jetpack_forms_alpha', '__return_false' );
268290
}
269291

270292
/**
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: changed
3+
4+
Adapt WordPress.com CFM flags to explicitly disable for excluded sites now that CFM is enabled by default in the Forms package.

projects/packages/jetpack-mu-wpcom/src/features/wpcom-contact-form-flags/wpcom-contact-form-flags.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,23 @@ function wpcom_is_central_forms_management_enabled( $blog_id = null ) {
5555
}
5656

5757
/**
58-
* Enable the Central Forms Management alpha features when the rollout
59-
* criteria are met. Called immediately on file load since this file is
60-
* required during plugins_loaded (priority 10) inside load_wpcom_sites_features(),
61-
* which is after the priority 1 that the wpcom mu-plugin uses.
58+
* Disable Central Forms Management for excluded WordPress.com sites.
59+
*
60+
* CFM is now enabled by default in the Forms package. This function
61+
* explicitly disables it for sites that should be excluded (e2e test
62+
* sites, sites with the disable-central-forms-management sticker).
63+
*
64+
* Called immediately on file load since this file is required during
65+
* plugins_loaded (priority 10) inside load_wpcom_sites_features().
6266
*/
63-
function wpcom_maybe_enable_central_forms_management() {
64-
if ( ! wpcom_is_central_forms_management_enabled() ) {
67+
function wpcom_maybe_disable_central_forms_management() {
68+
if ( wpcom_is_central_forms_management_enabled() ) {
6569
return;
6670
}
6771

68-
add_filter( 'jetpack_forms_alpha', '__return_true', 999 );
72+
add_filter( 'jetpack_forms_alpha', '__return_false', 999 );
6973
}
70-
wpcom_maybe_enable_central_forms_management();
74+
wpcom_maybe_disable_central_forms_management();
7175

7276
/**
7377
* Set the 'central-form-management' block editor feature flag.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: other
3+
4+
Update Forms e2e test to use explicit inner blocks for compatibility with Central Forms Management.

projects/plugins/jetpack/tests/e2e/specs/forms/submission.test.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,25 @@ test.describe( 'Forms: Submission', () => {
5454
await editor.insertBlock( {
5555
name: 'jetpack/contact-form',
5656
attributes: { formTitle },
57+
innerBlocks: [
58+
{
59+
name: 'jetpack/field-name',
60+
attributes: { required: true },
61+
},
62+
{
63+
name: 'jetpack/field-email',
64+
attributes: { required: true },
65+
},
66+
{
67+
name: 'jetpack/field-textarea',
68+
},
69+
{
70+
name: 'jetpack/button',
71+
attributes: { element: 'button', text: 'Contact Us' },
72+
},
73+
],
5774
} );
5875
const formBlock = editor.canvas.getByRole( 'document', { name: 'Block: Form' } );
59-
await formBlock.getByRole( 'button', { name: 'Add a contact form to your page.' } ).click();
6076

6177
await expect( formBlock ).toBeVisible();
6278
} );

0 commit comments

Comments
 (0)