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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ The filter controls whether the new flag is enabled by default or not. Default `
Example usage:

```js
addFilter('mrFeatureFlags.newFlag.defaultStatus', 'mr-feature-flags', () => {
addFilter('mrFeatureFlags.newFlag.defaultStatus', 'codeb-feature-flags', () => {
return false;
});
```
Expand Down
34 changes: 20 additions & 14 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
{
"name": "codeb/wp-feature-flags",
"description": "Allows developers to enable / disable features based on flags.",
"type": "wordpress-plugin",
"license": "MIT",
"repositories": [
{
"type": "vcs",
"url": "https://git@github.com/WordPress/wordpress-develop"
}
],
"type": "wordpress-plugin",
"require": {
"php": ">=8.1"
},
"require-dev": {
"wordpress/wordpress": "^6.4",
"phpunit/phpunit": "^9.4",
"brain/monkey": "^2.6",
"newsuk/nuk-wp-phpcs-config": "^0.2.0",
"newsuk/nuk-wp-phpstan-config": "^0.1.0",
"newsuk/nuk-wp-phpmd-config": "^0.1.0",
"newsuk/nuk-wp-phpstan-config": "^0.1.0",
"phpunit/phpunit": "^9.4",
"wordpress/wordpress": "^6.4",
"yoast/wp-test-utils": "^1.2"
},
"repositories": [
{
"type": "vcs",
"url": "https://git@github.com/WordPress/wordpress-develop"
}
],
"autoload": {
"psr-4": {
"CodeB\\FeatureFlags\\": [
Expand All @@ -34,16 +37,19 @@
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true,
"phpstan/extension-installer": true
},
"platform": {
"php": "8.1"
}
},
"scripts": {
"lint": "phpcs .",
"lint:fix": "phpcbf .",
"test:unit": "phpunit --dont-report-useless-tests --configuration ./phpunit.xml --testsuite unit --testdox --coverage-text",
"test:integration": "phpunit --dont-report-useless-tests --configuration ./phpunit-integration.xml --testsuite integration --testdox --coverage-text",
"test:multisite": "phpunit --dont-report-useless-tests --configuration ./phpunit-integration-multisite.xml --testsuite integration --testdox --coverage-text",
"phpmd": "phpmd plugin.php,includes text phpmd.xml.dist --color",
"phpstan": "phpstan analyse --memory-limit=2048M",
"phpstan-baseline": "phpstan analyse -b --allow-empty-baseline --memory-limit=2048M",
"phpmd": "phpmd plugin.php,includes text phpmd.xml.dist --color"
"test:integration": "phpunit --dont-report-useless-tests --configuration ./phpunit-integration.xml --testsuite integration --testdox --coverage-text",
"test:multisite": "phpunit --dont-report-useless-tests --configuration ./phpunit-integration-multisite.xml --testsuite integration --testdox --coverage-text",
"test:unit": "phpunit --dont-report-useless-tests --configuration ./phpunit.xml --testsuite unit --testdox --coverage-text"
}
}
9 changes: 7 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions includes/Api/Flags.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* API class for feature flags options
*
* @package mr-feature-flags
* @package codeb-feature-flags
* @since 0.1.0
*/

Expand All @@ -17,7 +17,7 @@
/**
* Class Settings
*
* @package mr-feature-flags
* @package codeb-feature-flags
* @since 0.1.0
*/
class Flags {
Expand Down Expand Up @@ -105,7 +105,7 @@ public function post_flags( WP_REST_Request $request ) {
$max_allowed_flags = apply_filters( 'mr_feature_flags_max_allowed', self::$max_flags );
if ( count( $input_data['flags'] ) > $max_allowed_flags ) {
// translators: %d is a placeholder for the maximum allowed flags.
$error_message = sprintf( __( 'Cannot add more than %d flags', 'mr-feature-flags' ), $max_allowed_flags );
$error_message = sprintf( __( 'Cannot add more than %d flags', 'codeb-feature-flags' ), $max_allowed_flags );
return new WP_Error( 'flag_limit_exceeded', $error_message, array( 'status' => 400 ) );
}

Expand All @@ -118,7 +118,7 @@ public function post_flags( WP_REST_Request $request ) {
);
}

return new WP_Error( 'invalid_input', __( 'Cannot update flags', 'mr-feature-flags' ), array( 'status' => 400 ) );
return new WP_Error( 'invalid_input', __( 'Cannot update flags', 'codeb-feature-flags' ), array( 'status' => 400 ) );
}

/**
Expand Down
4 changes: 2 additions & 2 deletions includes/Flag.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Utility class to expose flag methods.
*
* @package mr-feature-flags
* @package codeb-feature-flags
* @since 0.1.0
*/

Expand All @@ -13,7 +13,7 @@
/**
* Utils class for feature flags
*
* @package mr-feature-flags
* @package codeb-feature-flags
* @since 0.1.0
*/
class Flag {
Expand Down
4 changes: 2 additions & 2 deletions includes/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* This is the init file for the plugin
*
* @package mr-feature-flags
* @package codeb-feature-flags
* @since 0.1.0
*/

Expand All @@ -13,7 +13,7 @@
/**
* Class FeatureFlags
*
* @package mr-feature-flags
* @package codeb-feature-flags
* @since 0.1.0
*/
class Helper {
Expand Down
10 changes: 5 additions & 5 deletions includes/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Admin setting page for feature flags
*
* @package mr-feature-flags
* @package codeb-feature-flags
* @since 0.1.0
*/

Expand All @@ -13,7 +13,7 @@
/**
* Class Settings
*
* @package mr-feature-flags
* @package codeb-feature-flags
* @since 0.1.0
*/
class Settings {
Expand All @@ -37,10 +37,10 @@ public function register_feature_settings() {
public function register_settings() {

add_menu_page(
__( 'Feature Flags', 'mr-feature-flags' ),
__( 'Feature Flags', 'mr-feature-flags' ),
__( 'Feature Flags', 'codeb-feature-flags' ),
__( 'Feature Flags', 'codeb-feature-flags' ),
'manage_options',
'mr-feature-flags',
'codeb-feature-flags',
[ $this, 'render_page' ],
'data:image/svg+xml;base64,' . base64_encode( '<svg width="15" height="18" viewBox="0 0 2000 1792" xmlns="http://www.w3.org/2000/svg"><path fill="black" d="M0 896q0-130 51-248.5t136.5-204 204-136.5 248.5-51h768q130 0 248.5 51t204 136.5 136.5 204 51 248.5-51 248.5-136.5 204-204 136.5-248.5 51h-768q-130 0-248.5-51t-204-136.5-136.5-204-51-248.5zm1408 512q104 0 198.5-40.5t163.5-109.5 109.5-163.5 40.5-198.5-40.5-198.5-109.5-163.5-163.5-109.5-198.5-40.5-198.5 40.5-163.5 109.5-109.5 163.5-40.5 198.5 40.5 198.5 109.5 163.5 163.5 109.5 198.5 40.5z"/></svg>' )
);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "mr-feature-flags",
"name": "codeb-feature-flags",
"version": "0.1.0",
"description": "Allows developers to enable / disable features based on flags.",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<rule ref="WordPress.WP.I18n">
<properties>
<property name="text_domain" type="array">
<element value="mr-feature-flags"/>
<element value="codeb-feature-flags"/>
</property>
</properties>
</rule>
Expand Down
22 changes: 12 additions & 10 deletions plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@
* The plugin bootstrap file
*
* @since 0.1.0
* @package mr-feature-flags
* @package codeb-feature-flags
*
* @wordpress-plugin
* Plugin Name: Feature Flags
* Plugin URI: https://github.com/codebtech/wp-feature-flags
* Description: Allows developers to enable / disable features based on flags.
* Version: 0.1.0
* Requires at least: 6.4
* Requires PHP: 8.1
* Author: Mohan Raj
* Author URI: https://mohanraj.dev
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Text Domain: mr-feature-flags
* Text Domain: codeb-feature-flags
*/

declare( strict_types = 1 );
Expand All @@ -41,7 +43,7 @@
add_action(
'admin_enqueue_scripts',
static function ( string $page ): void {
if ( 'toplevel_page_mr-feature-flags' === $page ) {
if ( 'toplevel_page_codeb-feature-flags' === $page ) {
mr_feature_flags_load_settings_scripts();
}
}
Expand All @@ -58,7 +60,7 @@ function mr_feature_flags_load_settings_scripts(): void {
$settings_asset_file = require_once plugin_dir_path( MR_FEATURE_FLAGS_PLUGIN_PATH ) . 'build/settings.asset.php'; // @phpcs:ignore

wp_enqueue_script(
'mr-feature-flags',
'codeb-feature-flags',
$plugin_url . 'build/settings.js',
$settings_asset_file['dependencies'],
$settings_asset_file['version'],
Expand All @@ -68,7 +70,7 @@ function mr_feature_flags_load_settings_scripts(): void {
wp_enqueue_style( 'wp-edit-blocks' );

wp_enqueue_style(
'mr-feature-flags',
'codeb-feature-flags',
$plugin_url . 'build/settings.css',
[],
$settings_asset_file['version']
Expand All @@ -95,7 +97,7 @@ function mr_feature_flags_scripts_enqueue(): void {
$script_asset_file = include_once plugin_dir_path( MR_FEATURE_FLAGS_PLUGIN_PATH ) . 'build/index.asset.php';

wp_enqueue_script(
'mr-feature-flags-script',
'codeb-feature-flags-script',
$plugin_url . 'build/index.js',
$script_asset_file['dependencies'],
$script_asset_file['version'],
Expand All @@ -111,7 +113,7 @@ function mr_feature_flags_scripts_enqueue(): void {
}

wp_localize_script(
'mr-feature-flags-script',
'codeb-feature-flags-script',
'mrFeatureFlags',
[
'flags' => $flags_list,
Expand All @@ -130,17 +132,17 @@ function mr_feature_flags_scripts_enqueue(): void {

// Displays setting page link in plugin page.
add_filter(
'plugin_action_links_mr-feature-flags/plugin.php',
'plugin_action_links_codeb-feature-flags/plugin.php',
static function ( $links ) {
$url = esc_url(
add_query_arg(
'page',
'mr-feature-flags',
'codeb-feature-flags',
get_admin_url() . 'admin.php'
)
);

$settings_link = "<a href='$url'>" . __( 'Settings', 'mr-feature-flags' ) . '</a>';
$settings_link = "<a href='$url'>" . __( 'Settings', 'codeb-feature-flags' ) . '</a>';

array_push(
$links,
Expand Down
18 changes: 9 additions & 9 deletions src/components/FlagRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ const FlagRow = ({
const handleFlagEdit = (value: string, flagId: number) => {
if (checkIfFlagExists(flags, value)) {
// eslint-disable-next-line @wordpress/i18n-no-variables
setErrorMessage(__(ERROR_FLAG_EXISTS, 'mr-feature-flags'));
setErrorMessage(__(ERROR_FLAG_EXISTS, 'codeb-feature-flags'));
setDisableSave(true);
} //Alphanumeric,hypen and underscore validation
else if (value.match(/^[a-zA-Z0-9\_-]*$/)) {
setErrorMessage('');
setDisableSave(false);
} else {
// eslint-disable-next-line @wordpress/i18n-no-variables
setErrorMessage(__(ERROR_FLAG_INVALID, 'mr-feature-flags'));
setErrorMessage(__(ERROR_FLAG_INVALID, 'codeb-feature-flags'));
setDisableSave(true);
}

Expand Down Expand Up @@ -112,13 +112,13 @@ const FlagRow = ({
<Flex justify={'flex-start'}>
<FlexItem>
<TextControl
className="mr-feature-flags-input"
className="codeb-feature-flags-input"
ref={inputRef}
value={item.name}
onChange={(value) => handleFlagEdit(value, item.id)}
/>
</FlexItem>
<FlexItem className="mr-feature-flags-toggle">
<FlexItem className="codeb-feature-flags-toggle">
<ToggleControl
checked={item.enabled}
disabled={!!errorMessage}
Expand All @@ -127,26 +127,26 @@ const FlagRow = ({
/>
</FlexItem>

<FlexItem className="mr-feature-flags-sdk">
<FlexItem className="codeb-feature-flags-sdk">
<Button
variant="secondary"
label={__(
'Click to see SDK setting',
'mr-feature-flags'
'codeb-feature-flags'
)}
showTooltip
tooltipPosition="top right"
onClick={handleSdkModal}
>
{__('</> SDK', 'mr-feature-flags')}
{__('</> SDK', 'codeb-feature-flags')}
</Button>
</FlexItem>
<FlexItem className="mr-feature-flags-delete">
<FlexItem className="codeb-feature-flags-delete">
<Button
icon={'trash'}
isDestructive
variant="tertiary"
label={__('Delete Flag', 'mr-feature-flags')}
label={__('Delete Flag', 'codeb-feature-flags')}
onClick={() => handleDeleteModal(item)}
/>
</FlexItem>
Expand Down
8 changes: 4 additions & 4 deletions src/components/Flags.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ const Layout = (): JSX.Element => {
const response = await updateFlags({ ...input });
if ('status' in response && response.status === 200) {
createSuccessNotice(
__('Saved successfully!', 'mr-feature-flags'),
__('Saved successfully!', 'codeb-feature-flags'),
{
type: 'snackbar',
id: 'mr-feature-flags-snackbar',
id: 'codeb-feature-flags-snackbar',
icon: <>✅</>,
}
);
Expand All @@ -47,7 +47,7 @@ const Layout = (): JSX.Element => {
//@ts-ignore
createErrorNotice(error?.message, {
type: 'snackbar',
id: 'mr-feature-flags-snackbar',
id: 'codeb-feature-flags-snackbar',
icon: <>❌</>,
});
}
Expand Down Expand Up @@ -81,7 +81,7 @@ const Layout = (): JSX.Element => {
return (
<>
<div id="mr-feature-flag-layout">
<h1>{__('Feature Flags settings', 'mr-feature-flags')}</h1>
<h1>{__('Feature Flags settings', 'codeb-feature-flags')}</h1>
<div id="mr-feature-flag-content">
{lastFlag ? <Header /> : ''}
{isLoading ? (
Expand Down
Loading