wp-cli / wp-config-transformer

Programmatically edit a wp-config.php file
MIT License
81 stars 25 forks source link

I should be able to define new configs without an anchor point #10

Closed frankiejarrett closed 5 years ago

frankiejarrett commented 5 years ago

Attempting to add a new definition to an invalid anchor point will result in an error:

$config_transformer->add( 'constant', 'FOO', 'bar', [ 'anchor' => 'doesnotexist' ] );
// Fatal error: Uncaught Exception: Unable to locate placement anchor.

This requires the user to know the complete contents of the config file ahead of time so a real anchor point can be specified. This may not be possible in cases where a config file has been heavily modified by someone else.

I think users should be able to specify [ 'anchor' => false ] to anchor new definitions at the EOF.

schlessera commented 5 years ago

Yes, makes sense to have [ 'anchor' => false ] as a way to "append to EOF".

schlessera commented 5 years ago

We should even prefer to use a constant for this instead:

[ 'anchor' => WPConfigTransformer::NO_ANCHOR ]

When we map this to a flag in the config command later on, it should be irrelevant what the actual value of the constant is.

schlessera commented 5 years ago

Fixed via #23