@@ -85,23 +85,47 @@ public function render_provider_fields() {
85
85
]
86
86
);
87
87
88
- add_settings_field (
89
- 'number_of_titles ' ,
90
- esc_html__ ( 'Number of titles ' , 'classifai ' ),
91
- [ $ this ->feature_instance , 'render_input ' ],
92
- $ this ->feature_instance ->get_option_name (),
93
- $ this ->feature_instance ->get_option_name () . '_section ' ,
94
- [
95
- 'option_index ' => static ::ID ,
96
- 'label_for ' => 'number_of_titles ' ,
97
- 'input_type ' => 'number ' ,
98
- 'min ' => 1 ,
99
- 'step ' => 1 ,
100
- 'default_value ' => $ settings ['number_of_titles ' ],
101
- 'class ' => 'classifai-provider-field hidden provider-scope- ' . static ::ID , // Important to add this.
102
- 'description ' => esc_html__ ( 'Number of titles that will be generated in one request. ' , 'classifai ' ),
103
- ]
104
- );
88
+ switch ( $ this ->feature_instance ::ID ) {
89
+ case TitleGeneration::ID :
90
+ add_settings_field (
91
+ 'number_of_titles ' ,
92
+ esc_html__ ( 'Number of titles ' , 'classifai ' ),
93
+ [ $ this ->feature_instance , 'render_input ' ],
94
+ $ this ->feature_instance ->get_option_name (),
95
+ $ this ->feature_instance ->get_option_name () . '_section ' ,
96
+ [
97
+ 'option_index ' => static ::ID ,
98
+ 'label_for ' => 'number_of_titles ' ,
99
+ 'input_type ' => 'number ' ,
100
+ 'min ' => 1 ,
101
+ 'step ' => 1 ,
102
+ 'default_value ' => $ settings ['number_of_titles ' ],
103
+ 'class ' => 'classifai-provider-field hidden provider-scope- ' . static ::ID , // Important to add this.
104
+ 'description ' => esc_html__ ( 'Number of titles that will be generated in one request. ' , 'classifai ' ),
105
+ ]
106
+ );
107
+ break ;
108
+
109
+ case ContentResizing::ID :
110
+ add_settings_field (
111
+ 'number_of_suggestions ' ,
112
+ esc_html__ ( 'Number of suggestions ' , 'classifai ' ),
113
+ [ $ this ->feature_instance , 'render_input ' ],
114
+ $ this ->feature_instance ->get_option_name (),
115
+ $ this ->feature_instance ->get_option_name () . '_section ' ,
116
+ [
117
+ 'option_index ' => static ::ID ,
118
+ 'label_for ' => 'number_of_suggestions ' ,
119
+ 'input_type ' => 'number ' ,
120
+ 'min ' => 1 ,
121
+ 'step ' => 1 ,
122
+ 'default_value ' => $ settings ['number_of_suggestions ' ],
123
+ 'class ' => 'classifai-provider-field hidden provider-scope- ' . static ::ID , // Important to add this.
124
+ 'description ' => esc_html__ ( 'Number of suggestions that will be generated in one request. ' , 'classifai ' ),
125
+ ]
126
+ );
127
+ break ;
128
+ }
105
129
106
130
do_action ( 'classifai_ ' . static ::ID . '_render_provider_fields ' , $ this );
107
131
}
@@ -115,9 +139,21 @@ public function get_default_provider_settings(): array {
115
139
$ common_settings = [
116
140
'api_key ' => '' ,
117
141
'authenticated ' => false ,
118
- 'number_of_titles ' => 1 ,
119
142
];
120
143
144
+ /**
145
+ * Default values for feature specific settings.
146
+ */
147
+ switch ( $ this ->feature_instance ::ID ) {
148
+ case TitleGeneration::ID :
149
+ $ common_settings ['number_of_titles ' ] = 1 ;
150
+ break ;
151
+
152
+ case ContentResizing::ID :
153
+ $ common_settings ['number_of_suggestions ' ] = 1 ;
154
+ break ;
155
+ }
156
+
121
157
return $ common_settings ;
122
158
}
123
159
@@ -133,7 +169,16 @@ public function sanitize_settings( array $new_settings ): array {
133
169
134
170
$ new_settings [ static ::ID ]['api_key ' ] = $ api_key_settings [ static ::ID ]['api_key ' ];
135
171
$ new_settings [ static ::ID ]['authenticated ' ] = $ api_key_settings [ static ::ID ]['authenticated ' ];
136
- $ new_settings [ static ::ID ]['number_of_titles ' ] = sanitize_number_of_responses_field ( 'number_of_titles ' , $ new_settings [ static ::ID ], $ settings [ static ::ID ] );
172
+
173
+ switch ( $ this ->feature_instance ::ID ) {
174
+ case TitleGeneration::ID :
175
+ $ new_settings [ static ::ID ]['number_of_titles ' ] = sanitize_number_of_responses_field ( 'number_of_titles ' , $ new_settings [ static ::ID ], $ settings [ static ::ID ] );
176
+ break ;
177
+
178
+ case ContentResizing::ID :
179
+ $ new_settings [ static ::ID ]['number_of_suggestions ' ] = sanitize_number_of_responses_field ( 'number_of_suggestions ' , $ new_settings [ static ::ID ], $ settings [ static ::ID ] );
180
+ break ;
181
+ }
137
182
138
183
return $ new_settings ;
139
184
}
@@ -412,7 +457,7 @@ public function resize_content( int $post_id, array $args = array() ) {
412
457
$ args = wp_parse_args (
413
458
array_filter ( $ args ),
414
459
[
415
- 'num ' => $ settings ['number_of_suggestions ' ] ?? 1 ,
460
+ 'num ' => $ settings [ static :: ID ][ 'number_of_suggestions ' ] ?? 1 ,
416
461
]
417
462
);
418
463
@@ -574,16 +619,16 @@ public function get_debug_information(): array {
574
619
575
620
if ( $ this ->feature_instance instanceof TitleGeneration ) {
576
621
$ debug_info [ __ ( 'No. of titles ' , 'classifai ' ) ] = $ provider_settings ['number_of_titles ' ] ?? 1 ;
577
- $ debug_info [ __ ( 'Generate title prompt ' , 'classifai ' ) ] = wp_json_encode ( $ provider_settings ['generate_title_prompt ' ] ?? [] );
622
+ $ debug_info [ __ ( 'Generate title prompt ' , 'classifai ' ) ] = wp_json_encode ( $ settings ['generate_title_prompt ' ] ?? [] );
578
623
$ debug_info [ __ ( 'Latest response ' , 'classifai ' ) ] = $ this ->get_formatted_latest_response ( get_transient ( 'classifai_openai_chatgpt_title_generation_latest_response ' ) );
579
624
} elseif ( $ this ->feature_instance instanceof ExcerptGeneration ) {
580
625
$ debug_info [ __ ( 'Excerpt length ' , 'classifai ' ) ] = $ settings ['length ' ] ?? 55 ;
581
- $ debug_info [ __ ( 'Generate excerpt prompt ' , 'classifai ' ) ] = wp_json_encode ( $ provider_settings ['generate_excerpt_prompt ' ] ?? [] );
626
+ $ debug_info [ __ ( 'Generate excerpt prompt ' , 'classifai ' ) ] = wp_json_encode ( $ settings ['generate_excerpt_prompt ' ] ?? [] );
582
627
$ debug_info [ __ ( 'Latest response ' , 'classifai ' ) ] = $ this ->get_formatted_latest_response ( get_transient ( 'classifai_openai_chatgpt_excerpt_generation_latest_response ' ) );
583
628
} elseif ( $ this ->feature_instance instanceof ContentResizing ) {
584
629
$ debug_info [ __ ( 'No. of suggestions ' , 'classifai ' ) ] = $ provider_settings ['number_of_suggestions ' ] ?? 1 ;
585
- $ debug_info [ __ ( 'Expand text prompt ' , 'classifai ' ) ] = wp_json_encode ( $ provider_settings ['expand_text_prompt ' ] ?? [] );
586
- $ debug_info [ __ ( 'Condense text prompt ' , 'classifai ' ) ] = wp_json_encode ( $ provider_settings ['condense_text_prompt ' ] ?? [] );
630
+ $ debug_info [ __ ( 'Expand text prompt ' , 'classifai ' ) ] = wp_json_encode ( $ settings ['expand_text_prompt ' ] ?? [] );
631
+ $ debug_info [ __ ( 'Condense text prompt ' , 'classifai ' ) ] = wp_json_encode ( $ settings ['condense_text_prompt ' ] ?? [] );
587
632
$ debug_info [ __ ( 'Latest response ' , 'classifai ' ) ] = $ this ->get_formatted_latest_response ( get_transient ( 'classifai_openai_chatgpt_content_resizing_latest_response ' ) );
588
633
}
589
634
0 commit comments