Creating an Acorn Package
Have you been wondering how to get started with developing an Acorn package? We’ve updated the Acorn Package Development documentation and published a acorn-example-package repo to help you get started.
Why create an Acorn package?
Think about Acorn packages similar to any other dependency, like a WordPress plugin. If you ever want to reuse functionality on your Acorn sites, or release functionality as an open-source library, then creating an Acorn package is the ideal way to do so. By extracting your code into a package, you can make it easier to maintain your reusable code.
Packages can be anything from a simple utility class to a complex system with configuration, views, and WP-CLI commands.
Acorn packages are installed by Composer, just like Acorn itself is.
If you aren’t yet familiar with Laravel packages and service providers, make sure to read Laravel’s Package docs.
Getting started with Acorn package development
Visit the acorn-example-page repo on GitHub and then click the Use this template button to create a new repo with the template.
After creating your repo from the template, run the configure script to replace the placeholder names with your own:
$ php configure.php
The script will prompt you for your vendor name, package name, namespace, and other details. See the package development docs for non-interactive and dry-run usage.
You can work on a package locally by defining a local repository for the package on your WordPress project.
Existing packages to reference
There are several packages available for Acorn. Here are the first-party packages from Roots:
- roots/acorn-ai — WordPress Abilities API integration and AI support
- roots/acorn-fse-helper — Bootstrap FSE support in Acorn-based themes
- roots/acorn-mail — WordPress SMTP using Acorn’s mail configuration
- roots/acorn-post-types — Simple post types and taxonomies using Extended CPTs
- roots/acorn-prettify — Theme-agnostic front-end modifications
- roots/acorn-user-roles — Simple user role management
And a few community packages worth checking out:
- 40q/40q-seo-assistant — Editor-side SEO metadata suggestions
- generoi/sage-woocommerce — WooCommerce support for Sage 10
- log1x/acf-composer — ACF fields, blocks, widgets, and option pages
- millipress/acorn-millicache — MilliCache integration for Acorn and Bedrock
Create your own packages and share them with us on Roots Discourse!