Commit 068b578
committed
Code Quality: Improve
Add a `Data_Array` array-shape type describing every key returned by `WP_Post::to_array()`, and tighten each `WP_Post` property to the narrowest type the schema and code guarantee:
* `ID` and `post_parent` become `non-negative-int`.
* `comment_count` becomes `numeric-string`, and `post_author` becomes `numeric-string|''` (a user ID, or an empty string for a default post that has not yet been assigned an author).
* The always-populated `post_status`, `comment_status`, `ping_status`, and `post_type` slugs become `non-empty-string`, left open rather than enumerated so custom statuses and types remain valid.
* The magic `ancestors`, `post_category`, and `tags_input` accessors become precise lists (`list<non-negative-int>` and `list<non-empty-string>`).
The shape stays open because `WP_Post` permits dynamic properties. Fields that can legitimately be empty, including the datetime fields (which `get_default_post_to_edit()` may leave empty), stay `string`, and `menu_order` stays `int` since it can be negative.
Correct `WP_Post::$filter`, which was previously typed without `null` or the `'sample'` context: an unsanitized post has no `filter` (checked in core via `isset()` and `empty()`), and `get_sample_permalink()` has assigned `'sample'` since [8526]. Widen `sanitize_post_field()`'s `$context` to accept `'sample'` to match, which it already treats as a `'display'` context.
Also type `get_post_ancestors()` as returning `list<non-negative-int>`, read the post in `trackback_url_list()` via `to_array()` while guarding against a missing post, and cast `post_author` to a string in `WP_Customize_Nav_Menu_Item_Setting` and `inject_ignored_hooked_blocks_metadata_attributes()`, which each populate an object before passing it to `new WP_Post()`.
Developed in WordPress#12491.
Follow-up to r62648, r62694.
See #64898, #64896.
git-svn-id: https://develop.svn.wordpress.org/trunk@62717 602fd350-edb4-49c9-b593-d223f7449a82WP_Post type coverage.1 parent 0c5aa8e commit 068b578
5 files changed
Lines changed: 73 additions & 22 deletions
File tree
- src/wp-includes
- customize
- tests/phpunit/tests/customize
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1739 | 1739 | | |
1740 | 1740 | | |
1741 | 1741 | | |
1742 | | - | |
| 1742 | + | |
| 1743 | + | |
| 1744 | + | |
| 1745 | + | |
| 1746 | + | |
1743 | 1747 | | |
1744 | | - | |
| 1748 | + | |
| 1749 | + | |
| 1750 | + | |
1745 | 1751 | | |
1746 | 1752 | | |
1747 | 1753 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
18 | | - | |
19 | | - | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
20 | 52 | | |
21 | 53 | | |
22 | 54 | | |
| |||
26 | 58 | | |
27 | 59 | | |
28 | 60 | | |
| 61 | + | |
29 | 62 | | |
30 | 63 | | |
31 | 64 | | |
32 | 65 | | |
33 | 66 | | |
34 | 67 | | |
35 | | - | |
| 68 | + | |
| 69 | + | |
36 | 70 | | |
37 | 71 | | |
38 | 72 | | |
39 | | - | |
| 73 | + | |
40 | 74 | | |
41 | 75 | | |
42 | 76 | | |
| |||
85 | 119 | | |
86 | 120 | | |
87 | 121 | | |
| 122 | + | |
88 | 123 | | |
89 | 124 | | |
90 | 125 | | |
| |||
93 | 128 | | |
94 | 129 | | |
95 | 130 | | |
| 131 | + | |
96 | 132 | | |
97 | 133 | | |
98 | 134 | | |
| |||
101 | 137 | | |
102 | 138 | | |
103 | 139 | | |
| 140 | + | |
104 | 141 | | |
105 | 142 | | |
106 | 143 | | |
| |||
165 | 202 | | |
166 | 203 | | |
167 | 204 | | |
| 205 | + | |
168 | 206 | | |
169 | 207 | | |
170 | 208 | | |
| |||
189 | 227 | | |
190 | 228 | | |
191 | 229 | | |
| 230 | + | |
192 | 231 | | |
193 | 232 | | |
194 | 233 | | |
| |||
216 | 255 | | |
217 | 256 | | |
218 | 257 | | |
| 258 | + | |
| 259 | + | |
219 | 260 | | |
220 | | - | |
221 | | - | |
| 261 | + | |
| 262 | + | |
222 | 263 | | |
223 | 264 | | |
224 | 265 | | |
| |||
389 | 430 | | |
390 | 431 | | |
391 | 432 | | |
392 | | - | |
| 433 | + | |
393 | 434 | | |
394 | 435 | | |
395 | | - | |
396 | 436 | | |
397 | 437 | | |
398 | 438 | | |
| |||
401 | 441 | | |
402 | 442 | | |
403 | 443 | | |
| 444 | + | |
404 | 445 | | |
405 | 446 | | |
406 | 447 | | |
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
625 | 625 | | |
626 | 626 | | |
627 | 627 | | |
628 | | - | |
| 628 | + | |
629 | 629 | | |
630 | 630 | | |
631 | 631 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1185 | 1185 | | |
1186 | 1186 | | |
1187 | 1187 | | |
| 1188 | + | |
1188 | 1189 | | |
1189 | 1190 | | |
1190 | 1191 | | |
| |||
3001 | 3002 | | |
3002 | 3003 | | |
3003 | 3004 | | |
3004 | | - | |
| 3005 | + | |
| 3006 | + | |
3005 | 3007 | | |
3006 | 3008 | | |
3007 | 3009 | | |
3008 | 3010 | | |
3009 | 3011 | | |
3010 | 3012 | | |
3011 | 3013 | | |
3012 | | - | |
3013 | | - | |
| 3014 | + | |
| 3015 | + | |
3014 | 3016 | | |
3015 | 3017 | | |
3016 | | - | |
| 3018 | + | |
3017 | 3019 | | |
3018 | 3020 | | |
3019 | 3021 | | |
| |||
3286 | 3288 | | |
3287 | 3289 | | |
3288 | 3290 | | |
3289 | | - | |
| 3291 | + | |
| 3292 | + | |
3290 | 3293 | | |
3291 | 3294 | | |
3292 | 3295 | | |
| |||
3313 | 3316 | | |
3314 | 3317 | | |
3315 | 3318 | | |
3316 | | - | |
| 3319 | + | |
| 3320 | + | |
3317 | 3321 | | |
3318 | 3322 | | |
3319 | 3323 | | |
| |||
6149 | 6153 | | |
6150 | 6154 | | |
6151 | 6155 | | |
6152 | | - | |
6153 | | - | |
6154 | | - | |
| 6156 | + | |
| 6157 | + | |
6155 | 6158 | | |
6156 | 6159 | | |
| 6160 | + | |
6157 | 6161 | | |
6158 | 6162 | | |
6159 | 6163 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
950 | 950 | | |
951 | 951 | | |
952 | 952 | | |
953 | | - | |
| 953 | + | |
954 | 954 | | |
955 | 955 | | |
956 | 956 | | |
| |||
0 commit comments