Skip to content

Commit 5c156e0

Browse files
committed
update namespaces to codeb
1 parent 0c611eb commit 5c156e0

File tree

18 files changed

+69
-62
lines changed

18 files changed

+69
-62
lines changed

README.md

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ WordPress Feature flags plugin allow developers to configure features in plugins
1010

1111
### PHP filters
1212

13-
#### `mr_feature_flags_max_allowed`
13+
#### `codeb_feature_flags_max_allowed`
1414

1515
Filter to define the maximum number of allowed flags. It is recommended to keep this to default value, which is 20.
1616

1717
Example usage:
1818

1919
```php
2020
add_filter(
21-
'mr_feature_flags_max_allowed',
21+
'codeb_feature_flags_max_allowed',
2222
static function () {
2323
return 10;
2424
}
@@ -27,16 +27,20 @@ add_filter(
2727

2828
### JS filters
2929

30-
##### `mrFeatureFlags.newFlag.defaultStatus`
30+
##### `codebFeatureFlags.newFlag.defaultStatus`
3131

3232
The filter controls whether the new flag is enabled by default or not. Default `true`
3333

3434
Example usage:
3535

3636
```js
37-
addFilter('mrFeatureFlags.newFlag.defaultStatus', 'codeb-feature-flags', () => {
38-
return false;
39-
});
37+
addFilter(
38+
'codebFeatureFlags.newFlag.defaultStatus',
39+
'codeb-feature-flags',
40+
() => {
41+
return false;
42+
}
43+
);
4044
```
4145

4246
## Development setup
@@ -51,27 +55,33 @@ JS setup
5155

5256
- `yarn install`
5357
- `yarn build` to create the build
54-
- `yarn start` to start the development watch mode
58+
- `yarn start` to start the watch mode
59+
60+
### wp-env
61+
62+
This plugin uses `wp-env` setup to for local environment.
63+
64+
- `wp-env start` to start the containers
65+
- `wp-env stop` to stop the containers
66+
67+
More details on how to access local environment can be found [here](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-env/#quick-tldr-instructions).
5568

5669
## Linting and formatting
5770

5871
PHP
5972

6073
- `composer lint`
61-
- To auto fix the linting errors `composer lint:fix`
62-
63-
💡 [VSCode extension](https://marketplace.visualstudio.com/items?itemName=shevaua.phpcs) to auto format PHP files based on `phpcs.xml.dist` configuration
74+
- `composer lint:fix` to auto fix PHP linting errors.
6475

6576
JS
6677

6778
- `yarn lint:js`
68-
69-
💡 [VSCode extension](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode) to auto format JS / TS files based on `.prettierrc.js` configuration
79+
- `yarn lint:js:fix` to auto fix JS linting errors.
7080

7181
CSS
7282

7383
- `yarn lint:css`
74-
- To auto fix the css linting errors `yarn lint:css:fix`
84+
- `yarn lint:css:fix` to auto fix CSS linting errors.
7585

7686
## Testing
7787

@@ -85,10 +95,10 @@ CSS
8595

8696
### JS
8797

88-
- Run `yarn test:js` which will run all jest and React Testing Library tests
98+
- Run `yarn test:js` to run all Jest and React Testing Library tests
8999

90100
### E2E
91101

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

94-
- Run `yarn test:e2e` which will run all Playwright e2e tests.
104+
- Run `yarn test:e2e` to run all Playwright e2e tests.

includes/Api/Flags.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use WP_Error;
1414
use WP_REST_Server;
1515
use WP_REST_Request;
16+
use CodeB\FeatureFlags\Flag;
1617

1718
/**
1819
* Class Settings
@@ -22,13 +23,6 @@
2223
*/
2324
class Flags {
2425

25-
/**
26-
* Name in options table.
27-
*
28-
* @var string $option_name
29-
*/
30-
public static $option_name = 'mr_feature_flags';
31-
3226
/**
3327
* Maximum allowed flags.
3428
*
@@ -83,7 +77,7 @@ public function register_routes(): void {
8377
* @return mixed List of flags.
8478
*/
8579
public function get_all_flags() {
86-
$flags = get_option( self::$option_name, [] );
80+
$flags = get_option( Flag::$option_name, [] );
8781
return rest_ensure_response( $flags );
8882
}
8983

@@ -102,14 +96,14 @@ public function post_flags( WP_REST_Request $request ) {
10296
/**
10397
* Filter to update max allowed feature flags.
10498
*/
105-
$max_allowed_flags = apply_filters( 'mr_feature_flags_max_allowed', self::$max_flags );
99+
$max_allowed_flags = apply_filters( 'codeb_feature_flags_max_allowed', self::$max_flags );
106100
if ( count( $input_data['flags'] ) > $max_allowed_flags ) {
107101
// translators: %d is a placeholder for the maximum allowed flags.
108102
$error_message = sprintf( __( 'Cannot add more than %d flags', 'codeb-feature-flags' ), $max_allowed_flags );
109103
return new WP_Error( 'flag_limit_exceeded', $error_message, array( 'status' => 400 ) );
110104
}
111105

112-
update_option( self::$option_name, $input_data['flags'] );
106+
update_option( Flag::$option_name, $input_data['flags'] );
113107
return rest_ensure_response(
114108
array(
115109
'status' => 200,

includes/Flag.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Flag {
2323
*
2424
* @var string $option_name
2525
*/
26-
public static $option_name = 'mr_feature_flags';
26+
public static $option_name = 'codeb_feature_flags';
2727

2828

2929
/**

includes/Helper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* This is the init file for the plugin
3+
* Helper class
44
*
55
* @package codeb-feature-flags
66
* @since 0.1.0
@@ -11,7 +11,7 @@
1111
namespace CodeB\FeatureFlags;
1212

1313
/**
14-
* Class FeatureFlags
14+
* Class Helper
1515
*
1616
* @package codeb-feature-flags
1717
* @since 0.1.0

includes/Settings.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,6 @@ public function register_settings() {
5252
* @return void
5353
*/
5454
public function render_page(): void {
55-
echo '<div id="mr_feature_flags_settings_screen"></div>';
55+
echo '<div id="codeb_feature_flags_settings_screen"></div>';
5656
}
5757
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"start": "wp-scripts start",
77
"build": "wp-scripts build",
88
"lint:js": "wp-scripts lint-js",
9+
"lint:js:fix": "wp-scripts lint-js --fix",
910
"lint:css": "wp-scripts lint-style",
1011
"lint:css:fix": "npm run lint:css -- --fix",
1112
"test:js": "wp-scripts test-unit-js",

playwright.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default defineConfig({
1212
fullyParallel: true,
1313
forbidOnly: !!process.env.CI,
1414
retries: process.env.CI ? 2 : 0,
15-
workers: 4,
15+
workers: process.env.CI ? 4 : 1,
1616
reporter: 'html',
1717
use: {
1818
baseURL: process.env.WP_BASE_URL,

plugin.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
/**
3434
* API and Plugin version constants.
3535
*/
36-
define( 'MR_FEATURE_FLAGS_PLUGIN_PATH', __FILE__ );
36+
define( 'CODEB_FEATURE_FLAGS_PLUGIN_PATH', __FILE__ );
3737

3838
if ( ! file_exists( Flag::class ) ) {
3939
include_once __DIR__ . '/vendor/autoload.php';
@@ -44,7 +44,7 @@
4444
'admin_enqueue_scripts',
4545
static function ( string $page ): void {
4646
if ( 'toplevel_page_codeb-feature-flags' === $page ) {
47-
mr_feature_flags_load_settings_scripts();
47+
codeb_feature_flags_load_settings_scripts();
4848
}
4949
}
5050
);
@@ -54,10 +54,10 @@ static function ( string $page ): void {
5454
*
5555
* @return void
5656
*/
57-
function mr_feature_flags_load_settings_scripts(): void {
57+
function codeb_feature_flags_load_settings_scripts(): void {
5858

59-
$plugin_url = plugin_dir_url( MR_FEATURE_FLAGS_PLUGIN_PATH );
60-
$settings_asset_file = require_once plugin_dir_path( MR_FEATURE_FLAGS_PLUGIN_PATH ) . 'build/settings.asset.php'; // @phpcs:ignore
59+
$plugin_url = plugin_dir_url( CODEB_FEATURE_FLAGS_PLUGIN_PATH );
60+
$settings_asset_file = require_once plugin_dir_path( CODEB_FEATURE_FLAGS_PLUGIN_PATH ) . 'build/settings.asset.php'; // @phpcs:ignore
6161

6262
wp_enqueue_script(
6363
'codeb-feature-flags',
@@ -80,21 +80,21 @@ function mr_feature_flags_load_settings_scripts(): void {
8080
// Enqueue scripts and styles for front end.
8181
add_action(
8282
'wp_enqueue_scripts',
83-
__NAMESPACE__ . '\mr_feature_flags_scripts_enqueue'
83+
__NAMESPACE__ . '\codeb_feature_flags_scripts_enqueue'
8484
);
8585

8686
// Enqueue scripts and styles for wp-admin.
8787
add_action(
8888
'admin_enqueue_scripts',
89-
__NAMESPACE__ . '\mr_feature_flags_scripts_enqueue'
89+
__NAMESPACE__ . '\codeb_feature_flags_scripts_enqueue'
9090
);
9191

9292
/**
9393
* Enqueue scripts and assets for admin and front end
9494
*/
95-
function mr_feature_flags_scripts_enqueue(): void {
96-
$plugin_url = plugin_dir_url( MR_FEATURE_FLAGS_PLUGIN_PATH );
97-
$script_asset_file = include_once plugin_dir_path( MR_FEATURE_FLAGS_PLUGIN_PATH ) . 'build/index.asset.php';
95+
function codeb_feature_flags_scripts_enqueue(): void {
96+
$plugin_url = plugin_dir_url( CODEB_FEATURE_FLAGS_PLUGIN_PATH );
97+
$script_asset_file = include_once plugin_dir_path( CODEB_FEATURE_FLAGS_PLUGIN_PATH ) . 'build/index.asset.php';
9898

9999
wp_enqueue_script(
100100
'codeb-feature-flags-script',
@@ -114,20 +114,20 @@ function mr_feature_flags_scripts_enqueue(): void {
114114

115115
wp_localize_script(
116116
'codeb-feature-flags-script',
117-
'mrFeatureFlags',
117+
'codebFeatureFlags',
118118
[
119119
'flags' => $flags_list,
120120
]
121121
);
122122
}
123123

124124
// Registers feature flags admin setting page.
125-
$mr_feature_flags_admin_settings = new Settings();
126-
$mr_feature_flags_admin_settings->register_feature_settings();
125+
$codeb_feature_flags_admin_settings = new Settings();
126+
$codeb_feature_flags_admin_settings->register_feature_settings();
127127

128128
// Registers feature flags API's.
129-
$mr_feature_flags_register_api = new Flags();
130-
$mr_feature_flags_register_api->register();
129+
$codeb_feature_flags_register_api = new Flags();
130+
$codeb_feature_flags_register_api->register();
131131

132132

133133
// Displays setting page link in plugin page.
@@ -152,13 +152,13 @@ static function ( $links ) {
152152
}
153153
);
154154

155-
register_deactivation_hook( __FILE__, __NAMESPACE__ . '\mr_feature_flags_uninstall' );
155+
register_deactivation_hook( __FILE__, __NAMESPACE__ . '\codeb_feature_flags_uninstall' );
156156

157157
/**
158158
* Uninstall method for the plugin.
159159
*
160160
* @return void
161161
*/
162-
function mr_feature_flags_uninstall(): void {
162+
function codeb_feature_flags_uninstall(): void {
163163
delete_option( Flag::$option_name );
164164
}

src/components/Flags.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ const Layout = (): JSX.Element => {
8181
return (
8282
<>
8383
<div id="mr-feature-flag-layout">
84-
<h1>{__('Feature Flags settings', 'codeb-feature-flags')}</h1>
84+
<h1>{__('Feature Flags', 'codeb-feature-flags')}</h1>
8585
<div id="mr-feature-flag-content">
8686
{lastFlag ? <Header /> : ''}
8787
{isLoading ? (

src/components/SubmitControls.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const SubmitControls = ({
2323
}: SubmitControlsProps): JSX.Element => {
2424
const handleNewFlag = () => {
2525
const defaultStatus = applyFilters(
26-
'mrFeatureFlags.newFlag.defaultStatus',
26+
'codebFeatureFlags.newFlag.defaultStatus',
2727
true
2828
) as boolean;
2929
const newFlag = {

0 commit comments

Comments
 (0)