jamesrwilliams/wp-feature-flags
最新稳定版本:0.1.4-beta
Composer 安装命令:
composer require jamesrwilliams/wp-feature-flags
包简介
Easily register and work with feature flags in your theme.
关键字:
README 文档
README
This plugin is for WordPress theme developers who wish to add simple feature flags to their themes. These flags can be enabled via an admin interface, previewed on a per-user, or group basis, and even enabled via a query string for those without accounts. For planned development work please see the roadmap or issues labeled with enhancement.
Contents
Installation
Add this project's source code to your wp-content/plugins directory and enable it like you would any other plugin. It is also available via Packagist to use with composer.
composer require jamesrwilliams/flagpole
This plugin is currently not available via the WordPress Plugin directory however we are working towards that for v1.0.0.
Required theme changes
As this plugin is closely coupled with your theme code it is a good idea to add the following block to your theme to catch any errors if the Flagpole plugin is disabled for any reason.
if ( ! function_exists( 'flagpole_flag_enabled' ) ) { function flagpole_flag_enabled() { return false; } }
Register a flag
To register a flag, simply add the following to your theme's functions.php file using the flagpole_register_flag function:
if ( function_exists( 'flagpole_register_flag' ) ) { flagpole_register_flag([ 'title' => 'My awesome new feature', 'key' => 'correct-horse-battery-staple', 'enforced' => false, 'label' => 'All', 'description' => 'An example feature definition', 'stable' => false, ]); }
Wrapping the registration function call in a function_exists helps avoid errors if the plugin is disabled for any reason. You can also pass an array of flags to flagpole_register_flag to easily instantiate multiple flags at once.
Checking the status of a flag
In your templates you can then check the feature status using the flagpole_flag_enabled function in your PHP theme code to toggle features based on the status of your flags:
if ( flagpole_flag_enabled( 'flag_key' ) ) { /* flag_key is enabled! */ }
Replace flag_key with the key used in the flagpole_register_flag function to check if it is enabled.
Flag options/arguments
| Parameter | Type | Default | Description |
|---|---|---|---|
| key | string |
- | The unique key used in the template to check if a feature is enabled. |
| title | string |
"" | The human readable feature name. |
| description (optional) | string |
"" | A description displayed in the admin screen. |
| stable (optional) | boolean |
false |
If true, allows users to publish features from the admin area. |
| enforced (optional) | boolean |
false |
Setting this to true will override any user specific settings and will enforce the flag to be enabled for every user. Useful for deploying a flag before removing it from the codebase. |
| label | string |
All |
Using labels lets you group together flags that are similar. Adding a label will separate the flag out in the admin UI. |
Enabling flags
There are three ways to have a flag enabled with Flagpole. These are:
- Previewing - Enable a flag only for the current logged-in user.
- Publishing - Enable a flag for every visitor on the site.
- Enforcing - Flags which are enabled by default in the theme.
Previewing
A flag can be previewed for the current logged-in user by enabling the preview in the Flagpole admin screen.
Navigate to the Flagpole screen in the WP admin dashboard, located under Tools > Flagpole. Find a flag you wish to enable, and click the "enable preview" button.
This flag will now be enabled for this user until it is toggled again. Users can preview any number of flags at any one time. For previewing multiple flags at the same time check out Flag Groups.
Publishing
Publishing a flag enables it for every user that visits your site, this includes logged-out users. Any user can publish a feature as long as it has been marked as stable by setting the stable property to true in the flag registration block. This acts as a safety net allowing theme developers to mark features ready for publication.
E.g.
flagpole_register_flag([ 'title' => 'Feature ready for publication', 'key' => 'super-awesome-navigation-change', 'stable' => true, ]);
Enforcing
Enforcing a flag is where a developer can force a flag to be in a published state. This allows them to enable a flag via their source code by setting the 'enforced' option to true in the flag options. The idea behind enforced flags are a stepping stone before removing the flag logic from the theme. Enforced flags are displayed in a separate list in the admin area and are not interactive to users in the admin area.
flagpole_register_flag([ 'title' => 'An enforced flag', 'key' => 'enforced-flag', 'enforced' => true, ]);
Flag Groups
Flag Groups are a way to manage multiple flags at a time. You can preview Flag Groups like you can a single flag and by using the group URL parameter, and the group key you wish to enable.
A private group will require users to login to the site prior to activating the flags for them.
You can either preview a Flag Group by enabling it in the WP Admin as you would for a single flag, or you can use the query string method to enable a group of flags using the following query string format: ?group={groupKey}
Example:
https://www.example.com?group=battery-horse-staple
Shortcodes
This plugin adds a number of utility shortcodes to help debug the use of Flagpole flags.
debugFlagpole_flags
The shortcode by default shows all flags that are not enforced found in your theme. You can also specify which flags you're looking to debug specifically using the flag parameter like so with either a single key or a comma separated list:
Basic Usage:
// Single Key echo do_shortcode('[debugFlagpole_flags]');
This will display a table of all the non-enforced flags currently found in the active theme, including a status and, if they are enabled, a reason why.
You can specify single or multiple flag for this to output if you don't want to show everything.
// Multiple keys echo do_shortcode('[debugFlagpole_flags flag="key-1,key-2,key-3"]');
Passing the enforced value will display all enforced flags instead of the other flags. E.g:
echo do_shortcode('[debugFlagpole_flags enforced="true"]');
debugFlagpole_groups
Use the following shortcode to get a debug output for Flag Groups.
echo do_shortcode('[debugFlagpole_groups]');
debugFlagpole_db
Use the following shortcode to get a debug output for everything!
echo do_shortcode('[debugFlagpole_db]');
Contributing
Any PRs and suggestions are very welcome, along with ideas and discussions on issues.
jamesrwilliams/wp-feature-flags 适用场景与选型建议
jamesrwilliams/wp-feature-flags 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 20.28k 次下载、GitHub Stars 达 14, 最近一次更新时间为 2019 年 01 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「wordpress」 「feature flags」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 jamesrwilliams/wp-feature-flags 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 jamesrwilliams/wp-feature-flags 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 jamesrwilliams/wp-feature-flags 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A block that displays featured content - large image, title, description and link.
ZF2 module for the Opensoft Rollout library
MaxAl Subscriptions is a flexible plans and subscription management system for Laravel, with the required tools to run your SAAS like services efficiently. It's simple architecture, accompanied by powerful underlying to afford solid platform for your business.
A PHP trait to enable bitwise comparison of flags
Adds flags support to your model/entity
Rinvex Subscriptions is a flexible plans and subscription management system for Laravel, with the required tools to run your SAAS like services efficiently. It's simple architecture, accompanied by powerful underlying to afford solid platform for your business.
统计信息
- 总下载量: 20.28k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 14
- 点击次数: 15
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-01-17