Skip to content

Commit 48a8fb1

Browse files
authored
fix: guard ability category registration against double-fire _doing_it_wrong notice (#733)
WordPress core's wp_abilities_api_categories_init action can fire more than once per request on multisite. The four wp_register_ability_category calls ran unconditionally, so the second fire re-registered each category and tripped WP_Ability_Categories_Registry::register's _doing_it_wrong "already registered" notice. Wrap each registration in a wp_has_ability_category guard (with a function_exists fallback for the API itself) so a repeat fire is a clean no-op.
1 parent 8149372 commit 48a8fb1

1 file changed

Lines changed: 50 additions & 31 deletions

File tree

data-machine-code.php

Lines changed: 50 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -244,37 +244,56 @@ static function (): void {
244244
* enforces that categories are only registered during this action.
245245
*/
246246
function datamachine_code_register_ability_categories() {
247-
wp_register_ability_category(
248-
'datamachine-code-workspace',
249-
array(
250-
'label' => __('Code Workspace', 'data-machine-code'),
251-
'description' => __('Git workspace management — clone, read, write, edit, and git operations.', 'data-machine-code'),
252-
)
253-
);
254-
255-
wp_register_ability_category(
256-
'datamachine-code-github',
257-
array(
258-
'label' => __('GitHub', 'data-machine-code'),
259-
'description' => __('GitHub issue, pull request, and repository operations.', 'data-machine-code'),
260-
)
261-
);
262-
263-
wp_register_ability_category(
264-
'datamachine-code-code-task',
265-
array(
266-
'label' => __('Code Tasks', 'data-machine-code'),
267-
'description' => __('Create isolated coding tasks from structured source evidence packets.', 'data-machine-code'),
268-
)
269-
);
270-
271-
wp_register_ability_category(
272-
'datamachine-code-runtime',
273-
array(
274-
'label' => __('WordPress Runtime', 'data-machine-code'),
275-
'description' => __('Read-only inspection of the live WordPress runtime and allowlisted source roots.', 'data-machine-code'),
276-
)
277-
);
247+
if ( ! function_exists( 'wp_register_ability_category' ) ) {
248+
return;
249+
}
250+
251+
// Core's wp_abilities_api_categories_init action can fire more than once per
252+
// request on multisite; guard each registration so a repeat fire is a clean
253+
// no-op instead of tripping a _doing_it_wrong "already registered" notice.
254+
$has_category = function ( string $slug ): bool {
255+
return function_exists( 'wp_has_ability_category' ) && wp_has_ability_category( $slug );
256+
};
257+
258+
if ( ! $has_category( 'datamachine-code-workspace' ) ) {
259+
wp_register_ability_category(
260+
'datamachine-code-workspace',
261+
array(
262+
'label' => __('Code Workspace', 'data-machine-code'),
263+
'description' => __('Git workspace management — clone, read, write, edit, and git operations.', 'data-machine-code'),
264+
)
265+
);
266+
}
267+
268+
if ( ! $has_category( 'datamachine-code-github' ) ) {
269+
wp_register_ability_category(
270+
'datamachine-code-github',
271+
array(
272+
'label' => __('GitHub', 'data-machine-code'),
273+
'description' => __('GitHub issue, pull request, and repository operations.', 'data-machine-code'),
274+
)
275+
);
276+
}
277+
278+
if ( ! $has_category( 'datamachine-code-code-task' ) ) {
279+
wp_register_ability_category(
280+
'datamachine-code-code-task',
281+
array(
282+
'label' => __('Code Tasks', 'data-machine-code'),
283+
'description' => __('Create isolated coding tasks from structured source evidence packets.', 'data-machine-code'),
284+
)
285+
);
286+
}
287+
288+
if ( ! $has_category( 'datamachine-code-runtime' ) ) {
289+
wp_register_ability_category(
290+
'datamachine-code-runtime',
291+
array(
292+
'label' => __('WordPress Runtime', 'data-machine-code'),
293+
'description' => __('Read-only inspection of the live WordPress runtime and allowlisted source roots.', 'data-machine-code'),
294+
)
295+
);
296+
}
278297
}
279298

280299
/**

0 commit comments

Comments
 (0)