Opened 7 weeks ago
Last modified 7 weeks ago
#66225 new enhancement
Allow post_type_supports() to check for individual sub-features
| Reported by: | fabiankaegy | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | Posts, Post Types | Version: | |
| Severity: | normal | Keywords: | has-patch has-unit-tests |
| Cc: | Focuses: |
Description
Follow-up to #64156 and #66224.
#64156 lets repeated add_post_type_support() calls merge their array arguments, and #66224 lets remove_post_type_support() remove individual sub-features. post_type_supports() still only answers whether the feature as a whole is supported.
To check whether a post type has notes enabled on the editor feature today, you have to reach into the raw arguments yourself:
<?php $supports = get_all_post_type_supports( 'custom' ); $has_notes = isset( $supports['editor'][0]['notes'] ) && $supports['editor'][0]['notes'];
This was suggested by @mamaduka on the #64156 PR.
Proposal
Add an optional third parameter, $sub_feature:
<?php post_type_supports( 'custom', 'editor', 'notes' );
- For associative arguments, the sub-feature is supported when its key is set to a non-empty value, so
'notes' => falsecounts as not supported. - For list arguments (e.g. a
post-formatsstyle feature), the sub-feature is supported when the list contains it. - If the feature isn't supported, or has no array arguments, the result is
false. - Without the third parameter, behavior is unchanged.
Change History (1)
This ticket was mentioned in PR #13885 on WordPress/wordpress-develop by @fabiankaegy.
7 weeks ago
#1
- Keywords has-patch has-unit-tests added
#10426 merges array arguments across
add_post_type_support()calls and #13884 letsremove_post_type_support()drop individual sub-features.post_type_supports()is the last piece. Right now it can only tell you whethereditoris supported, not whethernotesis enabled on it. @Mamaduka suggested this on #10426.This adds an optional third
$sub_featureparameter:'notes' => falsecounts as not supported.post-formatsstyle feature): supported when the list contains the value.falseif the feature isn't supported or has no array arguments.I went with a non-empty check instead of
isset()so that explicitly disabling a sub-feature withfalsereads as unsupported. Happy to change that if folks prefer a plain key check.