Skip to content

Commit 89d3da9

Browse files
arraypressclaude
andcommitted
Register a field's callbacks when the page is registered, not when it renders
A field set's constructor is what registers a field's search source and its action handlers, and the request that searches or presses a button is never the request that drew the control. Built lazily per tab, those callbacks existed only on the renders where nobody needed them — so an action button on a settings page came back "Unknown action." every single time. The whole-page set rather than a tab's, because the names are the option name and the field key with no tab in them, so one covers every tab. It stores configuration and registers callbacks; the fields themselves are still built on demand. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Tk8y5eZa3CHVVSM6nVxsJw
1 parent 9e8229a commit 89d3da9

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

‎src/SettingFields.php‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,19 @@ public function __construct( string $id, array $config ) {
130130
// one. Nothing in register_setting() needs the admin to be loaded.
131131
$this->register_settings();
132132

133+
// Built now, not when a tab renders. The set's constructor is what
134+
// registers a field's search source and its action handlers, and the
135+
// request that searches or presses a button is never the request that
136+
// drew the control — so a set built lazily registers them only on the
137+
// renders where nobody needs them. An action button on a settings
138+
// page came back "Unknown action." every time it was pressed.
139+
//
140+
// The whole-page set rather than a tab's: the names are the option
141+
// name and the field key, with no tab in them, so one set covers
142+
// every tab. It stores configuration and registers callbacks; the
143+
// fields themselves are still built on demand.
144+
$this->set();
145+
133146
add_action( 'admin_menu', [ $this, 'register_menu' ] );
134147
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue' ] );
135148
add_filter( 'screen_settings', [ $this, 'render_screen_tools' ], 10, 2 );

0 commit comments

Comments
 (0)