yard/acf-registrar

PHP package to register ACF Field Groups, Forms and Option Pages

Maintainers

Package info

github.com/yardinternet/wp-acf-registrar

Type:package

pkg:composer/yard/acf-registrar

Statistics

Installs: 4

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 1

v2.0.0 2026-03-10 17:48 UTC

This package is auto-updated.

Last update: 2026-04-14 08:45:40 UTC


README

Code Style PHPStan Tests

Features

  • Register ACF Field groups
  • Register ACF Forms
  • Register ACF Option Pages

Installation

This package can be installed using composer

composer require yard/acf-registrar

Usage

To use this package in a standard WordPress plugin, you can use the Registrar to register hooks.

main file:

/**
 * Plugin Name: My Plugin
 */

require __DIR__ . '/vendor/autoload.php';

$fieldGroups$ = [
    \Plugin\FieldGroupClass::class,
    \Plugin\AnotherFieldGroupClass::class,
];

$registrar = new \Yard\Acf\Registrar();
$registrar->addFieldGroups($fieldGroups);
$registrar->addForm(\Plugin\FormClass::class);
$registrar->addOptionPage(\Plugin\OptionPageClass::class);
$registrar->register();

FieldGroup Usage

Extend Yard\Acf\Registar\FieldGroup to define a field group. Add the class to config/acf-registrar in the field_groups key. See Extended ACF for documentation about registering fields.

<?php

declare(strict_types=1);

namespace App\FieldGroups;

use Extended\ACF\Fields\Text;
use Extended\ACF\Location;
use Yard\Acf\Registrar\FieldGroup;

class Person extends FieldGroup
{
    public function getTitle(): string
    {
        return 'Instellingen Persoon';
    }

    public function getFields(): array
    {
        return [
            Text::make('Naam', 'name')
                ->instructions('De naam van de persoon.')
                ->required(true)
                ->placeholder('Voer de naam in'),
        ];
    }

    public function getLocation(): array
    {
        return [
            Location::where('post_type', '==', 'person'),
        ];
    }
}

Forms Usage

Extend Yard\Acf\Registrar\Forms to define a front-end form. Add the class to config/acf-registrar under the forms key.

getId() is required to define the form id, additional methods can be used to overwrite the given defaults.

<?php

declare(strict_types=1);

namespace App\Forms;

use Yard\Acf\Registrar\Form;

class Person extends Form
{
    public function getId(): string
    {
        return 'form-id';
    }

    public function getFields(): array
    {
        return [
            Person::SOME_FIELD,
            Person::MORE_FIELDS
        ];
    }

}

Option page Usage

Extend Yard\Acf\Registrar\OptionPage to define a option page. Add the class to config/acf-registrar under the option_pages key.

getPageTitle() is required to define the option page dashboard name and page title, additional methods can be used to overwrite the given defaults.

<?php

declare(strict_types=1);

namespace App\OptionPages;

use Yard\Acf\Registrar\OptionPage;

class PersonOptions extends OptionPage
{
    public function getPageTitle(): string
    {
        return 'Option page example';
    }

    public function getCapability(): string
    {
        return 'edit_posts';
    }

}

Option pages require the registration of 1 or more fieldgroups that are linked to the option page via:

<?php
public function getLocation(): array
    {
        return [
            Location::where('option_page', '==', 'acf-options-option-page-example'),
        ];
    }

About us

banner