Skip to content
Open
Changes from 1 commit
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
37 changes: 34 additions & 3 deletions includes/Classifai/Features/TextToSpeech.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -936,6 +940,20 @@ public function add_custom_settings_fields() {
'description' => __( 'Choose which post types support this feature.', 'classifai' ),
)
);

add_settings_field(
'post_statuses',
esc_html__( 'Allowed post statuses', 'classifai' ),
array( $this, 'render_checkbox_group' ),
$this->get_option_name(),
$this->get_option_name() . '_section',
array(
'label_for' => 'post_statuses',
'options' => \Classifai\get_post_statuses_for_language_settings(),
'default_values' => $settings['post_statuses'],
'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' ),
)
);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This only adds the setting for the legacy settings experience in ClassifAI. We are moving away from supporting this (it hasn't been the default v3.2.0) so there's two things needed here:

  1. I'd suggest removing this block as we'll be removing all of these legacy settings in an upcoming release anyway
  2. You'll need to add these settings via javascript. See here

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good catch, thanks — done in 683e07b. Removed the add_settings_field() block from the legacy PHP settings screen and added the equivalent control to src/js/settings/components/feature-additional-settings/text-to-speech.js, mirroring the existing post_statuses block the Classification feature's React settings already use (same window.classifAISettings.postStatuses data source — it's already localized in Admin/Settings.php, so no new PHP localization was needed). Ran this through wp-scripts lint-js and tsc --noEmit locally, both clean.

}

/**
Expand All @@ -961,10 +979,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,
);
}

Expand All @@ -985,6 +1006,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;
}

Expand Down