-
Notifications
You must be signed in to change notification settings - Fork 62
Enhancement/921 Add Custom and ACF Field targeting for Excerpt Generation #969
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
… in excerpt generation
…o-dismiss after 5 seconds
…ermission checks in excerpt generation
…vent listeners for meta field changes
------ --------------------------------------------------------------------- Line includes/Classifai/Admin/Settings.php ------ --------------------------------------------------------------------- 246 Function acf_get_fields not found. 🪪 function.notFound 💡 Learn more at https://phpstan.org/user-guide/discovering-symbols ------ --------------------------------------------------------------------- ------ --------------------------------------------------------------------- Line includes/Classifai/Features/ExcerptGeneration.php ------ --------------------------------------------------------------------- 521 Function acf_get_fields not found. 🪪 function.notFound 💡 Learn more at https://phpstan.org/user-guide/discovering-symbols 774 Expected 4 @param tags, found 3. 🪪 paramTag.count 834 Function acf_get_fields not found. Elapsed time: 17 seconds 🪪 function.notFound 💡 Learn more at https://phpstan.org/user-guide/discovering-symbols ------ ---------------------------------------------------------------------
@faisal-alvi thanks for the PR! Could you please fill out the PR template with description, changelog, and credits information so that we can properly review and merge this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the working on this and raising the PR @faisal-alvi. Overall it looks good. However, I have added few comments.
Additionally, I noticed that we are marking the default excerpt field as read-only/disabled when a custom meta field or ACF field is selected as the target field. I think we should keep the excerpt field as it is. We might instead show a notice near the excerpt generation button, indicating that the generated content will be saved into the selected custom field/ACF field. Otherwise, I believe we should leave the excerpt field unchanged, as there is no direct connection between them. I just wanted to know if there is a specific reasoning behind this. (cc: @dkotter any thoughts on this?)

Thanks!
'Change the target field in', | ||
'classifai' | ||
) + | ||
'<a href="' + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add_settings_field( | ||
'target_field', | ||
esc_html__( 'Target field', 'classifai' ), | ||
[ $this, 'render_target_field_settings' ], | ||
$this->get_option_name(), | ||
$this->get_option_name() . '_section', | ||
[ | ||
'label_for' => 'target_field', | ||
'default_value' => $settings['target_field_type'] ?? 'post_excerpt', | ||
'description' => __( 'Choose where to save the generated excerpt. You can target the default excerpt field, custom meta fields, or ACF fields.', 'classifai' ), | ||
] | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are not supporting legacy settings panel now. So, this is no longer needed now.
'target_custom_field' => '', | ||
'target_acf_field' => '', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: As we are already storing target_field_type
, can we merge this two into single as a target_field
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason for keeping these separate is to ensure that if the admin switches back to the previous type, they will still get the same field they were originally using.
* | ||
* @return array Array of ACF fields. | ||
*/ | ||
public function get_available_acf_fields() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noticed similar get_acf_fields()
function in Admin/Settings.php. Maybe better to move this to helper functions to prevent code duplication here?
Yeah, I agree feels a little weird to have that field disabled. I also think we may need further discussion on how exactly this should work. For instance, feels like we may want to allow multiple selections here, so someone can store this in the excerpt field and a custom field (similar to our Descriptive Text Generator where you can choose one or multiple options for storage). In addition, if I choose ACF or custom meta, I don't love the idea of having the And finally, if this Feature is on, we remove the core WordPress excerpt panel and replace it with our own, which allows us to add that generate button. Since that was introduced, WordPress has changed how the excerpt panel works and it's been on my list to bring those changes over to ClassifAI. Doesn't have to be done in this PR but might be a good opportunity to align our approach with core (or even investigate if there's a better option now to add that button). |
@iamdharmesh Thanks for the feedback!
Reference: classifai/src/js/features/excerpt-generation/classic/index.js Lines 104 to 111 in 0397277
![]() @dkotter Thanks for adding details. A few follow-ups from my side:
My assumption is that the AI-generated excerpt would be inserted into both the custom/ACF field and the Core field. If that’s the case, should we consider adding:
Personally, I feel the current location is still reasonable for now since we provide a clarifying note (screenshot above), but in the future, we could revisit placement. However, do you have a preferred spot in mind? Happy to make those changes. @iamdharmesh would also love your input here or on any other points.
Could you elaborate on what specific changes have been made in core? That would help us plan how best to align. |
Description of the Change
This PR implements custom field targeting for the ClassifAI excerpt generation feature, allowing users to save generated excerpts to custom fields beyond the default WordPress excerpt field. This enhancement supports editorial workflows that use structured content blocks, custom meta fields, or ACF fields for storing excerpts, etc.
editorial_subtitle
,custom_excerpt
,dek
)New Setting Field:
Block Editor (Custom Field):
Block Editor (ACF):
Classic Editor (ACF):
Closes #921
How to test the Change
Custom Meta Field Testing:
editorial_subtitle
,custom_excerpt
)ACF Field Testing:
Editor Testing:
Settings Testing:
Credits
Props @jeffpaul @faisal-alvi @iamdharmesh
Changelog Entry