diff --git a/includes/Classifai/Features/TextToSpeech.php b/includes/Classifai/Features/TextToSpeech.php
index ad525b3b1..30af4dfe2 100644
--- a/includes/Classifai/Features/TextToSpeech.php
+++ b/includes/Classifai/Features/TextToSpeech.php
@@ -255,7 +255,10 @@ public function add_meta_to_rest_api() {
public function rest_handle_audio( \WP_Post $post, WP_REST_Request $request ) {
$post_id = (int) $request->get_param( 'id' );
- if ( ! $this->is_feature_enabled() ) {
+ if (
+ ! in_array( $post->post_status, $this->get_supported_post_statuses(), true ) ||
+ ! $this->is_feature_enabled()
+ ) {
return;
}
@@ -614,6 +617,7 @@ function_exists( 'as_has_scheduled_action' ) &&
public function save_post_metadata( int $post_id ) {
if (
! in_array( get_post_type( $post_id ), $this->get_supported_post_types(), true ) ||
+ ! in_array( get_post_status( $post_id ), $this->get_supported_post_statuses(), true ) ||
! $this->is_feature_enabled()
) {
return;
@@ -961,10 +965,13 @@ protected function get_post_types_select_options(): array {
*/
public function get_feature_default_settings(): array {
return array(
- 'post_types' => array(
+ 'post_types' => array(
'post' => 'post',
),
- 'provider' => Speech::ID,
+ 'post_statuses' => array(
+ 'publish' => 'publish',
+ ),
+ 'provider' => Speech::ID,
);
}
@@ -985,6 +992,16 @@ public function sanitize_default_feature_settings( array $new_settings ): array
}
}
+ $post_statuses = \Classifai\get_post_statuses_for_language_settings();
+
+ foreach ( array_keys( $post_statuses ) as $post_status ) {
+ if ( ! isset( $new_settings['post_statuses'][ $post_status ] ) ) {
+ $new_settings['post_statuses'][ $post_status ] = '';
+ } else {
+ $new_settings['post_statuses'][ $post_status ] = sanitize_text_field( $new_settings['post_statuses'][ $post_status ] );
+ }
+ }
+
return $new_settings;
}
diff --git a/src/js/settings/components/feature-additional-settings/text-to-speech.js b/src/js/settings/components/feature-additional-settings/text-to-speech.js
index 701ecef24..497d74505 100644
--- a/src/js/settings/components/feature-additional-settings/text-to-speech.js
+++ b/src/js/settings/components/feature-additional-settings/text-to-speech.js
@@ -4,6 +4,7 @@
import { useSelect, useDispatch } from '@wordpress/data';
import { CheckboxControl } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
+import { decodeEntities } from '@wordpress/html-entities';
/**
* Internal dependencies
@@ -23,36 +24,70 @@ export const TextToSpeechSettings = () => {
select( STORE_NAME ).getFeatureSettings()
);
const { setFeatureSettings } = useDispatch( STORE_NAME );
- const { postTypes } = window.classifAISettings;
+ const { postTypes, postStatuses } = window.classifAISettings;
return (
-
- { Object.keys( postTypes || {} ).map( ( key ) => {
- return (
- {
- setFeatureSettings( {
- post_types: {
- ...featureSettings.post_types,
- [ key ]: value ? key : '0',
- },
- } );
- } }
- __nextHasNoMarginBottom
- />
- );
- } ) }
-
+ <>
+
+ { Object.keys( postStatuses || {} ).map( ( key ) => {
+ return (
+ {
+ setFeatureSettings( {
+ post_statuses: {
+ ...featureSettings.post_statuses,
+ [ key ]: value ? key : '0',
+ },
+ } );
+ } }
+ __nextHasNoMarginBottom
+ />
+ );
+ } ) }
+
+
+ { Object.keys( postTypes || {} ).map( ( key ) => {
+ return (
+ {
+ setFeatureSettings( {
+ post_types: {
+ ...featureSettings.post_types,
+ [ key ]: value ? key : '0',
+ },
+ } );
+ } }
+ __nextHasNoMarginBottom
+ />
+ );
+ } ) }
+
+ >
);
};