Skip to content

Abilities API: Allow marking a show_in_abilities object as read only - #16288

Open
jorgefilipecosta wants to merge 1 commit into
WordPress:trunkfrom
jorgefilipecosta:add/show-in-abilities-readonly
Open

jorgefilipecosta wants to merge 1 commit into
WordPress:trunkfrom
jorgefilipecosta:add/show-in-abilities-readonly

Conversation

@jorgefilipecosta

Copy link
Copy Markdown
Member

What?

Follow up to #16028 (comment).

  • show_in_abilities on a post type accepts array( 'readonly' => true ): the post type stays readable through abilities, and write abilities must leave it alone. true keeps meaning full access.
  • WP_Post_Type keeps the array as array( 'readonly' => bool ). Other values, including arrays without a boolean readonly, still become false.
  • Settings accept the same readonly key in their show_in_abilities array.
  • Adds wp_is_writable_through_abilities( $show_in_abilities ), which write abilities call to know whether an object's show_in_abilities value allows writes.

Why?

In 7.2 show_in_abilities only made a post type readable. The write abilities proposed for 7.3 make every flagged object writable, with no way to keep one read only (raised in #16028 (comment) and #10892 (comment)).

How?

  • class-wp-post-type.php: keeps an array with a boolean readonly key, reduced to that key.
  • abilities.php: adds wp_is_writable_through_abilities().
  • post.php, option.php: document the readonly key.
  • No reader changes: get_post_types( array( 'show_in_abilities' => true ) ) and the empty() checks already match a non-empty array, so read-only post types stay in core/content-query.

How the open write ability PRs would use the helper:

Testing

Verify unit tests are passing:

vendor/bin/phpunit --group abilities-api

AI assistance: the code, tests and this description were drafted with AI assistance (Claude Code) and reviewed by me.

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

Post types accept `array( 'readonly' => true )` for `show_in_abilities`, which keeps them readable through abilities and marks them read only. Settings accept the same `readonly` key in their `show_in_abilities` array.

The new `wp_is_writable_through_abilities()` function tells write abilities whether a `show_in_abilities` value allows writes.

See #66844.
@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.

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

Props jorgefilipecosta.

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


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub or WordPress.org user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

@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.

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