An open API service indexing awesome lists of open source software.

https://github.com/yardinternet/wp-acf-registrar

An Acorn package to register ACF fields
https://github.com/yardinternet/wp-acf-registrar

Last synced: about 4 hours ago
JSON representation

An Acorn package to register ACF fields

Awesome Lists containing this project

README

          

# ACF Registrar

[![Code Style](https://github.com/yardinternet/wp-acf-registrar/actions/workflows/format-php.yml/badge.svg?no-cache)](https://github.com/yardinternet/wp-acf-registrar/actions/workflows/format-php.yml)
[![PHPStan](https://github.com/yardinternet/wp-acf-registrar/actions/workflows/phpstan.yml/badge.svg?no-cache)](https://github.com/yardinternet/wp-acf-registrar/actions/workflows/phpstan.yml)
[![Tests](https://github.com/yardinternet/wp-acf-registrar/actions/workflows/run-tests.yml/badge.svg?no-cache)](https://github.com/yardinternet/wp-acf-registrar/actions/workflows/run-tests.yml)

## Features

- [x] Register ACF Field groups
- [x] Register ACF Forms
- [x] Register ACF Option Pages

## Installation

This package can be installed using composer

```shell
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:

```php
/**
* 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](https://github.com/vinkla/extended-acf) for documentation about registering fields.

```php
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