dekodeinteraktiv/hogan-core

ACF Pro 的模块化灵活内容系统

安装量: 16,598

依赖项: 16

建议者: 0

安全: 0

星标: 7

关注者: 9

分支: 0

开放问题: 11

类型:wordpress-plugin

1.4.3 2019-04-26 08:27 UTC

README

ACF Pro 的模块化灵活内容系统

安装

使用 Composer 安装 Hogan WordPress 插件,通过要求以下模块之一或仅使用以下核心框架:

$ composer require dekodeinteraktiv/hogan-core

每个模块以及核心框架本身都将作为单独的 WordPress 插件安装在 wp-content/plugin 文件夹中。

核心框架模块

添加模块

可以使用 Core 中的 register_module() 函数添加自定义模块。创建一个新的模块,该模块扩展 \Dekode\Hogan\Module 类,并将其添加到 Hogan 存储库中,如下所示

class DemoModule extends extends \Dekode\Hogan\Module {
  …
}

add_action( 'hogan/include_modules', function( \Dekode\Hogan\Core $core ) {
  require_once 'class-demomodule.php';
  $core->register_module( new DemoModule() );
}, 10, 1 );

用法

默认情况下,您将获得一个只针对 page 类型帖子激活的所有模块的 ACF 可变内容组。内置的 wysiwyg 编辑器将被移除。

将 Hogan 添加到其他帖子类型

Hogan 默认添加到页面。使用过滤器 hogan/field_group/default/supported_post_types 来声明对其他帖子类型的支持。

add_filter( 'hogan/field_group/default/supported_post_types', function( array $post_types ) : array {
	$post_types[] = 'post'; // Add Hogan support for posts.
	return $post_types;
}, 10, 2 );

自定义默认字段组

可以使用过滤器 hogan/field_group/<name>/args 过滤所有字段组,包括默认字段组。默认参数是

'name'                           => 'default',
'title'                          => __( 'Content Modules', 'hogan-core' ),
'modules'                        => [], // All modules.
'location'                       => [],
'hide_on_screen'                 => [],
'fields_before_flexible_content' => [],
'fields_after_flexible_content'  => [],

禁用默认字段组

如果您不想使用默认字段组,或者出于其他原因想自己设置自定义字段组,可以使用过滤器禁用字段组。

add_filter( 'hogan/field_group/default/enabled', '__return_false' );

添加自定义字段组

在动作 hogan/include_field_groups 中使用核心函数 register_field_group() 来注册自定义字段组。

add_action( 'hogan/include_field_groups', function( \Dekode\Hogan\Core $core ) {
  $args = []; // Your field group args.
  $core->register_field_group( $args );
}, 10, 1 );

请参阅上面的自定义默认字段组部分以获取可能的参数。

示例

此示例演示如何为 post 类型仅添加文本模块的自定义字段组。

add_action( 'hogan/include_field_groups', function( \Dekode\Hogan\Core $core ) {
  $core->register_field_group( [
    'name' => 'field_group_1',
    'title' => __( 'Field group title', 'text-domain' ),
    'modules' => [ 'text' ],
    'location' => [
      [
        [
		  'param' => 'post_type',
		  'operator' => '==',
          'value' => 'post',
        ],
      ],
    ],
  ] );
}, 10, 1);

将标题和引言添加到模块中

您可以为每个模块打开标题和/或引言字段。默认为无标题或引言。标题和引言将在特定模块的字段之前包含。例如,要启用 Hogan 网格的标题和引言,请使用

add_filter( 'hogan/module/text/heading/enabled', '__return_true' );
add_filter( 'hogan/module/text/lead/enabled', '__return_true' );

样式

Hogan 核心附带一个最小样式表。

Hogan 模块的宽度默认设置为 1360px。可以使用过滤器 hogan/frontend/content_width 来更改此值。

add_filter( 'hogan/frontend/content_width', function( int $content_width ) {
	return 1920;
}

如果您不想在主题中使用样式表,可以取消注册它。

wp_deregister_style( 'hogan-core' );

搜索

模块内容默认由 SearchWP 指数作为 内容。可以使用以下方式禁用此功能

add_filter( 'hogan/searchwp/index_modules_as_post_content', '__return_false' );

在本地运行测试

在开发过程中,在本地运行测试可能很有益,因为比提交更改并等待 Travis CI 运行测试要快。

我们将假设您已安装 gitsvnphpapachePHPUnit

  1. 在本地初始化测试环境:在插件目录中 cd 并运行安装脚本(您需要安装 wget)。

    bin/install-wp-tests.sh wordpress_test root '' localhost latest

    安装脚本首先在 /tmp 目录(默认)中安装 WordPress 的一个副本以及 WordPress 单元测试工具。然后创建一个数据库,在运行测试时使用。传递给 install-wp-tests.sh 的参数设置了测试数据库。

    • wordpress_test 是测试数据库的名称(所有数据将被删除!)
    • root 是 MySQL 用户名
    • '' 是 MySQL 用户密码
    • localhost 是 MySQL 服务器主机
    • latest 是 WordPress 版本;也可以是 3.7、3.6.2 等等。
  2. 运行插件测试

    phpunit

更多信息请参阅 https://make.wordpress.org/cli/handbook/plugin-unit-tests/#running-tests-locally

变更日志

请参阅 CHANGELOG.md