[wp-trac] [WordPress Trac] #49628: Add is_post_type_viewable filter
WordPress Trac
noreply at wordpress.org
Tue Nov 9 08:13:58 UTC 2021
#49628: Add is_post_type_viewable filter
-------------------------------------------------+-------------------------
Reporter: powerbuoy | Owner:
| hellofromTonya
Type: feature request | Status: reopened
Priority: normal | Milestone: 5.9
Component: Posts, Post Types | Version: 5.3.2
Severity: normal | Resolution:
Keywords: has-patch needs-dev-note commit | Focuses:
2nd-opinion | administration
-------------------------------------------------+-------------------------
Changes (by Cybr):
* keywords: has-patch needs-dev-note commit => has-patch needs-dev-note
commit 2nd-opinion
* status: closed => reopened
* resolution: fixed =>
Comment:
Sorry for barging in again. I'll provide my counter-arguments briefly this
time.
1. I agree that the return values of
`is_post_type_viewable()/is_post_type_viewable()` should remain boolean.
2. I disagree filters `is_post_type_viewable/is_post_status_viewable`
should be typed strictly.
Those are mutually exclusive: One does not affect the other.
1. The function return value doesn't change when you typecast the filter
with `(bool)`. This is in line with the goal.
2. We should not fix PHP's "quirks" for type juggling. PHP gives `[] ==
false` and `[false] == true`. Those quirks apply to everyone on every line
of comparative code they write.
Although this is not a new design pattern in Core, I consider them all
incorrect.
To repeat, I believe we should only strictly type filter return values
when applicable PHP code requires a strict type and would error out
without proper typing.
{{{#!php
function test( string $string ) {}
// This would error if not a stringable type is given. (int) 1 is still
acceptable. [] is not.
test( apply_filters( 'example', '' ) );
}}}
Filters `is_post_type_viewable/is_post_status_viewable` apply to no such
case; their container functions do, but those can typecast safely.
I'm asking for a second opinion, as well.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/49628#comment:26>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list