Code Monkey home page Code Monkey logo

acfoop's Introduction

ACFOOP

Use Object Oriented Programming to create fields groups for ACF.

Installation

composer require pjehan/acfoop

Usage

Create a container

Create a new class extending the abstract Container class:

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.

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:

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:

new Post();

Create fields

Then, you can add fields to the group. You can use one of the following Fields classes:

Text field

use Pjehan\Acfoop\Fields\Text;

$text = new Text('text_field', 'Text Field');
$group->addField($text);

acfoop's People

Contributors

pjehan avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.