tiny-pixel/block-sandbox

为严谨的WordPress创作者进行的块测试

安装: 7

依赖: 0

建议者: 0

安全性: 0

星标: 7

关注者: 2

分支: 1

开放问题: 3

类型:wordpress-plugin

dev-master 2020-05-14 10:22 UTC

This package is auto-updated.

Last update: 2024-09-14 20:04:21 UTC


README

Latest Stable Version Total Downloads License

此插件注册了一个包含多种常见/核心块的模板的《沙盒》帖子类型预设,无需任何配置即可开始使用。

它受到了coblocks/block-unit-test(现在为godaddy/block-unit-test 😬)的启发。

相比之下,block-sandbox的目标是

✅ 可修改的,具有易于阅读和修改的API

✅ 容易保持更新,因为块规范持续变化

✅ 不是Godaddy的知识产权。对Rich Tabor(get it!)没有意见,但不,谢谢

简单使用

$ composer require tiny-pixel/block-sandbox
$ wp plugin activate block-sandbox

程序化使用和配置

至少您需要创建CPT,应用模板并将其注册到WordPress中

add_action('init', function () {
    (new Sandbox())
        ->create()
        ->applyTemplate()
        ->register();
});

此外,还有几种方法可供您用于修改插件的行为。

附加额外块

如果您想向模板中添加额外的块,可以使用appendBlocks方法。

$extra = [['core/cover', [
    'align'   => 'wide',
    'url'     => 'example.png',
    'title'   => 'Additional block'
]]];

add_action('init', function () use ($extra) {
    (new Sandbox())
        ->createSandbox()
        ->appendBlocks($extra)
        ->applyTemplate()
        ->register();
});

覆盖模板

如果您想用您自己的模板完全替换包含的模板,可以使用setTemplate。只需传递包含块的数组。

$template = [
  ['core/cover', [
    'align'   => 'wide',
    'url'     => 'example.png',
    'title'   => 'Additional block']],

  ['core-embed/vimeo', [
    'caption' => '<em>écoute: El Guincho</em>',
    'align'   => 'wide',
    'url'     => 'https://vimeo.com/70237487']],
];

add_action('init', function () use ($template) {
    (new Sandbox())
        ->createSandbox()
        ->setTemplate($template)
        ->applyTemplate()
        ->register();
});

修改标签

如果您想将sandbox改为其他内容,可以使用setLabel。它需要一个包含新idsingularplural形式的标签的数组。

$label = [
  'id'       => 'test',
  'singular' => 'Test',
  'plural'   => 'Tests',
];

add_action('init', function () use ($label) {
    (new Sandbox())
        ->create()
        ->setLabel($label)
        ->applyTemplate()
        ->register();
});

以上所有内容

add_action('init', function () use ($template, $extra, $posttype) {
    (new Sandbox())
        ->create()
        ->setLabel($posttype)
        ->setTemplate($template)
        ->appendBlocks($extra)
        ->applyTemplate()
        ->register();
});

许可证

MIT许可证。快乐破解!