WP_CLI\Context

Admin::log_in_as_admin_user()privateWP-CLI 1.0

Ensure the current request is done under a logged-in administrator account.

A lot of premium plugins/themes have their custom update routines locked behind an is_admin() call.

Method of the class: Admin{}

No Hooks.

Return

null. Nothing.

Usage

// private - for code of main (parent) class only
$result = $this->log_in_as_admin_user();

Admin::log_in_as_admin_user() code WP-CLI 2.8.0-alpha

private function log_in_as_admin_user() {
	// TODO: Add logic to find an administrator user.
	$admin_user_id = 1;

	wp_set_current_user( $admin_user_id );

	$expiration = time() + DAY_IN_SECONDS;

	$_COOKIE[ AUTH_COOKIE ] = wp_generate_auth_cookie(
		$admin_user_id,
		$expiration,
		'auth'
	);

	$_COOKIE[ SECURE_AUTH_COOKIE ] = wp_generate_auth_cookie(
		$admin_user_id,
		$expiration,
		'secure_auth'
	);
}