定制 dekodeinteraktiv/hogan-core 二次开发

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

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

dekodeinteraktiv/hogan-core

Composer 安装命令:

composer require dekodeinteraktiv/hogan-core

包简介

Modular Flexible Content System for ACF Pro

README 文档

README

Modular Flexible Content System for ACF Pro

Installation

Install Hogan WordPress plugin using Composer by requiring any of the modules listed below or just the core framework using:

$ composer require dekodeinteraktiv/hogan-core

Each module and the core framework itself will be installed as seperate WordPress plugins in the wp-content/plugin folder.

Core Framework Modules

Module Installation
Text composer require dekodeinteraktiv/hogan-text
Forms composer require dekodeinteraktiv/hogan-form
Embed composer require dekodeinteraktiv/hogan-embed
Gallery composer require dekodeinteraktiv/hogan-gallery
Grid composer require dekodeinteraktiv/hogan-grid
Content Grid composer require dekodeinteraktiv/hogan-content-grid
Link list composer require dekodeinteraktiv/hogan-linklist
Links composer require dekodeinteraktiv/hogan-links
Banner composer require dekodeinteraktiv/hogan-banner
Image composer require dekodeinteraktiv/hogan-image
Expandable list composer require dekodeinteraktiv/hogan-expandable-list
Table composer require dekodeinteraktiv/hogan-table
Parallax Image composer require dekodeinteraktiv/hogan-parallax-image
Simple Posts composer require dekodeinteraktiv/hogan-simple-posts
Reusable Modules composer require dekodeinteraktiv/hogan-reusable-modules

Adding modules

Adding custom modules can be done using the register_module() function in Core. Create a new module that extends the \Dekode\Hogan\Module class and add it to the Hogan repository like this:

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 );

Usage

By default you will get a ACF Flexible Content group with all activated modules for post type page only. The built in wysiwyg editor will be removed.

Adding Hogan to other post types.

Hogan is by default added to pages. Use the filter hogan/field_group/default/supported_post_types to declare support to other 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 );

Customizing the default field group

All field groups, including the default one, can be filtered using the hogan/field_group/<name>/args filter. The default args are:

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

Disable default field group

If you don't want to use the default field group, or for some other reason want to setup a customized field group yourself, field groups can be disabled with a filter.

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

Adding custom field groups

Use the core function register_field_group() in action hogan/include_field_groups to register custom field groups.

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

See Customizing the default field group above for possible arguments.

Example:

This example demonstrates how to add a custom field group with just the text module for post type 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);

Adding header and lead to modules

You can turn on a heading and/or lead field for every single module. Default is no heading or lead. The heading and lead will be included before module specific fields. E.g. to enable heading and lead for Hogan Grid use:

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

Style

Hogan core comes with a minimal stylesheet.

The width of hogan modules is by default set to 1360px. This can be changed using the filter hogan/frontend/content_width:

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

If you don't want the stylesheet in your theme you can deregister it.

wp_deregister_style( 'hogan-core' );

Search

Modules content is by default indexed as Content by SearchWP. This can be disabled using:

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

Running tests locally

Running tests locally can be beneficial during development as it is quicker than committing changes and waiting for Travis CI to run the tests.

We’re going to assume that you have installed git, svn, php, apache and PHPUnit

  1. Initialize the testing environment locally: cd into the plugin directory and run the install script (you will need to have wget installed).

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

    The install script first it installs a copy of WordPress in the /tmp directory (by default) as well as the WordPress unit testing tools. Then it creates a database to be used while running tests. The parameters that are passed to install-wp-tests.sh setup the test database.

    • wordpress_test is the name of the test database (all data will be deleted!)
    • root is the MySQL user name
    • '' is the MySQL user password
    • localhost is the MySQL server host
    • latest is the WordPress version; could also be 3.7, 3.6.2 etc.
  2. Run the plugin tests:

    phpunit

For more info see https://make.wordpress.org/cli/handbook/plugin-unit-tests/#running-tests-locally

Changelog

See CHANGELOG.md.

dekodeinteraktiv/hogan-core 适用场景与选型建议

dekodeinteraktiv/hogan-core 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 18.59k 次下载、GitHub Stars 达 7, 最近一次更新时间为 2017 年 10 月 20 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 dekodeinteraktiv/hogan-core 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 dekodeinteraktiv/hogan-core 我们能提供哪些服务?
定制开发 / 二次开发

基于 dekodeinteraktiv/hogan-core 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 18.59k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 8
  • 点击次数: 11
  • 依赖项目数: 16
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: GPL-3.0-or-later
  • 更新时间: 2017-10-20