Skip to content

Commit 683e07b

Browse files
committed
Move post_statuses setting from legacy PHP settings to React UI
Per review feedback: the legacy PHP settings screen (add_settings_field) is being phased out and hasn't been the default since v3.2.0, so new settings should be added to the React settings UI instead. - Remove the post_statuses add_settings_field() block from TextToSpeech::add_custom_settings_fields(). - Add the equivalent control to src/js/settings/components/feature-additional-settings/text-to-speech.js, mirroring the existing post_statuses block already used by the Classification feature's React settings (same window.classifAISettings.postStatuses data source, already localized in Admin/Settings.php - no new PHP localization needed). The default settings, sanitization, and enforcement gates added in the previous commit are unchanged - those are backend/data-layer concerns independent of which UI renders the control.
1 parent c66cc99 commit 683e07b

2 files changed

Lines changed: 64 additions & 43 deletions

File tree

includes/Classifai/Features/TextToSpeech.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -940,20 +940,6 @@ public function add_custom_settings_fields() {
940940
'description' => __( 'Choose which post types support this feature.', 'classifai' ),
941941
)
942942
);
943-
944-
add_settings_field(
945-
'post_statuses',
946-
esc_html__( 'Allowed post statuses', 'classifai' ),
947-
array( $this, 'render_checkbox_group' ),
948-
$this->get_option_name(),
949-
$this->get_option_name() . '_section',
950-
array(
951-
'label_for' => 'post_statuses',
952-
'options' => \Classifai\get_post_statuses_for_language_settings(),
953-
'default_values' => $settings['post_statuses'],
954-
'description' => __( 'Choose which post statuses are allowed to generate audio, e.g. disable this for Draft to avoid generating audio for content that is still being edited.', 'classifai' ),
955-
)
956-
);
957943
}
958944

959945
/**

src/js/settings/components/feature-additional-settings/text-to-speech.js

Lines changed: 64 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import { useSelect, useDispatch } from '@wordpress/data';
55
import { CheckboxControl } from '@wordpress/components';
66
import { __ } from '@wordpress/i18n';
7+
import { decodeEntities } from '@wordpress/html-entities';
78

89
/**
910
* Internal dependencies
@@ -23,36 +24,70 @@ export const TextToSpeechSettings = () => {
2324
select( STORE_NAME ).getFeatureSettings()
2425
);
2526
const { setFeatureSettings } = useDispatch( STORE_NAME );
26-
const { postTypes } = window.classifAISettings;
27+
const { postTypes, postStatuses } = window.classifAISettings;
2728

2829
return (
29-
<SettingsRow
30-
label={ __( 'Allowed post types', 'classifai' ) }
31-
description={ __(
32-
'Choose which post types support this feature.',
33-
'classifai'
34-
) }
35-
className="settings-allowed-post-types"
36-
>
37-
{ Object.keys( postTypes || {} ).map( ( key ) => {
38-
return (
39-
<CheckboxControl
40-
id={ key }
41-
key={ key }
42-
checked={ featureSettings.post_types?.[ key ] === key }
43-
label={ postTypes?.[ key ] }
44-
onChange={ ( value ) => {
45-
setFeatureSettings( {
46-
post_types: {
47-
...featureSettings.post_types,
48-
[ key ]: value ? key : '0',
49-
},
50-
} );
51-
} }
52-
__nextHasNoMarginBottom
53-
/>
54-
);
55-
} ) }
56-
</SettingsRow>
30+
<>
31+
<SettingsRow
32+
label={ __( 'Allowed post statuses', 'classifai' ) }
33+
description={ __(
34+
'Choose which post statuses are allowed to generate audio, e.g. disable this for Draft to avoid generating audio for content that is still being edited.',
35+
'classifai'
36+
) }
37+
className="settings-allowed-post-statuses"
38+
>
39+
{ Object.keys( postStatuses || {} ).map( ( key ) => {
40+
return (
41+
<CheckboxControl
42+
id={ `post_status_${ key }` }
43+
key={ key }
44+
checked={
45+
featureSettings.post_statuses?.[ key ] === key
46+
}
47+
label={ decodeEntities( postStatuses?.[ key ] ) }
48+
onChange={ ( value ) => {
49+
setFeatureSettings( {
50+
post_statuses: {
51+
...featureSettings.post_statuses,
52+
[ key ]: value ? key : '0',
53+
},
54+
} );
55+
} }
56+
__nextHasNoMarginBottom
57+
/>
58+
);
59+
} ) }
60+
</SettingsRow>
61+
<SettingsRow
62+
label={ __( 'Allowed post types', 'classifai' ) }
63+
description={ __(
64+
'Choose which post types support this feature.',
65+
'classifai'
66+
) }
67+
className="settings-allowed-post-types"
68+
>
69+
{ Object.keys( postTypes || {} ).map( ( key ) => {
70+
return (
71+
<CheckboxControl
72+
id={ key }
73+
key={ key }
74+
checked={
75+
featureSettings.post_types?.[ key ] === key
76+
}
77+
label={ postTypes?.[ key ] }
78+
onChange={ ( value ) => {
79+
setFeatureSettings( {
80+
post_types: {
81+
...featureSettings.post_types,
82+
[ key ]: value ? key : '0',
83+
},
84+
} );
85+
} }
86+
__nextHasNoMarginBottom
87+
/>
88+
);
89+
} ) }
90+
</SettingsRow>
91+
</>
5792
);
5893
};

0 commit comments

Comments
 (0)