PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 3.5.3
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v3.5.3
4.9.2 4.9.1 4.9.0 4.8.2 4.8.1 4.8.0 4.7.0 4.6.2 4.6.1 4.6.0 4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 4.5.1 4.5.0 4.4.1 4.4.0 3.3.4 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 All 200 releases
← All changes | includes/REST/Settings.php +261 -281 4.9.23.5.3 View file →
@@ -1,366 +1,346 @@
1 1 <?php
2 2
3 3 namespace WPDeveloper\BetterDocs\REST;
4 4
5 +use WPDeveloper\BetterDocs\Admin\ReportEmail;
5 6 use WP_Query;
7 +use WP_User;
6 8 use WP_REST_Request;
9 +use WPDeveloper\BetterDocs\Core\BaseAPI;
10 +use WPDeveloper\BetterDocs\Admin\WPExporter;
7 11 use WPDeveloper\BetterDocs\Admin\CSVExporter;
12 +use WPDeveloper\BetterDocs\Admin\Importer\WPImport;
8 13 use WPDeveloper\BetterDocs\Admin\Importer\Parsers\CSV_Parser;
9 -use WPDeveloper\BetterDocs\Admin\Importer\WPImport;
10 -use WPDeveloper\BetterDocs\Admin\ReportEmail;
11 -use WPDeveloper\BetterDocs\Admin\XMLExporter;
12 -use WPDeveloper\BetterDocs\Core\BaseAPI;
13 -use WPDeveloper\BetterDocs\Dependencies\DI\DependencyException;
14 -use WPDeveloper\BetterDocs\Dependencies\DI\NotFoundException;
15 -use WPDeveloper\BetterDocsChatbot\Core\AIChatbot;
16 -use WPDeveloper\BetterDocs\Core\Settings as CoreSettings;
17 -use WPDeveloper\BetterDocs\Utils\Helper;
18 14
19 15 class Settings extends BaseAPI {
20 16
21 - public function permission_check(): bool {
22 - return current_user_can( 'edit_docs_settings' );
23 - }
17 + public function permission_check() {
18 + return current_user_can( 'edit_docs_settings' );
19 + }
24 20
25 21 public function register() {
26 - $this->get( 'settings', [ $this, 'get_settings' ] );
27 - $this->post( 'dark-mode', [ $this, 'dark_mode' ] );
28 - $this->post( 'settings', [ $this, 'save_settings' ] );
29 - $this->post( 'plugin_insights', [ $this, 'plugin_insights' ] );
22 + $this->get( 'settings', [$this, 'get_settings'] );
23 + $this->post( 'settings', [$this, 'save_settings'] );
24 + $this->post( 'plugin_insights', [$this, 'plugin_insights'] );
25 +
26 + $this->post( 'reporting-test', [$this, 'test_reporting'] );
27 + $this->post( 'export-docs', [$this, 'export_docs'] );
28 + $this->post( 'export-settings', [$this, 'export_settings'] );
29 + $this->post( 'import-docs', [$this, 'import_docs'] );
30 + $this->post( 'import-settings', [$this, 'import_settings'] );
31 + $this->post( 'parse-xml', [$this, 'parse_xml'] );
32 + $this->post( 'parse-csv', [$this, 'parse_csv'] );
33 + $this->post( 'migrate', [$this, 'migrate_plugins'] );
30 34 $this->post( 'create-sample-docs', [$this, 'sample_docs'] );
31 - $this->post( 'reporting-test', [ $this, 'test_reporting' ] );
32 - $this->post( 'export-docs', [ $this, 'export_docs' ] );
33 - $this->post( 'export-settings', [ $this, 'export_settings' ] );
34 - $this->post( 'import-docs', [ $this, 'import_docs' ] );
35 - $this->post( 'import-settings', [ $this, 'import_settings' ] );
36 - $this->post( 'parse-xml', [ $this, 'parse_xml' ] );
37 - $this->post( 'parse-csv', [ $this, 'parse_csv' ] );
38 - $this->post( 'migrate', [ $this, 'migrate_plugins' ] );
39 35 $this->post( 'helpscout-migration', [$this, 'helpscout_migration'] );
40 - $this->post( 'dashboard-mode', [$this, 'dashboard_mode'] );
41 36 }
42 37
43 - public function dashboard_mode( WP_REST_Request $request ) {
44 - $mode = $request->get_param( 'dashboard_mode' );
45 - return update_option( 'dashboard_mode', $mode );
46 - }
38 + public function sample_docs( WP_REST_Request $request ) {
39 + $action = $request->get_param( 'action' );
47 40
48 - public function dark_mode( WP_REST_Request $request ): bool {
49 - $dark_mode = rest_sanitize_boolean( $request->get_param( 'mode' ) );
41 + if ( $action == 'create-dummy-data' ) {
42 + $file = BETTERDOCS_ABSPATH . 'assets/admin/images/BetterDocs-sample-data.csv';
43 + $args = [
44 + 'fetch_attachments' => true,
45 + 'action' => '',
46 + 'existing_slug' => '',
47 + 'file_type' => 'text/csv'
48 + ];
49 + $wp_import_object = new WPImport( $file, $args );
50 + return $wp_import_object->run();
51 + }
52 + }
50 53
51 - if ( betterdocs()->settings->save( 'dark_mode', $dark_mode ) ) {
52 - return true;
53 - }
54 -
55 - return false;
56 - }
57 -
58 - public function sample_docs( WP_REST_Request $request ) {
59 - $action = $request->get_param( 'action' );
60 -
61 - if ( $action == 'create-dummy-data' ) {
62 - $file = BETTERDOCS_ABSPATH . 'assets/static/admin/images/BetterDocs-sample-data.csv';
63 - $args = [
64 - 'fetch_attachments' => true,
65 - 'action' => '',
66 - 'existing_slug' => '',
67 - 'file_type' => 'text/csv'
68 - ];
69 - $wp_import_object = new WPImport( $file, $args );
70 - return $wp_import_object->run();
71 - }
72 - }
73 -
74 54 public function export_docs( WP_REST_Request $request ) {
75 - $data = $request->get_params();
76 55 $args = [
77 56 'include_post_featured_image_as_attachment' => true,
78 57 'status' => 'publish',
79 - 'content' => $data['export_type'],
80 - 'selected_docs' => $data['export_docs'],
81 - 'include_faq' => $data['enable_export_faq'],
58 + 'content' => 'docs'
82 59 ];
83 60
84 - if ( $data['export_type'] == 'docs' && $data['export_docs'][0] != 'all' ) {
85 - $args['post__in'] = $data['export_docs'];
86 - }
61 + $data = $request->get_params();
87 62
88 - if ( $data['export_type'] == 'doc_category' || $data['export_type'] == 'knowledge_base' ) {
89 - $args['content'] = 'docs';
90 - }
63 + if ( $data['export_type'] == 'docs' && $data['export_docs'][0] != 'all' ) {
64 + $args['post__in'] = $data['export_docs'];
65 + }
91 66
92 - if ( $data['export_type'] == 'doc_category' && $data['export_categories'][0] != 'all' ) {
93 - $args['category_terms'] = $data['export_categories'];
94 - } else if ( $data['export_type'] == 'knowledge_base' && $data['export_kbs'][0] != 'all' ) {
95 - $args['kb_terms'] = $data['export_kbs'];
96 - }
67 + if ( $data['export_type'] == 'doc_category' && $data['export_categories'][0] != 'all' ) {
68 + $args['category_terms'] = $data['export_categories'];
69 + }
97 70
98 - if ( $data['export_type'] == 'glossaries' && $data['export_glossaries'][0] != 'all' ) {
99 - $args['glossary_terms'] = $data['export_glossaries'];
100 - unset( $args['selected_docs'] );
101 - }
71 + if ( $data['export_type'] == 'knowledge_base' && $data['export_kbs'][0] != 'all' ) {
72 + $args['kb_terms'] = $data['export_kbs'];
73 + }
102 74
103 - if ( $data['file_type'] == 'xml' ) {
104 - $exporter = new XMLExporter( $args );
105 - } else if ( $data['file_type'] == 'csv' ) {
75 + if ($data['file_type'] == 'xml') {
76 + $exporter = new WPExporter( $args );
77 + } else if ($data['file_type'] == 'csv') {
106 78 $exporter = new CSVExporter( $args );
107 79 }
108 80
109 - /**
110 - * @var XMLExporter|CSVExporter $exporter
111 - */
81 + return $exporter->run();
82 + }
112 83
113 - return $exporter->run();
114 - }
115 -
116 - public function export_settings( WP_REST_Request $request ): array {
84 + public function export_settings( WP_REST_Request $request ) {
117 85 $betterdocs_settings = get_option( 'betterdocs_settings' );
118 86 $json_str = json_encode( $betterdocs_settings, JSON_PRETTY_PRINT );
119 87 $file_name = 'betterdocs-settings.json';
88 + return [
89 + 'success' => true,
90 + 'data' => [
91 + 'filename' => $file_name,
92 + 'filetype' => 'text/json',
93 + 'download' => $json_str
94 + ]
95 + ];
96 + }
120 97
121 - return [
122 - 'success' => true,
123 - 'data' => [
124 - 'filename' => $file_name,
125 - 'filetype' => 'text/json',
126 - 'download' => $json_str,
127 - ]
128 - ];
129 - }
98 + public function import_settings( WP_REST_Request $request ) {
99 + $settings = $request->get_param( 'settings' );
100 + // Decode the JSON data into a PHP array
101 + $settings = json_decode( $settings, true );
102 + $save = update_option( 'betterdocs_settings', $settings );
130 103
131 - public function import_settings( WP_REST_Request $request ): array {
132 - $settings = $request->get_param( 'settings' );
133 - // Decode the JSON data into a PHP array
134 - $settings = json_decode( $settings, true );
135 - $saved = update_option( 'betterdocs_settings', $settings );
104 + if ( $save == true ) {
105 + return [
106 + 'status' => 'success'
107 + ];
108 + } else {
109 + return [
110 + 'status' => 'failed'
111 + ];
112 + }
113 + }
136 114
137 - if ( ! $saved ) {
138 - return [
139 - 'status' => 'failed'
140 - ];
141 - }
115 + public function import_docs( WP_REST_Request $request ) {
116 + $existing_slug = $request->get_param( 'existing_slug' );
117 + $action = $request->get_param( 'action' );
142 118
143 - return [
144 - 'status' => 'success'
145 - ];
146 - }
119 + $files = $request->get_file_params();
147 120
148 - public function import_docs( WP_REST_Request $request ): array {
149 - $existing_slug = $request->get_param( 'existing_slug' );
150 - $action = $request->get_param( 'action' );
151 -
152 - $files = $request->get_file_params();
153 -
154 121 $file = $files['file']['tmp_name'];
155 122
156 - $args = [
123 + $args = [
157 124 'fetch_attachments' => true,
158 - 'existing_slug' => $existing_slug,
159 - 'action' => $action,
160 - 'file_type' => $files['file']['type'],
161 - // The original upload name (with its extension) is the reliable
162 - // signal for choosing the parser; the browser-reported MIME on
163 - // $files['file']['type'] is not.
164 - 'file_name' => isset( $files['file']['name'] ) ? $files['file']['name'] : ''
125 + 'existing_slug' => $existing_slug,
126 + 'action' => $action,
127 + 'file_type' => $files['file']['type']
165 128 ];
166 129
167 - $wp_importer = new WPImport( $file, $args );
130 + $wp_importer = new WPImport( $file, $args );
168 131
169 - return $wp_importer->run();
170 - }
132 + return $wp_importer->run();
133 + }
171 134
172 - public function parse_xml( WP_REST_Request $request ): array {
173 - $data = $request->get_params();
174 - $existing_post_slugs = $this->get_existing_slugs( $data['posts'] );
135 + public function parse_xml( WP_REST_Request $request ) {
136 + $data = $request->get_params();
137 + $existing_post_slugs = $this->get_existing_slugs($data['posts']);
175 138
176 - // Output the array of existing post slugs
177 - return [
178 - 'status' => 'success',
179 - 'data' => $existing_post_slugs,
180 - ];
181 - }
139 + // Output the array of existing post slugs
140 + return [
141 + 'status' => 'success',
142 + 'data' => $existing_post_slugs,
143 + ];
144 + }
182 145
183 - public function parse_csv( WP_REST_Request $request ): array {
184 - $files = $request->get_file_params();
146 + public function parse_csv( WP_REST_Request $request ) {
147 + $files = $request->get_file_params();
185 148
186 149 $file = $files['file']['tmp_name'];
187 150
188 - $parser = new CSV_Parser();
151 + $parser = new CSV_Parser();
189 152 $parsed = $parser->parse( $file );
190 153
191 - $existing_post_slugs = [];
154 + if ( isset( $parsed['posts'] ) && is_array( $parsed['posts'] ) ) {
155 + $post_names = array_map(function ($post) {
156 + return $post['post_name'];
157 + }, $parsed['posts']);
158 + }
192 159
193 - if ( isset( $parsed['posts'] ) && is_array( $parsed['posts'] ) ) {
194 - $post_names = array_map(
195 - function ( $post ) {
196 - return $post['post_name'];
197 - },
198 - $parsed['posts']
199 - );
160 + $existing_post_slugs = $this->get_existing_slugs( $post_names) ;
200 161
201 - $existing_post_slugs = $this->get_existing_slugs( $post_names );
202 - }
162 + return [
163 + 'status' => 'success',
164 + 'data' => $existing_post_slugs,
165 + ];
166 + }
203 167
204 - return [
205 - 'status' => 'success',
206 - 'data' => $existing_post_slugs,
207 - ];
208 - }
168 + public function migrate_plugins( WP_REST_Request $request ) {
169 + betterdocs()->kbmigration->migrate();
209 170
210 - public function migrate_plugins( WP_REST_Request $request ): array {
211 - betterdocs()->kbmigration->migrate();
171 + return [
172 + 'status' => 'success'
173 + ];
174 + }
212 175
213 - return [
214 - 'status' => 'success'
215 - ];
216 - }
176 + public function helpscout_migration( WP_REST_Request $request ) {
177 + $api_key = $request->get_param('helpscout_api_key');
178 + $collection_id = $request->get_param('helpscout_collection_id');
217 179
218 - public function helpscout_migration( WP_REST_Request $request ) {
219 - $api_key = $request->get_param( 'helpscout_api_key' );
220 - $collection_id = $request->get_param( 'helpscout_collection_id' );
180 + if ( ! $api_key || ! $collection_id ) {
181 + return [
182 + 'status' => 'error',
183 + 'message' => esc_html__('Please provide both API Key and Collection ID', 'betterdocs')
184 + ];
185 + }
221 186
222 - if ( ! $api_key || ! $collection_id ) {
223 - return [
224 - 'status' => 'error',
225 - 'message' => esc_html__( 'Please provide both API Key and Collection ID', 'betterdocs' )
226 - ];
227 - }
187 + $api_endpoint = 'https://docsapi.helpscout.net/v1/collections/' . $collection_id . '/articles';
228 188
229 - $api_endpoint = 'https://docsapi.helpscout.net/v1/collections/' . $collection_id . '/articles?pageSize=1';
189 + $headers = array(
190 + 'Authorization' => 'Basic ' . base64_encode($api_key . ':X'),
191 + 'Content-Type' => 'application/json',
192 + );
230 193
231 - $headers = array(
232 - 'Authorization' => 'Basic ' . base64_encode( $api_key . ':X' ),
233 - 'Content-Type' => 'application/json',
234 - );
194 + $response = wp_remote_get($api_endpoint, array('headers' => $headers));
235 195
236 - $initial_response = wp_remote_get( $api_endpoint, array( 'headers' => $headers ) );
196 + if ( is_wp_error( $response ) ) {
197 + return [
198 + 'status' => 'error',
199 + 'message' => $response
200 + ];
201 + } else {
202 + $body = wp_remote_retrieve_body($response);
203 + $data = json_decode($body, true);
237 204
238 - if ( $initial_response['response']['code'] == '404' || $initial_response['response']['code'] == 401 ) {
239 - return [
240 - 'status' => 'error',
241 - 'message' => esc_html__( 'Unauthorized API Key or Collection ID', 'betterdocs' )
242 - ];
243 - }
205 + // Check if "articles" key exists in the response
206 + if (isset($data['articles']) && isset($data['articles']['items'])) {
207 + // Extract the articles
208 + $articles = $data['articles']['items'];
244 209
245 - // Enqueue migration task
246 - betterdocs()->backgroundProccessor->push_to_queue(
247 - array(
248 - 'headers' => $headers,
249 - 'initial_response' => $initial_response,
250 - 'api_key' => $api_key,
251 - 'collection_id' => $collection_id
252 - )
253 - )->save();
210 + // Fetch detailed information for each article
211 + $detailedArticles = [];
254 212
255 - // Start processing the queue
256 - betterdocs()->backgroundProccessor->dispatch();
213 + foreach ($articles as $article) {
214 + $articleId = $article['id'];
215 + $articleNumber = $article['number'];
257 216
258 - return [
259 - 'status' => 'success',
260 - 'message' => esc_html__( 'Migration process has started in the background.', 'betterdocs' )
261 - ];
262 - }
217 + // Make request to get detailed information for each article
218 + $articleEndpoint = "https://docsapi.helpscout.net/v1/articles/{$articleNumber}";
219 + $articleResponse = wp_remote_get($articleEndpoint, array('headers' => $headers));
263 220
264 - public function get_existing_slugs( $slugs ) {
265 - // Initialize the array for existing post slugs
266 - $existing_post_slugs = [];
221 + if (!is_wp_error($articleResponse)) {
222 + $articleBody = wp_remote_retrieve_body($articleResponse);
223 + $articleData = json_decode($articleBody, true);
267 224
268 - // Initialize the query arguments
269 - $args = [
270 - 'post_type' => [ 'docs', 'betterdocs_faq' ], // Change 'post' to your custom post type if applicable
271 - 'post_status' => 'publish',
272 - 'posts_per_page' => -1, // Retrieve all posts
273 - 'fields' => 'ids', // Retrieve only post IDs to reduce memory usage
274 - ];
225 + if (isset($articleData['article']) && isset($articleData['article']['text'])) {
226 + // Extract the article text
227 + $article['text'] = $articleData['article']['text'];
275 228
276 - // Create a new instance of WP_Query
277 - $query = new WP_Query( $args );
229 + // Extract category details
230 + $categories = $articleData['article']['categories'];
231 + $categoryDetails = [];
278 232
279 - // Get an array of post slugs from the query
280 - $all_post_slugs = array_map(
281 - function ( $post_id ) {
282 - return get_post_field( 'post_name', $post_id );
283 - },
284 - $query->posts
285 - );
233 + foreach ($categories as $categoryId) {
234 + $categoryEndpoint = "https://docsapi.helpscout.net/v1/categories/{$categoryId}";
235 + $categoryResponse = wp_remote_get($categoryEndpoint, array('headers' => $headers));
286 236
287 - // Restore original post data
288 - wp_reset_postdata();
237 + if (!is_wp_error($categoryResponse)) {
238 + $categoryBody = wp_remote_retrieve_body($categoryResponse);
239 + $categoryData = json_decode($categoryBody, true);
289 240
290 - // Find the intersection of the two arrays to get existing post slugs
291 - return array_intersect( $slugs, $all_post_slugs );
292 - }
241 + if (isset($categoryData['category']['name']) && isset($categoryData['category']['slug'])) {
242 + // Add category details to the article
243 + $categoryDetails[] = [
244 + 'name' => $categoryData['category']['name'],
245 + 'slug' => $categoryData['category']['slug'],
246 + ];
247 + }
248 + }
249 + }
293 250
294 - public function insights(): bool {
295 - return true;
296 - }
251 + // Add category details to the article
252 + $article['categories'] = $categoryDetails;
297 253
298 - public function get_settings(): array {
299 - $settings = betterdocs()->settings->get_all( true );
254 + // Add the article to the detailed articles array
255 + $detailedArticles[] = $article;
256 + }
257 + }
258 + }
300 259
301 - // Never hand raw API keys back over REST. The route is already gated to
302 - // `edit_docs_settings` (see permission_check() above), but get_all( true ) returned
303 - // UNMASKED values, so an authorized admin still received every key in full — the admin
304 - // UI only ever needs the masked form. Mask for managers, and strip entirely for anyone
305 - // else as defense-in-depth should that capability gate ever loosen. Mirrors the
306 - // admin-page localizer (Core\Settings::enqueue()) so the masked-key save round-trip
307 - // stays consistent.
308 - $sensitive_api_keys = CoreSettings::sensitive_api_key_fields();
309 - $can_manage = current_user_can( 'edit_docs_settings' );
310 - foreach ( $sensitive_api_keys as $api_key_field ) {
311 - if ( ! isset( $settings[ $api_key_field ] ) ) {
312 - continue;
313 - }
314 - if ( ! $can_manage ) {
315 - unset( $settings[ $api_key_field ] );
316 - continue;
317 - }
318 - if ( ! empty( $settings[ $api_key_field ] ) ) {
319 - $settings[ $api_key_field ] = Helper::mask_api_key( $settings[ $api_key_field ] );
320 - }
321 - }
260 + $wp_importer = new WPImport('');
322 261
323 - return $settings;
324 - }
262 + $result = $wp_importer->import_helpscout_data( $detailedArticles );
325 263
326 - public function save_settings( WP_REST_Request $request ) {
327 - $result = betterdocs()->settings->save_settings( $request->get_params() );
328 - if ( is_wp_error( $result ) ) {
329 - return $this->error( $result->get_error_code(), $result->get_error_message(), 400 );
330 - }
331 - if ( $result ) {
332 - return $this->success( __( 'Settings Saved!', 'betterdocs' ) );
333 - }
264 + return [
265 + 'status' => 'success',
266 + 'articles' => $result
267 + ];
268 + } else {
269 + return [
270 + 'status' => 'error',
271 + 'message' => esc_html__('Invalid API response format', 'betterdocs')
272 + ];
273 + }
274 + }
275 + }
334 276
335 - return $this->error( 'nothing_changed', __( 'There are no changes to be saved.', 'betterdocs' ), 200 );
336 - }
337 277
338 - /**
339 - * @throws NotFoundException
340 - * @throws DependencyException
341 - */
342 - public function test_reporting( $request ) {
343 - return $this->container->get( ReportEmail::class )->test_email_report( $request );
344 - }
345 278
346 - public function do_wizard_tracking(): bool {
347 - $insights = betterdocs()->admin->plugin_insights( true );
348 - // Get our data
349 - $insights->schedule_tracking();
350 - $insights->set_is_tracking_allowed( true, 'betterdocs' );
351 - if ( $insights->do_tracking( true ) ) {
352 - $insights->update_block_notice( 'betterdocs' );
353 - }
354 - if ( ! isset( $_COOKIE['betterdocs_insights_allowed'] ) ) {
355 - setcookie( 'betterdocs_insights_allowed', true, time() + ( 30 * 24 * 60 * 60 ), '/' );
356 - }
357 - return true;
358 - }
279 + public function get_existing_slugs( $slugs ) {
280 + // Initialize the array for existing post slugs
281 + $existing_post_slugs = [];
359 282
360 - public function plugin_insights( $request ) {
361 - if ( $this->do_wizard_tracking() ) {
362 - wp_send_json_success( 'done' );
363 - }
364 - wp_send_json_error( 'Something went wrong.' );
365 - }
283 + // Initialize the query arguments
284 + $args = [
285 + 'post_type' => 'docs', // Change 'post' to your custom post type if applicable
286 + 'post_status' => 'publish',
287 + 'posts_per_page' => -1, // Retrieve all posts
288 + 'fields' => 'ids' // Retrieve only post IDs to reduce memory usage
289 + ];
290 +
291 + // Create a new instance of WP_Query
292 + $query = new WP_Query( $args );
293 +
294 + // Get an array of post slugs from the query
295 + $all_post_slugs = array_map(function ($post_id) {
296 + return get_post_field('post_name', $post_id);
297 + }, $query->posts);
298 +
299 + // Restore original post data
300 + wp_reset_postdata();
301 +
302 + // Find the intersection of the two arrays to get existing post slugs
303 + $existing_post_slugs = array_intersect($slugs, $all_post_slugs);
304 +
305 + return $existing_post_slugs;
306 +
307 + }
308 + public function insights(){
309 + return true;
310 + }
311 +
312 + public function get_settings() {
313 + return betterdocs()->settings->get_all( true );
314 + }
315 +
316 + public function save_settings( WP_REST_Request $request ) {
317 + if ( betterdocs()->settings->save_settings( $request->get_params() ) ) {
318 + return $this->success( __( 'Settings Saved!', 'betterdocs' ) );
319 + }
320 +
321 + return $this->error( 'nothing_changed', __( 'There are no changes to be saved.', 'betterdocs' ), 200 );
322 + }
323 +
324 + public function test_reporting( $request ) {
325 + return $this->container->get( ReportEmail::class )->test_email_report( $request );
326 + }
327 +
328 + public function do_wizard_tracking() {
329 + $insights = betterdocs()->admin->plugin_insights( true );
330 + // Get our data
331 + $insights->schedule_tracking();
332 + $insights->set_is_tracking_allowed( true, 'betterdocs' );
333 + if ( $insights->do_tracking( true ) ) {
334 + $insights->update_block_notice( 'betterdocs' );
335 + }
336 +
337 + return true;
338 + }
339 +
340 + public function plugin_insights( $request ) {
341 + if ( $this->do_wizard_tracking() ) {
342 + wp_send_json_success( 'done' );
343 + }
344 + wp_send_json_error( 'Something went wrong.' );
345 + }
366 346 }