{"id":19107771,"url":"https://github.com/alleyinteractive/wp-experimental-features","last_synced_at":"2025-04-30T18:50:46.854Z","repository":{"id":39788879,"uuid":"310345562","full_name":"alleyinteractive/wp-experimental-features","owner":"alleyinteractive","description":"A feature flags system for beta testing experimental features in WordPress.","archived":false,"fork":false,"pushed_at":"2024-10-16T15:02:05.000Z","size":192,"stargazers_count":7,"open_issues_count":2,"forks_count":1,"subscribers_count":34,"default_branch":"develop","last_synced_at":"2024-10-19T07:26:06.495Z","etag":null,"topics":["wordpress","wordpress-plugin"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alleyinteractive.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-11-05T15:45:30.000Z","updated_at":"2024-10-16T14:58:42.000Z","dependencies_parsed_at":"2024-01-13T00:25:52.818Z","dependency_job_id":"acb30be8-ba0c-4566-9016-3fc0ef2d64b2","html_url":"https://github.com/alleyinteractive/wp-experimental-features","commit_stats":{"total_commits":49,"total_committers":6,"mean_commits":8.166666666666666,"dds":0.5102040816326531,"last_synced_commit":"fd8fa4ad5b0f5d02b24b5eca722db2ccd339cc67"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alleyinteractive%2Fwp-experimental-features","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alleyinteractive%2Fwp-experimental-features/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alleyinteractive%2Fwp-experimental-features/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alleyinteractive%2Fwp-experimental-features/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alleyinteractive","download_url":"https://codeload.github.com/alleyinteractive/wp-experimental-features/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223783042,"owners_count":17201915,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["wordpress","wordpress-plugin"],"created_at":"2024-11-09T04:13:54.415Z","updated_at":"2024-11-09T04:13:54.943Z","avatar_url":"https://github.com/alleyinteractive.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Experimental Features\nA WordPress plugin that creates a feature flags system for beta testing\nexperimental features in your themes or plugins.\n\n## Usage\n\n### Defining Feature Flags\n\nFeature flags are defined using a filter:\n\n```php\n/**\n * Define available feature flags.\n *\n * @param array $flags Feature flags that have been defined for the Experimental Features plugin.\n *\n * @return array The modified list of feature flags.\n */\nfunction filter_experimental_features_flags( $flags ): array {\n\t$flags['my-cool-feature'] = __( 'My Cool Feature', 'my-textdomain' );\n\n\treturn $flags;\n}\nadd_filter(\n\t'experimental_features_flags',\n\t__NAMESPACE__ . '\\filter_experimental_features_flags'\n);\n```\n\n### Checking the Value of Feature Flags\n\nThe value of a feature flag can be checked by running the feature flag slug\nthrough the `experimental_features_flag` filter. This allows for plugins and\nthemes to not break if the Experimental Features plugin is deactivated,\nbecause the filter will simply return the default value.\n\n```php\n$is_enabled = apply_filters(\n\t'experimental_features_flag',\n\tfalse,\n\t'my-cool-feature'\n);\n```\n\nIf the flag is not enabled, or if the Experimental Features plugin is not\nactive, then the default value (first parameter, `false` in the example above)\nwill be returned.\n\nIf you like, you could create a helper function for this in your plugin or\ntheme:\n\n```php\n/**\n * A helper function for determining if a feature flag is enabled.\n *\n * @param string $slug The feature flag slug to check.\n *\n * @return bool True if enabled, false if not.\n */\nfunction my_theme_flag_enabled( string $slug ): bool {\n\treturn (bool) apply_filters(\n\t\t'experimental_features_flag',\n\t\tfalse,\n\t\t$slug\n\t);\n}\n```\n\n### Toggling Feature Flags in the Admin\n\nIf you navigate to Settings \u003e Experimental Features while logged in to the\nWordPress admin as an administrator (or a user with the `manage_options`\ncapability) you can turn feature flags on and off via a simple checkbox\ninterface.\n\n### Toggling Feature Flags in the Admin Bar\n\nBy default the admin bar will include links to toggle all available feature flags individually. This can be turned off using a filter:\n\n```php\nadd_action( 'experimental_features_show_admin_bar', '__return_false' )\n```\n\n\u003cimg width=\"612\" alt=\"Screen Shot 2021-07-08 at 4 55 08 PM\" src=\"https://user-images.githubusercontent.com/346399/124989614-4b73a980-e00d-11eb-9e67-e1d4e46f4778.png\"\u003e\n\n### Listening for Flag Changes\n\nWordPress actions are fired when flags are enabled/disabled.\n\n#### On Any Flag Update\n\n```php\nadd_action(\n\t'experimental_features_flags_updated',\n\tfunction( $enabled, $disabled ) {\n\t\t// ...\n\t},\n\t10,\n\t2,\n);\n```\n\n#### When a Specific Flag is Enabled\n\n```php\nadd_action( 'experimental_features_flag_enabled_{feature-flag}', function() { ... } );\n```\n\n#### When a Specific Flag is Disabled\n\n```php\nadd_action( 'experimental_features_flag_disabled_{feature-flag}', function() { ... } );\n```\n\n### Retrieving Feature Flag Status in the REST API.\n\nThe status of feature flags can be retrieved via the REST API. The endpoint\n`/wp-json/experimental-features/v1/features` will return a JSON object with the\nstatus of all feature flags on the site.\n\n\n```json\n{\n\t\"my-cool-feature\": {\n\t\t\"label\": \"My Cool Feature\",\n\t\t\"status\": false\n\t}\n}\n```\n\n**By default, this is disabled.** To enable it, use the following filter:\n\n```php\nadd_filter( 'experimental_features_rest_api_enabled', '__return_true' );\n```\n\nThe default permissions for accessing the REST API endpoint would be for all\nusers. To restrict access you can filter the permissions callback to retrieve it\nto your needs:\n\n```php\nadd_filter(\n\t'experimental_features_rest_permission_callback',\n\tfunction () {\n\t\treturn current_user_can( 'manage_options' );\n\t},\n);\n```\n\nAll feature flags will appear on the endpoint by default. This can be filtered\nusing the `experimental_features_rest_api_flags` filter:\n\n```php\nadd_filter(\n\t'experimental_features_rest_api_flags',\n\tfunction ( $flags ) {\n\t\treturn array_filter(\n\t\t\t$flags,\n\t\t\t function ( $flag ) {\n\t\t\t\t// Only return the 'my-cool-feature' flag.\n\t\t\t\treturn 'my-cool-feature' === $flag;\n\t\t\t},\n\t\t\tARRAY_FILTER_USE_KEY\n\t\t);\n\t}\n);\n```\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Credits\n\nThis project is actively maintained by [Alley\nInteractive](https://github.com/alleyinteractive).\n\n- [All Contributors](../../contributors)\n\n## License\n\nThe GNU General Public License (GPL) license. Please see [License File](LICENSE) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falleyinteractive%2Fwp-experimental-features","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falleyinteractive%2Fwp-experimental-features","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falleyinteractive%2Fwp-experimental-features/lists"}