WP_CLI
Runner::get_global_config_path
Get the path to the global configuration YAML file.
Method of the class: Runner{}
No Hooks.
Returns
String|false.
Usage
$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.
Default:false
Runner::get_global_config_path() Runner::get global config path code WP-CLI 2.13.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}";
$dir = dirname( $config_path );
if ( ! is_dir( $dir ) ) {
mkdir( $dir, 0755, true );
}
touch( $config_path );
if ( file_exists( $config_path ) ) {
WP_CLI::debug( "Default global config does not exist, creating one in $config_path" );
}
}
if ( is_readable( $config_path ) ) {
return $config_path;
}
$this->global_config_path_debug = 'No readable global config found';
return false;
}