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

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