Skip to content

Navigation: Add dedicated capabilities for wp_navigation (backport GB #80478)#12647

Open
scruffian wants to merge 5 commits into
WordPress:trunkfrom
scruffian:backport/80478-navigation-menu-caps
Open

Navigation: Add dedicated capabilities for wp_navigation (backport GB #80478)#12647
scruffian wants to merge 5 commits into
WordPress:trunkfrom
scruffian:backport/80478-navigation-menu-caps

Conversation

@scruffian

Copy link
Copy Markdown
Contributor

Backport of Gutenberg PR WordPress/gutenberg#80478: Navigation: Add dedicated capabilities for wp_navigation.

Introduces granular capabilities for the wp_navigation post type (e.g. edit_navigation_menus, publish_navigation_menus) that were previously all mapped to edit_theme_options. Existing behavior is preserved by granting the new capabilities to any user with edit_theme_options via a user_has_cap filter, so no role/database migration is required. Sites that want stricter delegation can now grant the individual capabilities to other roles.

Includes:

  • src/wp-includes/post.php — replace the wp_navigation post type capabilities array in create_initial_post_types() with the new mapping.
  • src/wp-includes/rest-api/endpoints/class-wp-rest-navigation-fallback-controller.php — update get_item_permissions_check() to require create_posts + publish_posts (which now resolve to the navigation-specific caps) instead of edit_theme_options.
  • src/wp-includes/capabilities.php — add wp_get_navigation_menu_capability_names() and wp_maybe_grant_navigation_menus_caps().
  • src/wp-includes/default-filters.php — register the user_has_cap filter.

Test coverage will follow in a separate commit; the Gutenberg PR includes an extensive test file that needs adaptation for the Core surfaces.

Trac ticket: https://core.trac.wordpress.org/ticket/29213

Copilot AI review requested due to automatic review settings July 22, 2026 16:15
@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 scruffian.

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

@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR backports Gutenberg’s granular capability model for the wp_navigation post type into Core, replacing the historical “everything maps to edit_theme_options” approach while preserving existing behavior via a user_has_cap shim.

Changes:

  • Introduces navigation-specific primitive capabilities (e.g. edit_navigation_menus, publish_navigation_menus) for wp_navigation in create_initial_post_types().
  • Updates the Navigation Fallback REST permissions check to require the post type’s create_posts + publish_posts caps (now navigation-specific).
  • Adds a user_has_cap filter that grants the new navigation caps to users who can edit_theme_options, avoiding role/db migration.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
src/wp-includes/post.php Replaces wp_navigation post type capability mapping with dedicated navigation-menu capabilities.
src/wp-includes/rest-api/endpoints/class-wp-rest-navigation-fallback-controller.php Updates REST permission checks to rely on the post type’s create/publish capabilities.
src/wp-includes/capabilities.php Adds helper to enumerate nav-menu cap names and a user_has_cap shim to preserve legacy behavior.
src/wp-includes/default-filters.php Registers the new user_has_cap filter callback.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1370 to +1375
*
* These are the primitive capabilities used by the `wp_navigation` post type,
* mirrored from the mapping registered in `create_initial_post_types()`.
*
* @since 7.2.0
*
Comment on lines +1398 to +1403
* This preserves existing behavior for the `wp_navigation` post type without
* adding the new capabilities to roles in the database. Sites can still grant
* the new capabilities to roles independently.
*
* @since 7.2.0
*
Comment on lines +1378 to +1392
function wp_get_navigation_menu_capability_names() {
return array(
'create_navigation_menus',
'delete_navigation_menus',
'delete_others_navigation_menus',
'delete_private_navigation_menus',
'delete_published_navigation_menus',
'edit_navigation_menus',
'edit_others_navigation_menus',
'edit_private_navigation_menus',
'edit_published_navigation_menus',
'publish_navigation_menus',
'read_private_navigation_menus',
);
}
Comment on lines +1408 to +1416
function wp_maybe_grant_navigation_menus_caps( $allcaps, $caps ) {
if ( empty( $allcaps['edit_theme_options'] ) ) {
return $allcaps;
}

$navigation_menu_caps = wp_get_navigation_menu_capability_names();

if ( ! array_intersect( $caps, $navigation_menu_caps ) ) {
return $allcaps;
Copilot AI review requested due to automatic review settings July 22, 2026 16:24

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (2)

src/wp-includes/capabilities.php:1374

  • The new function’s docblock uses @since 7.2.0, but this change is being introduced while core reports 7.1-beta* in wp-includes/version.php. The @since tag should match the release version that will first include this API (likely 7.1.0).
 * @since 7.2.0

src/wp-includes/capabilities.php:1402

  • This @since tag should reflect the WordPress version where the capability-bridge filter is first available. Given core is currently 7.1-beta*, this should likely be 7.1.0 (rather than 7.2.0) unless the feature is explicitly deferred.
 * @since 7.2.0

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.

2 participants