承接 technote/gutenberg-packages 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

technote/gutenberg-packages

Composer 安装命令:

composer require technote/gutenberg-packages

包简介

Library to get gutenberg package info

README 文档

README

CI Status codecov CodeFactor License: GPL v2+ PHP: >=5.6 WordPress: >=5.5

This repository (Gutenberg Packages) manages versions of Gutenberg.

Gutenberg Packages is wrapper of this library.

Gutenberg Packages fetches version data from

  1. Library
  2. API (daily update)
  3. Gutenberg repository

and cache for a day.
(When the state (WP Core version or Gutenberg plugin state) changes, the cache is cleared).

Table of Contents

Details

Requirement

  • >= PHP 5.6
  • >= WordPress v5.5

Installation

composer require technote/gutenberg-packages

Usage

<?php
use Technote\GutenbergPackages;

$packages = new GutenbergPackages();

$packages->is_block_editor(); // true or false
$packages->get_gutenberg_version(); // e.g. 6.0.0 (empty string if Gutenberg plugin is not activated)

$packages->get_editor_package_versions(); // array of (package => version), false if block editor is invalid
/** e.g.
[
  "wp-a11y"        => "2.0.2",
  "wp-annotations" => "1.0.8",
  "wp-api-fetch"   => "2.2.8",

  ...

  "wp-url"         => "2.3.3",
  "wp-viewport"    => "2.1.1",
  "wp-wordcount"   => "2.0.3"
]
*/

$packages->get_editor_package_version( 'wp-editor' ); // e.g. 9.0.11
$packages->get_editor_package_version( 'editor' ); // same as above

$packages->is_support_editor_package( 'wp-editor' ); // true or false
$packages->is_support_editor_package( 'editor' ); // same as above

$packages->filter_packages( [
	'editor',
	'wp-editor',
	'test-package',
	'components',
	'wp-data',
	'wp-data',
] );
/** e.g.
[
	'wp-editor',
	'wp-components',
	'wp-data',
]
*/

$packages->fill_package_versions( [
	'editor',
	'wp-editor',
	'test-package',
	'components',
	'wp-data',
	'wp-data',
] );
/** e.g.
[
	'wp-editor'     => '9.0.11',
	'wp-components' => '7.0.8',
	'wp-data'       => '4.2.1',
]
*/

Motivation

There is no WP Core function to get version of Block Editor packages.
So it is hard to consider compatibility.

For example
Gutenberg v5.9 outputs message bellow.

wp.editor.BlockFormatControls is deprecated and will be removed. Please use wp.blockEditor.BlockFormatControls instead.

If your plugin uses wp-block-editor package like bellow, you get an error under WP v5.2.

const { BlockFormatControls } = wp.blockEditor;
Uncaught TypeError: Cannot destructure property `BlockFormatControls` of 'undefined' or 'null'.

From JavaScript, to check existence of property can solve this problem easily.

const { BlockFormatControls } = wp.blockEditor && wp.blockEditor.BlockEdit ? wp.blockEditor : wp.editor;

But you also need to know package validity from PHP because wp_enqueue_script needs dependencies.
If you pass wp-block-editor to wp_enqueue_script under WP v5.2, script is not enqueued.

<?php
wp_enqueue_script( 'test-script', 'path/to/javascript/index.js', [
	'wp-block-editor',
	'wp-components',
	'wp-compose',
	'wp-element',
	'wp-editor',
	'lodash',
] );

This library can help this problems.

<?php
use Technote\GutenbergPackages;

$packages = new GutenbergPackages();
wp_enqueue_script( 'test-script', 'path/to/javascript/index.js', $packages->filter_packages( [
	'wp-block-editor',
	'wp-components',
	'wp-compose',
	'wp-element',
	'wp-editor',
], [ 'lodash' ] ) );

If you use under WP v5.1, wp-block-editor is filtered.
And if you use over WP v5.2, wp-block-editor is not filtered.

You can also pass the package versions to JavaScript via wp_localize_script.

<?php
use Technote\GutenbergPackages;

$packages = new GutenbergPackages();

$depends = [
	'wp-block-editor',
	'wp-components',
	'wp-compose',
	'wp-data',
	'wp-element',
	'wp-editor',
];
wp_enqueue_script( 'test-script', 'path/to/javascript/index.js', $packages->filter_packages( $depends, [ 'lodash' ] ) );
wp_localize_script( 'test-script', 'PackageVersions', $packages->fill_package_versions( $depends) );
// JavaScript
console.log( PackageVersions );

Dependency

Author

GitHub (Technote)
Blog

technote/gutenberg-packages 适用场景与选型建议

technote/gutenberg-packages 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 35.54k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2019 年 07 月 05 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「wordpress」 「gutenberg」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

围绕 technote/gutenberg-packages 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 35.54k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 9
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: GPL-2.0
  • 更新时间: 2019-07-05