PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 4.5.3
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v4.5.3
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 3.5.2 All 199 releases
betterdocs / includes / Core / SetupWizard.php

SetupWizard.php in BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot 4.5.3, at includes/Core/SetupWizard.php

496 lines 18.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WPDeveloper\BetterDocs\Core;
4
5 use WPDeveloper\BetterDocs\Utils\Base;
6 use WPDeveloper\BetterDocs\Admin\Builder\Rules;
7 use WPDeveloper\BetterDocs\Admin\Builder\GlobalFields;
8
9 class SetupWizard extends Base {
10 private $settings;
11 public function __construct( Settings $settings ) {
12 $this->settings = $settings;
13
14 add_action( 'admin_enqueue_scripts', [ $this, 'enqueue' ] );
15 }
16
17 public function enqueue( $hook ) {
18 if ( $hook !== 'betterdocs_page_betterdocs-setup' ) {
19 return;
20 }
21
22 betterdocs()->assets->enqueue( 'betterdocs-quick-setup', 'admin/js/quick-setup.js' );
23 betterdocs()->assets->localize( 'betterdocs-quick-setup', 'betterdocsQuickSetup', GlobalFields::normalize( $this->quickbuilder_setup() ) );
24 betterdocs()->assets->enqueue( 'betterdocs-sweetalert', 'vendor/js/sweetalert.min.js', [] );
25 betterdocs()->assets->enqueue( 'betterdocs-icons', 'admin/btd-icon/style.css' );
26 betterdocs()->assets->enqueue( 'betterdocs-setup-wizard-qb-css', 'admin/css/quick-setup.css' );
27 betterdocs()->assets->enqueue( 'betterdocs-setup-wizard-new-css', 'admin/css/setup-wizard.css' );
28 betterdocs()->assets->enqueue( 'betterdocs-icons', 'admin//style.css' );
29 betterdocs()->assets->enqueue( 'betterdocs-setup-wizard-default-js', 'admin/js/setup-wizard.js', [ 'jquery', 'betterdocs-sweetalert' ] );
30
31 // Localize the script with new data
32 betterdocs()->assets->localize(
33 'betterdocs-setup-wizard',
34 'bdquicksetup',
35 [
36 'finish_txt' => __( 'Finish', 'betterdocs' ),
37 'next_txt' => __( 'Next', 'betterdocs' ),
38 'customizerurl' => $this->customizer_settings_url(),
39 'docspageurl' => $this->docs_page_url(),
40 'currentslug' => $this->settings->get( 'docs_slug' ),
41 'redirecturl' => admin_url( '/admin.php?page=betterdocs-settings' )
42 ]
43 );
44 }
45
46 public function normalize_options( $options ) {
47 return GlobalFields::normalize_fields( $options );
48 }
49
50 public function get_pages() {
51 $_pages = betterdocs()->query->get_posts(
52 [
53 'post_type' => 'page',
54 'numberposts' => -1,
55 'post_status' => 'publish',
56 'posts_per_page' => -1
57 ]
58 );
59
60 $__pages = [];
61
62 if ( ! empty( $_pages ) ) {
63 $__pages[0] = __( 'Select a Page', 'betterdocs' );
64 foreach ( $_pages->posts as $page ) {
65 $__pages[ $page->ID ] = esc_html( $page->post_title );
66 }
67 }
68
69 return $__pages;
70 }
71
72 public function quickbuilder_setup() {
73 $existing_plugins = betterdocs()->kbmigration->knowledge_base_plugins();
74 $quick_setup = [
75 'id' => 'betterdocs_quick_setup_metabox_wrapper',
76 'title' => __( 'Betterdocs Quick Setup', 'betterdocs' ),
77 'object_types' => [ 'betterdocs' ],
78 'context' => 'normal',
79 'priority' => 'high',
80 'show_header' => false,
81 'tab_number' => true,
82 'is_pro_active' => betterdocs()->is_pro_active(),
83 'logoURL' => betterdocs()->assets->icon( 'betterdocs-icon.svg', true ),
84 'layout' => 'vertical',
85 'values' => betterdocs()->is_pro_active() ? array_merge( betterdocs()->settings->get_all(), [ 'enable_credit' => true ] ) : array_merge( betterdocs()->settings->get_all(), [ 'enable_credit' => true ], $this->pro_settings_default_values() ),
86 'config' => [
87 'save_locally' => true,
88 'save' => true,
89 'active' => 'getting-started',
90 'sidebar' => false,
91 'title' => false,
92 'tab_number' => true,
93 'clickable' => false,
94 'completionTrack' => true,
95 'content_heading' => [],
96 'step' => [
97 'show' => true,
98 'buttons' => [
99 'skip' => __( 'Skip This Step', 'betterdocs' ),
100 'prev' => [
101 'name' => __( 'Previous', 'betterdocs' ),
102 'type' => 'customize',
103 'customName' => __( 'Previous', 'betterdocs' ),
104 'condition' => 'getting-started',
105 ],
106 'start' => [
107 'name' => 'Start',
108 'type' => 'customize',
109 'customName' => __( 'Proceed to Next Step', 'betterdocs' ),
110 'condition' => 'getting-started',
111 'ajax' => [
112 'on' => 'click',
113 'api' => '/betterdocs/v1/plugin_insights',
114 'data' => [
115 'product_list' => 'betterdocs'
116 ],
117 'hideSwal' => true
118 ]
119 ],
120 'next' => [
121 'name' => 'Next',
122 'type' => 'customize',
123 'customName' => __( 'Next', 'betterdocs' ),
124 'condition' => 'getting-started',
125 ],
126 'quick-builder-publish' => [
127 'name' => 'quick-builder-publish',
128 'type' => 'action',
129 'action' => 'btd_quick_build_launch'
130 ]
131 ],
132 'rules' => Rules::is( 'config.active', 'getting-started', true )
133 ]
134 ],
135 'submit' => [
136 'show' => false
137 ],
138 'tabs' => apply_filters(
139 'betterdocs_quick_setup_tabs',
140 [
141 'getting-started' => apply_filters(
142 'betterdocs_quick_setup_tab_getting_started',
143 [
144 'id' => 'getting-started',
145 'label' => __( 'Getting Started', 'betterdocs' ),
146 'classes' => 'getting-started',
147 'priority' => 10,
148 'fields' => [
149 'getting_started_header' => [
150 'name' => 'getting_started_header',
151 'type' => 'header',
152 'title' => __( 'Quick Launch', 'betterdocs' ),
153 'direction' => 'column',
154 'description' => __( 'Start your Knowledge Base configuration process with an easy-to-follow setup wizard.', 'betterdocs' ),
155 'icon' => '<img src="' . betterdocs()->assets->icon( 'icons/rocket.svg', true ) . '"/>',
156 'priority' => 1
157 ],
158 'betterdocs-quick-setup-start' => [
159 'name' => 'betterdocs-quick-setup-start',
160 'type' => 'section',
161 'priority' => 2,
162 'showSteps' => true,
163 'fields' => [
164 'betterdocs-quick-setup-start-collapse' => [
165 'name' => 'betterdocs-quick-setup-start-collapse',
166 'type' => 'collapse',
167 'priority' => 2,
168 'label' => __( 'By clicking this button, you are allowing this app to collect your information.', 'betterdocs' ),
169 'collapse_title' => __( 'What We Collect?', 'betterdocs' ),
170 'collapse_message' => __( 'We collect non-sensitive diagnostic data and plugin usage information. Your site URL, WordPress & PHP version, plugins & themes and email address to send you the discount coupon. This data lets us make sure this plugin always stays compatible with the most popular plugins and themes. No spam, we promise.', 'betterdocs' )
171 ]
172 ]
173 ]
174 ]
175 ]
176 ),
177
178 'setup-page' => apply_filters(
179 'betterdocs_quick_setup_tab_setup_page',
180 [
181 'id' => 'setup-page',
182 'label' => __( 'Setup Page', 'betterdocs' ),
183 'classes' => 'setup-page',
184 'priority' => 30,
185 'fields' => [
186 'setup_page_header' => [
187 'name' => 'setup_page_header',
188 'type' => 'header',
189 'title' => __( 'Page Setup Magic', 'betterdocs' ),
190 'direction' => 'row',
191 'description' => __( 'Configure the structure and layout of your documentation pages to match your preferences for an organized Knowledge Base.', 'betterdocs' ),
192 'icon' => '<img src="' . betterdocs()->assets->icon( 'icons/content-setting.svg', true ) . '"/>',
193 'priority' => 1
194 ],
195 'betterdocs-quick-setup-fields' => [
196 'name' => 'betterdocs-quick-setup-fields',
197 'type' => 'section',
198 'priority' => 2,
199 'fields' => [
200 'builtin_doc_page' => [
201 'name' => 'builtin_doc_page',
202 'type' => 'toggle',
203 'label' => __( 'Built-in Documentation Page', 'betterdocs' ),
204 'enable_disable_text_active' => true,
205 'default' => 1,
206 'priority' => 1,
207 'label_subtitle' => sprintf(
208 __( 'If you disable root slug for KB Archives, your individual knowledge base URL will be like this: %s', 'betterdocs' ),
209 'https://example.com/knowledgebase-1'
210 )
211 ],
212 'docs_page' => [
213 'name' => 'docs_page',
214 'label' => __( 'Docs Page', 'betterdocs' ),
215 'type' => 'select',
216 'default' => 0,
217 'priority' => 2,
218 'search' => true,
219 'options' => $this->normalize_options( $this->get_pages() ),
220 'label_subtitle' => __( 'You will need to insert BetterDocs Shortcode inside the page. This page will be used as docs permalink.', 'betterdocs' ),
221 'rules' => Rules::is( 'builtin_doc_page', false )
222 ],
223 'breadcrumb_doc_title' => [
224 'name' => 'breadcrumb_doc_title',
225 'type' => 'text',
226 'label' => __( 'Documentation Page Title', 'betterdocs' ),
227 'default' => __( 'Docs', 'betterdocs' ),
228 'priority' => 3,
229 'rules' => Rules::is( 'builtin_doc_page', true )
230 ],
231 'docs_slug' => [
232 'name' => 'docs_slug',
233 'type' => 'text',
234 'label' => __( 'BetterDocs Root Slug', 'betterdocs' ),
235 'default' => 'docs',
236 'priority' => 4,
237 'rules' => Rules::is( 'builtin_doc_page', true )
238 ],
239 'permalink_structure' => [
240 'name' => 'permalink_structure',
241 'type' => 'permalink_structure',
242 'label' => __( 'Single Docs Permalink', 'betterdocs' ),
243 'default' => PostType::permalink_structure(),
244 'priority' => 4,
245 'tags' => $this->normalize_options(
246 [
247 '%doc_category%' => '%doc_category%',
248 '%knowledge_base%' => '%knowledge_base%'
249 ]
250 ),
251 'label_subtitle' => __( 'Make sure to keep Docs Root Slug in the Single Docs Permalink. You are not able to keep it blank. You can use the available tags from below.', 'betterdocs' )
252 ],
253
254 'enable_glossaries' => [
255 'name' => 'enable_glossaries',
256 'type' => 'toggle',
257 'label' => __( 'Show Glossary', 'betterdocs' ),
258 'label_subtitle' => __( 'Enable the glossary feature to allow users to look up definitions for terms used within your encyclopedia or glossaries themselves.', 'betterdocs' ),
259 'enable_disable_text_active' => true,
260 'default' => false,
261 'priority' => 5,
262 'is_pro' => true
263 ],
264 'enable_encyclopedia' => [
265 'name' => 'enable_encyclopedia',
266 'type' => 'toggle',
267 'label' => __( 'Built-in Encyclopedia Page', 'betterdocs' ),
268 'enable_disable_text_active' => true,
269 'default' => false,
270 'priority' => 6,
271 'is_pro' => true
272 ],
273 'enable_credit' => [
274 'name' => 'enable_credit',
275 'type' => 'toggle',
276 'label' => __( 'Show Powered by BetterDocs', 'betterdocs' ),
277 'enable_disable_text_active' => true,
278 'default' => true,
279 'priority' => 7
280 ],
281 'enable_faq_schema' => [
282 'name' => 'enable_faq_schema',
283 'type' => 'toggle',
284 'label' => __( 'FAQ Schema', 'betterdocs' ),
285 'enable_disable_text_active' => true,
286 'default' => '',
287 'priority' => 8
288 ],
289 'advance_search' => apply_filters(
290 'betterdocs_advance_search_settings',
291 [
292 'name' => 'advance_search',
293 'type' => 'toggle',
294 'label' => __( 'Advanced Search', 'betterdocs' ),
295 'enable_disable_text_active' => true,
296 'default' => true,
297 'priority' => 9,
298 'is_pro' => true
299 ]
300 ),
301 'enable_disable' => apply_filters(
302 'betterdocs_setup_wizard_instant_answer',
303 [
304 'name' => 'enable_disable',
305 'type' => 'toggle',
306 'priority' => 10,
307 'label' => __( 'Instant Answer', 'betterdocs' ),
308 'enable_disable_text_active' => true,
309 'default' => false,
310 'is_pro' => true
311 ]
312 ),
313 ]
314 ]
315 ]
316 ]
317 ),
318 'create-content' => apply_filters(
319 'betterdocs_quick_setup_tab_create-content',
320 [
321 'id' => 'create-content',
322 'label' => __( 'Create Content', 'betterdocs' ),
323 'classes' => 'create-content',
324 'priority' => 40,
325 'fields' => [
326 'create_content_header' => [
327 'name' => 'create_content_header',
328 'type' => 'header',
329 'title' => __( 'Content Crafting', 'betterdocs' ),
330 'direction' => 'row',
331 'description' => __( 'Craft categories & articles for your Knowledge Base to efficiently organize and manage your repository with respective categories.', 'betterdocs' ),
332 'icon' => '<img src="' . betterdocs()->assets->icon( 'icons/create-content.svg', true ) . '"/>',
333 'priority' => 1
334 ],
335 'create_content_video' => [
336 'name' => 'create_content_video',
337 'type' => 'image',
338 'media' => [
339 'url' => betterdocs()->assets->icon( 'setup-wizard/DocCreate.gif', true )
340 ],
341 'priority' => 2
342 ]
343 ]
344 ]
345 ),
346 'customize' => apply_filters(
347 'betterdocs_quick_setup_tab_customize',
348 [
349 'id' => 'customize',
350 'label' => __( 'Customize', 'betterdocs' ),
351 'classes' => 'customize',
352 'priority' => 50,
353 'fields' => [
354 'customize_header' => [
355 'name' => 'customize_header',
356 'type' => 'header',
357 'title' => __( 'Style Your Documentation', 'betterdocs' ),
358 'direction' => 'row',
359 'description' => __( 'Personalize the appearance of your documentation page, articles, and archive pages using the power of this Customizer.', 'betterdocs' ),
360 'icon' => '<img src="' . betterdocs()->assets->icon( 'icons/customize.svg', true ) . '"/>',
361 'priority' => 1
362 ],
363 'customize_video' => [
364 'name' => 'customize_video',
365 'type' => 'image',
366 'media' => [
367 'url' => betterdocs()->assets->icon( 'setup-wizard/Customizer.gif', true )
368 ],
369 'priority' => 2
370 ]
371 ]
372 ]
373 ),
374 'finalize' => apply_filters(
375 'betterdocs_quick_setup_tab_finalize',
376 [
377 'id' => 'finalize',
378 'label' => __( 'Finalize', 'betterdocs' ),
379 'classes' => 'finalize',
380 'priority' => 60,
381 'fields' => [
382 'finalize_header' => [
383 'name' => 'finalize_header',
384 'type' => 'header',
385 'title' => __( 'Congratulations!', 'betterdocs' ),
386 'direction' => 'row',
387 'description' => __( 'Your documentation page is now ready for use. Enrich it with more articles to ensure proper categorization and valuable resources.', 'betterdocs' ),
388 'icon' => '<img src="' . betterdocs()->assets->icon( 'icons/thumbs-up.svg', true ) . '"/>',
389 'priority' => 1
390 ],
391 'finalize_video' => [
392 'name' => 'finalize_video',
393 'type' => 'image',
394 'media' => [
395 'url' => betterdocs()->assets->icon( 'setup-wizard/ThankYou.gif', true )
396 ],
397 'priority' => 2
398 ]
399 ]
400 ]
401 )
402 ]
403 )
404 ];
405
406 if ( $existing_plugins ) {
407 $quick_setup['tabs']['migration'] = apply_filters(
408 'betterdocs_quick_setup_tab_migration',
409 [
410 'id' => 'migration',
411 'label' => __( 'Migration', 'betterdocs' ),
412 'classes' => 'migration',
413 'priority' => 20,
414 'fields' => [
415 'migration_header' => [
416 'name' => 'migration_header',
417 'type' => 'header',
418 'title' => __( 'Migration', 'betterdocs' ),
419 'direction' => 'column',
420 'description' => __( 'We detected another Knoledge Base Plugin installed in this site. For BetterDocs to work efficiently, we will migrate the data from the plugin listed below, and deactivate the plugins, to avoid conflict.', 'betterdocs' ),
421 'icon' => '<img src="' . betterdocs()->assets->icon( 'icons/migration.svg', true ) . '"/>',
422 'priority' => 1,
423 ],
424 'betterdocs-quick-setup-migrate' => [
425 'name' => 'betterdocs-quick-setup-migrate',
426 'type' => 'section',
427 'priority' => 2,
428 'fields' => [
429 'migration_step' => [
430 'name' => 'migration_step',
431 'type' => 'migration',
432 'kb' => $existing_plugins[0][0],
433 'label' => sprintf(
434 /* translators: %s is the name of the plugin being migrated. */
435 __( 'Migrate %s', 'betterdocs' ),
436 $existing_plugins[0][1]
437 ),
438 'priority' => 10
439 ]
440 ]
441 ]
442 ]
443 ]
444 );
445 }
446
447 return $quick_setup;
448 }
449
450 public function views() {
451 betterdocs()->views->get( 'admin/setup-wizard' );
452 }
453
454 public function customizer_settings_url() {
455 $query = [
456 'autofocus[panel]' => 'betterdocs_customize_options',
457 'return' => admin_url( 'edit.php?post_type=docs' )
458 ];
459
460 $docs_slug = $this->settings->get( 'docs_slug', 'docs' );
461 if ( $docs_slug ) {
462 $query['url'] = site_url( '/' . $docs_slug );
463 }
464 $customizer_link = add_query_arg( $query, admin_url( 'customize.php' ) );
465
466 return esc_url( $customizer_link );
467 }
468
469 public function docs_page_url() {
470 return esc_url( site_url( '/' . $this->settings->get( 'docs_slug', 'docs' ) ) );
471 }
472
473 /**
474 * Call This Function As Helper, When Pro Is Deactivated, To Be Used As Settings Default Values, When Betterdocs Pro Is Deactivated
475 *
476 * @return array
477 */
478 public function pro_settings_default_values() {
479 return [
480 'multiple_kb' => false,
481 'enable_glossaries' => false,
482 'enable_encyclopedia' => false,
483 'analytics_from' => false,
484 'unique_visitor_count' => false,
485 'exclude_bot_analytics' => false,
486 'show_attachment' => false,
487 'show_related_docs' => false,
488 'advance_search' => false,
489 'child_category_exclude' => false,
490 'kb_based_search' => false,
491 'enable_disable' => false,
492 'enable_content_restriction' => false
493 ];
494 }
495 }
496