alleyinteractive/wp-experimental-features 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

alleyinteractive/wp-experimental-features

Composer 安装命令:

composer require alleyinteractive/wp-experimental-features

包简介

WP Experimental Features

README 文档

README

A WordPress plugin that creates a feature flags system for beta testing experimental features in your themes or plugins.

Usage

Defining Feature Flags

Feature flags are defined using a filter:

/**
 * Define available feature flags.
 *
 * @param array $flags Feature flags that have been defined for the Experimental Features plugin.
 *
 * @return array The modified list of feature flags.
 */
function filter_experimental_features_flags( $flags ): array {
	$flags['my-cool-feature'] = __( 'My Cool Feature', 'my-textdomain' );

	return $flags;
}
add_filter(
	'experimental_features_flags',
	__NAMESPACE__ . '\filter_experimental_features_flags'
);

Checking the Value of Feature Flags

The value of a feature flag can be checked by running the feature flag slug through the experimental_features_flag filter. This allows for plugins and themes to not break if the Experimental Features plugin is deactivated, because the filter will simply return the default value.

$is_enabled = apply_filters(
	'experimental_features_flag',
	false,
	'my-cool-feature'
);

If the flag is not enabled, or if the Experimental Features plugin is not active, then the default value (first parameter, false in the example above) will be returned.

If you like, you could create a helper function for this in your plugin or theme:

/**
 * A helper function for determining if a feature flag is enabled.
 *
 * @param string $slug The feature flag slug to check.
 *
 * @return bool True if enabled, false if not.
 */
function my_theme_flag_enabled( string $slug ): bool {
	return (bool) apply_filters(
		'experimental_features_flag',
		false,
		$slug
	);
}

Toggling Feature Flags in the Admin

If you navigate to Settings > Experimental Features while logged in to the WordPress admin as an administrator (or a user with the manage_options capability) you can turn feature flags on and off via a simple checkbox interface.

Toggling Feature Flags in the Admin Bar

By default the admin bar will include links to toggle all available feature flags individually. This can be turned off using a filter:

add_action( 'experimental_features_show_admin_bar', '__return_false' )

Screen Shot 2021-07-08 at 4 55 08 PM

Listening for Flag Changes

WordPress actions are fired when flags are enabled/disabled.

On Any Flag Update

add_action(
	'experimental_features_flags_updated',
	function( $enabled, $disabled ) {
		// ...
	},
	10,
	2,
);

When a Specific Flag is Enabled

add_action( 'experimental_features_flag_enabled_{feature-flag}', function() { ... } );

When a Specific Flag is Disabled

add_action( 'experimental_features_flag_disabled_{feature-flag}', function() { ... } );

Retrieving Feature Flag Status in the REST API.

The status of feature flags can be retrieved via the REST API. The endpoint /wp-json/experimental-features/v1/features will return a JSON object with the status of all feature flags on the site.

{
	"my-cool-feature": {
		"label": "My Cool Feature",
		"status": false
	}
}

By default, this is disabled. To enable it, use the following filter:

add_filter( 'experimental_features_rest_api_enabled', '__return_true' );

The default permissions for accessing the REST API endpoint would be for all users. To restrict access you can filter the permissions callback to retrieve it to your needs:

add_filter(
	'experimental_features_rest_permission_callback',
	function () {
		return current_user_can( 'manage_options' );
	},
);

All feature flags will appear on the endpoint by default. This can be filtered using the experimental_features_rest_api_flags filter:

add_filter(
	'experimental_features_rest_api_flags',
	function ( $flags ) {
		return array_filter(
			$flags,
			 function ( $flag ) {
				// Only return the 'my-cool-feature' flag.
				return 'my-cool-feature' === $flag;
			},
			ARRAY_FILTER_USE_KEY
		);
	}
);

Changelog

Please see CHANGELOG for more information on what has changed recently.

Credits

This project is actively maintained by Alley Interactive.

License

The GNU General Public License (GPL) license. Please see License File for more information.

alleyinteractive/wp-experimental-features 适用场景与选型建议

alleyinteractive/wp-experimental-features 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 27.33k 次下载、GitHub Stars 达 10, 最近一次更新时间为 2022 年 07 月 26 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 alleyinteractive/wp-experimental-features 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 27.33k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 10
  • 点击次数: 13
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 10
  • Watchers: 30
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0-or-later
  • 更新时间: 2022-07-26