src/WPConfigTransformer.php
public function update( $type, $name, $value, array $options = array() ) {
		if ( ! is_string( $value ) ) {
			throw new Exception( 'Config value must be a string.' );
		}

		$defaults = array(
			'add'       => true, // Add the config if missing.
			'raw'       => false, // Display value in raw format without quotes.
			'normalize' => false, // Normalize config output using WP Coding Standards.
		);

		list( $add, $raw, $normalize ) = array_values( array_merge( $defaults, $options ) );

		$add       = (bool) $add;
		$raw       = (bool) $raw;
		$normalize = (bool) $normalize;

		if ( ! $this->exists( $type, $name ) ) {
			return ( $add ) ? $this->add( $type, $name, $value, $options ) : false;
		}

		$old_src   = $this->wp_configs[ $type ][ $name ]['src'];
		$old_value = $this->wp_configs[ $type ][ $name ]['value'];
		$new_value = $this->format_value( $value, $raw );

		if ( $normalize ) {
			$new_src = $this->normalize( $type, $name, $new_value );
		} else {
			$new_parts    = $this->wp_configs[ $type ][ $name ]['parts'];
			$new_parts[1] = str_replace( $old_value, $new_value, $new_parts[1] ); // Only edit the value part.
			$new_src      = implode( '', $new_parts );
		}

		$contents = preg_replace(
			sprintf( '/(?<=^|;|<\?php\s|<\?\s)(\s*?)%s/m', preg_quote( trim( $old_src ), '/' ) ),
			'$1' . str_replace( '$', '\$', trim( $new_src ) ),
			$this->wp_config_src
		);

		return $this->save( $contents );
	}
public function update( $type, $name, $value, array $options = array() ) {
		if ( ! is_string( $value ) ) {
			throw new Exception( 'Config value must be a string.' );
		}

		$defaults = array(
			'add'       => true, // Add the config if missing.
			'raw'       => false, // Display value in raw format without quotes.
			'normalize' => false, // Normalize config output using WP Coding Standards.
		);

		list( $add, $raw, $normalize ) = array_values( array_merge( $defaults, $options ) );

		$add       = (bool) $add;
		$raw       = (bool) $raw;
		$normalize = (bool) $normalize;

		if ( ! $this->exists( $type, $name ) ) {
			return ( $add ) ? $this->add( $type, $name, $value, $options ) : false;
		}

		$old_src   = $this->wp_configs[ $type ][ $name ]['src'];
		$old_value = $this->wp_configs[ $type ][ $name ]['value'];
		$new_value = $this->format_value( $value, $raw );

		if ( $normalize ) {
			$new_src = $this->normalize( $type, $name, $new_value );
		} else {
			$new_parts    = $this->wp_configs[ $type ][ $name ]['parts'];
			$new_parts[1] = str_replace( $old_value, $new_value, $new_parts[1] ); // Only edit the value part.
			$new_src      = implode( '', $new_parts );
		}

		$contents = preg_replace(
			sprintf( '/(?<=^|;|<\?php\s|<\?\s)(\s*?)%s/m', preg_quote( trim( $old_src ), '/' ) ),
			'$1' . str_replace( '$', '\$', trim( $new_src ) ),
			$this->wp_config_src
		);

		return $this->save( $contents );
	}
public function update ( $ type , $ name , $ value , array $ options = array ( ) ) { if ( ! is_string ( $ value ) ) { throw new Exception ( 'Config value must be a string.' ) ; } $ defaults = array ( 'add' => true , // Add the config if missing. 'raw' => false , // Display value in raw format without quotes. 'normalize' => false , // Normalize config output using WP Coding Standards. ) ; list ( $ add , $ raw , $ normalize ) = array_values ( array_merge ( $ defaults , $ options ) ) ; $ add = ( bool ) $ add ; $ raw = ( bool ) $ raw ; $ normalize = ( bool ) $ normalize ; if ( ! $ this -> exists ( $ type , $ name ) ) { return ( $ add ) ? $ this -> add ( $ type , $ name , $ value , $ options ) : false ; } $ old_src = $ this -> wp_configs [ $ type ] [ $ name ] [ 'src' ] ; $ old_value = $ this -> wp_configs [ $ type ] [ $ name ] [ 'value' ] ; $ new_value = $ this -> format_value ( $ value , $ raw ) ; if ( $ normalize ) { $ new_src = $ this -> normalize ( $ type , $ name , $ new_value ) ; } else { $ new_parts = $ this -> wp_configs [ $ type ] [ $ name ] [ 'parts' ] ; $ new_parts [ 1 ] = str_replace ( $ old_value , $ new_value , $ new_parts [ 1 ] ) ; // Only edit the value part. $ new_src = implode ( '' , $ new_parts ) ; } $ contents = preg_replace ( sprintf ( '/(?<=^|;|<\?php\s|<\?\s)(\s*?)%s/m' , preg_quote ( trim ( $ old_src ) , '/' ) ) , '$1' . str_replace ( '$' , '\$' , trim ( $ new_src ) ) , $ this -> wp_config_src ) ; return $ this -> save ( $ contents ) ; }
Updates an existing config in the wp-config.php file.

@throws Exception If the config value provided is not a string.

@param string $type    Config type (constant or variable).
@param string $name    Config name.
@param string $value   Config value.
@param array  $options (optional) Array of special behavior options.

@return bool
Updates an existing config in the wp - config . php file .