feat: Update version to 1.7.0 and add term description length settings for AI-generated content

This commit is contained in:
2026-01-30 11:57:21 +00:00
parent 9df41ca85c
commit 5ddd3f8104
6 changed files with 307 additions and 76 deletions

View File

@@ -537,16 +537,38 @@ class Groq_AI_Prompt_Builder {
$keyword_limit = $this->settings_manager->get_rankmath_focus_keyword_limit( $settings );
$title_pixels = $this->settings_manager->get_rankmath_meta_title_pixel_limit( $settings );
$desc_pixels = $this->settings_manager->get_rankmath_meta_description_pixel_limit( $settings );
$top_char_range = $this->get_char_limit_range_values( $this->settings_manager->get_term_top_description_char_limit( $settings ) );
$bottom_char_range = $this->get_char_limit_range_values( $this->settings_manager->get_term_bottom_description_char_limit( $settings ) );
$top_description_text = __( 'Korte HTML-omschrijving (1 alinea) voor de standaard WordPress term description. Exact één alinea in <p>-tags.', GROQ_AI_PRODUCT_TEXT_DOMAIN );
if ( $top_char_range ) {
$top_description_text .= ' ' . sprintf(
__( 'Doel: ~%1$d tekens (±10%% ⇒ %2$d%3$d).', GROQ_AI_PRODUCT_TEXT_DOMAIN ),
$top_char_range['limit'],
$top_char_range['min'],
$top_char_range['max']
);
}
$bottom_description_text = __( 'Uitgebreide HTML-omschrijving (helemaal onderaan), 24 alineas, met paragrafen en eventueel lijstjes.', GROQ_AI_PRODUCT_TEXT_DOMAIN );
if ( $bottom_char_range ) {
$bottom_description_text .= ' ' . sprintf(
__( 'Doel: ~%1$d tekens (±10%% ⇒ %2$d%3$d).', GROQ_AI_PRODUCT_TEXT_DOMAIN ),
$bottom_char_range['limit'],
$bottom_char_range['min'],
$bottom_char_range['max']
);
}
$properties = [
'top_description' => [
'type' => 'string',
'description' => __( 'Korte HTML-omschrijving (1 alinea) voor de standaard WordPress term description. Exact één alinea in <p>-tags.', GROQ_AI_PRODUCT_TEXT_DOMAIN ),
'description' => $top_description_text,
'minLength' => 20,
],
'bottom_description' => [
'type' => 'string',
'description' => __( 'Uitgebreide HTML-omschrijving (helemaal onderaan), 24 alineas, met paragrafen en eventueel lijstjes.', GROQ_AI_PRODUCT_TEXT_DOMAIN ),
'description' => $bottom_description_text,
'minLength' => 20,
],
];
@@ -675,6 +697,8 @@ class Groq_AI_Prompt_Builder {
'"top_description":"..."',
'"bottom_description":"..."',
];
$top_char_range = $this->get_char_limit_range_values( $this->settings_manager->get_term_top_description_char_limit( $settings ) );
$bottom_char_range = $this->get_char_limit_range_values( $this->settings_manager->get_term_bottom_description_char_limit( $settings ) );
$rankmath_enabled = $this->settings_manager->is_module_enabled( 'rankmath', $settings );
if ( $rankmath_enabled ) {
@@ -693,9 +717,42 @@ class Groq_AI_Prompt_Builder {
$instruction .= ' ' . __( 'Zorg dat top_description en bottom_description geldige HTML bevatten. top_description moet exact één alinea zijn in <p>-tags. bottom_description moet 24 alineas bevatten.', GROQ_AI_PRODUCT_TEXT_DOMAIN );
$instruction .= ' ' . __( 'Voeg geen extra tekst buiten het JSON-object toe.', GROQ_AI_PRODUCT_TEXT_DOMAIN );
$instruction .= ' ' . __( 'Als in de context een sectie "Interne links" staat, verwerk dan 25 van deze links natuurlijk in bottom_description als HTML-links (<a href="URL">Anker</a>).', GROQ_AI_PRODUCT_TEXT_DOMAIN );
if ( $top_char_range ) {
$instruction .= ' ' . sprintf(
__( 'Houd top_description rond %1$d tekens en blijf tussen %2$d en %3$d tekens (±10%% marge).', GROQ_AI_PRODUCT_TEXT_DOMAIN ),
$top_char_range['limit'],
$top_char_range['min'],
$top_char_range['max']
);
}
if ( $bottom_char_range ) {
$instruction .= ' ' . sprintf(
__( 'Houd bottom_description rond %1$d tekens en blijf tussen %2$d en %3$d tekens (±10%% marge).', GROQ_AI_PRODUCT_TEXT_DOMAIN ),
$bottom_char_range['limit'],
$bottom_char_range['min'],
$bottom_char_range['max']
);
}
return $instruction;
}
private function get_char_limit_range_values( $limit ) {
$limit = absint( $limit );
if ( $limit <= 0 ) {
return null;
}
$min = (int) floor( $limit * 0.9 );
$max = (int) ceil( $limit * 1.1 );
return [
'limit' => $limit,
'min' => max( 1, $min ),
'max' => max( $min, $max ),
];
}
private function resolve_term_bottom_description_meta_key( $term = null, $settings = null ) {
$default_key = '';
if ( is_array( $settings ) && isset( $settings['term_bottom_description_meta_key'] ) ) {
@@ -716,9 +773,15 @@ class Groq_AI_Prompt_Builder {
'post_status' => 'publish',
'posts_per_page' => $limit,
'no_found_rows' => true,
'meta_key' => 'total_sales',
'orderby' => 'meta_value_num',
'orderby' => 'date',
'order' => 'DESC',
'meta_query' => [
[
'key' => '_stock_status',
'value' => 'instock',
'compare' => '=',
],
],
'tax_query' => [
[
'taxonomy' => $taxonomy,

View File

@@ -52,6 +52,8 @@ class Groq_AI_Settings_Manager {
'image_context_mode' => 'url',
'image_context_limit' => 3,
'response_format_compat' => false,
'term_top_description_char_limit' => 600,
'term_bottom_description_char_limit' => 1200,
];
$settings = get_option( $this->option_key, [] );
@@ -79,6 +81,15 @@ class Groq_AI_Settings_Manager {
isset( $settings['product_attribute_includes'] ) ? $settings['product_attribute_includes'] : []
);
$settings['term_top_description_char_limit'] = $this->sanitize_term_description_char_limit_value(
isset( $settings['term_top_description_char_limit'] ) ? $settings['term_top_description_char_limit'] : $defaults['term_top_description_char_limit'],
$defaults['term_top_description_char_limit']
);
$settings['term_bottom_description_char_limit'] = $this->sanitize_term_description_char_limit_value(
isset( $settings['term_bottom_description_char_limit'] ) ? $settings['term_bottom_description_char_limit'] : $defaults['term_bottom_description_char_limit'],
$defaults['term_bottom_description_char_limit']
);
return $settings;
}
@@ -114,6 +125,8 @@ class Groq_AI_Settings_Manager {
'image_context_mode' => 'url',
'image_context_limit' => 3,
'response_format_compat' => false,
'term_top_description_char_limit' => 600,
'term_bottom_description_char_limit' => 1200,
];
$current_settings = $this->all();
@@ -151,6 +164,15 @@ class Groq_AI_Settings_Manager {
$context_fields['images'] = true;
}
$top_char_limit = $this->sanitize_term_description_char_limit_value(
isset( $raw_input['term_top_description_char_limit'] ) ? $raw_input['term_top_description_char_limit'] : $defaults['term_top_description_char_limit'],
$defaults['term_top_description_char_limit']
);
$bottom_char_limit = $this->sanitize_term_description_char_limit_value(
isset( $raw_input['term_bottom_description_char_limit'] ) ? $raw_input['term_bottom_description_char_limit'] : $defaults['term_bottom_description_char_limit'],
$defaults['term_bottom_description_char_limit']
);
return [
'provider' => $provider,
'model' => $model,
@@ -174,6 +196,8 @@ class Groq_AI_Settings_Manager {
'response_format_compat' => ! empty( $raw_input['response_format_compat'] ),
'image_context_mode' => $image_mode,
'image_context_limit' => $image_limit,
'term_top_description_char_limit' => $top_char_limit,
'term_bottom_description_char_limit' => $bottom_char_limit,
'context_fields' => $context_fields,
'modules' => $this->sanitize_modules_settings(
$modules_posted ? $raw_input['modules'] : [],
@@ -211,6 +235,22 @@ class Groq_AI_Settings_Manager {
return $clean;
}
private function sanitize_term_description_char_limit_value( $value, $default ) {
$default_value = absint( $default ) > 0 ? absint( $default ) : 600;
if ( null === $value || '' === $value ) {
$value = $default_value;
}
$value = absint( $value );
if ( $value <= 0 ) {
$value = $default_value;
}
return max( 100, min( 5000, $value ) );
}
public function get_context_field_definitions() {
if ( null === $this->context_field_definitions ) {
$this->context_field_definitions = [
@@ -362,6 +402,26 @@ class Groq_AI_Settings_Manager {
return $this->sanitize_image_context_limit_value( $limit );
}
public function get_term_top_description_char_limit( $settings = null ) {
if ( null === $settings ) {
$settings = $this->all();
}
$value = isset( $settings['term_top_description_char_limit'] ) ? $settings['term_top_description_char_limit'] : 600;
return $this->sanitize_term_description_char_limit_value( $value, 600 );
}
public function get_term_bottom_description_char_limit( $settings = null ) {
if ( null === $settings ) {
$settings = $this->all();
}
$value = isset( $settings['term_bottom_description_char_limit'] ) ? $settings['term_bottom_description_char_limit'] : 1200;
return $this->sanitize_term_description_char_limit_value( $value, 1200 );
}
public function is_response_format_compat_enabled( $settings = null ) {
if ( null === $settings ) {
$settings = $this->all();