src/Config_Command.php
public function set( $args, $assoc_args ) {
		$path = $this->get_config_path();

		list( $name, $value ) = $args;
		$type                 = Utils\get_flag_value( $assoc_args, 'type' );

		$options = array();

		$option_flags = array(
			'raw'       => false,
			'add'       => true,
			'anchor'    => null,
			'placement' => null,
			'separator' => null,
		);

		foreach ( $option_flags as $option => $default ) {
			$option_value = Utils\get_flag_value( $assoc_args, $option, $default );
			if ( null !== $option_value ) {
				$options[ $option ] = $option_value;
				if ( 'separator' === $option ) {
					$options['separator'] = $this->parse_separator( $options['separator'] );
				}
			}
		}

		$adding = false;
		try {
			$config_transformer = new WPConfigTransformer( $path );

			switch ( $type ) {
				case 'all':
					$has_constant = $config_transformer->exists( 'constant', $name );
					$has_variable = $config_transformer->exists( 'variable', $name );
					if ( $has_constant && $has_variable ) {
						WP_CLI::error( "Found both a constant and a variable '{$name}' in the 'wp-config.php' file. Use --type=<type> to disambiguate." );
					}
					if ( ! $has_constant && ! $has_variable ) {
						if ( ! $options['add'] ) {
							$message = "The constant or variable '{$name}' is not defined in the 'wp-config.php' file.";
							WP_CLI::error( $message );
						}
						$type   = 'constant';
						$adding = true;
					} else {
						$type = $has_constant ? 'constant' : 'variable';
					}
					break;
				case 'constant':
				case 'variable':
					if ( ! $config_transformer->exists( $type, $name ) ) {
						if ( ! $options['add'] ) {
							WP_CLI::error( "The {$type} '{$name}' is not defined in the 'wp-config.php' file." );
						}
						$adding = true;
					}
			}

			$config_transformer->update( $type, $name, $value, $options );

		} catch ( Exception $exception ) {
			WP_CLI::error( "Could not process the 'wp-config.php' transformation.\nReason: {$exception->getMessage()}" );
		}

		$raw = $options['raw'] ? 'raw ' : '';
		if ( $adding ) {
			$message = "Added the {$type} '{$name}' to the 'wp-config.php' file with the {$raw}value '{$value}'.";
		} else {
			$message = "Updated the {$type} '{$name}' in the 'wp-config.php' file with the {$raw}value '{$value}'.";
		}

		WP_CLI::success( $message );
	}
public function set( $args, $assoc_args ) {
		$path = $this->get_config_path();

		list( $name, $value ) = $args;
		$type                 = Utils\get_flag_value( $assoc_args, 'type' );

		$options = array();

		$option_flags = array(
			'raw'       => false,
			'add'       => true,
			'anchor'    => null,
			'placement' => null,
			'separator' => null,
		);

		foreach ( $option_flags as $option => $default ) {
			$option_value = Utils\get_flag_value( $assoc_args, $option, $default );
			if ( null !== $option_value ) {
				$options[ $option ] = $option_value;
				if ( 'separator' === $option ) {
					$options['separator'] = $this->parse_separator( $options['separator'] );
				}
			}
		}

		$adding = false;
		try {
			$config_transformer = new WPConfigTransformer( $path );

			switch ( $type ) {
				case 'all':
					$has_constant = $config_transformer->exists( 'constant', $name );
					$has_variable = $config_transformer->exists( 'variable', $name );
					if ( $has_constant && $has_variable ) {
						WP_CLI::error( "Found both a constant and a variable '{$name}' in the 'wp-config.php' file. Use --type=<type> to disambiguate." );
					}
					if ( ! $has_constant && ! $has_variable ) {
						if ( ! $options['add'] ) {
							$message = "The constant or variable '{$name}' is not defined in the 'wp-config.php' file.";
							WP_CLI::error( $message );
						}
						$type   = 'constant';
						$adding = true;
					} else {
						$type = $has_constant ? 'constant' : 'variable';
					}
					break;
				case 'constant':
				case 'variable':
					if ( ! $config_transformer->exists( $type, $name ) ) {
						if ( ! $options['add'] ) {
							WP_CLI::error( "The {$type} '{$name}' is not defined in the 'wp-config.php' file." );
						}
						$adding = true;
					}
			}

			$config_transformer->update( $type, $name, $value, $options );

		} catch ( Exception $exception ) {
			WP_CLI::error( "Could not process the 'wp-config.php' transformation.\nReason: {$exception->getMessage()}" );
		}

		$raw = $options['raw'] ? 'raw ' : '';
		if ( $adding ) {
			$message = "Added the {$type} '{$name}' to the 'wp-config.php' file with the {$raw}value '{$value}'.";
		} else {
			$message = "Updated the {$type} '{$name}' in the 'wp-config.php' file with the {$raw}value '{$value}'.";
		}

		WP_CLI::success( $message );
	}
public function set ( $ args , $ assoc_args ) { $ path = $ this -> get_config_path ( ) ; list ( $ name , $ value ) = $ args ; $ type = Utils \ get_flag_value ( $ assoc_args , 'type' ) ; $ options = array ( ) ; $ option_flags = array ( 'raw' => false , 'add' => true , 'anchor' => null , 'placement' => null , 'separator' => null , ) ; foreach ( $ option_flags as $ option => $ default ) { $ option_value = Utils \ get_flag_value ( $ assoc_args , $ option , $ default ) ; if ( null !== $ option_value ) { $ options [ $ option ] = $ option_value ; if ( 'separator' === $ option ) { $ options [ 'separator' ] = $ this -> parse_separator ( $ options [ 'separator' ] ) ; } } } $ adding = false ; try { $ config_transformer = new WPConfigTransformer ( $ path ) ; switch ( $ type ) { case 'all' : $ has_constant = $ config_transformer -> exists ( 'constant' , $ name ) ; $ has_variable = $ config_transformer -> exists ( 'variable' , $ name ) ; if ( $ has_constant && $ has_variable ) { WP_CLI :: error ( "Found both a constant and a variable '{$name}' in the 'wp-config.php' file. Use --type=<type> to disambiguate." ) ; } if ( ! $ has_constant && ! $ has_variable ) { if ( ! $ options [ 'add' ] ) { $ message = "The constant or variable '{$name}' is not defined in the 'wp-config.php' file." ; WP_CLI :: error ( $ message ) ; } $ type = 'constant' ; $ adding = true ; } else { $ type = $ has_constant ? 'constant' : 'variable' ; } break ; case 'constant' : case 'variable' : if ( ! $ config_transformer -> exists ( $ type , $ name ) ) { if ( ! $ options [ 'add' ] ) { WP_CLI :: error ( "The {$type} '{$name}' is not defined in the 'wp-config.php' file." ) ; } $ adding = true ; } } $ config_transformer -> update ( $ type , $ name , $ value , $ options ) ; } catch ( Exception $ exception ) { WP_CLI :: error ( "Could not process the 'wp-config.php' transformation.\nReason: {$exception->getMessage()}" ) ; } $ raw = $ options [ 'raw' ] ? 'raw ' : '' ; if ( $ adding ) { $ message = "Added the {$type} '{$name}' to the 'wp-config.php' file with the {$raw}value '{$value}'." ; } else { $ message = "Updated the {$type} '{$name}' in the 'wp-config.php' file with the {$raw}value '{$value}'." ; } WP_CLI :: success ( $ message ) ; }
Sets the value of a specific constant or variable defined in wp-config.php file.

## OPTIONS

<name>
: Name of the wp-config.php constant or variable.

<value>
: Value to set the wp-config.php constant or variable to.

[--add]
: Add the value if it doesn't exist yet.
This is the default behavior, override with --no-add.

[--raw]
: Place the value into the wp-config.php file as is, instead of as a quoted string.

[--anchor=<anchor>]
: Anchor string where additions of new values are anchored around.
Defaults to "/* That's all, stop editing!".

[--placement=<placement>]
: Where to place the new values in relation to the anchor string.
---
default: 'before'
options:
- before
- after
---

[--separator=<separator>]
: Separator string to put between an added value and its anchor string.
The following escape sequences will be recognized and properly interpreted: '\n' => newline, '\r' => carriage return, '\t' => tab.
Defaults to a single EOL ("\n" on *nix and "\r\n" on Windows).

[--type=<type>]
: Type of the config value to set. Defaults to 'all'.
---
default: all
options:
- constant
- variable
- all
---

## EXAMPLES

# Set the WP_DEBUG constant to true.
$ wp config set WP_DEBUG true --raw

@when before_wp_load
Sets the value of a specific constant or variable defined in wp - config . php file .