Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Wp Config Transformer Laravel Package

wp-cli/wp-config-transformer

WP-CLI utility for safely reading and modifying WordPress wp-config.php values. Add, update, or remove constants, variables, and settings without manual editing, enabling reliable, scriptable configuration changes in automation and deployment workflows.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Installation Add the package via Composer in your Laravel project:

    composer require wp-cli/wp-config-transformer
    
  2. Basic Usage Initialize the transformer in a Laravel service or command:

    use WP_CLI\Utils\get_config_transformer;
    
    $transformer = get_config_transformer();
    $config = $transformer->get_config();
    
  3. First Use Case Update a single wp-config.php setting (e.g., DB_NAME):

    $transformer->set_config([
        'DB_NAME' => 'new_database_name',
    ]);
    $transformer->save_config();
    

Where to Look First


Implementation Patterns

Workflows

  1. Dynamic Configuration Updates Use in Laravel migrations or deploy scripts to sync wp-config.php with environment variables:

    $transformer->set_config([
        'DB_HOST' => env('DB_HOST'),
        'DB_USER' => env('DB_USER'),
        'DB_PASSWORD' => env('DB_PASSWORD'),
    ]);
    $transformer->save_config();
    
  2. Multi-Environment Handling Load different wp-config.php templates per environment (e.g., wp-config.staging.php):

    $transformer = get_config_transformer(config_path('wp-config.staging.php'));
    
  3. Seeding Defaults Pre-populate wp-config.php during Laravel’s bootstrap/app.php or a custom service provider:

    public function boot()
    {
        $transformer = get_config_transformer();
        if (!$transformer->get_config('AUTH_KEY')) {
            $transformer->set_config([
                'AUTH_KEY' => Str::random(64),
                'SECURE_AUTH_KEY' => Str::random(64),
                // ... other salts
            ]);
            $transformer->save_config();
        }
    }
    

Integration Tips

  • Laravel Filesystem: Use Storage::disk('local')->exists() to check for wp-config.php before transforming.
  • Validation: Combine with Laravel’s Validator to ensure config values meet expectations (e.g., DB_PASSWORD length).
  • Rollback Safety: Wrap transformations in transactions or backup wp-config.php before modifying:
    $backup = copy(config_path('wp-config.php'), config_path('wp-config.backup.php'));
    // ... transformations ...
    if ($backup) {
        unlink(config_path('wp-config.backup.php'));
    }
    

Gotchas and Tips

Pitfalls

  1. File Permissions

    • Ensure the Laravel app has write permissions for wp-config.php (typically 644).
    • Debug with: chmod 644 storage/wp-config.php (adjust path as needed).
  2. Path Resolution

    • The transformer defaults to wp-config.php in the current directory. Explicitly pass the full path:
      $transformer = get_config_transformer(public_path('wp-config.php'));
      
  3. Syntax Errors

    • Invalid PHP in wp-config.php (e.g., unclosed quotes) will break the transformer. Validate with:
      php -l /path/to/wp-config.php
      
  4. Caching

    • The transformer caches parsed config. Clear cache after manual edits:
      $transformer->clear_cache();
      

Debugging

  • Dry Runs: Use get_config() to inspect values before saving:
    print_r($transformer->get_config());
    
  • Logging: Log transformations for auditing:
    \Log::info('Updated wp-config', ['changes' => $transformer->get_config()]);
    

Extension Points

  1. Custom Config Keys Extend the transformer to handle non-standard keys (e.g., Laravel’s APP_DEBUG):

    $transformer->set_config([
        'APP_DEBUG' => env('APP_DEBUG', false),
        'WP_DEBUG' => env('WP_DEBUG', false),
    ]);
    
  2. Pre/Post Hooks Add Laravel events to trigger before/after transformations:

    event(new \App\Events\WpConfigUpdating($transformer->get_config()));
    $transformer->save_config();
    event(new \App\Events\WpConfigUpdated($transformer->get_config()));
    
  3. WP-CLI Integration Chain with WP-CLI commands for advanced use cases:

    wp config transform --path=/path/to/wp-config.php --set=DB_NAME=test_db
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle