codeb/wp-feature-flags

允许开发者根据标志启用/禁用功能。

安装: 1

依赖项: 0

建议者: 0

安全: 0

星标: 1

关注者: 1

分支: 0

开放问题: 5

语言:TypeScript

类型:wordpress-plugin


README

PHP lint & test JS lint & test E2E Tests codecov

稳定标签:0.3.2 需要:至少 6.2 测试到:6.6 需要 PHP:8.1

WordPress 功能标志插件允许开发者在服务器(PHP)和客户端(JS/TS)上配置功能标志背后的插件/主题中的功能。

安装

composer require codeb/wp-feature-flags

Packagist: https://packagist.org.cn/packages/codeb/wp-feature-flags

钩子

PHP 过滤器

codeb_feature_flags_max_allowed

过滤器用于定义允许的标志的最大数量。建议保留默认值,即 20。

示例用法

add_filter(
	'codeb_feature_flags_max_allowed',
	static function () {
		return 10;
	}
);

JS 过滤器

codebFeatureFlags.newFlag.defaultStatus

该过滤器控制新标志是否默认启用。默认 true

示例用法

addFilter(
	'codebFeatureFlags.newFlag.defaultStatus',
	'codeb-feature-flags',
	() => {
		return false;
	}
);

开发设置

构建插件

PHP 设置

  • composer install

JS 设置

  • yarn install
  • yarn build 创建构建
  • yarn start 启动监视模式

wp-env

此插件使用 wp-env 设置用于本地环境。

  • wp-env start 启动容器
  • wp-env stop 停止容器

有关如何访问本地环境的更多详细信息,请参阅 此处

代码检查和格式化

PHP

  • composer lint
  • composer lint:fix 自动修复 PHP 代码检查错误。

JS

  • yarn lint:js
  • yarn lint:js:fix 自动修复 JS 代码检查错误。

CSS

  • yarn lint:css
  • yarn lint:css:fix 自动修复 CSS 代码检查错误。

测试

PHP

WordPress 单元和集成测试依赖于 wp-env 设置。确保在运行测试之前运行 yarn wp-env:coverage

  • 运行单元测试 yarn php:unit
  • 运行集成测试 yarn php:integration
  • 作为多站运行集成测试 yarn php:multisite

JS

  • 运行所有 Jest 和 React Testing Library 测试 yarn test:js

E2E

E2E 测试依赖于 wp-env 设置。确保在运行测试之前运行 wp-env start

  • 运行所有 Playwright e2e 测试 yarn test:e2e

贡献

欢迎代码贡献、反馈、问题报告和功能建议。有关详细信息,请参阅 CONTRIBUTING.md