WP_CLI

Runner::get_wp_config_code()publicWP-CLI 1.0

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() WP-CLI 2.8.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 = explode( "\n", 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], 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[0] = substr( $wp_config_code[0], $length );
		}
	}

	$found_wp_settings = false;

	$lines_to_run = [];

	foreach ( $wp_config_code as $line ) {
		if ( preg_match( '/^\s*require.+wp-settings\.php/', $line ) ) {
			$found_wp_settings = true;
			continue;
		}

		$lines_to_run[] = $line;
	}

	if ( ! $found_wp_settings ) {
		WP_CLI::error( 'Strange wp-config.php file: wp-settings.php is not loaded directly.' );
	}

	$source = implode( "\n", $lines_to_run );
	$source = Utils\replace_path_consts( $source, $wp_config_path );
	return preg_replace( '|^\s*\<\?php\s*|', '', $source );
}