Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
New global flag:
--context
This PR adds a new global parameter
--context=<context>
which allows users to select in which WordPress context WP-CLI is supposed to execute its command(s).One of the main goals is to allow WP-CLI to run updates on premium plugins and themes without requiring any special setup.
Possible flags with this initial release:
cli
: The context which has been the default before introduction of this flag. This is something in-between a frontend and an admin request, to get around some of the quirks of WordPress when running on the console.admin
: A context that simulates running a command as if it would be executed in the administration backend. This is meant to be used to get around issues with plugins that limit functionality behind anis_admin()
check.auto
: Switches betweencli
andadmin
depending on which command is being used. For this initial release, allwp plugin *
andwp theme *
commands will useadmin
, while all other commands will usecli
.frontend
: [WIP] This does nothing yet.By default, the
--context
flag will be set tocli
with this initial release (v2.5.1). With WP-CLI v2.6.0, the default will change toauto
. This gradual deployment will allow hosters and site owners to run tests on v2.5.1 by manually setting the context before the default behavior is changed.New hook
before_registering_contexts
This PR adds a new hook
before_registering_contexts
which behaves like a filter with one argument:array<string, Context> $contexts
. When hooking into this hook, the callback should return (a potentially modified)$contexts
value. This can be used to remove or override bundled contexts or add new ones.To make this work, the hook functionality in WP-CLI (provided via
WP_CLI::do_hook()
) was modified to return the first argument if arguments were provided.Thanks to Cloudways for the special support and testing with the goal of solving the premium updates problem for everyone.