Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Onboarding and settings refactor to React #771

Open
wants to merge 163 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 158 commits
Commits
Show all changes
163 commits
Select commit Hold shift + click to select a range
951ca34
Updated current setting page slug to classifai_old.
iamdharmesh May 15, 2024
f16a7ba
Initial base react setting page.
iamdharmesh May 15, 2024
3d9608d
Created user access component.
iamdharmesh May 16, 2024
9852d84
Improved folder structure and some other improvements.
iamdharmesh May 16, 2024
bc8ecb0
Add data store for state management.
iamdharmesh May 17, 2024
85812e7
Update components as per to utilize data store.
iamdharmesh May 17, 2024
cab688f
Added sample providerSettings and additionalFeature settings filters.
iamdharmesh May 17, 2024
7d22280
Improvements in root component.
iamdharmesh May 18, 2024
e93c8fb
Add current service and feature releated functions in useSettings hook.
iamdharmesh May 18, 2024
6d0c083
Update in settings-wrapper component.
iamdharmesh May 18, 2024
8b92370
Set default service and feature based on tab.
iamdharmesh May 18, 2024
c598688
Re-structure folders in components folder.
iamdharmesh May 18, 2024
27f65da
Make use of <PluginArea /> to extend provider and additional feature …
iamdharmesh May 18, 2024
f8af6aa
Extend feature settings for comment-moderation feature.
iamdharmesh May 18, 2024
de46637
Extend open-moderation provider fields.
iamdharmesh May 18, 2024
0bf8054
narrow down the container
faisal-alvi May 24, 2024
9130c00
Fix header links.
iamdharmesh May 24, 2024
db671f9
button full width; min heights to tabs
faisal-alvi May 24, 2024
3836a24
Merge branch 'enhancement/react-settings' of github.com:10up/classifa…
Sidsector9 May 28, 2024
b5f74d2
improve re-rednering performance
Sidsector9 May 28, 2024
9e61e61
further improve performance
Sidsector9 May 28, 2024
b0bd72b
remove unused deps
Sidsector9 May 28, 2024
0c142e6
Move allowed roles to separate component.
iamdharmesh May 31, 2024
934bd57
Design improvements.
iamdharmesh Jun 5, 2024
9fc9b3f
Changed tab panel with react router dom.
iamdharmesh Jun 6, 2024
2d6ed38
Code Improvements
iamdharmesh Jun 6, 2024
a1252b6
Simplified extended code.
iamdharmesh Jun 6, 2024
b878683
Improved component re-rendering
iamdharmesh Jun 7, 2024
13e7a17
Added provider fields for the chatGPT, Gemini API and Azure OpenAI
iamdharmesh Jun 7, 2024
6066ece
Temporary stop E2E tests.
iamdharmesh Jun 7, 2024
c9617d1
Updated update settings API
iamdharmesh Jun 11, 2024
3f7e586
Added error notice in settings.
iamdharmesh Jun 11, 2024
6823007
Removed unwanted hook.
iamdharmesh Jun 11, 2024
9410cd0
Merge branch 'develop' of github.com:10up/classifai into enhancement/…
iamdharmesh Jun 27, 2024
f371339
Use context to avoid props-drilling
iamdharmesh Jun 28, 2024
d3179ca
Remove unwanted doc comments.
iamdharmesh Jun 28, 2024
acda4c0
Added provider settings for IBM watson NLU.
iamdharmesh Jun 28, 2024
eee6698
Updated UI for configured providers.
iamdharmesh Jun 28, 2024
8b17b65
Added additional openai providers.
iamdharmesh Jun 28, 2024
d6d0297
Added some more providers
iamdharmesh Jun 28, 2024
2f349d6
Match component style with admin color.
iamdharmesh Jun 28, 2024
ef5f224
Started Adding additional feature setting fields.
iamdharmesh Jun 28, 2024
f32682a
Indicate saving settings.
iamdharmesh Jun 28, 2024
9b66776
Added OpenAI dalle provider settings.
iamdharmesh Jul 15, 2024
7f20d04
Added additional settings for image tags generator feature.
iamdharmesh Jul 15, 2024
10e7b24
Add AWS polly providers.
iamdharmesh Jul 15, 2024
293b637
Added Azure Text to Speech provider settings.
iamdharmesh Jul 15, 2024
56bae2a
Added provider settings for the OpenAI TTS
iamdharmesh Jul 15, 2024
3b0a684
Added TTS feature settings.
iamdharmesh Jul 16, 2024
9fa97c1
Added Title generation settings.
iamdharmesh Jul 17, 2024
2ea55ee
Content resizing settings.
iamdharmesh Jul 17, 2024
42910c2
Excerpt generation settings.
iamdharmesh Jul 17, 2024
1c93d65
Initial classification settings.
iamdharmesh Jul 18, 2024
2b91a7c
Added classification settings.
iamdharmesh Jul 18, 2024
f58286c
Added moderation settings.
iamdharmesh Jul 18, 2024
2d0cc10
Make User Permissions panel toggle persistence.
iamdharmesh Jul 18, 2024
f25cf1c
Add ClassifAI registration
iamdharmesh Aug 3, 2024
6958ffe
Merge branch 'enhancement/react-settings' of github.com:10up/classifa…
Sidsector9 Aug 20, 2024
3ff60f4
Merge branch 'develop' into enhancement/react-settings
Sidsector9 Aug 20, 2024
a22327b
add fragment between Tooltip and Icon
Sidsector9 Aug 20, 2024
bbf2e4d
create the onboarding page
Sidsector9 Aug 20, 2024
78fdcff
use hook instead
Sidsector9 Aug 20, 2024
4638e83
add onboarding page
Sidsector9 Aug 23, 2024
9f03ef2
Merge branch 'enhancement/react-settings' of github.com:10up/classifa…
iamdharmesh Aug 26, 2024
72ae5e4
Display notice at feature level.
iamdharmesh Aug 26, 2024
9afdbc9
Add personalizer deprecation notice.
iamdharmesh Aug 26, 2024
d8e375d
Hide credentials fields if provider is configured.
iamdharmesh Aug 26, 2024
d5b682f
Fix PHPCS errors.
iamdharmesh Aug 26, 2024
50c50f3
Remove unwanted files.
iamdharmesh Aug 26, 2024
7913396
Remove admin component.
iamdharmesh Aug 27, 2024
6e012f6
Refactor onboarding steps.
iamdharmesh Aug 27, 2024
cd0fa2a
Added onSaveSuccess callback support.
iamdharmesh Aug 27, 2024
d7c29c8
Remove layout component.
iamdharmesh Aug 28, 2024
c4b63e7
Update finish step designs.
iamdharmesh Aug 28, 2024
85f9eaf
Refactor configure feature step.
iamdharmesh Aug 28, 2024
9766aac
Removed unwanted state from the onboarding process.
iamdharmesh Aug 28, 2024
6b16f63
Update onboarding header navigation.
iamdharmesh Aug 28, 2024
6f1b850
Added button links to last step.
iamdharmesh Aug 28, 2024
050e68b
Add registration step.
iamdharmesh Aug 28, 2024
94a497f
Merge branch 'enhancement/react-settings' of github.com:10up/classifa…
Sidsector9 Aug 29, 2024
5923c70
add previewer search control
Sidsector9 Aug 29, 2024
0c320fd
fetch results
Sidsector9 Aug 29, 2024
5da4860
color code results
Sidsector9 Aug 29, 2024
ecdbea8
add context for previewer
Sidsector9 Aug 29, 2024
2fa4887
add notice
Sidsector9 Aug 29, 2024
1186849
add close previewer button
Sidsector9 Aug 30, 2024
8f1d26a
modify embeddings result data format
Sidsector9 Aug 30, 2024
8ffd0f0
add support for OpenAIEmbedding
Sidsector9 Aug 30, 2024
b0eb75c
add previewer for IBMWatson
Sidsector9 Aug 31, 2024
1c0c285
move provider previewers into separate components
Sidsector9 Sep 1, 2024
dd9be21
Merge branch 'develop' of github.com:10up/classifai into enhancement/…
iamdharmesh Sep 4, 2024
90a0af1
Adding style to loading spinner.
iamdharmesh Sep 4, 2024
6acc9d0
Some design fixes on onboarding.
iamdharmesh Sep 4, 2024
4515563
Move notices under header.
iamdharmesh Sep 4, 2024
5b1e06c
Add current step stat on configure feature tabs in onboarding.
iamdharmesh Sep 4, 2024
adbd95b
Skip registration step if user is already registered.
iamdharmesh Sep 4, 2024
6a015ac
fix embeddings old previewer
Sidsector9 Sep 5, 2024
3556ab6
remove strict versioning from .nvmrc
iamdharmesh Sep 5, 2024
43d70f1
Merge branch 'enhancement/react-settings' of github.com:10up/classifa…
iamdharmesh Sep 5, 2024
0bba3ec
fix eslint errors
Sidsector9 Sep 5, 2024
3b7e331
Merge branch 'enhancement/react-settings' of github.com:10up/classifa…
Sidsector9 Sep 5, 2024
719a06f
fix phpcs errors
Sidsector9 Sep 5, 2024
6b4af66
Added filter `classifai_use_legacy_settings_panel` to enable legacy s…
iamdharmesh Sep 5, 2024
104e7bb
Fix setup role in rest API settings endpoint.
iamdharmesh Sep 5, 2024
fa5bc37
Merge branch 'enhancement/react-settings' of github.com:10up/classifa…
iamdharmesh Sep 5, 2024
b44da16
Fix setup link in plugin links and notice.
iamdharmesh Sep 5, 2024
2dea03e
Remove unwanted code.
iamdharmesh Sep 5, 2024
85239c4
Update regenerate embeddings processing code
iamdharmesh Sep 6, 2024
0397fd8
Fix Sass compile warning.
iamdharmesh Sep 13, 2024
a26ee4c
Fix default feature settings.
iamdharmesh Sep 16, 2024
2220a01
Fix IBM watson auth saving
iamdharmesh Sep 16, 2024
faaa5cb
Update admin tests.
iamdharmesh Sep 16, 2024
7645584
Update tests for the azure open AI excerpt generation.
iamdharmesh Sep 16, 2024
f32a301
Update E2E tests for google gemini API - excerpt generation.
iamdharmesh Sep 16, 2024
8162629
Update E2E tests for openAI ChatGPT
iamdharmesh Sep 16, 2024
643e6a9
Update E2E tests for moderation feature.
iamdharmesh Sep 16, 2024
c056570
Update E2E tests for resize content feature.
iamdharmesh Sep 16, 2024
34df979
Update E2E tests for speech to text feature.
iamdharmesh Sep 16, 2024
77f1be8
Update E2E tests for text to speech feature.
iamdharmesh Sep 16, 2024
926ac19
Update tests for the title generation feature.
iamdharmesh Sep 16, 2024
27a9e0e
Updated E2E tests for the IBM Watson NLU Classification feature.
iamdharmesh Sep 16, 2024
1d8285e
Update E2E tsets for the classification feature.
iamdharmesh Sep 16, 2024
0a7f902
Update tests for image generation feature.
iamdharmesh Sep 16, 2024
7bbbb2a
Update E2E tests for the image processing feature.
iamdharmesh Sep 16, 2024
1478080
Update E2E tests for PDF read feature.
iamdharmesh Sep 16, 2024
ab4c26a
Update E2E tests for the common feature fields.
iamdharmesh Sep 16, 2024
42e3199
Fix failing test.
iamdharmesh Sep 16, 2024
ae05a28
Enable E2E tests workflow.
iamdharmesh Sep 17, 2024
829ab2c
Merge branch 'develop' of github.com:10up/classifai into enhancement/…
iamdharmesh Sep 17, 2024
81f7ffc
Update react render to make it work in WP < 6.2 as well.
iamdharmesh Sep 17, 2024
8007bd6
get post status options using localize scripts.
iamdharmesh Sep 17, 2024
c233713
FIx settings in WP minimum env.
iamdharmesh Sep 17, 2024
563f5d5
Header design improvements.
iamdharmesh Sep 17, 2024
5d5de9a
Add react settings for the smart 404 feature.
iamdharmesh Sep 17, 2024
713dc42
Display error notice if EP is not install and active.
iamdharmesh Sep 17, 2024
492cbaf
Update E2E tests for Smart 404 feature.
iamdharmesh Sep 17, 2024
7944d43
Added command for enable disable features.
iamdharmesh Sep 17, 2024
121968f
Improvement in E2E tests and fix E2E tests for WP minimum environment.
iamdharmesh Sep 18, 2024
cdddf5a
Fix E2E tests Smart 404 feature.
iamdharmesh Sep 18, 2024
14fcc4c
Fix previewer for azure OpenAI embeddings provider.
iamdharmesh Sep 18, 2024
134b101
Update add feature and provider documentation for add fields to react…
iamdharmesh Sep 18, 2024
69fa836
Update documentation for the keep using legacy settings panel.
iamdharmesh Sep 18, 2024
a722d98
Added error handling.
iamdharmesh Sep 19, 2024
95c97de
Remove unwanted files.
iamdharmesh Sep 19, 2024
e7c66a3
display previewer only if provider is configured and feature is active.
iamdharmesh Sep 19, 2024
6e97f3f
Some slot name updates.
iamdharmesh Sep 20, 2024
eea4fd9
Sanitize status field in onboarding settings save.
iamdharmesh Sep 20, 2024
6ecae5d
Improved code by moving personalizer notice to separate component.
iamdharmesh Sep 20, 2024
8a3243f
Display notice for the in progress background processing of embedding…
iamdharmesh Sep 20, 2024
f73d7c4
Use v4.3.3 of deps review.
iamdharmesh Sep 26, 2024
eaa07bf
Merge branch 'develop' of github.com:10up/classifai into enhancement/…
iamdharmesh Sep 27, 2024
bb3b67a
Merge branch 'develop' of github.com:10up/classifai into enhancement/…
iamdharmesh Sep 27, 2024
dfcd4a2
Fix PHPStan error.
iamdharmesh Sep 27, 2024
3875313
Merge branch 'develop' of github.com:10up/classifai into develop
Sidsector9 Sep 28, 2024
32269d6
Merge branch 'enhancement/react-settings' of github.com:10up/classifa…
Sidsector9 Sep 28, 2024
21cd179
Merge branch 'develop' into enhancement/react-settings
Sidsector9 Sep 28, 2024
3d3116a
Minor updates to ensure we have return typing on new functions
dkotter Oct 11, 2024
ef3b1d0
Update most dependencies
dkotter Oct 11, 2024
5704b76
Add missing textdomain
dkotter Oct 11, 2024
bc39ea0
Keep User permissions collapsed by default.
iamdharmesh Oct 18, 2024
73150b5
Add Doc comments in JS files.
iamdharmesh Oct 18, 2024
05fca00
E2E tests update to handle collapsed "User Permissions" panel.
iamdharmesh Oct 18, 2024
66a87db
E2E: Open "User permissions" panel if closed.
iamdharmesh Oct 18, 2024
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
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ tests/*
vendor/*
bin/*
hookdocs/*
docs/*
6 changes: 5 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{

Check warning on line 1 in .eslintrc.json

View workflow job for this annotation

GitHub Actions / eslint

File ignored by default.
"globals": {
"wp": "readonly",
"jQuery": "readonly",
Expand All @@ -21,7 +21,11 @@
"Headers": "readonly",
"requestAnimationFrame": "readonly",
"React": "readonly",
"Block": "readonly"
"Block": "readonly",
"classifAISettings": "readonly"
},
"rules": {
"react/jsx-no-undef": "off"
},
"extends": ["plugin:@wordpress/eslint-plugin/recommended"],
"ignorePatterns": ["*.json", "webpack.config.js"]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dependency-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: 'Checkout Repository'
uses: actions/checkout@v4
- name: Dependency Review
uses: actions/dependency-review-action@v4
uses: actions/dependency-review-action@v4.3.3
with:
license-check: true
vulnerability-check: false
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v20.11.1
v20
199 changes: 165 additions & 34 deletions hookdocs/useful-snippets.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,6 @@ class MyProvider extends Provider {
$this->feature_instance = $feature_instance;
}

/**
* This method will be called by the feature to render the fields
* required by the provider, such as API key, endpoint URL, etc.
*
* This should also register settings that are required for the feature
* to work.
*/
public function render_provider_fields() {
$settings = $this->feature_instance->get_settings( static::ID );

$this->add_api_key_field();
}

/**
* Returns the default settings for this provider.
*
Expand Down Expand Up @@ -185,6 +172,87 @@ add_filter(
);
```

5. **Add required provider fields to the settings**
ClassifAI uses a React-based settings panel. To add the necessary provider fields, include the following code in a JavaScript file, and save it within your plugin's directory.

_**Note:** The provided code snippet uses modern JavaScript (ESNext and JSX), which requires a build step to compile it into a browser-compatible format. We recommend using the [@wordpress/scripts](https://www.npmjs.com/package/@wordpress/scripts) package to manage the build process. For a step-by-step guide on how to install and use this package, check out this tutorial: [Get started with wp-scripts](https://developer.wordpress.org/block-editor/getting-started/devenv/get-started-with-wp-scripts/)._

```js
/**
* WordPress dependencies
*/
import { registerPlugin } from '@wordpress/plugins';
import { useSelect, useDispatch } from '@wordpress/data';
import { Fill, TextControl } from '@wordpress/components';
import { __ } from '@wordpress/i18n';

const MyProviderSettings = () => {
const providerName = 'my_provider';
const featureSettings = useSelect( ( select ) =>
select( 'classifai-settings' ).getFeatureSettings()
);
const { setFeatureSettings } = useDispatch( 'classifai-settings' );
const providerSettings = featureSettings[ providerName ] || {};
const setProviderSettings = ( data ) =>
setFeatureSettings( {
[ providerName ]: {
...providerSettings,
...data,
},
} );

return (
<Fill name="ClassifAIProviderSettings">
Copy link
Member

@Sidsector9 Sidsector9 Oct 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to self:

Find out a way to make this easier so that 3rd-party devs don't have to write Fill.
Maybe try exporting a component on the window object which can be used to inject custom Provider settings.

<div className="settings-row">
<div className="settings-label">{ __( 'API Key', 'classifai' ) }</div>
<div className="settings-control">
<TextControl
value={ providerSettings.api_key || '' }
onChange={ ( value ) =>
setProviderSettings( { api_key: value } )
}
/>
<div className="settings-description">
{ __( 'Enter the provider API key.', 'classifai' ) }
</div>
</div>
</div>
</Fill>
);
};

registerPlugin( 'classifai-provider-my-provider', {
scope: 'my-provider', // Provider settings scope. replace "_" with "-" in your provider ID.
render: MyProviderSettings,
} );
```

6. **Enqueue Javascript assets**
To display the provider fields added in the previous step within the settings panel, we need to enqueue the corresponding JavaScript file. For guidance on enqueuing files in the admin area, refer to the "[Enqueue Script](https://developer.wordpress.org/plugins/javascript/enqueuing/#enqueue-script)" guide, but here’s a typical implementation.
```php
/**
* Enqueue the admin scripts.
*
* @param string $hook_suffix The current admin page.
*/
function my_provider_enqueue_admin_assets( $hook_suffix ) {
// Enqueue assets only on the ClassifAI settings page.
if ( 'tools_page_classifai' !== $hook_suffix ) {
return;
}

$asset_file = include( plugin_dir_path( __FILE__ ) . 'build/index.asset.php');

wp_enqueue_script(
'my-provider-scripts',
plugins_url( 'build/index.js', __FILE__ ),
$asset_file['dependencies'],
$asset_file['version']
);
}
add_action( 'admin_enqueue_scripts', 'my_provider_enqueue_admin_assets' );
```

## Add a new Feature

Starting in ClassifAI 3.0.0, it is easier to add your own Features. Most of the implementation details are left to you but there are a few key steps that need to be followed:
Expand Down Expand Up @@ -296,27 +364,6 @@ class MyFeature extends Feature {
return esc_html__( 'Enable this feature', 'text-domain' );
}

/**
* Add any needed custom fields.
*/
public function add_custom_settings_fields() {
$settings = $this->get_settings();

add_settings_field(
'custom_setting',
esc_html__( 'Custom setting', 'classifai' ),
[ $this, 'render_input' ],
$this->get_option_name(),
$this->get_option_name() . '_section',
[
'label_for' => 'custom_setting',
'placeholder' => esc_html__( 'Custom setting', 'text-domain' ),
'default_value' => $settings['custom_setting'],
'description' => esc_html__( 'Add a custom setting.', 'text-domain' ),
]
);
}

/**
* Returns the default settings for the feature.
*
Expand Down Expand Up @@ -372,3 +419,87 @@ add_filter(
}
);
```

4. **Add additional featured fields to the settings**
ClassifAI uses a React-based settings panel. To add the necessary additional feature fields, include the following code in a JavaScript file, and save it within your plugin's directory.

_**Note:** The provided code snippet uses modern JavaScript (ESNext and JSX), which requires a build step to compile it into a browser-compatible format. We recommend using the [@wordpress/scripts](https://www.npmjs.com/package/@wordpress/scripts) package to manage the build process. For a step-by-step guide on how to install and use this package, check out this tutorial: [Get started with wp-scripts](https://developer.wordpress.org/block-editor/getting-started/devenv/get-started-with-wp-scripts/)._

```js
/**
* WordPress dependencies
*/
import { TextControl, Fill } from '@wordpress/components';
import { registerPlugin } from '@wordpress/plugins';
import { __ } from '@wordpress/i18n';
import { useSelect, useDispatch } from '@wordpress/data';

const MyFeatureSettings = () => {
const featureSettings = useSelect( ( select ) =>
select( 'classifai-settings' ).getFeatureSettings()
);
const { setFeatureSettings } = useDispatch( 'classifai-settings' );
return (
<>
<Fill name="ClassifAIFeatureSettings">
<div className="settings-row">
<div className="settings-label">{ __( 'Custom setting', 'classifai' ) }</div>
<div className="settings-control">
<TextControl
value={ featureSettings.custom_setting || '' }
onChange={ ( value ) =>
setFeatureSettings( { custom_setting: value } )
}
/>
<div className="settings-description">
{ __( 'Choose what type of content to moderate.', 'classifai' ) }
</div>
</div>
</div>
</Fill>
</>
);
};

registerPlugin( 'classifai-feature-custom', {
scope: 'feature-custom', // Feature settings scope. replace "_" with "-" in your feature ID.
render: MyFeatureSettings,
} );
```

5. **Enqueue Javascript assets**
To display the addition feature fields added in the previous step within the settings panel, we need to enqueue the corresponding JavaScript file. For guidance on enqueuing files in the admin area, refer to the "[Enqueue Script](https://developer.wordpress.org/plugins/javascript/enqueuing/#enqueue-script)" guide, but here’s a typical implementation.
```php
/**
* Enqueue the admin scripts.
*
* @param string $hook_suffix The current admin page.
*/
function my_feature_enqueue_admin_assets( $hook_suffix ) {
// Enqueue assets only on the ClassifAI settings page.
if ( 'tools_page_classifai' !== $hook_suffix ) {
return;
}

$asset_file = include( plugin_dir_path( __FILE__ ) . 'build/index.asset.php');

wp_enqueue_script(
'my-feature-scripts',
plugins_url( 'build/index.js', __FILE__ ),
$asset_file['dependencies'],
$asset_file['version']
);
}
add_action( 'admin_enqueue_scripts', 'my_feature_enqueue_admin_assets' );
```

## Use Legacy settings
ClassifAI 3.2.0 introduces React-based settings and deprecates the PHP-based settings pages. If you have customizations in the legacy settings and would like to continue using the legacy settings panel, you can enable this by using the `classifai_use_legacy_settings_panel` filter hook.

However, please note that legacy settings will be completely removed in future releases. We recommend updating your customizations to use the React-based settings panel. If you encounter any issues, feel free to report them on our [GitHub repository](https://github.com/10up/classifai/).

Add the following snippet to your theme's `functions.php` file or a custom plugin.

```php
add_filter( 'classifai_use_legacy_settings_panel', '__return_true' );
```
65 changes: 63 additions & 2 deletions includes/Classifai/Admin/Notifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Classifai\Features\DescriptiveTextGenerator;
use Classifai\Features\Classification;
use function Classifai\should_use_legacy_settings_panel;

class Notifications {

Expand Down Expand Up @@ -44,6 +45,7 @@ public function maybe_render_notices() {
$this->thresholds_update_notice();
$this->v3_migration_completed_notice();
$this->render_embeddings_notice();
$this->render_notices();
}

/**
Expand Down Expand Up @@ -84,6 +86,11 @@ public function render_activation_notice() {
return;
}

$setup_url = admin_url( 'tools.php?page=classifai#/classifai_setup' );
if ( should_use_legacy_settings_panel() ) {
$setup_url = admin_url( 'admin.php?page=classifai_setup' );
}

// Prevent showing the default WordPress "Plugin Activated" notice.
unset( $_GET['activate'] ); // phpcs:ignore WordPress.Security.NonceVerification
?>
Expand All @@ -96,7 +103,7 @@ public function render_activation_notice() {
<h3 class="classifai-activation-message">
<?php esc_html_e( 'Congratulations, the ClassifAI plugin is now activated.', 'classifai' ); ?>
</h3>
<a class="classifai-button" href="<?php echo esc_url( admin_url( 'admin.php?page=classifai_setup' ) ); ?>">
<a class="classifai-button" href="<?php echo esc_url( $setup_url ); ?>">
<?php esc_html_e( 'Start setup', 'classifai' ); ?>
</a>
</div>
Expand Down Expand Up @@ -252,7 +259,7 @@ public function render_embeddings_notice() {
sprintf(
// translators: %1$s: Feature specific message; %2$s: URL to Feature settings.
__( 'ClassifAI has updated to the <code>text-embedding-3-small</code> embeddings model. <br>This requires regenerating any stored embeddings for functionality to work properly. <br><a href="%1$s">Click here to do that</a>, noting this will make multiple API requests to OpenAI.', 'classifai' ),
wp_nonce_url( admin_url( 'tools.php?page=classifai&tab=language_processing&feature=feature_classification' ), 'regen_embeddings', 'embeddings_nonce' )
wp_nonce_url( admin_url( 'admin-post.php?action=classifai_regen_embeddings' ), 'regen_embeddings', 'embeddings_nonce' )
)
);
?>
Expand Down Expand Up @@ -331,4 +338,58 @@ public function ajax_maybe_dismiss_notice() {

update_user_meta( get_current_user_id(), "classifai_dismissed_{$notice_id}", true );
}

/**
* Render any saved notices to display.
*/
public function render_notices() {
$notices = $this->get_notices();
if ( empty( $notices ) ) {
return;
}

foreach ( $notices as $notice ) {
if ( ! empty( $notice['message'] ) ) {
?>
<div class="notice notice-<?php echo esc_attr( $notice['type'] ); ?> is-dismissible">
<p><?php echo esc_html( $notice['message'] ); ?></p>
</div>
<?php
}
}
}

/**
* Get any saved notices to display.
*
* @return mixed
*/
public function get_notices() {
$notices = get_transient( 'classifai_notices' );
delete_transient( 'classifai_notices' );

return $notices;
}

/**
* Set a notice to be displayed.
*
* This will be displayed on the next page load.
* The notice will be stored in a transient.
*
* @param string $message The notice message.
* @param string $type The notice type.
*/
public function set_notice( string $message, string $type = 'info' ) {
$notices = get_transient( 'classifai_notices' );
if ( ! is_array( $notices ) ) {
$notices = [];
}

$notices[] = [
'type' => $type,
'message' => $message,
];
set_transient( 'classifai_notices', $notices );
}
}
Loading
Loading