peterhartree / feature-flags

WordPress plugin for easily configuring and working with feature flags/toggles in your theme.

Home Page:https://github.com/jamesrwilliams/feature-flags

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature flags for WordPress themes

This plugin is for developers. The aim is to simplify/speed up the process of working with feature flags.

Features

  • Adds an admin UI where users can enable/disable features for testing in a live environment.
  • Can enforce flags once you are happy for them to be deployed (allows for staged removal in source).

Planned development

Usage

Required theme changes

Due to the nature of this plugin requiring theme changes, it is a good idea to add the following to the your theme to catch any errors that may occur if the feature-flags plugin is disabled for any reason.

if ( ! function_exists( 'is_enabled' ) ) {
	function is_enabled() {
		return false;
	}
}

Register a flag

register_feature_flag( $args );

When registering a flag it is a good idea to wrap them in a function exists block to avoid any errors if the plugin is disabled for any reason. In your templates you can then check the feature status using:

if ( function_exists( 'register_feature_flag' ) ) {

    register_feature_flag([
        
        'title' => 'My awesome new feature',
        'key' => 'correct-horse-battery-staple',
        'enforced' => false,
        'description' => 'An example feature definition'
    
    ]);
}

Checking the status of a feature flag

is_enabled( 'feature-key' );

Replace feature-key with the key used in the register function to check if it is enabled.

Example

if ( is_enabled( 'correct-horse-battery-staple' ) ) {
    /* Flagged feature */
}

Options

key - string

The unique key used in the template to check if a feature is enabled.

title - string

The human readable feature name.

enforced (optional) - boolean - Default: false

Setting this to true will override any user specific settings and will enforce the flag to be true for every user. Useful for deploying a flag before removing it from the codebase.

description (optional) - string - Default: ''

A description displayed in the admin screen. Use to tell users what they are enabling and other information.

Standards

This project uses the WordPress VIP coding standards.

About

WordPress plugin for easily configuring and working with feature flags/toggles in your theme.

https://github.com/jamesrwilliams/feature-flags

License:MIT License


Languages

Language:PHP 84.4%Language:JavaScript 9.7%Language:CSS 5.9%