ergosarapu/wp-htmlblocks

WP HtmlBlocks 插件

安装次数: 997

依赖项: 0

建议者: 0

安全: 0

星星: 0

关注者: 1

分支: 0

开放问题: 0

类型:wordpress-plugin

v1.0.1 2021-02-09 09:39 UTC

This package is auto-updated.

Last update: 2024-09-09 17:05:35 UTC


README

Actions Status License: GPL v2

WP HtmlBlocks 插件

将 HTML 文档的片段捕获到 WordPress 块中,以便可以将 HTML 模板填充到 WordPress 内容中。非常适合快速且定期地创建基于 HTML 模板的新闻通讯。

使用 Composer 安装

该插件使用 Carbon Fields composer 依赖项。Carbon Fields 库包含 JS/CSS 资产,这些资产由 wp-admin 请求,但由于默认供应商目录不是网络目录,因此找不到。

一种解决方案是将 Carbon Fields 库安装到网络目录,通过更改 "htmlburger/carbon-fields" 的 installer-paths,相应地更改您的 composer.json

"extra": {
    "installer-paths": {
        "YOUR_DESIRED_LOCATION/vendor/{$vendor}/{$name}/": ["htmlburger/carbon-fields"]
    }
}

然后使用 Composer 需求 WP HtmlBlocks 插件

composer require "ergosarapu/wp-htmlblocks"

配置

当前当环境变量 HTMLBLOCKS_CONFIG 设置为有效的 YAML 配置文件时加载配置。对于多个配置,使用 PATH_SEPARATOR 分隔路径,例如:

  • Windows 上为 /path/to/config1.yml;/path/to/config2.yml
  • 其他情况下为 /path/to/config1.yml:/path/to/config2.yml

配置错误记录到 error_log,如果块在 WP 帖子编辑器中不出现,请从日志中查找原因。

示例

HTML

<html>
    <h1>Greeting</h1>
    <table>
        <tr>
            <td id="post_left">Post on left</td>
            <td id="post_right">Post on right</td>
        </tr>
    </table>
</html>

YAML 配置

block: # Define block
  html: example.html # Path to html template file
  name: Newsletter # Block name
  description: Newsletter block # Block description
  xpath: //html # Select whole HTML to render this Block
  icon: email # Block icon as WP Dashicon
  category: # Set category this Block appears under
    slug: newsletter
    title: Newsletter
    icon: email
  fields: # Create Fields for Block
    - field:
        type: text # Field type 'text' (can be any of Carbon Fields supported field types)
        name: greeting
        label: Enter Your greeting here
        replaces: # Define how Field values replaces sections in HTML 
          - replace:
              xpath: //h1/text() # XPath of section to replace in HTML
              value_path: greeting # Path to field value using dot notation
  blocks: # Define unlimited nested blocks
    - block:
        name: Two Posts
        description: Two Posts block
        xpath: //tr
        icon: block-default
        category:
          slug: newsletter
          title: Newsletter
          icon: email
        fields:
          - field:
              type: association
              name: posts
              label: Select Post or Page
              functions: # Configure Field using config methods supported by Carbon Fields
                - name: set_types
                  args:
                    - - type: post
                        post_type: post
                      - type: post
                        post_type: page
                - name: set_min
                  args:
                    - 2
                - name: set_max
                  args:
                    - 2
              replaces:
                - replace:
                    xpath: //td[@id="post_left"]/text()
                    function:
                      name: get_the_title
                      args:
                        - arg:
                            value_path: posts.0.id
                - replace:
                    xpath: //td[@id="post_right"]/text()
                    function: # Call arbitrary functions to render desired replacement result
                      name: strtoupper
                      args:
                        - arg:
                            function: # Pass another arbitrary function as an argument
                              name: get_the_title
                              args:
                                - arg:
                                    value_path: posts.1.id

WP 管理员中的结果块

WP Admin

渲染的 HTML 结果

<html>
<body>
    <h1>Hello World!</h1>
    <table>
        <tr>
            <td id="post_left">Privacy Policy</td>
            <td id="post_right">SAMPLE PAGE</td>
        </tr>
    </table>
</body>
</html>

注意! 最终结果取决于用于渲染帖子的模板。您可能希望在不带样式的模板中渲染输出,为此您可以使用特定的插件为帖子设置空白模板或修改您的主题以支持空白模板。

任务

  • composer build - 运行测试和代码检查进行构建
  • composer test - 运行测试
  • composer phpcs - 运行 PHP CodeSniffer
  • composer phpmd - 运行 PHP Mess Detector

许可证

许可下 GPLv2