WP_CLI\Context
Admin::process
Process the context to set up the environment correctly.
Method of the class: Admin{}
No Hooks.
Returns
null. Nothing (null).
Usage
$Admin = new Admin(); $Admin->process( $config );
- $config(array) (required)
- Associative array of configuration data.
Admin::process() Admin::process code WP-CLI 2.13.0-alpha
public function process( $config ) {
if ( defined( 'WP_ADMIN' ) ) {
if ( ! WP_ADMIN ) {
WP_CLI::warning( 'Could not fake admin request.' );
}
return;
}
WP_CLI::debug( 'Faking an admin request', Context::DEBUG_GROUP );
// Define `WP_ADMIN` as being true. This causes the helper method
// `is_admin()` to return true as well.
define( 'WP_ADMIN', true ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedConstantFound
// Set a fake entry point to ensure wp-includes/vars.php does not throw
// notices/errors. This will be reflected in the global `$pagenow`
// variable being set to 'wp-cli-fake-admin-file.php'.
$_SERVER['PHP_SELF'] = '/wp-admin/wp-cli-fake-admin-file.php';
// Bootstrap the WordPress administration area.
WP_CLI::add_wp_hook(
'init',
function () {
$this->log_in_as_admin_user();
$this->load_admin_environment();
},
defined( 'PHP_INT_MIN' ) ? PHP_INT_MIN : -2147483648, // phpcs:ignore PHPCompatibility.Constants.NewConstants.php_int_minFound
0
);
}