PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 4.4.1
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v4.4.1
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.4.1, at includes/Core/SetupWizard.php

493 lines 18.3 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' => __( 'If you disable root slug for KB Archives, your individual knowledge base URL will be like this: https://example.com/knowledgebase-1', 'betterdocs' )
208 ],
209 'docs_page' => [
210 'name' => 'docs_page',
211 'label' => __( 'Docs Page', 'betterdocs' ),
212 'type' => 'select',
213 'default' => 0,
214 'priority' => 2,
215 'search' => true,
216 'options' => $this->normalize_options( $this->get_pages() ),
217 'label_subtitle' => __( 'You will need to insert BetterDocs Shortcode inside the page. This page will be used as docs permalink.', 'betterdocs' ),
218 'rules' => Rules::is( 'builtin_doc_page', false )
219 ],
220 'breadcrumb_doc_title' => [
221 'name' => 'breadcrumb_doc_title',
222 'type' => 'text',
223 'label' => __( 'Documentation Page Title', 'betterdocs' ),
224 'default' => __( 'Docs', 'betterdocs' ),
225 'priority' => 3,
226 'rules' => Rules::is( 'builtin_doc_page', true )
227 ],
228 'docs_slug' => [
229 'name' => 'docs_slug',
230 'type' => 'text',
231 'label' => __( 'BetterDocs Root Slug', 'betterdocs' ),
232 'default' => 'docs',
233 'priority' => 4,
234 'rules' => Rules::is( 'builtin_doc_page', true )
235 ],
236 'permalink_structure' => [
237 'name' => 'permalink_structure',
238 'type' => 'permalink_structure',
239 'label' => __( 'Single Docs Permalink', 'betterdocs' ),
240 'default' => PostType::permalink_structure(),
241 'priority' => 4,
242 'tags' => $this->normalize_options(
243 [
244 '%doc_category%' => '%doc_category%',
245 '%knowledge_base%' => '%knowledge_base%'
246 ]
247 ),
248 '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' )
249 ],
250
251 'enable_glossaries' => [
252 'name' => 'enable_glossaries',
253 'type' => 'toggle',
254 'label' => __( 'Show Glossary', 'betterdocs' ),
255 'label_subtitle' => __( 'Enable the glossary feature to allow users to look up definitions for terms used within your encyclopedia or glossaries themselves.', 'betterdocs' ),
256 'enable_disable_text_active' => true,
257 'default' => false,
258 'priority' => 5,
259 'is_pro' => true
260 ],
261 'enable_encyclopedia' => [
262 'name' => 'enable_encyclopedia',
263 'type' => 'toggle',
264 'label' => __( 'Built-in Encyclopedia Page', 'betterdocs' ),
265 'enable_disable_text_active' => true,
266 'default' => false,
267 'priority' => 6,
268 'is_pro' => true
269 ],
270 'enable_credit' => [
271 'name' => 'enable_credit',
272 'type' => 'toggle',
273 'label' => __( 'Show Powered by BetterDocs', 'betterdocs' ),
274 'enable_disable_text_active' => true,
275 'default' => true,
276 'priority' => 7
277 ],
278 'enable_faq_schema' => [
279 'name' => 'enable_faq_schema',
280 'type' => 'toggle',
281 'label' => __( 'FAQ Schema', 'betterdocs' ),
282 'enable_disable_text_active' => true,
283 'default' => '',
284 'priority' => 8
285 ],
286 'advance_search' => apply_filters(
287 'betterdocs_advance_search_settings',
288 [
289 'name' => 'advance_search',
290 'type' => 'toggle',
291 'label' => __( 'Advanced Search', 'betterdocs' ),
292 'enable_disable_text_active' => true,
293 'default' => true,
294 'priority' => 9,
295 'is_pro' => true
296 ]
297 ),
298 'enable_disable' => apply_filters(
299 'betterdocs_setup_wizard_instant_answer',
300 [
301 'name' => 'enable_disable',
302 'type' => 'toggle',
303 'priority' => 10,
304 'label' => __( 'Instant Answer', 'betterdocs' ),
305 'enable_disable_text_active' => true,
306 'default' => false,
307 'is_pro' => true
308 ]
309 ),
310 ]
311 ]
312 ]
313 ]
314 ),
315 'create-content' => apply_filters(
316 'betterdocs_quick_setup_tab_create-content',
317 [
318 'id' => 'create-content',
319 'label' => __( 'Create Content', 'betterdocs' ),
320 'classes' => 'create-content',
321 'priority' => 40,
322 'fields' => [
323 'create_content_header' => [
324 'name' => 'create_content_header',
325 'type' => 'header',
326 'title' => __( 'Content Crafting', 'betterdocs' ),
327 'direction' => 'row',
328 'description' => __( 'Craft categories & articles for your Knowledge Base to efficiently organize and manage your repository with respective categories.', 'betterdocs' ),
329 'icon' => '<img src="' . betterdocs()->assets->icon( 'icons/create-content.svg', true ) . '"/>',
330 'priority' => 1
331 ],
332 'create_content_video' => [
333 'name' => 'create_content_video',
334 'type' => 'image',
335 'media' => [
336 'url' => betterdocs()->assets->icon( 'setup-wizard/DocCreate.gif', true )
337 ],
338 'priority' => 2
339 ]
340 ]
341 ]
342 ),
343 'customize' => apply_filters(
344 'betterdocs_quick_setup_tab_customize',
345 [
346 'id' => 'customize',
347 'label' => __( 'Customize', 'betterdocs' ),
348 'classes' => 'customize',
349 'priority' => 50,
350 'fields' => [
351 'customize_header' => [
352 'name' => 'customize_header',
353 'type' => 'header',
354 'title' => __( 'Style Your Documentation', 'betterdocs' ),
355 'direction' => 'row',
356 'description' => __( 'Personalize the appearance of your documentation page, articles, and archive pages using the power of this Customizer.', 'betterdocs' ),
357 'icon' => '<img src="' . betterdocs()->assets->icon( 'icons/customize.svg', true ) . '"/>',
358 'priority' => 1
359 ],
360 'customize_video' => [
361 'name' => 'customize_video',
362 'type' => 'image',
363 'media' => [
364 'url' => betterdocs()->assets->icon( 'setup-wizard/Customizer.gif', true )
365 ],
366 'priority' => 2
367 ]
368 ]
369 ]
370 ),
371 'finalize' => apply_filters(
372 'betterdocs_quick_setup_tab_finalize',
373 [
374 'id' => 'finalize',
375 'label' => __( 'Finalize', 'betterdocs' ),
376 'classes' => 'finalize',
377 'priority' => 60,
378 'fields' => [
379 'finalize_header' => [
380 'name' => 'finalize_header',
381 'type' => 'header',
382 'title' => __( 'Congratulations!', 'betterdocs' ),
383 'direction' => 'row',
384 'description' => __( 'Your documentation page is now ready for use. Enrich it with more articles to ensure proper categorization and valuable resources.', 'betterdocs' ),
385 'icon' => '<img src="' . betterdocs()->assets->icon( 'icons/thumbs-up.svg', true ) . '"/>',
386 'priority' => 1
387 ],
388 'finalize_video' => [
389 'name' => 'finalize_video',
390 'type' => 'image',
391 'media' => [
392 'url' => betterdocs()->assets->icon( 'setup-wizard/ThankYou.gif', true )
393 ],
394 'priority' => 2
395 ]
396 ]
397 ]
398 )
399 ]
400 )
401 ];
402
403 if ( $existing_plugins ) {
404 $quick_setup['tabs']['migration'] = apply_filters(
405 'betterdocs_quick_setup_tab_migration',
406 [
407 'id' => 'migration',
408 'label' => __( 'Migration', 'betterdocs' ),
409 'classes' => 'migration',
410 'priority' => 20,
411 'fields' => [
412 'migration_header' => [
413 'name' => 'migration_header',
414 'type' => 'header',
415 'title' => __( 'Migration', 'betterdocs' ),
416 'direction' => 'column',
417 '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' ),
418 'icon' => '<img src="' . betterdocs()->assets->icon( 'icons/migration.svg', true ) . '"/>',
419 'priority' => 1,
420 ],
421 'betterdocs-quick-setup-migrate' => [
422 'name' => 'betterdocs-quick-setup-migrate',
423 'type' => 'section',
424 'priority' => 2,
425 'fields' => [
426 'migration_step' => [
427 'name' => 'migration_step',
428 'type' => 'migration',
429 'kb' => $existing_plugins[0][0],
430 'label' => sprintf(
431 /* translators: %s is the name of the plugin being migrated. */
432 __( 'Migrate %s', 'betterdocs' ),
433 $existing_plugins[0][1]
434 ),
435 'priority' => 10
436 ]
437 ]
438 ]
439 ]
440 ]
441 );
442 }
443
444 return $quick_setup;
445 }
446
447 public function views() {
448 betterdocs()->views->get( 'admin/setup-wizard' );
449 }
450
451 public function customizer_settings_url() {
452 $query = [
453 'autofocus[panel]' => 'betterdocs_customize_options',
454 'return' => admin_url( 'edit.php?post_type=docs' )
455 ];
456
457 $docs_slug = $this->settings->get( 'docs_slug', 'docs' );
458 if ( $docs_slug ) {
459 $query['url'] = site_url( '/' . $docs_slug );
460 }
461 $customizer_link = add_query_arg( $query, admin_url( 'customize.php' ) );
462
463 return esc_url( $customizer_link );
464 }
465
466 public function docs_page_url() {
467 return esc_url( site_url( '/' . $this->settings->get( 'docs_slug', 'docs' ) ) );
468 }
469
470 /**
471 * Call This Function As Helper, When Pro Is Deactivated, To Be Used As Settings Default Values, When Betterdocs Pro Is Deactivated
472 *
473 * @return array
474 */
475 public function pro_settings_default_values() {
476 return [
477 'multiple_kb' => false,
478 'enable_glossaries' => false,
479 'enable_encyclopedia' => false,
480 'analytics_from' => false,
481 'unique_visitor_count' => false,
482 'exclude_bot_analytics' => false,
483 'show_attachment' => false,
484 'show_related_docs' => false,
485 'advance_search' => false,
486 'child_category_exclude' => false,
487 'kb_based_search' => false,
488 'enable_disable' => false,
489 'enable_content_restriction' => false
490 ];
491 }
492 }
493