WP_CLI

Runner::get_global_config_path()publicWP-CLI 1.0

Get the path to the global configuration YAML file.

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

Хуков нет.

Возвращает

Строку|false.

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

$Runner = new Runner();
$Runner->get_global_config_path( $create_config_file );
$create_config_file(true|false)
If a config file doesn't exist, should it be created? Defaults to false.
По умолчанию: false

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

public function get_global_config_path( $create_config_file = false ) {

	if ( getenv( 'WP_CLI_CONFIG_PATH' ) ) {
		$config_path                    = getenv( 'WP_CLI_CONFIG_PATH' );
		$this->global_config_path_debug = 'Using global config from WP_CLI_CONFIG_PATH env var: ' . $config_path;
	} else {
		$config_path                    = Utils\get_home_dir() . '/.wp-cli/config.yml';
		$this->global_config_path_debug = 'Using default global config: ' . $config_path;
	}

	// If global config doesn't exist create one.
	if ( true === $create_config_file && ! file_exists( $config_path ) ) {
		$this->global_config_path_debug = "Default global config doesn't exist, creating one in {$config_path}";
		Process::create( Utils\esc_cmd( 'touch %s', $config_path ) )->run();
	}

	if ( is_readable( $config_path ) ) {
		return $config_path;
	}

	$this->global_config_path_debug = 'No readable global config found';

	return false;
}