Skip to content

Add allowed post statuses setting for Text to Speech feature - #1160

Open
Moferanoluwa wants to merge 2 commits into
10up:developfrom
Moferanoluwa:feat/tts-allowed-post-statuses
Open

Add allowed post statuses setting for Text to Speech feature#1160
Moferanoluwa wants to merge 2 commits into
10up:developfrom
Moferanoluwa:feat/tts-allowed-post-statuses

Conversation

@Moferanoluwa

Copy link
Copy Markdown

Description

Fixes #1000. As described in the issue, a client's "Sponsored Posts" workflow makes numerous text changes on Drafts, and Public Post Preview was showing the wrong/stale audio because Text to Speech currently generates audio for any post status, including Draft and Pending.

@dkotter noted:

We do have a few Features that have settings in place to allow you to choose the post statuses that the Feature will run under so I could see the case of adding that for the Text to Speech Feature.

This adds exactly that, mirroring the existing pattern:

  • The Classification feature already has a post_statuses checkbox-group setting (see add_custom_settings_fields() there). I added the equivalent field to TextToSpeech.
  • Feature::get_supported_post_statuses() already exists as a shared base-class method (reads $this->get_settings()['post_statuses']) — Classification already uses it, TextToSpeech just wasn't populating or checking that setting yet.
  • Default is Publish only (matching Classification's own default), so out of the box audio will no longer regenerate on every Draft save — which is the behavior the issue asks for. Anyone who wants the old behavior back can just check "Draft" in the new setting.

Changes

In includes/Classifai/Features/TextToSpeech.php:

  • get_feature_default_settings() — add post_statuses default (publish only).
  • add_custom_settings_fields() — add the post_statuses checkbox-group field, using the same \Classifai\get_post_statuses_for_language_settings() helper Classification uses.
  • sanitize_default_feature_settings() — sanitize the new setting the same way post_types already is.
  • save_post_metadata() — gate audio generation (classic editor / meta box save path) on get_supported_post_statuses(), same pattern as the existing post_types check right next to it.
  • rest_handle_audio() — same gate for the block editor / REST save path, since that's the path Gutenberg actually uses and is likely what the reporter's workflow hits.

Testing/Review Recommendations

I don't have a full WordPress + PHP environment set up locally, so I wasn't able to run this repo's PHPCS/PHPUnit suite myself. I verified by careful manual review instead:

  • Matched the exact existing pattern for post_types in this same file (settings field registration, default settings, sanitization) rather than inventing a new convention.
  • Confirmed get_supported_post_statuses() and get_post_statuses_for_language_settings() are already generic, shared, base-class/helper functions (already used by Classification), not something specific to that feature — so no new helper needed.
  • Re-read the full diff for brace/array syntax correctness given I couldn't run php -l locally.

Happy to adjust the default (e.g. include Pending too) or extend the meta-box visibility logic if you'd like the box itself hidden for disallowed statuses — I kept this PR to the functional gate to start.

AI Usage

  • Tool: Claude Code (Claude Sonnet)
  • Type: Locating the existing post_types/post_statuses pattern in Classification.php and the shared Feature base class, then mirroring it for TextToSpeech.
  • Scope: includes/Classifai/Features/TextToSpeech.php only.

Text to Speech currently generates audio for any post status (including
Draft and Pending), which causes stale/incorrect audio to be attached
to public post previews while a post is still being actively edited
through several rounds of changes.

Add a "post_statuses" setting to the feature, mirroring the existing
pattern already used by the post_types setting and by the Classification
feature's post_statuses field:
- New settings field (checkbox group) to choose allowed post statuses,
  defaulting to Publish only.
- Enforce the setting in both audio-generation entry points:
  save_post_metadata() (classic editor / meta box save) and
  rest_handle_audio() (block editor / REST save).

Fixes 10up#1000
@Moferanoluwa
Moferanoluwa requested review from a team, dkotter and jeffpaul as code owners July 29, 2026 18:15
@dkotter dkotter added this to the 4.0.0 milestone Jul 30, 2026
Comment on lines +944 to +956
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.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New Option: No "Text2Speak" Generation for Drafts

2 participants