Skip to content

Commit

Permalink
REST API Endpoint (#49)
Browse files Browse the repository at this point in the history
* Add new helper methods and REST API route

* Remove helper methods

* README

* Adding tests for the REST API and fixing other test

* CHANGELOG

* Removing schedule from actions

* Testing CI

* Remove lock

* Bump to PHP 8.2

* Fix README

* Allow the features on the REST API to be filtered

* Fixing amount
  • Loading branch information
srtfisher authored Feb 19, 2024
1 parent d6cdc18 commit fc897dc
Show file tree
Hide file tree
Showing 14 changed files with 291 additions and 6,848 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ on:
branches:
- develop
pull_request:
schedule:
- cron: '0 0 * * *'

jobs:
coding-standards:
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@ on:
branches:
- develop
pull_request:
schedule:
- cron: '0 0 * * *'

jobs:
php-tests:
strategy:
matrix:
php: [8.0]
php: [8.2]
wordpress: ["latest"]
multisite: [true, false]
uses: alleyinteractive/.github/.github/workflows/php-tests.yml@main
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Dependencies
vendor
composer.lock

# Log files
*.log
Expand Down
16 changes: 10 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,23 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.2.0] -- 2022-07-26
## 1.3.0 - 2024-02-16

- Adding hooks for listening to feature flags by @srtfisher in https://github.com/alleyinteractive/wp-experimental-features/pull/5
- Fix up composer.json by @kevinfodness in https://github.com/alleyinteractive/wp-experimental-features/pull/8
- Add tests for hooks, use Mantle for testing by @srtfisher in https://github.com/alleyinteractive/wp-experimental-features/pull/
- Added REST API endpoint for features.

## [1.1.0] - 2021-10-21
## 1.2.0 -- 2022-07-26

- Adding hooks for listening to feature flags.
- Fix up composer.json.
- Add tests for hooks, use Mantle for testing.

## 1.1.0 - 2021-10-21

- Adds an admin bar toggle for flags.
- Adds a changelog.
- Converts Travis tests to GitHub Actions and updates linting and tests to latest standards.

## [1.0.0] - 2020-11-09
## 1.0.0 - 2020-11-09

### Added

Expand Down
69 changes: 69 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,72 @@ add_action( 'experimental_features_flag_enabled_{feature-flag}', function() { ..
```php
add_action( 'experimental_features_flag_disabled_{feature-flag}', function() { ... } );
```

### Retrieving Feature Flag Status in the REST API.

The status of feature flags can be retrieved via the REST API. The endpoint
`/wp-json/experimental-features/v1/features` will return a JSON object with the
status of all feature flags on the site.


```json
{
"my-cool-feature": {
"label": "My Cool Feature",
"status": false
}
}
```

**By default, this is disabled.** To enable it, use the following filter:

```php
add_filter( 'experimental_features_rest_api_enabled', '__return_true' );
```

The default permissions for accessing the REST API endpoint would be for all
users. To restrict access you can filter the permissions callback to retrieve it
to your needs:

```php
add_filter(
'experimental_features_rest_permission_callback',
function () {
return current_user_can( 'manage_options' );
},
);
```

All feature flags will appear on the endpoint by default. This can be filtered
using the `experimental_features_rest_api_flags` filter:

```php
add_filter(
'experimental_features_rest_api_flags',
function ( $flags ) {
return array_filter(
$flags,
function ( $flag ) {
// Only return the 'my-cool-feature' flag.
return 'my-cool-feature' === $flag;
},
ARRAY_FILTER_USE_KEY
);
}
);
```

## Changelog

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

## Credits

This project is actively maintained by [Alley
Interactive](https://github.com/alleyinteractive).

- [All Contributors](../../contributors)

## License

The GNU General Public License (GPL) license. Please see [License File](LICENSE) for more information.
7 changes: 2 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,13 @@
"source": "https://github.com/alleyinteractive/wp-experimental-features"
},
"require-dev": {
"alleyinteractive/alley-coding-standards": "^1.0",
"mantle-framework/testkit": "^0.11"
"alleyinteractive/alley-coding-standards": "^2.0",
"mantle-framework/testkit": "^0.12"
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true,
"alleyinteractive/composer-wordpress-autoloader": true
},
"platform": {
"php": "8.0.26"
}
},
"scripts": {
Expand Down
Loading

0 comments on commit fc897dc

Please sign in to comment.