定制 yard/acf-registrar 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

yard/acf-registrar

最新稳定版本:v2.0.0

Composer 安装命令:

composer require yard/acf-registrar

包简介

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

README 文档

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

统计信息

  • 总下载量: 4
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 7
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-14

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固