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

Core Command Laravel Package

wp-cli/core-command

WP-CLI package providing the wp core command set to download, install, update, and manage WordPress core. Includes update checking via the Version Check API with flags for major/minor comparisons, forced checks, and flexible output formats.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Installation:

    composer require wp-cli/core-command
    

    Ensure wp-cli/wp-cli is also installed as a dependency.

  2. Basic Usage: Check if WordPress is installed in the current directory:

    wp core is-installed
    

    Exit code 0 means WordPress is installed; non-zero means it is not.

  3. First Use Case: Install WordPress in a new directory:

    wp core install --url=https://example.com --title="My Site" --admin_user=admin --admin_email=admin@example.com
    

Where to Look First

  • Command Reference: The package implements wp core commands. Run wp core --help to see all available subcommands.
  • Documentation: The README.md provides detailed usage examples for each command.
  • Source Code: The core logic is in src/Command/CoreCommand.php and related classes in the src/ directory.

Implementation Patterns

Usage Patterns

  1. Automated WordPress Setup: Use wp core download followed by wp core install in deployment scripts:

    wp core download --locale=en_US --path=/var/www/html
    wp core install --url=https://example.com --title="My Site" --admin_user=admin --admin_email=admin@example.com
    
  2. Update Workflows: Check for updates and apply them in a single command:

    wp core check-update --minor
    wp core update --minor --force
    
  3. Multisite Management: Convert an existing single-site to multisite:

    wp core multisite-convert --title="My Network" --subdomains
    
  4. CI/CD Integration: Use wp core is-installed to conditionally run WordPress-specific tasks:

    if wp core is-installed; then
        wp plugin install my-plugin
    else
        echo "WordPress not installed. Skipping plugin installation."
    fi
    

Workflows

  1. Local Development:

    • Use wp core download --locale=fr_FR to set up a French WordPress instance.
    • Test updates with --dry-run before applying them:
      wp core update-db --dry-run
      
  2. Server Maintenance:

    • Schedule wp core update in a cron job for automated updates.
    • Use wp core check-update-db --network to verify all sites in a multisite network are up-to-date.
  3. Custom Installations:

    • Skip default themes/plugins during download:
      wp core download --skip-content
      
    • Install WordPress in a subdirectory and update URLs afterward:
      wp core install --url=https://example.com/blog --title="Blog"
      wp option update siteurl https://example.com/blog
      

Integration Tips

  1. Laravel Artisan Integration: Create a custom Artisan command to wrap wp core commands:

    // app/Console/Commands/InstallWordPress.php
    namespace App\Console\Commands;
    
    use Illuminate\Console\Command;
    use Symfony\Component\Process\Process;
    
    class InstallWordPress extends Command
    {
        protected $signature = 'wp:install {url} {title} {email}';
        protected $description = 'Install WordPress using wp-cli';
    
        public function handle()
        {
            $process = new Process(['wp', 'core', 'install',
                '--url=' . $this->argument('url'),
                '--title=' . $this->argument('title'),
                '--admin_user=admin',
                '--admin_email=' . $this->argument('email')
            ]);
            $process->run();
            $this->output->writeln($process->getOutput());
        }
    }
    

    Register the command in app/Console/Kernel.php:

    protected $commands = [
        Commands\InstallWordPress::class,
    ];
    

    Run with:

    php artisan wp:install https://example.com "My Site" admin@example.com
    
  2. Environment-Specific Configurations: Use Laravel's .env to store sensitive data (e.g., admin passwords) and pass them securely:

    wp core install --url=https://example.com --title="My Site" --admin_user=admin --admin_email=admin@example.com --prompt=admin_password < <(echo -n "securepassword123")
    
  3. Logging and Error Handling: Redirect output to Laravel logs for debugging:

    $process = new Process(['wp', 'core', 'update']);
    $process->run(function ($type, $buffer) {
        \Log::info($buffer);
    });
    

Gotchas and Tips

Pitfalls

  1. Permission Issues:

    • Ensure the web server user (e.g., www-data, nginx) has write permissions to the WordPress directory and wp-content.
    • Use --force cautiously; it may overwrite critical files if misused.
  2. Multisite Rewrite Rules: After converting to multisite, manually update .htaccess or nginx.conf to avoid 404 errors. The package does not automate this.

  3. Locale Limitations: Downloading a locale for an older WordPress version may fail. Use --skip-locale-check to bypass this:

    wp core download --locale=fr_FR --version=5.0 --skip-locale-check
    
  4. Update Locks: If you see Error: Another update is currently in progress, clear the lock manually:

    wp option delete core_updater.lock
    
  5. Network vs. Single-Site: Commands like wp core check-update-db --network require a multisite installation. Misuse may lead to unexpected behavior.

Debugging

  1. Verbose Output: Use --debug with WP-CLI for detailed logs (requires WP-CLI >= 2.0):

    WP_CLI_DEBUG=1 wp core update
    
  2. Dry Runs: Always test database updates with --dry-run first:

    wp core update-db --dry-run
    
  3. Checksum Failures: If checksums fail during updates, use --insecure temporarily (not recommended for production):

    wp core update --insecure
    

Tips

  1. Custom Paths: Specify a custom path for downloads/installations to avoid cluttering the current directory:

    wp core download --path=/tmp/wordpress
    
  2. Version Pinning: Update to a specific version (e.g., for testing):

    wp core update --version=5.8.2
    
  3. Output Formatting: Use --format=json for machine-readable output in scripts:

    wp core check-update --format=json
    
  4. Skip Emails: Avoid sending emails during automated installs:

    wp core install --skip-email
    
  5. Composer Integration: Use wp-cli/wp-cli and wp-cli/core-command together in composer.json:

    {
        "require": {
            "wp-cli/wp-cli": "^2.7",
            "wp-cli/core-command": "^2.5"
        }
    }
    
  6. Testing: Leverage Behat steps for automated testing. Example:

    Given a WP install
    When I run `wp core version`
    Then STDOUT should be a version string == "5.8.2"
    
  7. Caching: Downloaded WordPress files are cached locally. Clear the cache with:

    wp cache flush
    
  8. Subdirectory Installs: For subdirectory installs (e.g., /blog), update siteurl and home options post-install:

    wp option update siteurl https://example.com/blog
    wp option update home https://example.com/blog
    
  9. Custom User Tables: If using custom user tables (e.g., CUSTOM_USER_TABLE), ensure the tables exist before running wp core install. The package ignores admin_email and admin_password if the user already exists.

  10. HTTPS/SSL: For secure downloads, ensure your server trusts the WordPress SSL certificate. Use --insecure only as a last resort.

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