Skip to content

Conversation

schlessera
Copy link
Member

@schlessera schlessera commented Nov 17, 2021

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 an is_admin() check.
  • auto: Switches between cli and admin depending on which command is being used. For this initial release, all wp plugin * and wp theme * commands will use admin, while all other commands will use cli.
  • frontend: [WIP] This does nothing yet.

By default, the --context flag will be set to cli with this initial release (v2.5.1). With WP-CLI v2.6.0, the default will change to auto. 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.

@schlessera schlessera added this to the 2.5.1 milestone Nov 17, 2021
@schlessera schlessera marked this pull request as ready for review November 22, 2021 17:41
@schlessera schlessera requested a review from a team as a code owner November 22, 2021 17:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant