humanmade/wp-flags

Lightweight WordPress plugin to enable exposing feature flags to end-users, based on code-based ( or admin UI in the future ) criteria.

Installs: 42 581

Dependents: 0

Suggesters: 0

Security: 0

Stars: 34

Watchers: 24

Forks: 3

Open Issues: 5

Type:wordpress-plugin

0.0.8 2021-11-11 14:29 UTC

This package is auto-updated.

Last update: 2024-07-11 20:50:36 UTC


README

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 git@github.com: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!