Navigation: Add dedicated capabilities for wp_navigation (backport GB #80478)#12647
Navigation: Add dedicated capabilities for wp_navigation (backport GB #80478)#12647scruffian wants to merge 5 commits into
Conversation
|
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 Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe 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
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
There was a problem hiding this comment.
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) forwp_navigationincreate_initial_post_types(). - Updates the Navigation Fallback REST permissions check to require the post type’s
create_posts+publish_postscaps (now navigation-specific). - Adds a
user_has_capfilter that grants the new navigation caps to users who canedit_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.
| * | ||
| * 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 | ||
| * |
| * 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 | ||
| * |
| 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', | ||
| ); | ||
| } |
| 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; |
There was a problem hiding this comment.
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 reports7.1-beta*inwp-includes/version.php. The@sincetag should match the release version that will first include this API (likely7.1.0).
* @since 7.2.0
src/wp-includes/capabilities.php:1402
- This
@sincetag should reflect the WordPress version where the capability-bridge filter is first available. Given core is currently7.1-beta*, this should likely be7.1.0(rather than7.2.0) unless the feature is explicitly deferred.
* @since 7.2.0
Backport of Gutenberg PR WordPress/gutenberg#80478: Navigation: Add dedicated capabilities for
wp_navigation.Introduces granular capabilities for the
wp_navigationpost type (e.g.edit_navigation_menus,publish_navigation_menus) that were previously all mapped toedit_theme_options. Existing behavior is preserved by granting the new capabilities to any user withedit_theme_optionsvia auser_has_capfilter, 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 thewp_navigationpost typecapabilitiesarray increate_initial_post_types()with the new mapping.src/wp-includes/rest-api/endpoints/class-wp-rest-navigation-fallback-controller.php— updateget_item_permissions_check()to requirecreate_posts+publish_posts(which now resolve to the navigation-specific caps) instead ofedit_theme_options.src/wp-includes/capabilities.php— addwp_get_navigation_menu_capability_names()andwp_maybe_grant_navigation_menus_caps().src/wp-includes/default-filters.php— register theuser_has_capfilter.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