#53235 closed defect (bug) (fixed)
Ensure consistent type for integer properties of WP_Post, WP_Term, and WP_User
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 5.8 | Priority: | normal |
| Severity: | normal | Version: | |
| Component: | General | Keywords: | has-patch needs-dev-note |
| Focuses: | Cc: |
Description (last modified by )
Background: #52995.
Some properties of the WP_Post, WP_Term, and WP_User classes are documented as integers, so it should be a safe assumption to always treat them as such. However, that is not the case when get_post() or get_term() is called with an edit, attribute, or js context, because all values are run through esc_attr() or esc_js() in that case, and these properties are unexpectedly converted to strings.
As WordPress moves to strict type comparisons in tickets like #52627 or #52482, it is important to make the type of these properties consistent in all contexts, so that using strict comparison does not cause unexpected issues.
This applies to the following functions:
sanitize_post_field()sanitize_term_field()sanitize_user_field()
and the following properties:
WP_Post::IDWP_Post::post_parentWP_Post::menu_orderWP_Term::term_idWP_Term::term_taxonomy_idWP_Term::parentWP_Term::countWP_Term::term_groupWP_User::ID
Attachments (1)
Change History (8)
#1
@
4 years ago
- Keywords has-patch added
- Owner set to SergeyBiryukov
- Status changed from new to accepted
#4
follow-up:
↓ 6
@
4 years ago
- Keywords needs-dev-note added
I vaguely remember something like this causing problems in the past but can't find the solution, ie whether converting to string was deliberate or a dev note was published.
I did find this slack discussion between @pento and @boonebgorges but not the outcome.
#6
in reply to:
↑ 4
;
follow-up:
↓ 7
@
4 years ago
Replying to peterwilsoncc:
I vaguely remember something like this causing problems in the past but can't find the solution, ie whether converting to string was deliberate or a dev note was published.
Could that be about the WP_Post::post_author and WP_Post::comment_count properties in #22324? They were indeed left as a string at the time for backward compatibility.
#7
in reply to:
↑ 6
@
4 years ago
Replying to SergeyBiryukov:
Could that be about the
WP_Post::post_authorandWP_Post::comment_countproperties in #22324? They were indeed left as a string at the time for backward compatibility.
The slack discussion mentions term IDs, I remember because I was sitting next to a theme author who discovered the type change when they had something along the lines of get_option( 'my_special_term_id' ) === /* a term ID */ in their code
In this ticket, we're not changing the type of properties, just making sure they always match the documented type.
Excellent. In that case, I expect it's not a problem for this ticket and the solution at the time was a dev note.
In 50935: