Repository navigation
Abilities API: Allow marking a show_in_abilities object as read only - #16288
jorgefilipecosta wants to merge 1 commit into
Conversation
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.
|
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: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
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. |
What?
Follow up to #16028 (comment).
show_in_abilitieson a post type acceptsarray( 'readonly' => true ): the post type stays readable through abilities, and write abilities must leave it alone.truekeeps meaning full access.WP_Post_Typekeeps the array asarray( 'readonly' => bool ). Other values, including arrays without a booleanreadonly, still becomefalse.readonlykey in theirshow_in_abilitiesarray.wp_is_writable_through_abilities( $show_in_abilities ), which write abilities call to know whether an object'sshow_in_abilitiesvalue allows writes.Why?
In 7.2
show_in_abilitiesonly 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 booleanreadonlykey, reduced to that key.abilities.php: addswp_is_writable_through_abilities().post.php,option.php: document thereadonlykey.get_post_types( array( 'show_in_abilities' => true ) )and theempty()checks already match a non-empty array, so read-only post types stay incore/content-query.How the open write ability PRs would use the helper:
core/content-create,core/content-updateandcore/content-deleteabilities #16028: checkwp_is_writable_through_abilities( $post_type_object->show_in_abilities )in the create, update and delete permission callbacks, and leave read-only post types out of the write abilities'typeenum.core/settings-updateability #10892: add the check to thewritable_settingsfilter, next to the schemareadonlycheck, by carrying each setting'sshow_in_abilitiesvalue in its exposed entry.core/media-query,core/media-upload,core/media-updateandcore/media-deleteabilities #16138: check theattachmentpost type in the upload, update and delete abilities, on top ofcan_use_media().core/terms-query,core/term-create,core/term-updateandcore/term-deleteabilities #16102: accept the same array inWP_Taxonomyand check the helper in the term create, update and delete abilities.core/user-create,core/user-updateandcore/user-deleteabilities #16074: nothing to change, users have noshow_in_abilitiesflag.Testing
Verify unit tests are passing:
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