Skip to content

Conversation

@dkotter
Copy link
Collaborator

@dkotter dkotter commented Nov 14, 2025

What?

Partially closes #10

Continues work on the Title Generation Experiment, with initial scaffold work done in #61 and the execution functionality done in #67.

Why?

We now have a Title Generation Ability that can be triggered to generate title suggestions but that requires you to make direct API requests. This PR adds in the UI that allows users to easily trigger this Ability from the post edit screen.

How?

  • Uses the Asset_Loader class within the Title_Generation Experiment to load the needed JS file when we're on the post edit screen for a post that has title support.
  • Adds in a TitleToolbar component and TitleToolbarWrapper component (using typescript though can change to plain JS if we want)
  • When the title is a block (when using the template preview mode) we modify the Edit component of that block to use the new TitleToolbar component
  • When the title isn't a block (normal editing mode), we load the TitleToolbarWrapper component as a plugin which will then find the title field and inject the TitleToolbar component
  • In either case, we show a toolbar above the title that has a button in it. When clicked, we show a loading state and when titles are returned, those are loaded in a modal within a textarea. The user can then choose which title (if any) they want to select and optionally make edits before selection. Once they select a title, we set that as the title for the post and trigger an autosave
  • Adds in all necessary dependencies

Testing Instructions

  1. Pull changes and run npm i && npm run build && composer install --no-dev
  2. Go to Settings > AI Credentials and ensure you add at least one valid API key
  3. Go to Settings > AI Experiments and ensure the Title Generation Experiment is enabled
  4. Add a new post or edit an existing post
  5. Click into the title field and ensure you see a toolbar with a button that says either Generate or Re-generate depending on if you have an existing title or not
  6. Click on that button and ensure a loading state shows
  7. Once the request completes, ensure a modal opens with title suggestions. Ensure you can select a title (and optionally edit a title first) and that title is set within the post

Testing Instructions for Keyboard

Screenshots

Toolbar with Generate button when no existing title Toolbar with Re-generate button when there is an existing title Loading state of the toolbar when the button is clicked Modal that shows title options, allowing you to edit and select a title

Test using WordPress Playground

The changes in this pull request can be previewed and tested using this WordPress Playground instance:

Click here to test this pull request.

@dkotter dkotter added this to the 0.1.0 milestone Nov 14, 2025
@dkotter dkotter self-assigned this Nov 14, 2025
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I know, huge amount of line changes here but is needed to include all the various WordPress components we're using, otherwise linting will complain about importing things that don't exist

@codecov
Copy link

codecov bot commented Nov 14, 2025

Codecov Report

❌ Patch coverage is 0% with 16 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (trunk@1f48035). Learn more about missing BASE report.
⚠️ Report is 86 commits behind head on trunk.

Files with missing lines Patch % Lines
.../Experiments/Title_Generation/Title_Generation.php 0.00% 16 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##             trunk      #83   +/-   ##
========================================
  Coverage         ?   29.19%           
  Complexity       ?      142           
========================================
  Files            ?       14           
  Lines            ?      846           
  Branches         ?        0           
========================================
  Hits             ?      247           
  Misses           ?      599           
  Partials         ?        0           
Flag Coverage Δ
unit 29.19% <0.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Member

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

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

@dkotter Overall this is looking good, but a few concerns regarding coding standards and dependencies.


const ExampleExperiment = () => {
return <div className="test">{ __( 'Example Experiment', 'ai' ) }</div>;
return <div className="test">{__('Example Experiment', 'ai')}</div>;
Copy link
Member

Choose a reason for hiding this comment

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

Why this "correction"? Before it was using WordPress Coding Standards, and now it isn't.

Copy link
Collaborator Author

@dkotter dkotter Nov 24, 2025

Choose a reason for hiding this comment

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

We use wp-scripts here for linting (npm run lint:js which will run wp-scripts lint-js) and it was flagging this. I've always assumed the linting wp-scripts enforces is what WordPress wants (seems it uses https://www.npmjs.com/package/@wordpress/eslint-plugin) but if there's a better/more canonical approach to enforcing JS coding standards, happy to switch up our tooling for that

Copy link
Member

@felixarntz felixarntz Nov 25, 2025

Choose a reason for hiding this comment

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

That is really strange. I don't know if there was a recent update, but I've been using wp-scripts myself and it would always enforce the opposite (I.e. WordPress Coding Standards). Is there something else at play here maybe that leads to the regular Prettier taking over the WordPress specific version? 🤔

This needs some more digging because that's not something that should be changed without broader consensus by the Core developers. A few years ago there was actually a proposal to change it which ended up rejected.

Copy link
Collaborator Author

@dkotter dkotter Nov 25, 2025

Choose a reason for hiding this comment

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

Yeah, not sure what's going on. We didn't have an ESLint config file so I was hoping adding that (done in f755562) would fix it. That did end up flagging additional errors (fixed in fc4d178) but still doesn't allow me to add extra spaces around things (I reverted the spacing change in that example file and you can now see the error it's flagging: https://github.com/WordPress/ai/actions/runs/19657884624/job/56298366699?pr=83#step:5:11).

I feel like I'm missing something simple here, a config file or dependency, but I'm not seeing anything obvious

Copy link
Member

Choose a reason for hiding this comment

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

Is there maybe a conflicting version of prettier installed that's not the wp-prettier fork? If some dependency uses prettier, maybe that's what's happening.

@wordpress/scripts uses wp-prettier, so that's all as I thought it would be. But maybe another dependency is pulling in the "real" prettier, and that might cause the problem?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Okay, think I got this fixed. Had to delete multiple dependencies (and the package-lock.json file) but finally got it installing correctly. Doing a quick search, seems the wrong version got installed in #73 though still not quite sure how. But I've got it working now and I've fixed up all lint errors so things should match proper coding standards now

@jeffpaul jeffpaul requested a review from felixarntz November 25, 2025 20:29
Copy link
Member

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

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

@dkotter LGTM!

There appear to be some transient PHPUnit CI failures though.

.prettierrc Outdated
@@ -0,0 +1 @@
"@wordpress/prettier-config"
Copy link
Member

Choose a reason for hiding this comment

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

What does this do? Why is it needed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This loads in the WP prettier config to ensure those rules are used when running prettier. But this was part of me experimenting to get things fixed so I've reverted this to how it was initially setup, which removes this file from this PR: fb62804

Copy link
Member

@JasonTheAdams JasonTheAdams left a comment

Choose a reason for hiding this comment

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

Great work, @dkotter!

@dkotter
Copy link
Collaborator Author

dkotter commented Nov 25, 2025

There appear to be some transient PHPUnit CI failures though.

Yeah, the PHPUnit tests are failing on trunk since we set our WP minimum to 6.9 in #78 :(

Getting this error: Failed to activate plugin. Current WordPress version (6.8.3) does not meet minimum requirements for AI Experiments. The plugin requires WordPress 6.9

@felixarntz
Copy link
Member

There appear to be some transient PHPUnit CI failures though.

Yeah, the PHPUnit tests are failing on trunk since we set our WP minimum to 6.9 in #78 :(

Getting this error: Failed to activate plugin. Current WordPress version (6.8.3) does not meet minimum requirements for AI Experiments. The plugin requires WordPress 6.9

Why don't we set it to 6.8 for now, so that we don't have these problems? It should still be fine to submit to .org like that. Bumping the minimum requirement to 6.9 probably takes 5 minutes and could be done on release day :)

@jeffpaul
Copy link
Member

Why don't we set it to 6.8 for now, so that we don't have these problems? It should still be fine to submit to .org like that. Bumping the minimum requirement to 6.9 probably takes 5 minutes and could be done on release day :)

I went ahead and did that in 77ac717 and then updated #28 to include:

Bump minimum WP version to 6.9 (ensuring this covers any additional concerns from #94)

...as a precursor to submitting to WPORG.

Assuming tests pass here, I'll merge this in.

@jeffpaul jeffpaul merged commit e86c5be into WordPress:trunk Nov 26, 2025
20 of 22 checks passed
@jeffpaul jeffpaul linked an issue Nov 26, 2025 that may be closed by this pull request
5 tasks
@dkotter dkotter deleted the feature/title-generation-ui branch December 1, 2025 22:32
@jeffpaul
Copy link
Member

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.

Add UI controls in post editor for rewriting titles Title Generation / Rewriting

4 participants