Giter VIP home page Giter VIP logo

feature-flags's Introduction

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($options);

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 In template 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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.