Replies: 2 comments 1 reply
-
CC @swissspidy, as I don't know if maintainers get notified about new discussions. 🙂 ✌🏽 |
Beta Was this translation helpful? Give feedback.
0 replies
-
Thanks! Yeah we actually not get notified and I can't seem to find a way to subscribe to new topics here... That's probably why we don't really advertise this Discussions feature for the org. Given that this is a clear feature request it's probably easier to just create an issue for this instead of a discussion topic. This must have come up before too but I can't find any prior issue for it right now. cc @schlessera maybe you know more? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Proposal:
In WP-CLI, the function
current_user_can()
currently returnsfalse
by default because there is no authenticated user during command execution. This causes issues when using functions likewp_insert_post()
withtax_input
in custom WP-CLI commands, as the capability check fails, preventing terms from being assigned.I propose that
current_user_can()
should always returntrue
in WP-CLI context, given that using WP-CLI already implies full administrative control over the WordPress installation.Rationale:
Full System Control Already Exists – A user with WP-CLI access can create (super) administrators, modify database entries, and override any permissions manually. Since WP-CLI is an inherently privileged tool, enforcing capability checks does not add security but creates unnecessary roadblocks.
Inconsistent Behavior – Many WordPress functions rely on
current_user_can()
for capability checks. Contrary to running certain actions via the UI, when running them with WP-CLI, these checks fail unexpectedly, requiring developers to set the current user for the command manually. This adds extra complexity without clear benefits.Enhancing Developer Experience – WP-CLI is meant to streamline administrative tasks. Making
current_user_can()
always returntrue
would eliminate the need for workarounds, improving the efficiency of developers and system administrators.Alternative Approaches:
WP_CLI
-specific filter (e.g.,wp_cli_always_allow_caps
) could be introduced to optionally override capability checks when WP-CLI is in use.current_user_can()
could returntrue
only for critical capabilities likeassign_terms
,edit_posts
, andmanage_options
.--user
could be used to work around the issue, but it has drawbacks:I would love to hear your thoughts on whether this change would be beneficial. Are there any edge cases or unintended consequences that should be considered?
Thank you!
Beta Was this translation helpful? Give feedback.
All reactions