Commit 0d59cc4
committed
Code Quality: Short-circuit Ajax handlers when the supplied post does not exist.
`get_post()` returns `null` for a nonexistent post, but four Ajax handlers dereferenced the result without checking: `wp_ajax_add_meta()`, `wp_ajax_inline_save()`, `wp_ajax_save_attachment()`, and `wp_ajax_save_attachment_compat()`. Each now bails when `null` is returned. Since these functions return `never`, subsequent references to `$post` do not cause static analysis errors. In `wp_ajax_add_meta()` the check is folded into the existing capability check, since `$post` is only dereferenced in the branch that adds meta.
These paths are unreachable in core, as `current_user_can( 'edit_post', ... )` already blocks for a nonexistent post. The guards are defensive as a plugin filtering capabilities could still reach them, and they give static analysis the non-null narrowing it needs.
Developed as subset of WordPress#12488.
Follow-up to r62704, r62703.
See #64898.
git-svn-id: https://develop.svn.wordpress.org/trunk@62705 602fd350-edb4-49c9-b593-d223f7449a821 parent 1e521e7 commit 0d59cc4
1 file changed
Lines changed: 10 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1621 | 1621 | | |
1622 | 1622 | | |
1623 | 1623 | | |
1624 | | - | |
| 1624 | + | |
1625 | 1625 | | |
1626 | 1626 | | |
1627 | 1627 | | |
| |||
2106 | 2106 | | |
2107 | 2107 | | |
2108 | 2108 | | |
| 2109 | + | |
| 2110 | + | |
| 2111 | + | |
2109 | 2112 | | |
2110 | 2113 | | |
2111 | 2114 | | |
| |||
3134 | 3137 | | |
3135 | 3138 | | |
3136 | 3139 | | |
| 3140 | + | |
| 3141 | + | |
| 3142 | + | |
3137 | 3143 | | |
3138 | 3144 | | |
3139 | 3145 | | |
| |||
3225 | 3231 | | |
3226 | 3232 | | |
3227 | 3233 | | |
| 3234 | + | |
| 3235 | + | |
| 3236 | + | |
3228 | 3237 | | |
3229 | 3238 | | |
3230 | 3239 | | |
| |||
0 commit comments