Commit 2b5320a811a for woocommerce
commit 2b5320a811a489a332a3b45425af3e4ee073e6de
Author: Daniel Mallory <daniel.mallory@automattic.com>
Date: Thu Nov 26 14:38:17 2026 +0000
Register the settings screen's fields on the server (#70777)
* fix(settings): Register the admin screens' script modules when the build loads late
The admin screens build registers its script modules on `wp_default_scripts`. That action usually fires before `init`, when the build loads, so the modules were never registered and couldn't be imported by id.
Register them straight after loading the build when the action has already run.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(settings): Register the settings screen's fields on the server
Gutenberg 24.3 made the JavaScript `registerEntityField` a no-op, and WordPress 7.2 reads entity fields from the server instead. The settings screen registered the cheque fields in JavaScript, so it crashed or showed an empty form.
- Move the cheque fields to a field collection in `admin-screens/packages/entity-fields`, with a `field.php` per field. wp-build copies the collection into the build, and `ChequeSettings` registers it with `wp_register_entity_field_collection()`.
- Keep the instructions' value handling in the collection's script module, `@woocommerce/entity-fields/cheque`.
- Wait for the editor to load the fields before showing the form, and show the error if it can't.
- Only offer the screen when the Entity fields API exists, from WordPress 7.2 or Gutenberg 24.3.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* refactor(settings): Move the settings record types to the settings route
`SettingsRecord` and `SettingsField` are only used by the settings screen, so they belong with it rather than in the entity fields package.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* fix(settings): Stop the settings screen crashing before its record loads
The settings record is `false` until it loads, but the form validated it with the fields straight away. When the fields loaded first, or the record request failed, the instructions field read `false.settings` and the screen went blank instead of showing the form or the load error.
Validate without fields until the record is there.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Refactor admin screens integration: remove unused AdminScreens dependency and streamline loading process
* Merge branch 'trunk' of https://github.com/woocommerce/woocommerce into fix/settings-screen-server-entity-fields
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Luigi Teschio <gigitux@gmail.com>
diff --git a/plugins/woocommerce/admin-screens/.gitignore b/plugins/woocommerce/admin-screens/.gitignore
index 8e2715c9a0d..5d85719a82d 100644
--- a/plugins/woocommerce/admin-screens/.gitignore
+++ b/plugins/woocommerce/admin-screens/.gitignore
@@ -1,2 +1,7 @@
# wp-build output, a symlink to ../assets/client/routes
/build
+
+# Transpiled wp-build packages
+/packages/*/build
+/packages/*/build-module
+/packages/*/build-types
diff --git a/plugins/woocommerce/admin-screens/README.md b/plugins/woocommerce/admin-screens/README.md
index 765b8a792d1..aea97d6d5ee 100644
--- a/plugins/woocommerce/admin-screens/README.md
+++ b/plugins/woocommerce/admin-screens/README.md
@@ -2,6 +2,8 @@
Experimental admin pages built with wp-build, DataForm and core-data. Each folder in `routes/` is a wp-build route.
+Pages get their fields from the Entity fields API in WordPress 7.2. `packages/entity-fields` holds one field collection per page: a `field.php` per field, which PHP registers, and a script module for the parts PHP can't describe.
+
```sh
pnpm --filter=@woocommerce/plugin-woocommerce build:project:admin-screens
pnpm --filter=@woocommerce/plugin-woocommerce watch:build:project:admin-screens
diff --git a/plugins/woocommerce/admin-screens/entity-fields/cheque/description/field.ts b/plugins/woocommerce/admin-screens/entity-fields/cheque/description/field.ts
deleted file mode 100644
index d210c78549c..00000000000
--- a/plugins/woocommerce/admin-screens/entity-fields/cheque/description/field.ts
+++ /dev/null
@@ -1,21 +0,0 @@
-/**
- * External dependencies
- */
-import { __ } from '@wordpress/i18n';
-
-/**
- * Internal dependencies
- */
-import type { Field } from '@wordpress/dataviews';
-import type { ChequeSettings } from '../types';
-
-export const field: Field< ChequeSettings > = {
- id: 'description',
- type: 'text',
- Edit: 'textarea',
- label: __( 'Description', 'woocommerce' ),
- description: __(
- 'Payment method description that the customer will see during checkout.',
- 'woocommerce'
- ),
-};
diff --git a/plugins/woocommerce/admin-screens/entity-fields/cheque/enabled/field.ts b/plugins/woocommerce/admin-screens/entity-fields/cheque/enabled/field.ts
deleted file mode 100644
index b94d69c9004..00000000000
--- a/plugins/woocommerce/admin-screens/entity-fields/cheque/enabled/field.ts
+++ /dev/null
@@ -1,17 +0,0 @@
-/**
- * External dependencies
- */
-import { __ } from '@wordpress/i18n';
-
-/**
- * Internal dependencies
- */
-import type { Field } from '@wordpress/dataviews';
-import type { ChequeSettings } from '../types';
-
-export const field: Field< ChequeSettings > = {
- id: 'enabled',
- type: 'boolean',
- Edit: 'toggle',
- label: __( 'Enable check payments', 'woocommerce' ),
-};
diff --git a/plugins/woocommerce/admin-screens/entity-fields/cheque/index.ts b/plugins/woocommerce/admin-screens/entity-fields/cheque/index.ts
deleted file mode 100644
index c6b266fd720..00000000000
--- a/plugins/woocommerce/admin-screens/entity-fields/cheque/index.ts
+++ /dev/null
@@ -1,22 +0,0 @@
-/**
- * Fields of the cheque settings page, in the order the form shows them.
- */
-
-/**
- * Internal dependencies
- */
-import type { Field } from '@wordpress/dataviews';
-import type { ChequeSettings } from './types';
-import { field as enabled } from './enabled/field';
-import { field as title } from './title/field';
-import { field as description } from './description/field';
-import { field as instructions } from './instructions/field';
-
-const fields: Field< ChequeSettings >[] = [
- enabled,
- title,
- description,
- instructions,
-];
-
-export default fields;
diff --git a/plugins/woocommerce/admin-screens/entity-fields/cheque/instructions/field.ts b/plugins/woocommerce/admin-screens/entity-fields/cheque/instructions/field.ts
deleted file mode 100644
index cad24737d05..00000000000
--- a/plugins/woocommerce/admin-screens/entity-fields/cheque/instructions/field.ts
+++ /dev/null
@@ -1,28 +0,0 @@
-/**
- * External dependencies
- */
-import { __ } from '@wordpress/i18n';
-
-/**
- * Internal dependencies
- */
-import type { Field } from '@wordpress/dataviews';
-import type { ChequeSettings } from '../types';
-
-export const field: Field< ChequeSettings > = {
- id: 'instructions',
- type: 'text',
- Edit: 'textarea',
- label: __( 'Instructions', 'woocommerce' ),
- description: __(
- 'Instructions that will be added to the thank you page and emails.',
- 'woocommerce'
- ),
- getValue: ( { item } ) => {
- const setting = item.settings.instructions;
- return typeof setting === 'string' ? setting : ( setting?.value ?? '' );
- },
- setValue: ( { value } ) => ( {
- settings: { instructions: String( value ) },
- } ),
-};
diff --git a/plugins/woocommerce/admin-screens/entity-fields/cheque/title/field.ts b/plugins/woocommerce/admin-screens/entity-fields/cheque/title/field.ts
deleted file mode 100644
index 0683167ef34..00000000000
--- a/plugins/woocommerce/admin-screens/entity-fields/cheque/title/field.ts
+++ /dev/null
@@ -1,20 +0,0 @@
-/**
- * External dependencies
- */
-import { __ } from '@wordpress/i18n';
-
-/**
- * Internal dependencies
- */
-import type { Field } from '@wordpress/dataviews';
-import type { ChequeSettings } from '../types';
-
-export const field: Field< ChequeSettings > = {
- id: 'title',
- type: 'text',
- label: __( 'Title', 'woocommerce' ),
- description: __(
- 'Payment method name that the customer will see during checkout.',
- 'woocommerce'
- ),
-};
diff --git a/plugins/woocommerce/admin-screens/eslint.config.mjs b/plugins/woocommerce/admin-screens/eslint.config.mjs
index 2138940d708..301887a7020 100644
--- a/plugins/woocommerce/admin-screens/eslint.config.mjs
+++ b/plugins/woocommerce/admin-screens/eslint.config.mjs
@@ -31,6 +31,14 @@ const rulesOf = ( configs ) =>
Object.assign( {}, ...configs.map( ( config ) => config.rules ?? {} ) );
export default [
+ {
+ // wp-build transpiles each package into these folders.
+ ignores: [
+ 'packages/*/build/',
+ 'packages/*/build-module/',
+ 'packages/*/build-types/',
+ ],
+ },
...woocommerce.map( escalateWarnings ),
{
files: [ '**/*.ts', '**/*.tsx' ],
diff --git a/plugins/woocommerce/admin-screens/packages/entity-fields/package.json b/plugins/woocommerce/admin-screens/packages/entity-fields/package.json
new file mode 100644
index 00000000000..435c170b70a
--- /dev/null
+++ b/plugins/woocommerce/admin-screens/packages/entity-fields/package.json
@@ -0,0 +1,14 @@
+{
+ "name": "@woocommerce/entity-fields",
+ "private": true,
+ "description": "Fields of the experimental settings screens, registered on the server with the Entity fields API.",
+ "module": "build-module/cheque/index.mjs",
+ "wpScriptModuleExports": {
+ "./cheque": "./build-module/cheque/index.mjs"
+ },
+ "wpCopyFiles": {
+ "files": [
+ "src/**/*.php"
+ ]
+ }
+}
diff --git a/plugins/woocommerce/admin-screens/packages/entity-fields/src/cheque/description/field.php b/plugins/woocommerce/admin-screens/packages/entity-fields/src/cheque/description/field.php
new file mode 100644
index 00000000000..d6958bb79c1
--- /dev/null
+++ b/plugins/woocommerce/admin-screens/packages/entity-fields/src/cheque/description/field.php
@@ -0,0 +1,17 @@
+<?php
+/**
+ * The payment method description shown at checkout.
+ *
+ * @package WooCommerce\Admin
+ */
+
+declare( strict_types = 1 );
+
+defined( 'ABSPATH' ) || exit;
+
+return array(
+ 'type' => 'text',
+ 'Edit' => 'textarea',
+ 'label' => __( 'Description', 'woocommerce' ),
+ 'description' => __( 'Payment method description that the customer will see during checkout.', 'woocommerce' ),
+);
diff --git a/plugins/woocommerce/admin-screens/packages/entity-fields/src/cheque/enabled/field.php b/plugins/woocommerce/admin-screens/packages/entity-fields/src/cheque/enabled/field.php
new file mode 100644
index 00000000000..33d6298b231
--- /dev/null
+++ b/plugins/woocommerce/admin-screens/packages/entity-fields/src/cheque/enabled/field.php
@@ -0,0 +1,16 @@
+<?php
+/**
+ * Whether check payments are enabled.
+ *
+ * @package WooCommerce\Admin
+ */
+
+declare( strict_types = 1 );
+
+defined( 'ABSPATH' ) || exit;
+
+return array(
+ 'type' => 'boolean',
+ 'Edit' => 'toggle',
+ 'label' => __( 'Enable check payments', 'woocommerce' ),
+);
diff --git a/plugins/woocommerce/admin-screens/packages/entity-fields/src/cheque/index.php b/plugins/woocommerce/admin-screens/packages/entity-fields/src/cheque/index.php
new file mode 100644
index 00000000000..d014b4579c2
--- /dev/null
+++ b/plugins/woocommerce/admin-screens/packages/entity-fields/src/cheque/index.php
@@ -0,0 +1,20 @@
+<?php
+/**
+ * The `cheque` collection: the fields of the cheque settings page.
+ *
+ * Each field folder's `field.php` holds its data. `instructions/field.ts` adds what PHP can't
+ * describe, through the `@woocommerce/entity-fields/cheque` script module.
+ *
+ * @package WooCommerce\Admin
+ */
+
+declare( strict_types = 1 );
+
+defined( 'ABSPATH' ) || exit;
+
+return array(
+ 'origin' => 'woocommerce',
+ 'kind' => 'woo_settings_payments',
+ 'name' => 'cheque',
+ 'module' => '@woocommerce/entity-fields/cheque',
+);
diff --git a/plugins/woocommerce/admin-screens/packages/entity-fields/src/cheque/index.ts b/plugins/woocommerce/admin-screens/packages/entity-fields/src/cheque/index.ts
new file mode 100644
index 00000000000..2f0fcce6c1a
--- /dev/null
+++ b/plugins/woocommerce/admin-screens/packages/entity-fields/src/cheque/index.ts
@@ -0,0 +1,18 @@
+/**
+ * Script module of the `cheque` collection: `@woocommerce/entity-fields/cheque`.
+ *
+ * The fields' data is in their `field.php` files. This module adds the parts PHP can't describe.
+ */
+
+/**
+ * Internal dependencies
+ */
+import type { FieldsScriptParts } from '../types';
+import type { ChequeSettings } from './types';
+import { fieldExtensions as instructions } from './instructions/field';
+
+const fields: FieldsScriptParts< ChequeSettings > = {
+ instructions,
+};
+
+export default fields;
diff --git a/plugins/woocommerce/admin-screens/packages/entity-fields/src/cheque/instructions/field.php b/plugins/woocommerce/admin-screens/packages/entity-fields/src/cheque/instructions/field.php
new file mode 100644
index 00000000000..0b87b92aff1
--- /dev/null
+++ b/plugins/woocommerce/admin-screens/packages/entity-fields/src/cheque/instructions/field.php
@@ -0,0 +1,18 @@
+<?php
+/**
+ * The instructions added to the thank you page and emails. Its value is read and written in
+ * `field.ts`, next to this file.
+ *
+ * @package WooCommerce\Admin
+ */
+
+declare( strict_types = 1 );
+
+defined( 'ABSPATH' ) || exit;
+
+return array(
+ 'type' => 'text',
+ 'Edit' => 'textarea',
+ 'label' => __( 'Instructions', 'woocommerce' ),
+ 'description' => __( 'Instructions that will be added to the thank you page and emails.', 'woocommerce' ),
+);
diff --git a/plugins/woocommerce/admin-screens/packages/entity-fields/src/cheque/instructions/field.ts b/plugins/woocommerce/admin-screens/packages/entity-fields/src/cheque/instructions/field.ts
new file mode 100644
index 00000000000..b3a2303f224
--- /dev/null
+++ b/plugins/woocommerce/admin-screens/packages/entity-fields/src/cheque/instructions/field.ts
@@ -0,0 +1,15 @@
+/**
+ * Internal dependencies
+ */
+import type { FieldsScriptParts } from '../../types';
+import type { ChequeSettings } from '../types';
+
+export const fieldExtensions: FieldsScriptParts< ChequeSettings >[ string ] = {
+ getValue: ( { item } ) => {
+ const setting = item.settings.instructions;
+ return typeof setting === 'string' ? setting : ( setting?.value ?? '' );
+ },
+ setValue: ( { value } ) => ( {
+ settings: { instructions: String( value ) },
+ } ),
+};
diff --git a/plugins/woocommerce/admin-screens/packages/entity-fields/src/cheque/title/field.php b/plugins/woocommerce/admin-screens/packages/entity-fields/src/cheque/title/field.php
new file mode 100644
index 00000000000..025dbe86bed
--- /dev/null
+++ b/plugins/woocommerce/admin-screens/packages/entity-fields/src/cheque/title/field.php
@@ -0,0 +1,16 @@
+<?php
+/**
+ * The payment method name shown at checkout.
+ *
+ * @package WooCommerce\Admin
+ */
+
+declare( strict_types = 1 );
+
+defined( 'ABSPATH' ) || exit;
+
+return array(
+ 'type' => 'text',
+ 'label' => __( 'Title', 'woocommerce' ),
+ 'description' => __( 'Payment method name that the customer will see during checkout.', 'woocommerce' ),
+);
diff --git a/plugins/woocommerce/admin-screens/entity-fields/cheque/types.ts b/plugins/woocommerce/admin-screens/packages/entity-fields/src/cheque/types.ts
similarity index 100%
rename from plugins/woocommerce/admin-screens/entity-fields/cheque/types.ts
rename to plugins/woocommerce/admin-screens/packages/entity-fields/src/cheque/types.ts
diff --git a/plugins/woocommerce/admin-screens/packages/entity-fields/src/types.ts b/plugins/woocommerce/admin-screens/packages/entity-fields/src/types.ts
new file mode 100644
index 00000000000..e29d442fc2d
--- /dev/null
+++ b/plugins/woocommerce/admin-screens/packages/entity-fields/src/types.ts
@@ -0,0 +1,13 @@
+/**
+ * External dependencies
+ */
+import type { Field } from '@wordpress/dataviews';
+
+/**
+ * The JavaScript parts of a collection's fields, keyed by field id. It is the shape of a field
+ * collection's script module default export, which the editor merges into the server's fields.
+ */
+export type FieldsScriptParts< Item > = Record<
+ string,
+ Partial< Omit< Field< Item >, 'id' > >
+>;
diff --git a/plugins/woocommerce/admin-screens/routes/settings/entities.ts b/plugins/woocommerce/admin-screens/routes/settings/entities.ts
index 52646632a09..1e93df8a819 100644
--- a/plugins/woocommerce/admin-screens/routes/settings/entities.ts
+++ b/plugins/woocommerce/admin-screens/routes/settings/entities.ts
@@ -7,7 +7,7 @@ export const ENTITY_KIND = 'woo_settings_payments';
/**
* A core-data entity config for a settings page. The page's URL segment is the entity name and
- * its record ID, and its fields are registered separately in `entity-fields/`.
+ * its record ID, and its fields are registered on the server from `packages/entity-fields/`.
*/
export interface SettingsEntityConfig {
kind: string;
diff --git a/plugins/woocommerce/admin-screens/routes/settings/entity-fields.ts b/plugins/woocommerce/admin-screens/routes/settings/entity-fields.ts
index fa14da9a4da..0cd3e34ee23 100644
--- a/plugins/woocommerce/admin-screens/routes/settings/entity-fields.ts
+++ b/plugins/woocommerce/admin-screens/routes/settings/entity-fields.ts
@@ -1,15 +1,12 @@
/**
* External dependencies
*/
-import { dispatch } from '@wordpress/data';
-import { store as editorStore } from '@wordpress/editor';
-import type { Field } from '@wordpress/dataviews';
import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis';
/**
* Internal dependencies
*/
-import type { SettingsField } from '../../entity-fields/types';
+import type { SettingsField } from './types';
// The editor's field registry is private. This logic will be replaced once the Field Collection API is available.
const { unlock } = __dangerousOptInToUnstableAPIsOnlyForCoreModules(
@@ -17,36 +14,15 @@ const { unlock } = __dangerousOptInToUnstableAPIsOnlyForCoreModules(
'@wordpress/routes'
);
-interface EntityFieldActions {
- registerEntityField: < Item >(
- kind: string,
- name: string,
- field: Field< Item >
- ) => void;
-}
-
interface EntityFieldSelectors {
getEntityFields: ( kind: string, name: string ) => SettingsField[];
+ hasFinishedResolution: ( selector: string, args: unknown[] ) => boolean;
+ getResolutionError: ( selector: string, args: unknown[] ) => unknown;
}
/**
- * Add fields to an entity in the editor's field registry.
- */
-export function registerEntityFields< Item >(
- kind: string,
- name: string,
- fields: Field< Item >[]
-): void {
- const { registerEntityField } = unlock< EntityFieldActions >(
- dispatch( editorStore )
- );
- fields.forEach( ( field ) => {
- registerEntityField( kind, name, field );
- } );
-}
-
-/**
- * Read an entity's fields from the editor store's selectors.
+ * Read an entity's fields from the editor store's selectors. The editor loads them from the
+ * fields registered on the server, with the JavaScript parts of their script modules.
*/
export function getEntityFields(
editorSelectors: unknown,
@@ -58,3 +34,24 @@ export function getEntityFields(
name
);
}
+
+/**
+ * Whether the editor has finished loading an entity's fields, and the error if loading failed.
+ */
+export function getEntityFieldsStatus(
+ editorSelectors: unknown,
+ kind: string,
+ name: string
+): { hasLoaded: boolean; error: unknown } {
+ const selectors = editorSelectors as EntityFieldSelectors;
+ return {
+ hasLoaded: selectors.hasFinishedResolution( 'getEntityFields', [
+ kind,
+ name,
+ ] ),
+ error: selectors.getResolutionError( 'getEntityFields', [
+ kind,
+ name,
+ ] ),
+ };
+}
diff --git a/plugins/woocommerce/admin-screens/routes/settings/route.tsx b/plugins/woocommerce/admin-screens/routes/settings/route.tsx
index 0cf7962c19a..e223c1e2553 100644
--- a/plugins/woocommerce/admin-screens/routes/settings/route.tsx
+++ b/plugins/woocommerce/admin-screens/routes/settings/route.tsx
@@ -8,14 +8,11 @@ import { notFound } from '@wordpress/route';
/**
* Internal dependencies
*/
-import chequeFields from '../../entity-fields/cheque';
import { ENTITY_KIND, getCoreEntities } from './entities';
-import { registerEntityFields } from './entity-fields';
export const route = {
beforeLoad: async ( { params }: { params: { page?: string } } ) => {
await dispatch( coreStore ).addEntities( getCoreEntities() );
- registerEntityFields( ENTITY_KIND, 'cheque', chequeFields );
if (
! params.page ||
! select( coreStore ).getEntityConfig( ENTITY_KIND, params.page )
diff --git a/plugins/woocommerce/admin-screens/routes/settings/stage.tsx b/plugins/woocommerce/admin-screens/routes/settings/stage.tsx
index 891400bf399..4517a92456e 100644
--- a/plugins/woocommerce/admin-screens/routes/settings/stage.tsx
+++ b/plugins/woocommerce/admin-screens/routes/settings/stage.tsx
@@ -19,13 +19,14 @@ import { useState } from 'react';
/**
* Internal dependencies
*/
-import type { SettingsRecord } from '../../entity-fields/types';
import { ENTITY_KIND } from './entities';
import type { SettingsEntityConfig } from './entities';
-import { getEntityFields } from './entity-fields';
+import { getEntityFields, getEntityFieldsStatus } from './entity-fields';
+import type { SettingsField, SettingsRecord } from './types';
import './style.scss';
const EMPTY_FORM: Form = { fields: [] };
+const EMPTY_FIELDS: SettingsField[] = [];
/**
* Use REST error messages without assuming requests reject with Error instances.
@@ -53,25 +54,30 @@ function SettingsForm( { config }: { config: SettingsEntityConfig } ) {
status: 'success' | 'error';
message: string;
} >();
- const { fields, isSaving, loadError } = useSelect(
+ const { fields, hasFields, isSaving, loadError } = useSelect(
( select ) => {
const core = select( coreStore );
+ const editor = select( editorStore );
+ const fieldsStatus = getEntityFieldsStatus( editor, kind, name );
return {
- fields: getEntityFields( select( editorStore ), kind, name ),
+ fields: getEntityFields( editor, kind, name ),
+ hasFields: fieldsStatus.hasLoaded,
isSaving: core.isSavingEntityRecord( kind, name, name ),
- loadError: core.getResolutionError( 'getEntityRecord', [
- kind,
- name,
- name,
- ] ),
+ loadError:
+ core.getResolutionError( 'getEntityRecord', [
+ kind,
+ name,
+ name,
+ ] ) ?? fieldsStatus.error,
};
},
[ kind, name ]
);
- const data = editedRecord as SettingsRecord | undefined;
+ // The record is `false` until it loads. Validate without fields until then, so their getters never read it.
+ const data = ( editedRecord as SettingsRecord | false ) || undefined;
const { validity, isValid } = useFormValidity(
data ?? {},
- fields,
+ data ? fields : EMPTY_FIELDS,
form ?? EMPTY_FORM
);
const saveSettings = async () => {
@@ -96,7 +102,7 @@ function SettingsForm( { config }: { config: SettingsEntityConfig } ) {
}
};
const hasLoadError = !! loadError;
- const isReady = ! hasLoadError && !! data && !! form;
+ const isReady = ! hasLoadError && !! data && !! form && hasFields;
// Breadcrumbs link through the router, which only leaves the screen for an absolute URL.
const paymentsUrl = new URL(
'admin.php?page=wc-settings&tab=checkout',
diff --git a/plugins/woocommerce/admin-screens/entity-fields/types.ts b/plugins/woocommerce/admin-screens/routes/settings/types.ts
similarity index 100%
rename from plugins/woocommerce/admin-screens/entity-fields/types.ts
rename to plugins/woocommerce/admin-screens/routes/settings/types.ts
diff --git a/plugins/woocommerce/changelog/fix-settings-screen-server-entity-fields b/plugins/woocommerce/changelog/fix-settings-screen-server-entity-fields
new file mode 100644
index 00000000000..f331eedec4e
--- /dev/null
+++ b/plugins/woocommerce/changelog/fix-settings-screen-server-entity-fields
@@ -0,0 +1,4 @@
+Significance: patch
+Type: dev
+Comment: Register the experimental settings screen's fields on the server for WordPress 7.2; flag-gated, no merchant change.
+
diff --git a/plugins/woocommerce/includes/class-woocommerce.php b/plugins/woocommerce/includes/class-woocommerce.php
index 341cb5041e0..cc3d96a4186 100644
--- a/plugins/woocommerce/includes/class-woocommerce.php
+++ b/plugins/woocommerce/includes/class-woocommerce.php
@@ -42,7 +42,6 @@ use Automattic\WooCommerce\Internal\Email\EmailLogger;
use Automattic\WooCommerce\Internal\Admin\Marketplace;
use Automattic\WooCommerce\Internal\Admin\MenuIcons;
use Automattic\WooCommerce\Internal\Admin\OrderMilestoneEasterEgg;
-use Automattic\WooCommerce\Internal\Admin\Screens\AdminScreens;
use Automattic\WooCommerce\Internal\Admin\Screens\Settings\ChequeSettings;
use Automattic\WooCommerce\Internal\Admin\Screens\Settings\SettingsScreen;
use Automattic\WooCommerce\Proxies\LegacyProxy;
@@ -424,7 +423,6 @@ final class WooCommerce {
$container->get( OrderMilestoneEasterEgg::class );
$container->get( CustomerEmailVerification::class );
$container->get( OrderLogsCleanupHelper::class );
- $container->get( AdminScreens::class );
$container->get( ChequeSettings::class );
$container->get( SettingsScreen::class );
$container->get( AbilitiesTracking::class );
diff --git a/plugins/woocommerce/src/Internal/Admin/FeaturePlugin.php b/plugins/woocommerce/src/Internal/Admin/FeaturePlugin.php
index 2a487d427b9..68242695354 100644
--- a/plugins/woocommerce/src/Internal/Admin/FeaturePlugin.php
+++ b/plugins/woocommerce/src/Internal/Admin/FeaturePlugin.php
@@ -26,6 +26,7 @@ use Automattic\WooCommerce\Admin\ReportsSync;
use Automattic\WooCommerce\Internal\Admin\CategoryLookup;
use Automattic\WooCommerce\Internal\Admin\Events;
use Automattic\WooCommerce\Internal\Admin\Onboarding\Onboarding;
+use Automattic\WooCommerce\Internal\Admin\Screens\AdminScreens;
/**
* Feature plugin main class.
@@ -108,6 +109,10 @@ class FeaturePlugin {
*/
public function on_plugins_loaded() {
$this->hooks();
+
+ // The screen loader needs the admin feature filter registered by hooks().
+ wc_get_container()->get( AdminScreens::class )->handle_init();
+
$this->includes();
}
diff --git a/plugins/woocommerce/src/Internal/Admin/Screens/AdminScreens.php b/plugins/woocommerce/src/Internal/Admin/Screens/AdminScreens.php
index 7303da66c50..1aeda5d973a 100644
--- a/plugins/woocommerce/src/Internal/Admin/Screens/AdminScreens.php
+++ b/plugins/woocommerce/src/Internal/Admin/Screens/AdminScreens.php
@@ -25,16 +25,7 @@ class AdminScreens {
public const FEATURE_FLAG = 'experimental-admin-screens';
/**
- * Register hooks.
- *
- * @internal
- */
- public function __construct() {
- add_action( 'init', array( $this, 'handle_init' ) );
- }
-
- /**
- * Load the build output in admin requests while the flag is on.
+ * Load the build output during admin bootstrap while the feature flag is on.
*
* @internal
*
diff --git a/plugins/woocommerce/src/Internal/Admin/Screens/Settings/ChequeSettings.php b/plugins/woocommerce/src/Internal/Admin/Screens/Settings/ChequeSettings.php
index a800103ebb1..c54bb941e2b 100644
--- a/plugins/woocommerce/src/Internal/Admin/Screens/Settings/ChequeSettings.php
+++ b/plugins/woocommerce/src/Internal/Admin/Screens/Settings/ChequeSettings.php
@@ -22,14 +22,40 @@ defined( 'ABSPATH' ) || exit;
final class ChequeSettings {
/**
- * Register the layout.
+ * Register the fields and the layout.
*
* @internal
*/
public function __construct() {
+ add_action( 'wp_entity_fields_api_init', array( $this, 'handle_wp_entity_fields_api_init' ) );
add_filter( 'get_entity_view_config_woo_settings_payments_cheque', array( $this, 'handle_get_entity_view_config_woo_settings_payments_cheque' ) );
}
+ /**
+ * Register the cheque fields with the Entity fields API, from the collection wp-build copies
+ * out of `admin-screens/packages/entity-fields`.
+ *
+ * @internal
+ *
+ * @since 11.4.0
+ */
+ public function handle_wp_entity_fields_api_init(): void {
+ $directory = $this->get_fields_directory();
+ if ( ! Features::is_enabled( AdminScreens::FEATURE_FLAG ) || ! function_exists( 'wp_register_entity_field_collection' ) || ! is_dir( $directory ) ) {
+ return;
+ }
+ wp_register_entity_field_collection( $directory );
+ }
+
+ /**
+ * Path to the built cheque field collection.
+ *
+ * @return string
+ */
+ private function get_fields_directory(): string {
+ return WC_ABSPATH . 'assets/client/routes/scripts/entity-fields/cheque';
+ }
+
/**
* Set the fields shown by the cheque form.
*
diff --git a/plugins/woocommerce/src/Internal/Admin/Screens/Settings/SettingsScreen.php b/plugins/woocommerce/src/Internal/Admin/Screens/Settings/SettingsScreen.php
index 8b78ee1a635..34dafd35e1b 100644
--- a/plugins/woocommerce/src/Internal/Admin/Screens/Settings/SettingsScreen.php
+++ b/plugins/woocommerce/src/Internal/Admin/Screens/Settings/SettingsScreen.php
@@ -57,14 +57,15 @@ final class SettingsScreen {
/**
* Whether the screen can be used on this site.
*
- * It needs the admin screens feature flag.
+ * It needs the admin screens feature flag and the Entity fields API, which WordPress 7.2 and
+ * Gutenberg 24.3 provide.
*
* @since 11.3.0
*
* @return bool
*/
public function is_available(): bool {
- return Features::is_enabled( AdminScreens::FEATURE_FLAG );
+ return Features::is_enabled( AdminScreens::FEATURE_FLAG ) && function_exists( 'wp_register_entity_field_collection' );
}
/**