Download the PHP package wp-grogu/acf-manager without Composer
On this page you can find all versions of the php package wp-grogu/acf-manager. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download wp-grogu/acf-manager
More information about wp-grogu/acf-manager
Files in wp-grogu/acf-manager
Package acf-manager
Short Description An Object-Oriented library used to create ACF field groups and gutemberg blocks, and retreive the data easily. Requires Wordpress, ACF.
License MIT
Informations about the package acf-manager
Grogu ACF Manager
- Introduction
- Requirements
- Installation
- Usage
- Create a field group
- Create a Gutemberg block
- Working with flexible content
- Retreiving your fields (FieldSet class)
- Field casting
- Contribute
Introduction
This package brings an object-oriented approach to Wordpress Advanced Custom Fields (ACF) plugin. ACF manager will help you to create field groups, gutemberg blocks, options pages and flexible content directly in individual PHP classes, so you keep a clean and structured app folder. Using this package will make forget about the ACF back-office interface, allowing you to version control your ACF groups and make it a breeze to push your changes to multiple environments.
In addition to thoses (awesome) features, you will also receive back FieldSet
objects instead of arrays when retreiving your fields from the database, which enables fields casting into Models, classes, or any other transformed data based on the field name (eg. a field named "image" may become an App\Models\Attachment
object, with all the corresponding attributes and methods).
Behing the scene, acf-manager uses a custom fork of wordplate/extended-acf
package, coming with an explicit documentation, so make sure to checkout the official repositiory to discover how to define fields.
To make use of Eloquent Models (and corresponding builts-in transformers) in your app, if not already included in your framework, we highly recommand having a look at the ObjectPress library which brings some of the best Laravel features in any Wordpress installation.
This package comes as a standalone but is fully compatible with Bedrock/Sage 10 stack, with a native Wordpress theme (with an autoload logic setted up), and probably with many other frameworks out here.
Basic usage
At it's most basic usage, the plugin may be used this way to create a field group :
This package has a config file to manage your blocks registration without the need to use wordpress hooks :
It's also a breeze to create Flexible content sections :
Finally, when receiving back your fields, you may parse them into Field sets to benefit from casting and fluent interface allowing multiple accessors on the class :
The FieldSet
class is completely fluent and all of those methods are valid to get values :
Ready to get started ?
Requirements
ACF manager has some requirements :
- PHP
>= 8.0
- Wordpress
- ACF plugin enabled
Installation
-
Use composer to install the package in your theme directory :
-
Create an
Acf
namespace inside your autoloadedapp/
folder, which may look like this : -
Bootload the module in your
functions.php
file : - Create the
config/acf.php
file which will hold your configuration using WP-CLI :
Or copy/paste it directly from the source file.
Usage
Every field group or gutemberg block has it's own individual class/file. Each of them has, obviously, some fields, and some may also have one or more locations. All of them are defined using the great wordplate/extended-acf package, which provides a fluent API around ACF.
Create a field group
To create a group, run the following WP-CLI command :
A new file is created :
You may manage some additionnal configurations for the group using class properties :
Once your fields and locations are defined, you may register your new group in the config/acf.php
config file, using the groups
key :
You may also combine fields from another group using the PHP splat operator :
Create a Gutemberg block
// WIP
Working with flexible content
Because your fields are defined in individual classes, it becomes really easy to copy your fields from one group to another, or transform them into layouts. For this example, we will assume you are defining each of your flexible layouts as separate field groups, inside a app/Acf/Groups
directory. You would define your Flexible and it's layouts this way :
Make sure that the App\Acf\Templates\FreeSection
group is registred inside your acf config file, et voilà !
Behind the scene, the layout's FieldGroup $title
and $slug
properties are used to define the layout. However, if you need more control on the field registration, you can manually define your layout :
Retreiving your fields (FieldSet class)
// WIP
Field casting
// WIP
Contribute
Feel free to contribute ! You may send merge request.
All versions of acf-manager with dependencies
laravel/helpers Version ^1.0
tgeorgel/wordplate-acf Version ^2.0.0
wp-grogu/laravel-fluent-plus Version dev-master