greenpeace/planet4-plugin-gutenberg-blocks
最新稳定版本:v1.110.0
Composer 安装命令:
composer require greenpeace/planet4-plugin-gutenberg-blocks
包简介
This repository contains the WordPress plugin that provides the gutenberg blocks for Planet4 project
README 文档
README
What is it?
This the WordPress Gutenberg blocks plugin for Greenpeace Planet 4 project. You can learn more about this project on the Planet 4 blog.
Contribute
The best place to start is from the main Planet 4 repo that contains all the necessary information and tickets to get started.
How to use this plugin in Planet 4
You can use the plugin in WordPress directly, by including it in your composer.json file:
"require": {
...
"greenpeace/planet4-plugingutenberg-plugin" : "X.X.X",
...
},
Assets build
You'll need npm to install the dependencies, just run npm install to install them.
To develop:
- run
npm startto start a watcher that will rebuild every time you make a change. - run
npm run buildto manually build the files.
Build Setup
WordPress provides a single dependency for the whole build setup including:
- Babel: the transpiler for JSX & ES6 syntax to browser-compatible JS
- Webpack: the bundler for all the JS modules and dependency resolution
How to develop a new block you ask?
-
Create a new class that extends
Base_Block(P4GBKS\Blocks\Base_Block) inside directory classes/blocks. The class name should follow a naming convention, for example, Blockname and its file name should be class-blockname.php. -
Implement its parent's class abstract method. In block's constructor, you need to define the block's details (fields, schema) using
register_block_typeand in method prepare_data() you need to prepare the data which will be used for rendering. -
Create the template file that will be used to render your block inside directory templates/blocks. If the name of the file is blockname.twig then you need to set the BLOCK_NAME constant as 'blockname' It also works with HTML templates. Just add 'php' as the 3rd argument of the block() method.
-
Add your new class name to the array inside Loader's (
P4GBKS\Loader) constructor. -
Create a new folder inside react-blocks/src/blocks named after your block Blockname (first letter capital - rest lowercase). Create two new files inside that folder named Blockname.js and BlocknameBlock.js.
BlocknameBlock.js should be a class that uses wordpress registerBlockType to define the block's attributes, schema and
edit()function.edit()function should return a react component that will be used for rendering the block in the editor.save()function should return null as we use server-side rendering currently.Blockname.js should be a class that defines a React component that implements
renderEdit()andrenderView().renderEdit()should be used to render the block in the editor, to define editor-specific things as sidebar options, in-place edit components, and so on.renderView()will be used both in the editor and in the frontend site to render the block's contents, as we are rendering blocks using React in the frontend too.To learn more details about the rendering logic, refer to the blocks page in Planet 4 Gitbook.
-
Create a new sccs file inside react-blocks/src/blocks/styles named after your block Blockname.scss to use for block's frontend styling.
Create a new file named BlocknameEditor.scss to use for block's editor styling if you need to style the block in the editor.
-
Finally, before committing do npm run build to build the plugin's assets and vendor/bin/phpcs to check for any PHP styling errors in your code.
greenpeace/planet4-plugin-gutenberg-blocks 适用场景与选型建议
greenpeace/planet4-plugin-gutenberg-blocks 是一款 基于 JavaScript 开发的 Composer 扩展包,目前已累计 79.23k 次下载、GitHub Stars 达 51, 最近一次更新时间为 2019 年 07 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 greenpeace/planet4-plugin-gutenberg-blocks 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 greenpeace/planet4-plugin-gutenberg-blocks 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 79.23k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 53
- 点击次数: 20
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0
- 更新时间: 2019-07-11
