Skip to content
On this page

Registries

Forme has the concept of registry classes. Their main purpose is to register a collection of a particular type of asset or functions with WordPress via action hooks.

For example, the standard Forme theme boilerplate has a class called PublicQueueRegistry. This is wired up to the wp_enqueue_scripts action hook, and contains all your script and style enqueues.

The boilerplate also has a shortcode registry, a theme support registry, and more, but you can create whatever makes sense to you. They are essentially just a way of organising and grouping together related actions that need to fire on a particular hook.

Interface

Registries are classes with a public method named (appropriately enough) register, within which you do whatever needs to happen.

They should implement Forme\Framework\Registry\RegistryInterface, and should be wired up to the relevant action hook via app/config/hooks.yaml

php
// app\Registry\HelloWorldRegistry.php
<?php

declare(strict_types=1);

namespace Foo\Bar\Registry;

use Forme\Framework\Registry\RegistryInterface;

final class HelloWorldRegistry implements RegistryInterface
{

    public function register(): void
    {
        // register all the things
    }
}

Code Generation

You can create a new registry via the cli:

bash
forme make registry FooBar

This will make a new empty registry class YourNameSpace\YourApp\Registry\FooBarRegistry and hook it up with init. You'll need to edit app/config/hooks.yaml manually if you need to connect it to a different action.

Made by Moussa Clarke @ Sanders Web Works with ❤️