--context flag for determining the context in which WordPress is loaded#385
--context flag for determining the context in which WordPress is loaded#385danielbachhuber wants to merge 4 commits intomasterfrom
Conversation
|
Needs functional tests, regardless of the implementation. |
|
See |
We don't actually need to also load /wp-admin/includes/admin.php, as it's loaded already at the bottom of wp-cli.php
|
This is good to go. We're already loading all of the admin utilities at the bottom of |
features/flags.feature
Outdated
There was a problem hiding this comment.
How about casting to (bool)? Would be more explicit.
In that case, why not just always set WP_ADMIN to true? We could skip |
|
What I mean is that the default context should be 'admin', since when you're using WP-CLI, you're not displaying a template; you're performing administrative actions. And since I don't want to think about other contexts right now, we don't need the |
This is why commit messages should explain why, not just what: 5b6efb9 I don't have a strong opinion against always defining WP_ADMIN as true, other than WP_Query behavior changes in a substantial way. |
|
And that brought up #351, which was similar to my idea of using WP-CLI for unit testing, but I think this bit is spot on:
So, no |
|
In summary: WP-CLI has always loaded most of the code for wp-admin because most commands need it. Then, it sort of pretended it was also loading the front-end, for doing integration testing. (#69) Then it pretended it was loading wp-admin, to side-step caching plugins. (#164) Then it stopped pretending it was loading wp-admin, because we found a better way to side-step caching plugins. (#352) TODO:
|
|
Ok, this sounds reasonable to me. I'll let you take the lead on resolving how it should be done. Let me know if I can help in any way. |
|
Going to continue working on this PR, since it has all the background now. |
|
Took a look through
All the rest are related to specific admin screens. |
Most of the built-in commands need access to code from wp-admin/includes/ so it makes sense to load it upfront. Since we're already doing that, it seems like a good idea to also announce this fact to plugins, by setting WP_ADMIN to true. And since we're setting WP_ADMIN to true, we don't need to set up the global $wp_query instance anymore, because the only admin screen where it's set is the post list screen (wp-admin/edit.php). See #385
... where "loading WordPress" also includes loading plugins and themes. Also, define WP_NETWORK_ADMIN and WP_USER_ADMIN, for completeness. see #385
It's a good approach, but not great. I partially feel like we need to alter the entire wp-cli load process (e.g. requiring
wp-admin/index.php) in order to properly load the admin context. Opinions welcome.