Use different action for admin context logic by schlessera · Pull Request #5663 · wp-cli/wp-cli

The -context=admin logic was hooking some of its logic to the admin_init action. However, as the loading was adapted, the requirement for triggering the admin_init action ended up within the action's closures, causing the entire construct to not be executed at all.

This PR changes the --context=admin logic to use init instead of admin_init, and adds custom (hacky) logic to load the admin environment accordingly.

This hacky approach for loading the admin environment is used to ensure we stick with the behavior of whatever WordPress version is being used. Inlining the code would make this hard to accomplish.