Skip to content

--context flag for determining the context in which WordPress is loaded#385

Closed
danielbachhuber wants to merge 4 commits intomasterfrom
context-admin
Closed

--context flag for determining the context in which WordPress is loaded#385
danielbachhuber wants to merge 4 commits intomasterfrom
context-admin

Conversation

@danielbachhuber
Copy link
Member

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.

@scribu
Copy link
Member

scribu commented Apr 12, 2013

Needs functional tests, regardless of the implementation.

@scribu
Copy link
Member

scribu commented Apr 12, 2013

See flags.feature for some examples.

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
@danielbachhuber
Copy link
Member Author

This is good to go. We're already loading all of the admin utilities at the bottom of wp-cli.php, so I think simply defining WP_ADMIN is all we need.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about casting to (bool)? Would be more explicit.

@scribu
Copy link
Member

scribu commented Apr 19, 2013

We're already loading all of the admin utilities at the bottom of wp-cli.php

In that case, why not just always set WP_ADMIN to true? We could skip Utils\set_wp_query() then.

@scribu
Copy link
Member

scribu commented Apr 19, 2013

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 --context flag at all, for the time being.

@scribu
Copy link
Member

scribu commented Apr 19, 2013

The $wp_query global handling was introduced way back in 8924c97 along with --url in #69.

In hindsight, I didn't end up using --url for functional testing. The WordPress test suite already has a handy go_to() method for that.

@danielbachhuber
Copy link
Member Author

In that case, why not just always set WP_ADMIN to true?

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.

@scribu
Copy link
Member

scribu commented Apr 19, 2013

This is why commit messages should explain why, not just what: 5b6efb9

That code was added in #164 and then removed as part of #352, but yeah, being part of a pull request isn't a good excuse.

@scribu
Copy link
Member

scribu commented Apr 19, 2013

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:

I know that a lot more would need to be built out to actually allow WP_CLI to mock up a front end page load, use the template loader, and so on

So, no --context=frontend for now.

@scribu
Copy link
Member

scribu commented Apr 19, 2013

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:

  • treat WP-CLI as an alternative UI to wp-admin
  • stop pretending to do a front-end page load

@danielbachhuber
Copy link
Member Author

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.

@scribu
Copy link
Member

scribu commented Apr 19, 2013

Going to continue working on this PR, since it has all the background now.

@scribu scribu reopened this Apr 19, 2013
@ghost ghost assigned scribu Apr 19, 2013
@scribu
Copy link
Member

scribu commented Apr 23, 2013

Took a look through wp-admin/admin.php (the file that gets loaded by all admin screens) and the only relevant bits I found were these:

  • defining WP_ADMIN, WP_USER_ADMIN and WP_NETWORK_ADMIN
  • load wp-load.php
  • load wp-admin/includes/admin.php
  • do_action('admin_init');
  • do_action('admin_action_' . $_REQUEST['action']);

All the rest are related to specific admin screens.

scribu added a commit that referenced this pull request Apr 23, 2013
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
@scribu scribu closed this Apr 23, 2013
@scribu scribu deleted the context-admin branch April 23, 2013 14:05
scribu added a commit that referenced this pull request Apr 23, 2013
... where "loading WordPress" also includes loading plugins and themes.

Also, define WP_NETWORK_ADMIN and WP_USER_ADMIN, for completeness.

see #385
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.

2 participants