Beta Flags … now with A/B Testing!
Beta Flags allow developers to manage the release of new features. Instead of having code execute as soon as it is deployed to the production environment. You can now wrap it in a beta flag conditional and activate it from the back end. A/B Testing works very similarly, except that instead of turnin
Beta Flags allow developers to manage the release of new features. Instead of having code execute as soon as it is deployed to the production environment. You can now wrap it in a beta flag conditional and activate it from the back end.
A/B Testing works very similarly, except that instead of turning a code block on or off, they allow you to turn it on 50% of the time. This uses a slight variant on the URL used to display a post or term page, which can then be tracked in an analytics service (e.g. Adobe Omniture, Google 360).
The Basics of Beta Flags
To create a new beta flag, open the configuration JSON file. A copy of this file is provided with this plugin and is stored at data/beta-flags.json . You may prefer to create a copy in the root of your theme, the same folder that contains functions.php ( [theme]/beta-flags.json ).
The JSON file follows the format below: { "flags": { "sidebar_web": { "title": "Beta Flags IN THEME", "description": "Add a sidebar to the post page", "author": "Charles Jaimet" }, "library_admin": { "title": "Beta Flags QA: Plugin Admin Test", "description": "For Beta Flag testing in admin interface", "author": "Charles Jaimet" } } }
Each flag is defined by a key (e.g. sidebar_web, library_admin), representing an object with a title, description, and author. The key must be unique, and is used throughout to identify the given flag.
Once you have activated the plugin (there are no special instructions for this), navigate to Tools > Beta Flags in the admin interface ( /wp-admin/tools.php?page=beta-flags ). Here you will find the flags from your JSON file if you have created it correctly.
A note about JSON, the easiest mistake to make is to put a comma after the last element in an array or object. This will break the JSON but is easy enough to fix when you know what to look for. Kinda like forgetting a semi-colon in PHP. Stupid semi-colons…
When you first load the plugin, and any time after you update the JSON file, you should return to this admin screen. New flags are disabled by default, and can only be enabled here. Check the box in the Enabled column beside each flag you want to turn on. Click Save Changes when done.
In your theme or other plugins, you can use these beta flag keys to control feature execution by wrapping a conditional around the relevant code. Try to group your wrapped code into a single function, method, or class to avoid littering your theme with beta flag conditionals.
The public function beta_flag_enabled( $key ) will return a true|false value if the beta flag is enabled.