Feature flags are a powerful tool for controlling the availability of features on your site. By enabling or disabling flags, you can control what is active on your site without needing to deploy new code.
Features are defined in the switcheroo.json file located in the root of your project.
Each feature has:
You can toggle each feature within the Switcheroo Settings in the WP Admin (Settings -> Switcheroo).
You can wrap your feature-specific code in a conditional statement to check if a flag is enabled.
For example, use the switcheroo_flag_status('my_feature') function to determine whether a feature is active and include its logic conditionally.
Each feature flag can be assigned a status, allowing for better organisation and understanding of the feature’s state:
You can also manage your feature flags via the command line using WP-CLI. The wp switcheroo command allows you to view and modify feature flags.
Examples:
– wp switcheroo: List all flags and their statuses.
– wp switcheroo my_feature: Check the status of the my_feature flag.
– wp switcheroo my_feature on: Enable the my_feature flag.
– wp switcheroo my_feature off: Disable the my_feature flag.