Giter Site home page Giter Site logo

wp-flags's Introduction

Flags
Lightweight WordPress plugin to enable exposing feature flags to end-users, based on code-based ( or admin UI in the future ) criteria.
A Human Made project. Maintained by @shadyvb.

NOTE: This is a work-in-progress plugin.

Installation

Using Composer

  • Require the package in your project

composer require humanmade/wp-flags

Using submodules

  • Add the plugin as a submodule ( adjust the path as necessary )

git submodule add [email protected]:humanmade/wp-flags.git content/plugins/wp-flags

Usage

use HumanMade\Flags\Flags;

add_action( 'init', function() {
    Flags::add( 'new-flag', 'New Flag', [
        // Is the flag exposed to users ?
        'available' => function() {
            return current_user_can( 'manage_options' );
        },
        // At what level the flag can be set. One of `user` or `site`
        'scope' => 'user',
        // Default flag status
        'active' => true,
        // Is the flag controllable by users ?
        'optin' => true,
        // Custom icon ? ( dashicon-compatible )
        'icon' => 'dashboard',
        // Custom attribute ?
        'some_custom_meta_key' => 'some_value',
    ] );

    // OR just..
    $flag = Flags::add( 'another-flag', 'Another flag' );
    $flag->on( 'active', function( $active, $flag ) {
        // do something based on active status change
    } );

    // Execute logic based on flag status
    if ( Flags::get( 'new-flag' )->active ) {
        show_the_new_sidebar();
    } );
} );

Scope of Setting a Flag

A flag can be set at either the user or site scope, which determines how a flag is controlled. A user-scoped flag can be turned on or off by each user for that user only on a site, whereas a site-scoped flag is turned on or off for every user and is controlled in the site settings.

Credits

Written and maintained by Shady Sharaf. Thanks to all our contributors.

Interested in joining in on the fun? Join us, and become human!

wp-flags's People

Contributors

abhishek-kaushik avatar goldenapples avatar mikeselander avatar paulshryock avatar shadyvb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wp-flags's Issues

Icon to indicate state.

The admin bar UI uses a green colour to indicate the active state, however it would be nice to have a tick/cross icon as well - initially I was a little confused by the current state/

Support site-wide flag activation

Some features need to be enabled on a site-bases, so needs to be saveable as a site option rather than a user option.

We kinda have semi-support for that now with the available argument which can be a callback to restrict the flag control to specific roles, but we need to hook another adapter for site-wide options, which can be triggered from a new argument: scope => 'user' | 'site' and then specific adapters ( in users.php or site.php ) can then manage the saving / retrieving / activation of the flag.

Add WP_CLI commands for listing and updating flag states

It would be nice to have a cli command for quickly setting flags, or for viewing the state of all flags for a user or site.

This is easy enough to do already by accessing the user meta or options directly, but it would still be beneficial to add a little syntactic sugar around it. An example use case is when making a deployment to a multisite network which introduces new flags which have to be activated differently on the different sites.

The basic API structure I'm imagining is something like:

# List the active state of all flags on the current site 
wp flag site list

# List the active state of all flags for a given user on the current site 
wp flag user list <user>

# Show the state of, and maybe details about, a specific flag
wp flag site get <flag>
wp flag user get <user> <flag>
 
# Set the state of a flag
wp flag site set <flag> <value>
wp flag user set <user> <flag> <value>
 
# Activate/deactivate all flags for a user or site
wp flag site set-all <value>
wp flag user set-all <user> <value>

Manage flags without admin bar

Need to be able to enable flags for other users, and for users without the admin bar available.

On a current project, we hide the admin bar for author users. We need to be able to enable flags for these users.

It is fine for the UI to remain hidden for these users, and an admin can enable for them.

How about a CLI command? And/or display the UI on the author profile page?

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.