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

422 lines 24.0 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( 'betterdocs-setup-wizard', 'bdquicksetup', [
33 'finish_txt' => __( 'Finish', 'betterdocs' ),
34 'next_txt' => __( 'Next', 'betterdocs' ),
35 'customizerurl' => $this->customizer_settings_url(),
36 'docspageurl' => $this->docs_page_url(),
37 'currentslug' => $this->settings->get( 'docs_slug' ),
38 'redirecturl' => admin_url( '/admin.php?page=betterdocs-settings' )
39 ] );
40 }
41
42 public function normalize_options( $options ) {
43 return GlobalFields::normalize_fields( $options );
44 }
45
46 public function get_pages() {
47 $_pages = betterdocs()->query->get_posts( [
48 'post_type' => 'page',
49 'numberposts' => -1,
50 'post_status' => 'publish',
51 'posts_per_page' => -1
52 ] );
53
54 $__pages = [];
55
56 if ( ! empty( $_pages ) ) {
57 $__pages[0] = __( 'Select a Page', 'betterdocs' );
58 foreach ( $_pages->posts as $page ) {
59 $__pages[$page->ID] = esc_html( $page->post_title );
60 }
61 }
62
63 return $__pages;
64 }
65
66 public function quickbuilder_setup() {
67 $existing_plugins = betterdocs()->kbmigration->knowledge_base_plugins();
68 $quick_setup = [
69 'id' => 'betterdocs_quick_setup_metabox_wrapper',
70 'title' => __( 'Betterdocs Quick Setup', 'betterdocs' ),
71 'object_types' => ['betterdocs'],
72 'context' => 'normal',
73 'priority' => 'high',
74 'show_header' => false,
75 'tab_number' => true,
76 'is_pro_active' => betterdocs()->is_pro_active(),
77 'logoURL' => betterdocs()->assets->icon( 'betterdocs-icon.svg', true ),
78 'layout' => 'vertical',
79 'values' => array_merge(betterdocs()->settings->get_all(), ['enable_credit' => true]),
80 'config' => [
81 'save_locally' => true,
82 'save' => true,
83 'active' => 'getting-started',
84 'sidebar' => false,
85 'title' => false,
86 'tab_number' => true,
87 'clickable' => false,
88 'completionTrack' => true,
89 'content_heading' => [],
90 'step' => [
91 'show' => true,
92 'buttons' => [
93 'skip' => __( 'Skip This Step', 'betterdocs' ),
94 'prev' => __( 'Previous', 'betterdocs' ),
95 'next' => [
96 'name' => 'Next',
97 'type' => 'customize',
98 'customName' => 'Proceed to Next Step',
99 'condition' => 'getting-started',
100 // 'ajax' => [
101 // 'api' => "/betterdocs/v1/plugin_insights",
102 // 'data' => [
103 // 'type' => "@type",
104 // 'source' => "@source",
105 // 'field' => "product_list"
106 // ],
107 // 'rules' => Rules::is( 'config.active', 'getting-started', false ),
108 // 'hideSwal' => true
109 // ]
110 ],
111 'quick-builder-publish' => [
112 'name' => 'quick-builder-publish',
113 'type' => 'action',
114 'action' => 'btd_quick_build_launch'
115 ]
116 ],
117 'rules' => Rules::is( 'config.active', 'getting-started', true )
118 ]
119 ],
120 'submit' => [
121 'show' => false
122 ],
123 'tabs' => apply_filters( 'betterdocs_quick_setup_tabs', [
124 'getting-started' => apply_filters( 'betterdocs_quick_setup_tab_getting_started', [
125 'id' => 'getting-started',
126 'label' => __( 'Getting Started', 'betterdocs' ),
127 'classes' => 'getting-started',
128 'priority' => 10,
129 'fields' => [
130 'getting_started_header' => [
131 'name' => 'getting_started_header',
132 'type' => 'header',
133 'title' => __( 'Quick Launch', 'betterdocs' ),
134 'direction' => 'column',
135 'description' => __( 'Start your Knowledge Base configuration process with an easy-to-follow setup wizard.', 'betterdocs' ),
136 'icon' => '<img src="' . betterdocs()->assets->icon( 'icons/rocket.svg', true ) . '"/>',
137 'priority' => 1
138 ],
139 'betterdocs-quick-setup-start' => [
140 'name' => 'betterdocs-quick-setup-start',
141 'type' => 'section',
142 'priority' => 2,
143 'showSteps' => true,
144 'fields' => [
145 'betterdocs-quick-setup-start-collapse' => [
146 'name' => 'betterdocs-quick-setup-start-collapse',
147 'type' => 'collapse',
148 'priority' => 2,
149 'label' => __( 'By clicking this button, you are allowing this app to collect your information.', 'betterdocs' ),
150 'collapse_title' => __( 'What We Collect?', 'betterdocs' ),
151 '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' )
152 ]
153 ]
154 ]
155 ]
156 ] ),
157
158 'setup-page' => apply_filters( 'betterdocs_quick_setup_tab_setup_page', [
159 'id' => 'setup-page',
160 'label' => __( 'Setup Page', 'betterdocs' ),
161 'classes' => 'setup-page',
162 'priority' => 30,
163 'fields' => [
164 'setup_page_header' => [
165 'name' => 'setup_page_header',
166 'type' => 'header',
167 'title' => __( 'Page Setup Magic', 'betterdocs' ),
168 'direction' => 'row',
169 'description' => __( 'Configure the structure and layout of your documentation pages to match your preferences for an organized Knowledge Base.', 'betterdocs' ),
170 'icon' => '<img src="' . betterdocs()->assets->icon( 'icons/content-setting.svg', true ) . '"/>',
171 'priority' => 1
172 ],
173 'betterdocs-quick-setup-fields' => [
174 'name' => 'betterdocs-quick-setup-fields',
175 'type' => 'section',
176 'priority' => 2,
177 'fields' => [
178 'builtin_doc_page' => [
179 'name' => 'builtin_doc_page',
180 'type' => 'toggle',
181 'label' => __( 'Built-in Documentation Page', 'betterdocs' ),
182 'enable_disable_text_active' => true,
183 'default' => 1,
184 'priority' => 1,
185 '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' )
186 ],
187 'docs_page' => [
188 'name' => 'docs_page',
189 'label' => __( 'Docs Page', 'betterdocs' ),
190 'type' => 'select',
191 'default' => 0,
192 'priority' => 2,
193 'search' => true,
194 'options' => $this->normalize_options( $this->get_pages() ),
195 'label_subtitle' => __( 'You will need to insert BetterDocs Shortcode inside the page. This page will be used as docs permalink.', 'betterdocs' ),
196 'rules' => Rules::is( 'builtin_doc_page', false )
197 ],
198 'breadcrumb_doc_title' => [
199 'name' => 'breadcrumb_doc_title',
200 'type' => 'text',
201 'label' => __( 'Documentation Page Title', 'betterdocs' ),
202 'default' => __( 'Docs', 'betterdocs' ),
203 'priority' => 3,
204 'rules' => Rules::is( 'builtin_doc_page', true )
205 ],
206 'docs_slug' => [
207 'name' => 'docs_slug',
208 'type' => 'text',
209 'label' => __( 'BetterDocs Root Slug', 'betterdocs' ),
210 'default' => 'docs',
211 'priority' => 4,
212 'rules' => Rules::is( 'builtin_doc_page', true )
213 ],
214 'permalink_structure' => [
215 'name' => 'permalink_structure',
216 'type' => 'permalink_structure',
217 'label' => __( 'Single Docs Permalink', 'betterdocs' ),
218 'default' => PostType::permalink_structure(),
219 'priority' => 4,
220 'tags' => $this->normalize_options( [
221 '%doc_category%' => '%doc_category%',
222 '%knowledge_base%' => '%knowledge_base%'
223 ] ),
224 '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' )
225 ],
226
227 'enable_glossaries' => [
228 'name' => 'enable_glossaries',
229 'type' => 'toggle',
230 'label' => __( 'Show Glossary', 'betterdocs' ),
231 'label_subtitle' => __( 'Enable the glossary feature to allow users to look up definitions for terms used within your encyclopedia or glossaries themselves.', 'betterdocs' ),
232 'enable_disable_text_active' => true,
233 'default' => false,
234 'priority' => 5,
235 'is_pro' => true
236 ],
237 'enable_encyclopedia' => [
238 'name' => 'enable_encyclopedia',
239 'type' => 'toggle',
240 'label' => __( 'Built-in Encyclopedia Page', 'betterdocs' ),
241 'enable_disable_text_active' => true,
242 'default' => false,
243 'priority' => 6,
244 'is_pro' => true
245 ],
246 'enable_credit' => [
247 'name' => 'enable_credit',
248 'type' => 'toggle',
249 'label' => __( 'Show Powered by BetterDocs', 'betterdocs' ),
250 'enable_disable_text_active' => true,
251 'default' => true,
252 'priority' => 7
253 ],
254 'enable_faq_schema' => [
255 'name' => 'enable_faq_schema',
256 'type' => 'toggle',
257 'label' => __( 'FAQ Schema', 'betterdocs' ),
258 'enable_disable_text_active' => true,
259 'default' => '',
260 'priority' => 8
261 ],
262 'advance_search' => apply_filters( 'betterdocs_advance_search_settings', [
263 'name' => 'advance_search',
264 'type' => 'toggle',
265 'label' => __( 'Advanced Search', 'betterdocs' ),
266 'enable_disable_text_active' => true,
267 'default' => true,
268 'priority' => 9,
269 'is_pro' => true
270 ] ),
271 'enable_disable' => [
272 'name' => 'enable_disable',
273 'type' => 'toggle',
274 'priority' => 10,
275 'label' => __( 'Instant Answer', 'betterdocs' ),
276 'enable_disable_text_active' => true,
277 'default' => true,
278 'is_pro' => true
279 ]
280 ]
281 ]
282 ]
283 ] ),
284 'create-content' => apply_filters( 'betterdocs_quick_setup_tab_create-content', [
285 'id' => 'create-content',
286 'label' => __( 'Create Content', 'betterdocs' ),
287 'classes' => 'create-content',
288 'priority' => 40,
289 'fields' => [
290 'create_content_header' => [
291 'name' => 'create_content_header',
292 'type' => 'header',
293 'title' => __( 'Content Crafting', 'betterdocs' ),
294 'direction' => 'row',
295 'description' => __( 'Craft categories & articles for your Knowledge Base to efficiently organize and manage your repository with respective categories.', 'betterdocs' ),
296 'icon' => '<img src="' . betterdocs()->assets->icon( 'icons/create-content.svg', true ) . '"/>',
297 'priority' => 1
298 ],
299 'create_content_video' => [
300 'name' => 'create_content_video',
301 'type' => 'image',
302 'media' => [
303 'url' => betterdocs()->assets->icon( 'setup-wizard/DocCreate.gif', true )
304 ],
305 'priority' => 2
306 ]
307 ]
308 ] ),
309 'customize' => apply_filters( 'betterdocs_quick_setup_tab_customize', [
310 'id' => 'customize',
311 'label' => __( 'Customize', 'betterdocs' ),
312 'classes' => 'customize',
313 'priority' => 50,
314 'fields' => [
315 'customize_header' => [
316 'name' => 'customize_header',
317 'type' => 'header',
318 'title' => __( 'Style Your Documentation', 'betterdocs' ),
319 'direction' => 'row',
320 'description' => __( 'Personalize the appearance of your documentation page, articles, and archive pages using the power of this Customizer.', 'betterdocs' ),
321 'icon' => '<img src="' . betterdocs()->assets->icon( 'icons/customize.svg', true ) . '"/>',
322 'priority' => 1
323 ],
324 'customize_video' => [
325 'name' => 'customize_video',
326 'type' => 'image',
327 'media' => [
328 'url' => betterdocs()->assets->icon( 'setup-wizard/Customizer.gif', true )
329 ],
330 'priority' => 2
331 ]
332 ]
333 ] ),
334 'finalize' => apply_filters( 'betterdocs_quick_setup_tab_finalize', [
335 'id' => 'finalize',
336 'label' => __( 'Finalize', 'betterdocs' ),
337 'classes' => 'finalize',
338 'priority' => 60,
339 'fields' => [
340 'finalize_header' => [
341 'name' => 'finalize_header',
342 'type' => 'header',
343 'title' => __( 'Congratulations!', 'betterdocs' ),
344 'direction' => 'row',
345 'description' => __( 'Your documentation page is now ready for use. Enrich it with more articles to ensure proper categorization and valuable resources.', 'betterdocs' ),
346 'icon' => '<img src="' . betterdocs()->assets->icon( 'icons/thumbs-up.svg', true ) . '"/>',
347 'priority' => 1
348 ],
349 'finalize_video' => [
350 'name' => 'finalize_video',
351 'type' => 'image',
352 'media' => [
353 'url' => betterdocs()->assets->icon( 'setup-wizard/ThankYou.gif', true )
354 ],
355 'priority' => 2
356 ]
357 ]
358 ] )
359 ] )
360 ];
361
362 if ( $existing_plugins ) {
363 $quick_setup['tabs']['migration'] = apply_filters( 'betterdocs_quick_setup_tab_migration', [
364 'id' => 'migration',
365 'label' => __( 'Migration', 'betterdocs' ),
366 'classes' => 'migration',
367 'priority' => 20,
368 'fields' => [
369 'migration_header' => [
370 'name' => 'migration_header',
371 'type' => 'header',
372 'title' => __( 'Migration', 'betterdocs' ),
373 'direction' => 'column',
374 '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' ),
375 'icon' => '<img src="' . betterdocs()->assets->icon( 'icons/migration.svg', true ) . '"/>',
376 'priority' => 1,
377 ],
378 'betterdocs-quick-setup-migrate' => [
379 'name' => 'betterdocs-quick-setup-migrate',
380 'type' => 'section',
381 'priority' => 2,
382 'fields' => [
383 'migration_step' => [
384 'name' => "migration_step",
385 'type' => 'migration',
386 'kb' => $existing_plugins[0][0],
387 'label' => __( 'Migrate ' . $existing_plugins[0][1], 'betterdocs' ),
388 'priority' => 10
389 ]
390 ]
391 ]
392 ]
393 ] );
394 }
395
396 return $quick_setup;
397 }
398
399 public function views() {
400 betterdocs()->views->get( 'admin/setup-wizard' );
401 }
402
403 public function customizer_settings_url() {
404 $query = [
405 'autofocus[panel]' => 'betterdocs_customize_options',
406 'return' => admin_url( 'edit.php?post_type=docs' )
407 ];
408
409 $docs_slug = $this->settings->get( 'docs_slug', 'docs' );
410 if ( $docs_slug ) {
411 $query['url'] = site_url( '/' . $docs_slug );
412 }
413 $customizer_link = add_query_arg( $query, admin_url( 'customize.php' ) );
414
415 return esc_url( $customizer_link );
416 }
417
418 public function docs_page_url() {
419 return esc_url( site_url( '/' . $this->settings->get( 'docs_slug', 'docs' ) ) );
420 }
421 }
422