Tuesday, June 23, 2026
HomeEveryday WordPressBuild WP-CLI commands and automate maintenance with Acorn

Build WP-CLI commands and automate maintenance with Acorn


You likely have PHP scripts that do various jobs, such as cleaning up orphaned post metadata or deleting expired transients. Over time, that collection grows and lives in a theme file, a plugin folder, or a tucked-away directory. Acorn helps to rein in this disorganization by bringing Laravel’s Artisan Console to WordPress.

This means you can build custom WP-CLI commands with structured class files that centralize your maintenance logic. These commands run consistently across development, staging, and production using progress indicators, formatted table output, proper error handling, and more. You can then trigger them via SSH, schedule them with cron jobs, or execute them during deployments.

How to install Acorn and run commands

The first step is to install the dependencies you need. Acorn needs PHP 8.2 or higher, Composer for managing dependencies, and WP-CLI running on your server. Kinsta includes WP-CLI on all hosting plans, so you can start building commands straight away.

You install Acorn through Composer using composer require roots/acorn within the project root. Then add boot code to either your theme’s functions.php file or your main plugin file:

 'https://roots.io/acorn/docs/installation/',
            'link_text' => __('Acorn Docs: Installation', 'domain'),
        ]
    );
}

add_action('after_setup_theme', function () {
    Application::configure()
        ->withProviders([
            AppProvidersThemeServiceProvider::class,
        ])
        ->boot();
}, 0);

The zero-config setup stores application cache and logs in the WordPress cache directory at [wp-content]/cache/acorn/, with your commands living in the theme’s app/ directory.

The traditional structure follows Laravel conventions, such as dedicated directories for app/, config/, storage/, and resources/ at your project root. You set this up with one line:

wp acorn acorn:init storage && wp acorn vendor:publish --tag=acorn

If you run wp acorn list, this verifies your installation by displaying all the available Acorn commands. From this point, all custom commands you create are stored in the app/Console/Commands/ directory. Acorn automatically discovers any command classes in this location and registers them with WP-CLI.



Source link

RELATED ARTICLES
Continue to the category

LEAVE A REPLY

Please enter your comment!
Please enter your name here


Most Popular

Recent Comments