Skip to content

Refactor wp config create to set config values through WPConfigTransformer#226

Draft
Copilot wants to merge 8 commits into
mainfrom
copilot/refactor-config-command-validation
Draft

Refactor wp config create to set config values through WPConfigTransformer#226
Copilot wants to merge 8 commits into
mainfrom
copilot/refactor-config-command-validation

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 27, 2026

wp config create still had a separate value-writing path from the transformer-backed commands, which duplicated escaping/validation behavior and made new validation logic hard to centralize. This change makes create a thin wrapper: render defaults first, then apply requested values through wp-cli/wp-config-transformer.

  • Create flow now routes value writes through transformer

    • Render wp-config.mustache with baseline defaults (including empty placeholders for salts when needed).
    • After file creation, apply user-provided DB/table-prefix values via WPConfigTransformer::update().
    • Apply generated salts via WPConfigTransformer::update() when salts are generated.
    • Keep fallback remote salts injection behavior intact when local generation fails.
  • Removed create-specific escaping path

    • Deleted the legacy escape_config_value() path used only by create.
    • Value formatting/escaping behavior is now consistently handled by the transformer library for transformed entries.
  • Focused feature coverage for transformer-path escaping

    • Added a config create feature scenario covering special-character handling for DB_CHARSET to ensure values written through the transformer are preserved and readable via wp config get.
$config_transformer->update(
	'constant',
	'DB_CHARSET',
	$assoc_args['dbcharset'],
	[ 'add' => true ]
);

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor config command to always validate in config transformer library Refactor wp config create to set config values through WPConfigTransformer May 27, 2026
Copilot AI requested a review from swissspidy May 27, 2026 09:27
@swissspidy

This comment was marked as resolved.

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>

This comment was marked as resolved.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 27, 2026

Codecov Report

❌ Patch coverage is 92.00000% with 8 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/Config_Command.php 92.00% 8 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors wp config create so that config values are written via WPConfigTransformer, aligning the create flow with the transformer-backed config set/update behavior and centralizing escaping/formatting logic in the transformer library.

Changes:

  • Render wp-config.mustache with baseline defaults (and salt placeholders when generating salts), then apply user-provided DB/table-prefix values via WPConfigTransformer::update().
  • Apply locally generated salts via transformer updates, while preserving the remote-salts fallback when local generation fails.
  • Add a feature scenario to validate special-character handling for DB_CHARSET through the transformer-backed write path.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/Config_Command.php Refactors config create to render defaults first and then write user-provided values/salts using WPConfigTransformer.
features/config-create.feature Adds coverage ensuring DB_CHARSET values with quotes/backslashes are written/read correctly via transformer.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/Config_Command.php Outdated
Comment on lines +392 to +410
$config_transformer->update(
$entry['type'],
$entry['name'],
$assoc_args[ $arg_name ],
[ 'add' => true ]
);

if ( false !== strpos( $assoc_args[ $arg_name ], '\\' ) ) {
$config_transformer->remove( $entry['type'], $entry['name'] );
$config_transformer->add(
$entry['type'],
$entry['name'],
$assoc_args[ $arg_name ],
[
'anchor' => $entry['anchor'],
'placement' => 'before',
]
);
}
Comment thread src/Config_Command.php Outdated
Comment on lines +430 to +434
} catch ( Exception $exception ) {
WP_CLI::error( "Could not process the '{$wp_config_file_name}' transformation.\nReason: {$exception->getMessage()}" );
}

WP_CLI::success( "Generated '{$wp_config_file_name}' file." );
Copilot AI and others added 4 commits May 27, 2026 18:08
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor config command to always validate in config transformer library

3 participants