Installation
# What is Acorn?
Acorn is a way to use Laravel components inside of WordPress.
# Why use Acorn?
Acorn brings elements of the Laravel ecosystem to any WordPress plugin or theme.
To put it simply, Acorn provides a way to gracefully load a Laravel application container inside of WordPress while respecting the WordPress lifecycle and template hierarchy.
This means you get access to Laravel's artisan commands through the use of wp acorn
. You can utilize Blade templates. You gain access to third-party packages built specifically for Acorn. And we provide some first-party components as well, such as view composers and assets management.
# Installing Acorn with Composer
We recommend that you install Acorn on your WordPress install managed by Composer, such as with Bedrock:
$ composer require roots/acorn
If you don't use Composer to manage your WordPress install and you are using a Sage-based theme, you can install Acorn with Composer from your theme directory. Navigate to your theme folder and then run the command above.
# Booting Acorn
Acorn must be booted in order to use it. Sage and Radicle already handle booting Acorn.
Boot Acorn in your own theme or plugin
Add the following in your theme's functions.php
file, or in your main plugin file:
<?php
if (! function_exists('\Roots\bootloader')) {
wp_die(
__('You need to install Acorn to use this site.', 'domain'),
'',
[
'link_url' => 'https://roots.io/acorn/docs/installation/',
'link_text' => __('Acorn Docs: Installation', 'domain'),
]
);
}
add_action('after_setup_theme', fn () => \Roots\bootloader()->boot(), 0);
# Add the autoload dump script
Acorn has a function that should be added to the scripts
section of your composer.json
file for the post-autoload-dump
event. To automatically configure this script, run the following command:
$ wp acorn acorn:install
Select Yes when prompted to install the Acorn autoload dump script.
wp acorn
commands won't work if your theme/plugin that boots Acorn hasn't been activated and will result in the following message:
Error: 'acorn' is not a registered wp command.
Manually adding Acorn's post autoload dump function
Open composer.json
and add Acorn's postAutoloadDump
function to Composer's post-autoload-dump
event in the scripts
:
"scripts": {
//...
"post-autoload-dump": [
"Roots\\Acorn\\ComposerScripts::postAutoloadDump"
]
}
# Server requirements
Acorn's server requirements are minimal, and mostly come from WordPress and Laravel 10's requirements.
- PHP >=8.1 with extensions: BCMath, Ctype, Fileinfo, JSON, Mbstring, Tokenizer, XML
- WordPress >= 5.4
- WP-CLI
Contributors
Last updated
Support Roots
Help us continue to build and maintain our open source projects. We’re a small team of independent developers and every little bit helps.
Sponsor Roots on GitHub