Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pjehan/acfoop
https://github.com/pjehan/acfoop
Last synced: 10 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/pjehan/acfoop
- Owner: pjehan
- License: mit
- Created: 2022-05-24T20:41:03.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2024-03-04T17:18:06.000Z (10 months ago)
- Last Synced: 2024-04-15T15:53:27.830Z (9 months ago)
- Language: PHP
- Size: 54.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ACFOOP
Use Object Oriented Programming to create fields groups for ACF.
## Installation
```shell
composer require pjehan/acfoop
```## Usage
### Create a container
Create a new class extending the abstract Container class:
```php
use Pjehan\Acfoop\Container;class Post extends Container
{
}
```### Create a group
Override the `addCustomFields` method to add your fields groups.
This method is automatically called when the hook 'acf/init' is fired.```php
use Pjehan\Acfoop\Container;
use Pjehan\Acfoop\FieldGroup;class Post extends Container
{
public const GROUP_SLUG = 'group_post';public function addCustomFields(): void
{
$group = new FieldGroup(self::GROUP_SLUG, 'My Group');
}
}
```You can also set the group's location rules:
```php
use Pjehan\Acfoop\Container;
use Pjehan\Acfoop\FieldGroup;
use Pjehan\Acfoop\Location;class Post extends Container
{
public const GROUP_SLUG = 'group_post';public function addCustomFields(): void
{
$group = new FieldGroup(self::GROUP_SLUG, 'My Group');
$group->addLocation(new Location('post_type', 'post'));
}
}
```Then, you can instantiate the class and the `addCustomFields` method will be called automatically:
```php
new Post();
```### Create fields
Then, you can add fields to the group.
You can use one of the following Fields classes:- [Text](#text-field)
#### Text field
```php
use Pjehan\Acfoop\Fields\Text;$text = new Text('text_field', 'Text Field');
$group->addField($text);
```