Skip to content

Conversation

faisal-alvi
Copy link
Contributor

Description of the Change

This PR integrates ClassifAI's Content Generation feature with WordPress's native Quick Draft widget on the admin dashboard. Users can now generate AI-powered content directly from the Quick Draft interface, creating new draft posts with AI-generated content based on their prompts.

989-quick-draft-AI

Key Features:

  • Adds a "Create Draft from Prompt Content" button next to the existing "Save Draft" button
  • Uses the existing Content Generation provider configured in ClassifAI settings
  • Creates new draft posts with AI-generated content while preserving the original title
  • Includes proper error handling and user feedback
  • Adds a settings toggle to enable/disable this feature (enabled by default)
  • Maintains full compatibility with existing Quick Draft functionality
image

Closes #989.

How to test the Change

  1. Enable Content Generation:

    • Go to ClassifAI Settings → Content Generation
    • Configure a provider (OpenAI, Azure OpenAI, etc.)
    • Ensure "Enable Quick Draft Integration" is checked (default)
  2. Test Quick Draft Integration:

    • Navigate to WordPress Admin Dashboard
    • Locate the Quick Draft widget
    • Enter a title and some content in the Content field
    • Click "Create Draft from Prompt Content" button
    • Verify a new draft post is created with AI-generated content
    • Check that the new draft appears in "Your Recent Drafts" section

Changelog Entry

Added - Content Generation integration with WordPress Quick Draft widget for streamlined AI-powered content creation

Credits

Props @jeffpaul @faisal-alvi

Checklist:

@faisal-alvi faisal-alvi self-assigned this Sep 18, 2025
@github-actions github-actions bot added this to the 3.8.0 milestone Sep 18, 2025
FILE: QuickDraftIntegration.php
-----------------------------------------------------------------------------------------------
FOUND 7 ERRORS AND 9 WARNINGS AFFECTING 16 LINES
-----------------------------------------------------------------------------------------------
  17 | ERROR | Whitespace found at end of line (Squiz.WhiteSpace.SuperfluousWhitespace.EndLine)
  70 | ERROR | Whitespace found at end of line (Squiz.WhiteSpace.SuperfluousWhitespace.EndLine)
 128 | ERROR | Whitespace found at end of line (Squiz.WhiteSpace.SuperfluousWhitespace.EndLine)
 164 | WARNING | Array double arrow not aligned correctly; expected 1 space(s) between "'sanitize_callback'" and double arrow, but found 2. (WordPress.Arrays.MultipleStatementAlignment.DoubleArrowNotAligned)
 165 | WARNING | Array double arrow not aligned correctly; expected 1 space(s) between "'validate_callback'" and double arrow, but found 2. (WordPress.Arrays.MultipleStatementAlignment.DoubleArrowNotAligned)
 166 | WARNING | Array double arrow not aligned correctly; expected 7 space(s) between "'description'" and double arrow, but found 8. (WordPress.Arrays.MultipleStatementAlignment.DoubleArrowNotAligned)
 179 | ERROR | Function closing brace must go on the next line following the body; found 1 blank lines before brace (PSR2.Methods.FunctionClosingBrace.SpacingBeforeClose)
 187 | WARNING | The method parameter $request is never used (Generic.CodeAnalysis.UnusedFunctionParameter.Found)
 255 | ERROR | Opening parenthesis of a multi-line function call must be the last content on the line (PEAR.Functions.FunctionCallSignature.ContentAfterOpenBracket)
 256 | WARNING | Array double arrow not aligned correctly; expected 2 space(s) between "'post_id'" and double arrow, but found 6. (WordPress.Arrays.MultipleStatementAlignment.DoubleArrowNotAligned)
 257 | WARNING | Array double arrow not aligned correctly; expected 1 space(s) between "'edit_url'" and double arrow, but found 5. (WordPress.Arrays.MultipleStatementAlignment.DoubleArrowNotAligned)
 258 | WARNING | Array double arrow not aligned correctly; expected 2 space(s) between "'content'" and double arrow, but found 6. (WordPress.Arrays.MultipleStatementAlignment.DoubleArrowNotAligned)
 259 | WARNING | Array double arrow not aligned correctly; expected 4 space(s) between "'title'" and double arrow, but found 8. (WordPress.Arrays.MultipleStatementAlignment.DoubleArrowNotAligned)
 260 | WARNING | Array double arrow not aligned correctly; expected 2 space(s) between "'success'" and double arrow, but found 6. (WordPress.Arrays.MultipleStatementAlignment.DoubleArrowNotAligned)
 261 | ERROR | Closing parenthesis of a multi-line function call must be on a line by itself (PEAR.Functions.FunctionCallSignature.CloseBracketLine)
 264 | ERROR | The closing brace for the class must go on the next line after the body (PSR2.Classes.ClassDeclaration.CloseBraceAfterBody)
-----------------------------------------------------------------------------------------------
/home/runner/work/classifai/classifai/src/js/features/quick-draft/index.js
Error:    11:56  error  Insert `·`                                                                                                                                                                  prettier/prettier
Error:    17:3   error  Unexpected console statement                                                                                                                                                no-console
Error:    21:2   error  Unexpected console statement                                                                                                                                                no-console
Error:    24:46  error  Insert `·`                                                                                                                                                                  prettier/prettier
Error:    35:9   error  Variables should not be assigned until just prior its first reference. An early return statement may leave this variable unused                                             @wordpress/no-unused-vars-before-return
Error:    40:4   error  Unexpected alert                                                                                                                                                            no-alert
Error:    40:4   error  'alert' is not defined                                                                                                                                                      no-undef
Error:    45:50  error  Replace `·'classifai-generate-content'·` with `⏎↹↹↹'classifai-generate-content'⏎↹↹`                                                                                         prettier/prettier
Error:    46:1   error  Delete `↹↹`                                                                                                                                                                 prettier/prettier
Error:    49:26  error  'classifaiQuickDraft' is not defined                                                                                                                                        no-undef
Error:    51:3   error  Unexpected console statement                                                                                                                                                no-console
Error:    58:5   error  Expected property shorthand                                                                                                                                                 object-shorthand
Error:    59:5   error  Expected property shorthand                                                                                                                                                 object-shorthand
Error:    61:6   error  Replace `.then(·function` with `⏎↹↹↹.then(·function·`                                                                                                                       prettier/prettier
Error:    62:4   error  Replace `console.log(·'ClassifAI·Quick·Draft:·API·response·received',·response·);` with `↹console.log(⏎↹↹↹↹↹'ClassifAI·Quick·Draft:·API·response·received',⏎↹↹↹↹↹response`  prettier/prettier
Error:    62:4   error  Unexpected console statement                                                                                                                                                no-console
Error:    63:4   error  Insert `↹);⏎`                                                                                                                                                               prettier/prettier
Error:    64:4   error  Insert `↹`                                                                                                                                                                  prettier/prettier
Error:    65:5   error  Insert `↹`                                                                                                                                                                  prettier/prettier
Error:    66:1   error  Insert `↹`                                                                                                                                                                  prettier/prettier
Error:    67:5   error  Insert `↹`                                                                                                                                                                  prettier/prettier
Error:    69:1   error  Insert `↹`                                                                                                                                                                  prettier/prettier
Error:    70:5   error  Insert `↹`                                                                                                                                                                  prettier/prettier
Error:    72:1   error  Insert `↹`                                                                                                                                                                  prettier/prettier
Error:    73:1   error  Insert `↹`                                                                                                                                                                  prettier/prettier
Error:    74:5   error  Replace `setTimeout(·function` with `↹setTimeout(·function·`                                                                                                                prettier/prettier
Error:    75:1   error  Insert `↹`                                                                                                                                                                  prettier/prettier
Error:    75:6   error  'location' is not defined                                                                                                                                                   no-undef
Error:    76:5   error  Insert `↹`                                                                                                                                                                  prettier/prettier
Error:    77:4   error  Insert `↹`                                                                                                                                                                  prettier/prettier
Error:    78:1   error  Replace `↹↹↹↹throw·new·Error(·response.message·||·classifaiQuickDraft.error·` with `↹↹↹↹↹throw·new·Error(⏎↹↹↹↹↹↹response.message·||·classifaiQuickDraft.error⏎↹↹↹↹↹`        prettier/prettier
Error:    78:42  error  'classifaiQuickDraft' is not defined                                                                                                                                        no-undef
Error:    79:1   error  Insert `↹`                                                                                                                                                                  prettier/prettier
Error:    80:3   error  Replace `}·).catch(·function` with `↹}·)⏎↹↹↹.catch(·function·`                                                                                                              prettier/prettier
Error:    81:1   error  Insert `↹`                                                                                                                                                                  prettier/prettier
Error:    81:4   error  Unexpected console statement                                                                                                                                                no-console
Error:    82:1   error  Insert `↹`                                                                                                                                                                  prettier/prettier
Error:    82:4   error  Unexpected alert                                                                                                                                                            no-alert
Error:    82:4   error  'alert' is not defined                                                                                                                                                      no-undef
Error:    82:28  error  'classifaiQuickDraft' is not defined                                                                                                                                        no-undef
Error:    83:3   error  Replace `}·).finally(·function` with `↹}·)⏎↹↹↹.finally(·function·`                                                                                                          prettier/prettier
Error:    84:1   error  Insert `↹`                                                                                                                                                                  prettier/prettier
Error:    85:1   error  Insert `↹`                                                                                                                                                                  prettier/prettier
Error:    86:4   error  Insert `↹`                                                                                                                                                                  prettier/prettier
Error:    86:27  error  'classifaiQuickDraft' is not defined                                                                                                                                        no-undef
Error:    87:1   error  Insert `↹`                                                                                                                                                                  prettier/prettier
Error:   114:53  error  Insert `·`                                                                                                                                                                  prettier/prettier
Error:   120:23  error  Insert `·`                                                                                                                                                                  prettier/prettier
@faisal-alvi faisal-alvi marked this pull request as ready for review September 19, 2025 14:25
@faisal-alvi faisal-alvi requested review from a team, dkotter and jeffpaul as code owners September 19, 2025 14:25
@github-actions github-actions bot added the needs:code-review This requires code review. label Sep 19, 2025
@faisal-alvi faisal-alvi removed request for a team and jeffpaul September 19, 2025 14:25
message.className = 'notice notice-success is-dismissible';
message.innerHTML = `
<p>
Draft created successfully!
Copy link
Collaborator

Choose a reason for hiding this comment

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

There's a handful of strings in here that we aren't passing through translation that would be ideal to do

Comment on lines +309 to +312
public function init_quick_draft_integration() {
$quick_draft = new \Classifai\Features\QuickDraftIntegration();
$quick_draft->init();
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure I love initializing this here. Since this is tied to the Content Generation Feature, would it make more sense to initialize this in that class?

setTimeout(function() {
var saveButton = $('#save-post');
if (saveButton.length && !$('#classifai-generate-content').length) {
var generateButton = $('<input type="button" id="classifai-generate-content" class="button" value="<?php echo esc_js( __( 'Create Draft from Prompt Content', 'classifai' ) ); ?>" style="margin-left: 10px;" />');
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since we're loading custom CSS, can we remove this inline style here and add it there instead?

* Register Quick Draft specific endpoints.
*/
public function register_endpoints() {
register_rest_route(
Copy link
Collaborator

Choose a reason for hiding this comment

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

I almost think a better approach here would be to register a more generic endpoint in the Content Generation Feature class that allows generating content that isn't associated with a post ID (or modify our existing endpoint to support that). That way we don't end up with a very specific endpoint here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs:code-review This requires code review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Integrate Content Generation into Quick Draft widget on admin dashboard

2 participants