Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .env.dist
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
# Basic Wordpress Data

# ./local env vars
DB_HOST=mysql
DB_PORT=3306
DB_PASSWORD=p@55w0rd
DB_NAME=wordpress
DB_USER=root

# wp-env env vars
WP_BASE_URL=http://localhost:8888
WP_USERNAME=admin
WP_PASSWORD=password
WP_AUTH_STORAGE=.auth/wordpress.json
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
. "$(dirname -- "$0")/_/husky.sh"

yarn lint:js && yarn test:js
yarn lint:css
composer lint
composer test:unit
78 changes: 64 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,74 @@
[![JS lint & test](https://github.com/codebtech/wp-feature-flags/actions/workflows/js.yml/badge.svg)](https://github.com/codebtech/wp-feature-flags/actions/workflows/js.yml)
[![E2E Tests](https://github.com/codebtech/wp-feature-flags/actions/workflows/e2e.yml/badge.svg)](https://github.com/codebtech/wp-feature-flags/actions/workflows/e2e.yml)

Contributors: Mohan Raj Pachaiyappan
Tags: feature-flags, feature-flag, wp-feature-flags
Requires at least: 6.2
Tested up to: 6.4
Stable tag: 1.0.0
Requires PHP: 7.4
Contributor link: https://github.com/m0hanraj
Feature flags allows developers to configure features in plugins/themes behind the feature flags on both Server(PHP) and Client(JS/TS) side.Feature flags allow developers to configure features in plugins/themes behind the feature flags on both the server (PHP) and client (JS/TS) side.

## Description
## Hooks

Feature flags allows developers to configure features behind the feature flags on both Server(PHP) and Client(JS/TS) side.
### JS Filters

## Frequently Asked Questions
##### mrFeatureFlags.newFlag.defaultStatus

### Does this plugin work with PHP 8?
The filter controls whether the new flag is enabled by default or not. Default `true`

Yes, it's actively tested and working up to PHP 8.3
Example usage:

### Does this plugin work with latest WordPress?
```js
addFilter('mrFeatureFlags.newFlag.defaultStatus', 'mr-feature-flags', () => {
return false;
});
```

Yes, it's actively tested and working up to WordPress 6.4.3
## Development setup

To build the plugin

PHP setup

- `composer install`

JS setup

- `yarn install`
- `yarn build` to create the build
- `yarn start` to start the development watch mode

## Linting and formatting

PHP

- `composer lint`
- To auto fix the linting errors `composer lint:fix`

💡 [VSCode extension](https://marketplace.visualstudio.com/items?itemName=shevaua.phpcs) to auto format PHP files based on `phpcs.xml.dist` configuration

JS

- `yarn lint:js`

💡 [VSCode extension](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode) to auto format JS / TS files based on `.prettierrc` configuration

CSS

- `yarn lint:css`
- To auto fix the css linting errors `yarn lint:css:fix`

## Testing

### PHP

- Run `./local` from your preferred CLI. Ensure you have Docker installed and running.
- The setup will automatically ssh into the container.
- To run unit tests `composer run test:unit`
- To run integrations tests `composer run test:integration`
- To run integrations tests as multisite `composer run test:multisite`

### JS

- Run `yarn test:js` which will run all jest and React Testing Library tests

### E2E

The E2E tests depends on `wp-env` setup. Ensure you run `wp-env start` before running the tests.

- Run `yarn test:e2e` which will run all Playwright e2e tests.
8 changes: 4 additions & 4 deletions includes/Api/Flags.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* API class for feature flags options
*
* @package mr-feature-flags
* @since 1.0.0
* @since 0.1.0
*/

declare(strict_types = 1);
Expand All @@ -18,7 +18,7 @@
* Class Settings
*
* @package mr-feature-flags
* @since 1.0.0
* @since 0.1.0
*/
class Flags {

Expand All @@ -32,7 +32,7 @@ class Flags {
/**
* Register feature flag endpoints.
*
* @since 1.0.0
* @since 0.1.0
*/
public function register(): void {
add_action(
Expand All @@ -44,7 +44,7 @@ public function register(): void {
/**
* Register routes.
*
* * @since 1.0.0
* * @since 0.1.0
*/
public function register_routes(): void {
register_rest_route(
Expand Down
6 changes: 3 additions & 3 deletions includes/Flag.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Utility class to expose flag methods.
*
* @package mr-feature-flags
* @since 1.0.0
* @since 0.1.0
*/

declare(strict_types = 1);
Expand All @@ -14,7 +14,7 @@
* Utils class for feature flags
*
* @package mr-feature-flags
* @since 1.0.0
* @since 0.1.0
*/
class Flag {

Expand All @@ -31,7 +31,7 @@ class Flag {
*
* @param string $flag name of the flag.
* @return bool
* @since 1.0.0
* @since 0.1.0
*/
public static function is_enabled( string $flag ): bool {
$flags = get_option( self::$option_name, [] );
Expand Down
6 changes: 3 additions & 3 deletions includes/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* This is the init file for the plugin
*
* @package mr-feature-flags
* @since 1.0.0
* @since 0.1.0
*/

declare(strict_types = 1);
Expand All @@ -14,7 +14,7 @@
* Class FeatureFlags
*
* @package mr-feature-flags
* @since 1.0.0
* @since 0.1.0
*/
class Helper {

Expand All @@ -25,7 +25,7 @@ class Helper {
* @param string $field field to search.
* @param string $flag name of the flag.
* @return boolean
* @since 1.0.0
* @since 0.1.0
*/
public function search_flag( $flags, $field, $flag ) {

Expand Down
8 changes: 4 additions & 4 deletions includes/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Admin setting page for feature flags
*
* @package mr-feature-flags
* @since 1.0.0
* @since 0.1.0
*/

declare(strict_types = 1);
Expand All @@ -14,15 +14,15 @@
* Class Settings
*
* @package mr-feature-flags
* @since 1.0.0
* @since 0.1.0
*/
class Settings {

/**
* Register feature flag settings page.
*
* @return void
* @since 1.0.0
* @since 0.1.0
*/
public function register_feature_settings() {
add_action( 'admin_menu', [ $this, 'register_settings' ] );
Expand All @@ -32,7 +32,7 @@ public function register_feature_settings() {
* Register settings action method.
*
* @return void
* @since 1.0.0
* @since 0.1.0
*/
public function register_settings() {

Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
{
"name": "mr-feature-flags",
"version": "1.0.0",
"version": "0.1.0",
"description": "Allows developers to enable / disable features based on flags.",
"scripts": {
"start": "wp-scripts start",
"build": "wp-scripts build",
"lint:js": "wp-scripts lint-js",
"lint:css": "wp-scripts lint-style",
"lint:css:fix": "npm run lint:css -- --fix",
"test:js": "wp-scripts test-unit-js",
"test:watch": "wp-scripts test-unit-js --watch",
"prepare": "husky install",
Expand Down
4 changes: 2 additions & 2 deletions plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
/**
* The plugin bootstrap file
*
* @since 1.0.0
* @since 0.1.0
* @package mr-feature-flags
*
* @wordpress-plugin
* Plugin Name: Feature Flags
* Description: Allows developers to enable / disable features based on flags.
* Version: 1.0.0
* Version: 0.1.0
* Author: Mohan Raj
* Author URI: https://mohanraj.dev
* License: GPL-2.0+
Expand Down
4 changes: 3 additions & 1 deletion src/styles/settings.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
.feature-flag-snackbar {
bottom: 3.5rem;
position: fixed;

.components-snackbar__icon {
left: 18px;
top: auto;
}
}

.feature-flag-loader {

.components-spinner {
width: 20px;
height: 20px;
Expand All @@ -40,7 +42,7 @@
}

.mr-feature-flags-clipboard-base {
color: darkgray !important;
color: #a9a9a9 !important;
float: right;
position: relative;
right: 40px;
Expand Down