WP_CLI

Runner::check_root()privateWP-CLI 1.0

Метод класса: Runner{}

Хуков нет.

Возвращает

null. Ничего (null).

Использование

// private - только в коде основоного (родительского) класса
$result = $this->check_root();

Код Runner::check_root() WP-CLI 2.8.0-alpha

private function check_root() {
	if ( $this->config['allow-root'] || getenv( 'WP_CLI_ALLOW_ROOT' ) ) {
		return; # they're aware of the risks!
	}
	if ( count( $this->arguments ) >= 2 && 'cli' === $this->arguments[0] && in_array( $this->arguments[1], [ 'update', 'info' ], true ) ) {
		return; # make it easier to update root-owned copies
	}
	if ( ! function_exists( 'posix_geteuid' ) ) {
		return; # posix functions not available
	}
	if ( posix_geteuid() !== 0 ) {
		return; # not root
	}

	WP_CLI::error(
		"YIKES! It looks like you're running this as root. You probably meant to " .
		"run this as the user that your WordPress installation exists under.\n" .
		"\n" .
		"If you REALLY mean to run this as root, we won't stop you, but just " .
		'bear in mind that any code on this site will then have full control of ' .
		"your server, making it quite DANGEROUS.\n" .
		"\n" .
		"If you'd like to continue as root, please run this again, adding this " .
		"flag:  --allow-root\n" .
		"\n" .
		"If you'd like to run it as the user that this site is under, you can " .
		"run the following to become the respective user:\n" .
		"\n" .
		"    sudo -u USER -i -- wp <command>\n" .
		"\n"
	);
}