Skip to content

Add create taxonomies beta in editor sidebar - #549

Open
faisalahammad wants to merge 2 commits into
WordPress:trunkfrom
faisalahammad:enhancement/155-create-taxonomy-editor
Open

faisalahammad wants to merge 2 commits into
WordPress:trunkfrom
faisalahammad:enhancement/155-create-taxonomy-editor

Conversation

@faisalahammad

Copy link
Copy Markdown

Adds an opt-in beta feature that lets admins create a taxonomy without leaving the post editor. The panel lives in the document settings sidebar and shows only the essential settings: singular label, plural label, taxonomy key and the hierarchical toggle. The new taxonomy is bound to the post type currently being edited, so it is ready to use on that screen straight away.

This covers the creation half of the request in #155. Editing and deleting taxonomies still happen on the existing Taxonomies screen, which is unchanged.

How it works

A new REST route, POST /scf/v1/taxonomies, handles the create request. It reuses the same input mapping, capability check and validation rules as the classic admin save path in admin-taxonomy.php, then persists through acf_update_internal_post_type(). Reserved keys (post_tag, category, nav_menu, and the other built in ones), duplicate keys and invalid keys are rejected with a specific error, so the sidebar does not need to duplicate that logic to stay safe.

The sidebar UI is a small plugin registered with PluginDocumentSettingPanel, so it sits with the other document settings rather than a modal. The key is derived from the singular label until the user edits it, and the panel is hidden on internal wp_* entities and on post types that are not shown in the admin.

The classic creation flow is untouched, and the whole feature is behind the create_taxonomies beta flag.

Beta registry fix

The beta flag could not be turned on before this PR. include_beta_features() referenced a class file that does not exist, and register_beta_features() registered nothing, so the Features screen had no entries to toggle. That path is fixed here so the new flag actually works. Registering the features also brings back the existing editor_sidebar entry, which had the same problem.

How to test

  1. Go to Field Groups > Beta Features and enable "Create Taxonomies in the Editor".
  2. Open any post for editing. A "Create Taxonomy" panel appears in the document settings sidebar.
  3. Type a singular label such as "Book" and check the key field fills in as book.
  4. Fill in the plural label and click Create Taxonomy.
  5. The editor reloads and the taxonomy is created and bound to that post type. Confirm it in the Taxonomies screen.
  6. Try a reserved key like category or an existing key, and confirm the panel shows a clear error instead of creating anything.
  7. Turn the beta feature off and confirm the panel is gone and POST /wp-json/scf/v1/taxonomies returns 404.

Tests run

  • composer test:php - full PHPUnit suite, 2953 tests pass. New coverage in tests/php/includes/rest-api/SCFRestCreateTaxonomyTest.php for the endpoint (success, duplicate, reserved, invalid key, unknown post type, permissions, and the route being absent when the beta is off).
  • composer test:phpstan - clean on the changed files.
  • composer lint:php - clean on the changed lines.
  • npm run test:unit - full Jest suite passes, including the new validation tests.
  • npm run build - builds without errors.

See #155

@github-actions

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props faisalahammad.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Adds an opt-in beta feature that lets admins create a taxonomy
straight from the post editor sidebar. The form takes the
essential settings only (labels, key, hierarchical) and binds
the new taxonomy to the post type being edited.

The beta flag could never turn on before because the registry
included a missing class file and registered no features, so
that path is fixed as part of this.

New REST endpoint /scf/v1/taxonomies handles the create request
with the same validation rules as the classic admin screen
(reserved keys, duplicates, key charset and length).

See WordPress#155
Trunk renamed the editor preview menu item to
"Preview (opens in a new tab)", which no longer matches the
exact label the e2e helpers look for, so every preview test
timed out waiting for the new page.

Match on the shared "Preview ... new tab" text instead, which
works on all the supported WordPress versions.
@faisalahammad
faisalahammad force-pushed the enhancement/155-create-taxonomy-editor branch from 6a6e8a5 to 7563d02 Compare September 24, 2026 22:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant