Move text-to-speech audio generation to Action Scheduler#1042
Move text-to-speech audio generation to Action Scheduler#1042
Conversation
✅ WordPress Plugin Check Report
📊 ReportAll checks passed! No errors or warnings found. 🤖 Generated by WordPress Plugin Check Action • Learn more about Plugin Check |
…can ensure that user is set, otherwise permissions won't work
There was a problem hiding this comment.
Note I've pushed a couple commits to ensure Action Scheduler is properly loaded when the TTS Feature is turned on and to ensure we set the proper current user so permission checks pass.
But in my testing, I never saw the message that lets you know processing is happening. I see that's supposed to be happening: Audio generation is in progress, but that never showed for me.
In addition, would be great if things updated dynamically with no need for a page refresh. Right now you have to refresh a handful of times and eventually the processing is done and you see the audio player but would be great if we could continually listen for processing to be done and update the UI as needed
…essing now happens in the background
Quick follow up. Tested a bit more and found out it was a bug in how we register meta, in particular if used on post types other than post (I was testing on a page). I've pushed a fix for this and I am seeing the processing message now. That said, you still have to refresh to see the final result and it would be great if it could auto update the UI once that is done. Also could use the same fix for the error message. I've pushed a small fix for that now as it was previously only showing during the save event, so if an error happens now, it will never render. This renders now but again, only if you refresh the page. |
peterwilsoncc
left a comment
There was a problem hiding this comment.
Just a couple of notes inline.
The main one is about including a cap check before scheduling the task given the new changes to the generate function.
When testing with the classic editor, I noticed that the status doesn't update once the audio is generated, it sticks with the in progress message.
It's the classic editor so happy if that's intentional.
| return; | ||
| } | ||
|
|
||
| // We enqueue the async action to generate the audio, if available. |
There was a problem hiding this comment.
Before scheduling the job, I think it would be best to do a cap check: if ( ! current_user_can( 'edit_post', $post_id ) && ( ! defined( 'WP_CLI' ) || ! WP_CLI ) )
By the time this part of the function is reached, I think it's been checked but it wold be good to have it here as a little protection for our future selves if it gets moved.
There was a problem hiding this comment.
So we do already have a current_user_can check in this function a few lines above:
if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || ! current_user_can( 'edit_post', $post_id ) || 'revision' === get_post_type( $post_id ) ) {
return;
}
Are you saying we should add an additional check here? Or move that check down to here?
There was a problem hiding this comment.
So we do already have a
current_user_cancheck in this function a few lines above:
Sorry Darin, we really do. "In my defense, I have none."
…. Simplify getting the post ID
I didn't change how things work in the classic editor and I think that's fine for now. If we get reports that people are still using the classic editor here we can make this a nicer experience |
peterwilsoncc
left a comment
There was a problem hiding this comment.
I didn't change how things work in the classic editor and I think that's fine for now. If we get reports that people are still using the classic editor here we can make this a nicer experience
Cool, it's been about eight years.
Thanks for following up, these changes look good to me.
| return; | ||
| } | ||
|
|
||
| // We enqueue the async action to generate the audio, if available. |
There was a problem hiding this comment.
So we do already have a
current_user_cancheck in this function a few lines above:
Sorry Darin, we really do. "In my defense, I have none."
Description of the Change
Text-to-speech audio generation is no longer run synchronously during the REST “generate audio” request or when saving the post. It is offloaded to Action Scheduler so that:
How to test the Change
Changelog Entry
Credits
Props @rahulsprajapati, @dkotter
Checklist: