Skip to content
Acorn

Roots is an independent open source org, supported only by developers like you. We’ve been improving the WordPress developer experience since 2011, and your support keeps it independent.

Developing Packages for Acorn

View as Markdown:

We have an Acorn Example Package repo that can be used as a template for creating your own Acorn packages. It's similar to some of the other Laravel package templates out there, but more specific to Acorn.

Creating Acorn packages is useful for when you want to reuse specific functionality on your Acorn-powered WordPress sites, or open-sourcing functionality that's not tied directly to your site. You can think of Acorn packages similiar to WordPress plugins, or any other dependency.

Packages are installed by Composer, just like Acorn is.

We recommend referencing the Laravel docs on Packages

Creating an Acorn package

From the roots/acorn-example-package repo, click the Use this template button to create a new repo with the template.

After cloning your new repo, 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. You can also run it non-interactively:

$ php configure.php --no-interaction --author-name="Your Name" --author-email="[email protected]" --vendor-slug="your-vendor" --vendor-namespace="YourVendor" --package-slug="your-package" --class-name="YourPackage" --package-description="Your package description"

To preview changes without modifying any files, use --dry-run:

$ php configure.php --dry-run

Developing an Acorn package

Once your package is created, clone your new git repo somewhere on your machine that's accessible from a WordPress site with Acorn installed. To work on a package locally, you can require it by defining a new local repository from the composer.json file used for your site/theme:

  "repositories": [
    {
      "type": "path",
      "url": "./packages/vendor-name/example-package"
    }
  ],

Replace ./packages/vendor-name/example-package above with the path to your local package, along with the correct names.

Then require the package in your project:

$ composer require vendor-name/example-package

Then run the Acorn WP-CLI command to discover your package:

$ wp acorn package:discover
  INFO  Discovering packages.

  vendor-name/example-package ...... DONE
  roots/sage ....................... DONE

If you haven't already, run php configure.php from the root of your package to replace the placeholder names

Last updated