morningtrain/wp-acf-helper 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

morningtrain/wp-acf-helper

最新稳定版本:v0.2.1

Composer 安装命令:

composer require morningtrain/wp-acf-helper

包简介

ACF helpers to WordPress

README 文档

README

Some helpers to standialize Advanced Custom Fields (ACF) use in our projects.

Table of Contents

Introduction

This package is made to standialize the way we are using Advanced Custom Fields (ACF) in our projects.

It makes it easy to handle ACF JSON files, hide ACF administration area and check if ACF is not installed or activated on the site.

Getting Started

To get started install the package as described below in Installation.

To use the package have a look at Usage

Installation

Install with composer.

composer require morningtrain/wp-acf-helper

Usage

Add JSON folder

To add a foldere where ACF should look for JSON field groups

// Add folder to look for JSON files in ./resources/acf-fields
\Morningtrain\WP\ACFHelper\ACFHelper::registerJsonFolder(__DIR__ . '/resources/acf-fields');

Use JSON folder as save folder

To use the added JSON folder as the folder where ACF use the useAsSaveFolder method on the returned JsonPath object. You can optionally set a namespace, which is used to force saving in specific folder if more than one project sets a save folder.

OBS: ACF will not create the folder, so it shall exist before ACF saves in the folder.

// Add folder to look for JSON files in ./resources/acf-fields and use it as save folder
\Morningtrain\WP\ACFHelper\ACFHelper::registerJsonFolder(__DIR__ . '/resources/acf-fields')->useAsSaveFolder('some_namespace');

If you will force saving in your folder, define a constant in wp-config.php with the namespace set in useAsSaveFolder.

define('ACF_SAVE_FOLDER', 'some_namespace');

Hide Administration

To hide aministration from the WP backend.

\Morningtrain\WP\ACFHelper\ACFHelper::hideAdmin();

This will hide ACF from the WP administration.

Hide Administration Except On Specific Environments

You can hide admin except on specific environments defined by WP_ENVIRONMENT_TYPE in wp-config.php.

\Morningtrain\WP\ACFHelper\ACFHelper::hideAdminExceptOn([
    'local',
    'development'
]);

Possible values are ‘local’, ‘development’, ‘staging’, and ‘production’.

To define the environment add this to wp-config.php

define('WP_ENVIRONMENT_TYPE', 'local');

Check if ACF is installed and activated

To check if ACF is activated

// Abort if ACF is not activated
if(!\Morningtrain\WP\ACFHelper\ACFHelper::isACFActivated()) {
    return;
}

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-01-10