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

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