hametuha/wp-block-creator

WordPress 主题的 Gutenberg 块创建器。

1.3.0 2024-04-16 05:21 UTC

This package is auto-updated.

Last update: 2024-09-16 06:17:52 UTC


README

主题的 Gutenberg 块创建器。

CI/CD for PHP Library

安装

composer require hametuha/wp-block-creator

如何使用

假设你的主题

  • 使用 [wp-enqueue-manager] 准备好的头部。
  • 你的主题的 PHP 已经准备好使用 PSR-0
  • 每个块都继承自 Hametuha\WpBlockCreator\Patter\AbstractBlock
  • 目录结构如下。
your-theme
├src/YourTeam/YourTheme/Blocks
│├ExampleBlock.php
│└AnotherBlock.php
└dist
 ├css/blocks
 │├example-block.css
 │└another-block.css
 └js/blocks
  ├example-block.js
  └another-block.js

然后,在你的 functions.php 中调用静态方法。

<?php

// Register blocks assets.
\Hametuha\WpBlockCreator::register( [
	'namespace' => "YourTeam\\YourTheme\\Blocks",
	'dir'       => get_template_directory() . '/src/YourTeam/YourTheme/Blocks',
	'scripts'   => get_template_directory() . '/dist/js/blocks',
	'styles'    => get_template_directory() . '/dist/css/blocks',
	'prefix'    => 'your-theme-',
] );

现在所有块都将自动包含。您不需要逐个加载。您可以在任何时候添加新块。

所有 JavaScript 和 CSS 都将使用 wp-enqueue-manager 的力量注册。像下面这样写正确的头部

/*!
 * Header description here.
 *
 * deps=jquery,wp-element,wp-api-fetch
 */
/**
 * Header comment.
 * 
 * deps=bootstrap
 */

有关更多详细信息,请参阅 wp-enqueue-managerREADME.md

许可证

GPL 3.0 或更高版本。兼容 WordPress。