WP_CLI
Runner::get_wp_config_code
Returns wp-config.php code, skipping the loading of wp-settings.php.
Метод класса: Runner{}
Хуков нет.
Возвращает
Строку.
Использование
$Runner = new Runner(); $Runner->get_wp_config_code( $wp_config_path );
- $wp_config_path(строка)
- Config file path. If left empty, it tries to locate the wp-config.php file automatically.
По умолчанию:''
Код Runner::get_wp_config_code() Runner::get wp config code WP-CLI 2.13.0-alpha
public function get_wp_config_code( $wp_config_path = '' ) {
if ( empty( $wp_config_path ) ) {
$wp_config_path = Utils\locate_wp_config();
}
$wp_config_code = file_get_contents( $wp_config_path );
// Detect and strip byte-order marks (BOMs).
// This code assumes they can only be found on the first line.
foreach ( self::BYTE_ORDER_MARKS as $bom_name => $bom_sequence ) {
WP_CLI::debug( "Looking for {$bom_name} BOM", 'bootstrap' );
$length = strlen( $bom_sequence );
while ( substr( $wp_config_code, 0, $length ) === $bom_sequence ) {
WP_CLI::warning(
"{$bom_name} byte-order mark (BOM) detected in wp-config.php file, stripping it for parsing."
);
$wp_config_code = substr( $wp_config_code, $length );
}
}
$count = 0;
$wp_config_code = preg_replace( '/\s*require(?:_once)?\s*.*wp-settings\.php.*\s*;/', '', $wp_config_code, -1, $count );
if ( 0 === $count ) {
WP_CLI::error( 'Strange wp-config.php file: wp-settings.php is not loaded directly.' );
}
$source = Utils\replace_path_consts( $wp_config_code, $wp_config_path );
return preg_replace( '|^\s*\<\?php\s*|', '', $source );
}