PHP code example of wp-cli / wp-config-transformer

1. Go to this page and download the library: Download wp-cli/wp-config-transformer library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

wp-cli / wp-config-transformer example snippets


$config_transformer = new WPConfigTransformer( '/path/to/wp-config.php' );

$config_transformer->update( 'constant', 'WP_DEBUG', 'true', array( 'raw' => true ) );
$config_transformer->add( 'constant', 'MY_SPECIAL_CONFIG', 'foo' );
$config_transformer->remove( 'constant', 'MY_SPECIAL_CONFIG' );

$config_transformer->update( 'variable', 'table_prefix', 'wp_custom_' );
$config_transformer->add( 'variable', 'my_special_global', 'foo' );
$config_transformer->remove( 'variable', 'my_special_global' );

if ( $config_transformer->exists( 'constant', 'MY_SPECIAL_CONFIG' ) ) {
	// do stuff
}

if ( $config_transformer->exists( 'variable', 'my_special_global' ) ) {
	// do stuff
}

                 define   (    'WP_DEBUG'   ,
    false, false     )
;

$config_transformer->update( 'constant', 'WP_DEBUG', 'true', array( 'raw' => true, 'normalize' => true ) );

define( 'WP_DEBUG', true );

$config_transformer->update( 'constant', 'ABSPATH', "dirname( __FILE__ ) . '/somewhere/else/'", array( 'raw' => true ) );

$config_transformer->update( 'constant', 'FOO', 'bar', array( 'anchor' => '/** Absolute path to the WordPress directory' ) ); // Default

$config_transformer->update( 'constant', 'FOO', 'bar', array( 'placement' => 'before' ) ); // Default
$config_transformer->update( 'constant', 'BAZ', 'qux', array( 'placement' => 'after' ) );

$config_transformer->update( 'constant', 'FOO', 'bar', array( 'separator' => PHP_EOL . PHP_EOL ) ); // Default
$config_transformer->update( 'constant', 'FOO', 'bar', array( 'separator' => PHP_EOL ) );

$config_transformer->update( 'constant', 'FOO', 'bar', array( 'add' => true ) ); // Default
$config_transformer->update( 'constant', 'FOO', 'bar', array( 'add' => false ) );

$config_transformer->exists( 'constant', 'FOO' ); // Returns false
$config_transformer->update( 'constant', 'FOO', 'bar', array( 'add' => false ) ); // Returns false

                 define   (    'WP_DEBUG'   ,
    false, false     )
;

$config_transformer->update( 'constant', 'WP_DEBUG', 'true', array( 'raw' => true ) );

                 define   (    'WP_DEBUG'   ,
    true, false     )
;

$config_transformer->update( 'constant', 'FOO', 'bar', array( 'anchor' => '/** My special location' ) );

if ( $config_transformer->exists( 'constant', 'FOO' ) ) {
    $config_transformer->update( 'constant', 'FOO', 'bar' );
} else {
    $config_transformer->add( 'constant', 'FOO', 'bar', array( 'anchor' => '/** My special area' ) );
}

define( 'WP_DEBUG', true );
define( 'WP_SCRIPT_DEBUG', true );
$table_prefix = 'wp_';
$my_var = 'foo';

define( 'WP_DEBUG', true ); define( 'WP_SCRIPT_DEBUG', true );
$table_prefix = 'wp_'; $my_var = 'foo';

define( 'WP_DEBUG', true, false );
define( 'WP_DEBUG', true, FALSE );
define( 'foo', true, true );
define( 'foo', true, TRUE );

define( 'WP_DEBUG', true, 0 );
define( 'WP_DEBUG', true, 'yes' );
define( 'WP_DEBUG', true, 'this comma, will break everything' );