kernl / wp-feature-flags
WordPress 特性标记。
v1.1.0
2019-09-19 14:00 UTC
Requires
- php: >=5.4
README
这是 Kernl 特性标记的 WordPress 客户端库。它使使用特性标记变得简单,并添加了一些针对 WordPress 的特定性能优化。
安装
安装库的最佳方式是使用 Composer。
composer require kernl/wp-feature-flags
使用
require __DIR__ . '/vendor/autoload.php';
// The feature flag product key. This can be found in the Kernl web app
// in the "Feature Flags" menu.
$kernlFeatureFlagProductKey = '58cb023bc9689c1fe811615d';
// The user identifier is how Kernl identifies the user requesting flags.
// This should be unique for every user.
$userIdentifier = 'jack@kernl.us';
$kff = new kernl\WPFeatureFlags($kernlFeatureFlagProductKey, $userIdentifier);
// This says "For the product defined above, does this flag exists,
// and if so, is it active for the given user?".
if ($kff->active('GITHUB_ON_OFF')) {
add_action('admin_notices', 'feature_flag_active');
}
function feature_flag_active() {
?>
<div class="notice notice-success is-dismissible">
<p>Great work! The feature flag is active.</p>
</div>
<?php
}
性能优化
该库通过将用户标记数据存储为瞬态来执行一些小的性能优化。默认时间长度为 5 分钟,因此您的标记状态最终将变得一致。