Apply parameters that user create and post update silently discard - #637
Apply parameters that user create and post update silently discard#637swissspidy wants to merge 4 commits into
Conversation
Three documented parameters accept a value and drop it: - `user create --user_nicename` and `--rich_editing`. User_Command::create() builds an explicit stdClass for wp_insert_user() and never sets either property, so both are read off $assoc_args nowhere. - `post create` / `post update --post_modified` and `--post_modified_gmt`. wp_insert_post() computes both itself and never reads them from $postarr; on update they are unconditionally current_time( 'mysql' ). All three report success. These are the same silent no-op as wp-cli/wp-cli#5286, reached from the other side: there the parameter name is wrong, here the name is right and the value is discarded anyway. These scenarios fail on main. The fix follows in the next commit. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014SSZzqMJRDTiLiDxQEPYcL
Makes the tests from the previous commit pass. user create: set user_nicename and rich_editing on the object handed to wp_insert_user(). Both use the same `false` default as the neighbouring properties, which core reads as "not supplied" - user_nicename then falls back to the login and rich_editing to 'true'. post create / post update: wp_insert_post() derives post_modified and post_modified_gmt itself and never reads them back from $postarr, so apply the requested value through the wp_insert_post_data filter, registered around the insert and removed straight after. When only one of the pair is given the other is derived from it, so the two never disagree. That last change makes a previously harmless bug visible: `post create --from-post` copies the source post's fields, and post_modified was not among the ones it unset. Core ignored it before, so the duplicate got the current time; now it would inherit the original's. Unset it alongside post_date, and cover it with a scenario. The alternative to all of this is to remove the parameters from the docblocks instead. That is a smaller change but loses functionality the documentation has been promising, so it seemed the wrong way round - happy to invert it. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014SSZzqMJRDTiLiDxQEPYcL
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
@schlessera Any preference? |
Draft. These are the two pre-existing bugs noticed while auditing field lists for wp-cli/wp-cli#5286, now with tests. Independent of #636 and #6392 — branched off
mainand reviewable on its own.Same failure as #5286 reached from the other side: there the parameter name is wrong and the value is dropped, here the name is right and the value is dropped anyway. Both report success.
What's broken
user create--user_nicenameuser create--rich_editingpost create--post_modified,--post_modified_gmtpost update--post_modified,--post_modified_gmtUser_Command::create()builds an explicitstdClassforwp_insert_user()and never sets either property.wp_insert_post()derivespost_modified/post_modified_gmtitself and never reads them from$postarr— on update they are unconditionallycurrent_time( 'mysql' ).Note
user createhas no catch-all, so it is already strictly validated. It accepts these two parameters because they are documented, and then drops them.Commits are test-first
b4355e0adds the scenarios and fails.aeaa92bmakes them pass. Reviewable in that order, and verified in that order with Behat by checkingsrc/out at each commit:The two that pass in both states are deliberate controls — nicename falling back to the login, and
post_modifieddefaulting to now when not asked for. Without them a red run would not distinguish a real bug from a broken harness.Full suites
Run on both database backends; the results are identical.
post.featurepost-create-duplicate.featureuser.featureThe one
user.featurefailure is pre-existing and unrelated. It is the multisite duplicate-email scenario, which expectsSorry, that email address is already used!while current core trunk returnsThis email address is already registered. Log in with this address or choose another one.Confirmed by re-running that scenario withsrc/checked out atorigin/main, where it fails identically. My diff does not touch it.Tested against WordPress trunk (
7.2-alpha), which is what this environment could obtain — worth noting since that is also the source of the message change above.One regression this surfaced
Making
post_modifiedlive exposed a latent bug inpost create --from-post. It copies the source post's fields and unsetspost_date,post_date_gmt,guidandID— but notpost_modified. Harmless while core ignored it; with this change the duplicate would inherit the original's modification date instead of the current time. Fixed by unsetting it alongsidepost_date, with a scenario inpost-create-duplicate.feature.The design question
For
post_modifiedthe alternative is to remove the parameters from the docblocks rather than make them work. Smaller change, but it drops functionality the documentation has been advertising since it was added, and "set the modification date" is a reasonable thing to want from an admin tool. I went with making them work; inverting it is a small diff if you'd rather.There is no such question for
user create— those two are unambiguous.🤖 Generated with Claude Code
https://claude.ai/code/session_014SSZzqMJRDTiLiDxQEPYcL