Download the PHP package boxuk/wp-feature-flags without Composer

On this page you can find all versions of the php package boxuk/wp-feature-flags. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package wp-feature-flags

WP Feature Flags

A plugin used to manage the publishing of features.

 Use case

At BoxUK, we release code behind feature flags. There are lots of reasons for this, but it mainly allows us to release code more frequently and at lower risk.

We use flags to slowly roll out functionality in increments, across environments. They also let us hide features without a code deploy if we spot bugs.

Registering a flag

Registering flags is handled using the FlagRegister singleton calling it's register_flag() method. It's recommended you load flags as early as possible in the load order, either by hooking to muplugins_loaded, or even calling the registration method un-hooked so that the flag registry can be populated as early as possible. We recommend that all flags are loaded before the init hook so that reading the flag status can be added after this.

A simple flag registration looks like this:

There's also a register_flags() where you can pass an array of Flag objects.

A new flag instance can be added with the following properties:

There are extra attributes that can be set in this array that give you more control over your flags.

You could use more complex logic to determine if a flag has an enforced state, such as by using functions like wp_get_environment_type(), but bare in mind these functions may not be ready until later in the loading sequence and as such you may want to hook your registration to a hook such as muplugins_loaded.

Using Flags

PHP

Ideally reading a flags status shouldn't be used before the init hook, and registration should happen before that point. This is to ensure that all flags have been registered and that the current user is logged in so we can determine if a user does have access.

The simplest check would be to use the is_enabled() method, which takes into consideration if a flag has a forced state or enabled on a per-user basis to give a valid answer.

Alternatively, all the other flag properties can be checked independently if you want more fine-control of the state of your flag.

Load Order

If you access flags before the init hook you will be able to read the state but this will very much depend on the load-order. In theory you can read a flag status as soon as you have registered the flag, since the underlying code only requires access to get_option() and get_usermeta(). However, to get the user-based value for flags requires a user-id and get_current_user_id() is not available until after init, so results will vary depending on if a user-ID is required.

As you can see, in most instances you may want to wait for the init hook before checking a flag's status since any users who are opted in to the flag will not be enabled. This may also cause complexities if you're using the flag check in multiple points in the firing sequence in a WP application and the published state might change depending on your load state.

Javascript

Flags are all registered and managed in the PHP application, but you may need to read the status of a flag in JavaScript. This package exports a number of functions to help. Install the @boxuk/wp-feature-flags package in your project and import the dependancies you'd like to use.

The following functions are available:

Function Description
useFlags() or getFlags() Returns an array of Flag objects, which you can iterate over for whatever reason.
useFlag(key) or getFlag(key) Returns a specific Flag object for the given key, or undefined if not found.
useFlagEnabled(key) or getFlagEnabled(key) Returns a boolean value of a flag, considering if the flag is forcibly enabled or disabled, and the current user's state.
registerStore() Registers the store if not already. This store is not registered on the frontend of the site by default, so you'll need to call this at least once in your code. This is only required for the use* functions.

Retrieving flags is asynchronous, so the get* functions are all async. If you're using React you can use the use* hooks to have your components re-render automatically based on the async value resolving.

The definition of a Flag object is the same as the PHP declaration above, with the exception that there is an array of users on the flag, which consists of a numeric-string value of user IDs. ie. [ '1', '2', '3' ].

Example Code:

Contributing

Please do not submit any Pull Requests here. They will be closed.

Please submit your PR here instead: https://github.com/boxuk/wp-packages

This repository is what we call a "subtree split": a read-only subset of that main repository. We're looking forward to your PR there!


All versions of wp-feature-flags with dependencies

PHP Build Version
Package Version
No informations.
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package boxuk/wp-feature-flags contains the following files

Loading the files please wait ....