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 / Settings.php

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

2,920 lines 121.8 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 WP_User;
7 use WPDeveloper\BetterDocs\Admin\Builder\GlobalFields;
8 use WPDeveloper\BetterDocs\Admin\Builder\Rules;
9 use WPDeveloper\BetterDocs\Utils\Base;
10 use WPDeveloper\BetterDocs\Utils\Database;
11 use WPDeveloper\BetterDocs\Utils\Helper;
12
13
14 class Settings extends Base {
15 public $base_key = 'betterdocs_settings';
16
17 /**
18 * Database class
19 * @var Database
20 */
21 protected $database;
22
23 private $deprecated = [];
24
25 private $cannot_be_empty = [
26 'breadcrumb_doc_title',
27 'docs_slug',
28 'category_slug',
29 'tag_slug',
30 'permalink_structure',
31 'docs_page'
32 ];
33
34 public function __construct( Database $database ) {
35 $this->database = $database;
36 $this->deprecated = $this->deprecated_settings();
37
38 add_filter( 'betterdocs_settings_tabs', [ $this, 'import_export_settings' ] );
39 add_filter( 'betterdocs_settings_tabs', [ $this, 'maybe_remove_git_tab' ], 20 );
40
41 add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_old' ], 99 );
42 add_action( 'admin_enqueue_scripts', [ $this, 'enqueue' ], 99 );
43
44 // if ( isset( $_GET['page'] ) && $_GET['page'] === 'betterdocs-settings' && ! has_action( 'betterdocs_settings_header' ) ) {
45 // add_action( 'betterdocs_settings_header', [ $this, 'header' ] );
46 // }
47
48 add_action( 'wp_ajax_betterdocs_dark_mode', [ $this, 'dark_mode' ] );
49 add_filter( 'betterdocs_settings_tab_advance', [ $this, 'hide_roles_management' ], 11, 1 );
50 add_action( 'betterdocs::settings::saved', [ $this, 'fallback_slugs' ], 99, 3 );
51 }
52
53 public function fallback_slugs( $_saved, $_settings, $_old_settings = [] ) {
54 $_default = $this->get_default();
55 foreach ( $this->cannot_be_empty as $key ) {
56 if ( $key === 'docs_page' && ! $_settings['builtin_doc_page'] && empty( $_settings[ $key ] ) ) {
57 $this->save( 'builtin_doc_page', true );
58 continue;
59 }
60
61 if ( empty( $_settings[ $key ] ) ) {
62 $this->save( $key, $_default[ $key ] );
63 }
64 }
65 }
66
67 /**
68 * Get the settings URL for admin
69 * @return string
70 */
71 public function url() {
72 return esc_url( admin_url( 'admin.php?page=betterdocs-settings' ) );
73 }
74
75 /**
76 * This method is responsible for enqueueing scripts in settings panel
77 *
78 * @param string $hook
79 *
80 * @return void
81 * @since 2.5.0
82 */
83 public function enqueue( $hook ) {
84 if ( ! betterdocs()->is_betterdocs_screen( $hook ) ) {
85 return;
86 }
87
88 wp_enqueue_media();
89 wp_enqueue_script( 'betterdocs-admin' );
90
91 $settings = GlobalFields::normalize( $this->settings_args() );
92
93 // Mask sensitive API keys before they reach the browser. Non-admins still get them stripped entirely below.
94 $sensitive_api_keys = [ 'ai_autowrite_api_key', 'ai_chatbot_api_key' ];
95 foreach ( $sensitive_api_keys as $api_key_field ) {
96 if ( ! empty( $settings['values'][ $api_key_field ] ) ) {
97 $settings['values'][ $api_key_field ] = Helper::mask_api_key( $settings['values'][ $api_key_field ] );
98 }
99 }
100
101 if ( ! current_user_can( 'edit_docs_settings' ) ) {
102 foreach ( $sensitive_api_keys as $api_key_field ) {
103 if ( isset( $settings['values'][ $api_key_field ] ) ) {
104 unset( $settings['values'][ $api_key_field ] );
105 }
106 }
107 }
108
109 // Inject raw git settings to bypass get() fallback (e.g., '' -> 'docs')
110 if ( isset( $settings['values'] ) ) {
111 $settings['values']['git_provider'] = $this->get_raw_field( 'git_provider', 'github' );
112 $settings['values']['git_repository_url'] = $this->get_raw_field( 'git_repository_url', '' );
113 $settings['values']['git_branch'] = $this->get_raw_field( 'git_branch', '' );
114 $settings['values']['git_docs_directory'] = $this->get_raw_field( 'git_docs_directory', '' );
115 }
116
117 betterdocs()->assets->localize( 'betterdocs-admin', 'betterdocsAdminSettings', $settings );
118 betterdocs()->assets->enqueue( 'betterdocs-icons', 'admin/btd-icon/style.css' );
119 }
120
121 public function enqueue_old( $hook ) {
122 // FREE & Pro Version Compatibility Check
123 if ( ! betterdocs()->is_betterdocs_screen( $hook ) ) {
124 return;
125 }
126
127 $this->enqueue( 'betterdocs_page_betterdocs-settings' );
128 }
129
130 /**
131 * This method is responsible for printing header in dashboard settings page.
132 *
133 * @param string $hook
134 *
135 * @return void
136 * @since 2.5.0
137 */
138 public function header( $hook ) {
139 if ( $hook !== 'settings' ) {
140 return;
141 }
142
143 betterdocs()->views->get( 'admin/template-parts/settings-header' );
144 betterdocs()->views->get( 'admin/template-parts/settings-header-2' );
145 }
146
147 /**
148 * A list of deprecated settings keys.
149 *
150 * @return array
151 * @since 2.5.0
152 */
153 public function deprecated_settings() {
154 return [];
155 }
156
157 /**
158 * Dynamic migration caller.
159 *
160 * @return void
161 * @since 2.5.0
162 */
163 public function migration( $version ) {
164 if ( $version > 250 ) {
165 for ( $v = 250; $v <= $version; $v ++ ) {
166 $_func = "v{$v}";
167 if ( method_exists( $this, $_func ) ) {
168 call_user_func( [ $this, $_func ] );
169 }
170 }
171 }
172 }
173
174 /**
175 * Migration for version 2.5.0
176 *
177 * @return void
178 * @since 2.5.0
179 */
180 public function v250() {
181 if ( $this->get( 'alphabetically_order_term', false ) ) {
182 $this->save( 'terms_orderby', 'name' );
183 }
184
185 if ( $orderby = $this->get( 'alphabetically_order_post', false ) ) {
186 if ( $orderby === '1' ) {
187 $this->save( 'alphabetically_order_post', 'title' );
188 }
189 }
190 }
191
192 /**
193 * A list of default settings data.
194 *
195 * @return array
196 * @since 1.0.0
197 *
198 */
199 public function get_default() {
200 $_default = [
201 'multiple_kb' => '',
202 'enable_export_faq' => true,
203 'builtin_doc_page' => true,
204 'breadcrumb_doc_title' => __( 'Docs', 'betterdocs' ),
205 'enable_category_hierarchy_slugs' => false,
206 'docs_slug' => 'docs',
207 'docs_page' => 0,
208 'category_slug' => 'docs-category',
209 'tag_slug' => 'docs-tag',
210 'permalink_structure' => 'docs/',
211 'enable_faq_schema' => false,
212 'live_search' => true,
213 'advance_search' => false,
214 'popular_keyword_limit' => 5,
215 'search_letter_limit' => 3,
216 'search_placeholder' => __( 'Search...', 'betterdocs' ),
217 'search_not_found_text' => __( 'Sorry, no docs were found.', 'betterdocs' ),
218 'search_result_image' => true,
219 'search_modal_search_type' => 'all',
220 'masonry_layout' => true,
221 'docs_list_icon' => [],
222 'category_title_link' => false,
223 'terms_orderby' => 'betterdocs_order',
224 'alphabetically_order_term' => false,
225 'terms_order' => 'ASC',
226 'alphabetically_order_post' => 'betterdocs_order',
227 'docs_order' => 'ASC',
228 'nested_subcategory' => false,
229 'column_number' => 3,
230 'posts_number' => 10,
231 'post_count' => true,
232 'count_text' => __( 'Docs', 'betterdocs' ),
233 'count_text_singular' => __( 'Doc', 'betterdocs' ),
234 'exploremore_btn' => true,
235 'exploremore_btn_txt' => __( 'Explore More', 'betterdocs' ),
236 'doc_single' => 1,
237 'enable_toc' => true,
238 'toc_title' => __( 'Table of Contents', 'betterdocs' ),
239 'toc_hierarchy' => true,
240 'toc_list_number' => false,
241 'toc_dynamic_title' => false,
242 'enable_sticky_toc' => true,
243 'sticky_toc_offset' => 100,
244 'collapsible_toc_mobile' => false,
245 'supported_heading_tag' => [ '1', '2', '3', '4', '5', '6' ],
246 'enable_post_title' => true,
247 'title_link_ctc' => true,
248 'enable_breadcrumb' => true,
249 'breadcrumb_home_text' => __( 'Home', 'betterdocs' ),
250 'enable_breadcrumb_home_text' => true,
251 'breadcrumb_home_url' => get_home_url(),
252 'enable_breadcrumb_category' => true,
253 'enable_breadcrumb_title' => true,
254 'enable_sidebar_cat_list' => true,
255 'enable_print_icon' => true,
256 'enable_tags' => true,
257 'email_feedback' => true,
258 'feedback_link_text' => __( 'Still stuck? How can we help?', 'betterdocs' ),
259 'reaction_feedback_text' => __( 'Thanks for your feedback', 'betterdocs' ),
260 'feedback_url' => '',
261 'feedback_form_title' => __( 'How can we help?', 'betterdocs' ),
262 'email_address' => get_option( 'admin_email' ),
263 'show_last_update_time' => true,
264 'enable_navigation' => true,
265 'enable_comment' => true,
266 'enable_credit' => false,
267 'enable_archive_sidebar' => true,
268 'archive_nested_subcategory' => true,
269 'archive_enable_pagination' => false,
270 'enable_content_restriction' => false,
271 'enable_reporting' => false,
272 'enable_sample_data' => false,
273 'reporting_day' => 'monday',
274 'reporting_email' => get_option( 'admin_email' ),
275 'enable_write_with_ai' => true,
276 'enable_faq_write_with_ai' => true,
277 'write_with_ai_model' => 'gpt-4o-mini',
278 'ai_autowrite_api_key' => '',
279 'ai_autowrite_max_token' => 1500,
280 'enable_article_summary' => false,
281 'article_summary_model' => 'gpt-4o-mini',
282 'article_summary_max_token' => 1500,
283 'enable_estimated_reading_time' => true,
284 'enable_encyclopedia' => false,
285 'enable_glossaries' => false,
286 'show_glossary_suggestions' => true,
287 'enable_ai_chatbot' => false,
288 'estimated_reading_time_title' => '',
289 'estimated_reading_time_text' => __( 'min read', 'betterdocs' ),
290 'singular_estimated_reading_time_text' => __( 'min read', 'betterdocs' ),
291 'betterdocs_access_control_repeater' => [],
292 'internal_knowledge_base_type' => 'basic',
293 'betterdocs_access_control_repeater_kb' => [],
294 'enable_git_integration' => false,
295 ];
296
297 $_default = apply_filters( 'betterdocs_default_settings', $_default );
298 // $_default = apply_filters_deprecated(
299 // 'betterdocs_option_default_settings', [$_default], '2.5.0',
300 // 'betterdocs_default_settings', 'betterdocs_option_default_settings will be removed from v3.5.0.'
301 // );
302
303 return $_default;
304 }
305
306 /**
307 * A list of default settings for pro plugins.
308 *
309 * @return array
310 * @since 2.5.0
311 */
312 public function get_pro_defaults() {
313 return [];
314 }
315
316 public function is_elementor_pro() {
317 return is_plugin_active( 'elementor-pro/elementor-pro.php' );
318 }
319
320 /**
321 * Get full site editor links for docs page.
322 *
323 * @return string
324 * @since 3.5.8
325 */
326 public function gutenberg_link() {
327 if ( betterdocs()->helper->current_theme_is_fse_theme() ) {
328 return admin_url( 'site-editor.php?postType=wp_template&postId=betterdocs/betterdocs//archive-docs' );
329 } else {
330 return 'https://betterdocs.co/docs/betterdocs-provides-full-site-editor-support/';
331 }
332 }
333
334 /**
335 * Get elementor theme builder link for docs page.
336 *
337 * @return string
338 * @since 3.5.8
339 */
340 public function elementor_link() {
341 if ( $this->is_elementor_pro() ) {
342 return admin_url( 'admin.php?page=elementor-app#/site-editor/templates/doc-archive' );
343 } else {
344 return 'https://betterdocs.co/docs/docs-page-with-elementor/';
345 }
346 }
347
348 public function customizer_link() {
349 $query['autofocus[panel]'] = 'betterdocs_customize_options';
350 $query['return'] = admin_url( 'edit.php?post_type=docs' );
351 $builtin_doc_page = betterdocs()->settings->get( 'builtin_doc_page' );
352 $docs_slug = betterdocs()->settings->get( 'docs_slug' );
353 $docs_page = betterdocs()->settings->get( 'builtin_doc_page' );
354
355 if ( $builtin_doc_page == 1 && $docs_slug ) {
356 $query['url'] = site_url( '/' . $docs_slug );
357 } elseif ( $builtin_doc_page != 1 && $docs_page ) {
358 $post_info = get_post( $docs_page );
359 $query['url'] = site_url( '/' . $post_info->post_name );
360 }
361
362 return add_query_arg( $query, admin_url( 'customize.php' ) );
363 }
364
365 public function design_tab() {
366 $settings = [];
367
368 $settings['gutenberg_link'] = [
369 'name' => 'gutenberg_link',
370 'type' => 'action',
371 'action' => 'betterdocs_settings_gutenberg_link',
372 'button' => betterdocs()->helper->current_theme_is_fse_theme() ? __( 'Design with Gutenberg', 'betterdocs' ) : __( 'Learn More', 'betterdocs' ),
373 'url' => $this->gutenberg_link(),
374 'customizer_img' => betterdocs()->assets->icon( 'customizer/gutenberg-preview.png', true ),
375 'priority' => 1
376 ];
377
378 $settings['elementor_link'] = [
379 'name' => 'elementor_link',
380 'type' => 'action',
381 'action' => 'betterdocs_settings_elementor_link',
382 'button' => $this->is_elementor_pro() ? __( 'Design with Elementor', 'betterdocs' ) : __( 'Learn More', 'betterdocs' ),
383 'url' => $this->elementor_link(),
384 'customizer_img' => betterdocs()->assets->icon( 'customizer/elementor-preview.png', true ),
385 'priority' => 2
386 ];
387
388 if ( ! betterdocs()->helper->current_theme_is_fse_theme() ) {
389 $settings['customizer_link'] = [
390 'name' => 'customizer_link',
391 'type' => 'action',
392 'action' => 'betterdocs_settings_customizer_link',
393 'button' => __( 'Customize in BetterDocs', 'betterdocs' ),
394 'url' => $this->customizer_link(),
395 'customizer_img' => betterdocs()->assets->icon( 'customizer/customizer-preview.png', true ),
396 'priority' => 3
397 ];
398 }
399
400 return $settings;
401 }
402
403 /**
404 * Get All Roles
405 * dynamically
406 *
407 * @return array
408 */
409 public function get_roles() {
410 $roles = wp_roles()->role_names;
411 unset( $roles['subscriber'] );
412
413 return $roles;
414 }
415
416 /**
417 * Set dark mode
418 *
419 * @return void
420 * @since 1.0.0
421 */
422 public function dark_mode() {
423 if ( ! check_ajax_referer( 'doc_cat_order_nonce', 'nonce', false ) ) {
424 wp_send_json_error();
425 }
426
427 if ( isset( $_POST['mode'] ) ) {
428 if ( $this->save( 'dark_mode', rest_sanitize_boolean( $_POST['mode'] ) ) ) { // phpcs:ignore
429 wp_send_json_success();
430 }
431 }
432
433 wp_send_json_error();
434 }
435
436 public function get_normalized_value( $key, $value, $default = null ) {
437 $_origin_value = $_value = $value;
438
439 if ( in_array( $_value, [ 'on', 'off', '1', 'false', 'true' ], true ) ) {
440 switch ( $_value ) {
441 case 'on':
442 case 'ON':
443 case '1':
444 case 'true':
445 $_value = true;
446 break;
447 case 'off':
448 case 'OFF':
449 case '':
450 case 'false':
451 $_value = false;
452 break;
453 }
454 }
455
456 $this->type_validation( $_value, $default );
457
458 return $_value;
459 }
460
461 public function get_normalized_values( $values, $default_values = [] ) {
462 if ( empty( $values ) ) {
463 return [];
464 }
465
466 $_settings = [];
467 foreach ( $values as $key => $value ) {
468 $_default_value = isset( $default_values[ $key ] ) ? $default_values[ $key ] : null;
469 $_settings[ $key ] = $this->get_normalized_value( $key, $value, $_default_value );
470 }
471
472 return $_settings;
473 }
474
475 public function get_all( $raw = false ) {
476 $_default_settings = $raw ? [] : array_merge( $this->get_default(), $this->get_pro_defaults() );
477 $_settings = $this->database->get( $this->base_key, $_default_settings );
478
479 return $this->get_normalized_values( $_settings, $_default_settings );
480 }
481
482 public function type_validation( &$value, $defaultValue = null ) {
483 if ( $defaultValue !== null ) {
484 /**
485 * Check if value is not in same type
486 */
487 $_default_type = gettype( $defaultValue );
488
489 if ( ! ( is_scalar( $defaultValue ) && is_scalar( $value ) ) && empty( $value ) ) {
490 $value = $defaultValue;
491 }
492
493 settype( $value, $_default_type );
494 }
495 }
496
497 /**
498 * Get settings value by key
499 *
500 * @param string $key
501 * @param mixed $default
502 * @param bool $get_all
503 *
504 * @return mixed
505 * @since 2.5.0
506 *
507 */
508 public function get( $key, $default = null ) {
509 $_default_settings = array_merge( $this->get_default(), $this->get_pro_defaults() );
510 $_settings = $this->database->get( $this->base_key, $_default_settings );
511
512 $_value = $default;
513 switch ( true ) {
514 // Check if it's a PRO Option
515 case ! isset( $_default_settings[ $key ] ):
516 $_value = $default;
517 break;
518 // Check if it's a FREE Option and not in DB.
519 case ! isset( $_settings[ $key ] ) && isset( $_default_settings[ $key ] ):
520 $_value = $default !== null ? $default : $_default_settings[ $key ];
521 break;
522 // Check if it's a FREE Option
523 case isset( $_settings[ $key ] ) && isset( $_default_settings[ $key ] ):
524 $_value = $_settings[ $key ];
525 break;
526 }
527
528 $_value = $this->get_normalized_value( $key, $_value, isset( $_default_settings[ $key ] ) ? $_default_settings[ $key ] : null );
529
530 if ( gettype( $_value ) === 'string' ) {
531 if ( empty( $_value ) && $default != null ) {
532 $_value = $default;
533 } elseif ( empty( $_value ) && $default === null && isset( $_default_settings[ $key ] ) ) {
534 $_value = $_default_settings[ $key ];
535 }
536 }
537
538 return $_value;
539 }
540
541 public function get_raw_field( $key, $default = null ) {
542 $_settings = $this->database->get( $this->base_key, [] );
543
544 if ( isset( $_settings[ $key ] ) ) {
545 return $this->get_normalized_value( $key, $_settings[ $key ], $default );
546 }
547
548 return $default;
549 }
550
551 public function save( $key, $value ) {
552 $_settings = $this->database->get( $this->base_key, [] );
553 $_settings[ $key ] = $value;
554
555 return $this->database->save( $this->base_key, $_settings );
556 }
557
558 public function save_settings( $settings ) {
559 $existing_plugins = betterdocs()->kbmigration->knowledge_base_plugins();
560 if ( ! current_user_can( 'edit_docs_settings' ) ) {
561 return new WP_Error( 'unauthorized_action', __( 'You don\'t have any rights for saving settings.', 'betterdocs' ) );
562 }
563
564 // Quickbuilder sends back the full UI-loaded payload. To avoid overwriting values that we
565 // asynchronously updated in the DB via AJAX (like Git integration fields), we strictly remove them
566 // from the incoming save payload so that the freshly loaded `$_old_settings` values persist.
567 $exclude_ajax_keys = [ 'git_provider', 'git_repository_url', 'git_branch', 'git_docs_directory' ];
568 foreach ( $exclude_ajax_keys as $key ) {
569 if ( array_key_exists( $key, $settings ) ) {
570 unset( $settings[ $key ] );
571 }
572 if ( isset( $settings['values'] ) && is_array( $settings['values'] ) && array_key_exists( $key, $settings['values'] ) ) {
573 unset( $settings['values'][ $key ] );
574 }
575 }
576
577 $_old_settings = $this->database->get( $this->base_key, $this->get_default() );
578
579 // The frontend only ever sees masked API keys. If a submitted value matches the mask of
580 // the stored value, the user did not change it — restore the original so the mask string
581 // is never persisted.
582 $sensitive_api_keys = [ 'ai_autowrite_api_key', 'ai_chatbot_api_key' ];
583 foreach ( $sensitive_api_keys as $api_key_field ) {
584 if ( ! isset( $settings[ $api_key_field ] ) ) {
585 continue;
586 }
587 $stored = isset( $_old_settings[ $api_key_field ] ) ? $_old_settings[ $api_key_field ] : '';
588 if ( $stored !== '' && trim( (string) $settings[ $api_key_field ] ) === Helper::mask_api_key( $stored ) ) {
589 $settings[ $api_key_field ] = $stored;
590 }
591 }
592
593 // @todo: sanitize the data before inject in DB.
594 $_normalized_settings = $this->get_normalized_values( $settings );
595 if ( $existing_plugins && isset( $_normalized_settings['migration_step'] ) && $_normalized_settings['migration_step'] == true ) {
596 betterdocs()->kbmigration->migrate();
597 }
598 $_settings = wp_parse_args( $_normalized_settings, $_old_settings );
599
600 // Check if there are actual changes before saving.
601 // update_option returns false when values serialize identically, which can happen
602 // due to object caching or type normalization even when user made changes.
603 $_has_changes = $_settings != $_old_settings;
604
605 $_saved = $this->database->save( $this->base_key, $_settings );
606
607 do_action_ref_array( 'betterdocs::settings::saved', [ $_saved, $_settings, $_old_settings, &$this ] );
608
609 // Return true if save succeeded OR if there were changes to attempt saving.
610 // This handles cases where update_option returns false due to identical serialization
611 // (e.g., object caching, type coercion during serialization).
612 return $_saved || $_has_changes;
613 }
614
615 public function views( $hook ) {
616 return betterdocs()->views->get( 'admin/settings' );
617 }
618
619 public function save_default_settings() {
620 $_settings = $this->get_all();
621
622 return $this->database->save( $this->base_key, $_settings );
623 }
624
625 public function get_pages() {
626 $_pages = betterdocs()->query->get_posts( [
627 'post_type' => 'page',
628 'numberposts' => - 1,
629 'post_status' => 'publish',
630 'posts_per_page' => - 1
631 ] );
632
633 $__pages = [];
634
635 if ( ! empty( $_pages ) ) {
636 $__pages[0] = __( 'Select a Page', 'betterdocs' );
637 foreach ( $_pages->posts as $page ) {
638 $__pages[ $page->ID ] = esc_html( $page->post_title );
639 }
640 }
641
642 return $__pages;
643 }
644
645 public function settings_args() {
646 $wp_roles = $this->normalize_options( $this->get_roles() );
647
648 $roles_for_ikb = $this->normalize_options( array_merge( [ 'all' => __( 'All logged in users', 'betterdocs' ) ], wp_roles()->role_names ) );
649
650 unset( $roles_for_ikb['administrator'] );
651
652 $settings = [
653 'id' => 'betterdocs_settings_metabox_wrapper',
654 'title' => __( 'betterdocs', 'betterdocs' ),
655 'object_types' => [ 'betterdocs' ],
656 'context' => 'normal',
657 'priority' => 'high',
658 'show_header' => false,
659 'tabnumber' => false,
660 'is_pro_active' => betterdocs()->is_pro_active(),
661 'logoURL' => betterdocs()->assets->icon( 'betterdocs-icon.svg', true ),
662 'layout' => 'vertical',
663 'config' => [
664 'active' => 'tab-general',
665 'sidebar' => true,
666 'title' => false
667 ],
668 'submit' => [
669 'show' => true,
670 'label' => __( 'Save', 'betterdocs' ),
671 'loadingLabel' => __( 'Saving...', 'betterdocs' ),
672 'class' => 'save-settings',
673 'rules' => Rules::logicalRule( [
674 Rules::is( 'config.active', 'tab-design', true ),
675 Rules::is( 'config.active', 'tab-shortcodes', true ),
676 Rules::is( 'config.active', 'tab-instant-answer', true ),
677 Rules::is( 'config.active', 'tab-import-export', true ),
678 Rules::is( 'config.active', 'tab-migration', true )
679 ], 'and' )
680 ],
681 'values' => betterdocs()->is_pro_active() ? $this->get_all() : array_merge( $this->get_all(), $this->pro_settings_default_values() ),
682 'tabs' => apply_filters( 'betterdocs_settings_tabs', [
683 'tab-general' => apply_filters( 'betterdocs_settings_tab_general', [
684 'id' => 'tab-general',
685 'label' => __( 'General', 'betterdocs' ),
686 'classes' => 'tab-general',
687 'priority' => 10,
688 'fields' => [
689 'title-general' => apply_filters( 'betterdocs_encyclopedia_settings', [
690 'name' => 'title-general-tab',
691 'type' => 'section',
692 'label' => __( 'General Settings', 'betterdocs' ),
693 'priority' => 10,
694 'fields' => [
695 'multiple_kb' => apply_filters( 'betterdocs_multi_kb_settings', [
696 'name' => 'multiple_kb',
697 'type' => 'toggle',
698 'label' => __( 'Multiple Knowledge Base', 'betterdocs' ),
699 'enable_disable_text_active' => true,
700 'default' => '',
701 'priority' => 1,
702 'is_pro' => true
703 ] ),
704 'builtin_doc_page' => [
705 'name' => 'builtin_doc_page',
706 'type' => 'toggle',
707 'label' => __( 'Built-in Documentation Page', 'betterdocs' ),
708 'enable_disable_text_active' => true,
709 'default' => 1,
710 'priority' => 2
711 ],
712 'enable_category_hierarchy_slugs' => [
713 'name' => 'enable_category_hierarchy_slugs',
714 'type' => 'toggle',
715 'label' => __( 'Enable Category Hierarchy Slug', 'betterdocs' ),
716 'enable_disable_text_active' => true,
717 'default' => false,
718 'priority' => 3,
719 'label_subtitle' => __( "Shows Hierarchy Based Permalink Slugs For Doc Categories & Single Doc Page", 'betterdocs' )
720 ],
721 'breadcrumb_doc_title' => [
722 'name' => 'breadcrumb_doc_title',
723 'type' => 'text',
724 'label' => __( 'Documentation Page Title', 'betterdocs' ),
725 'default' => __( 'Docs', 'betterdocs' ),
726 'priority' => 4,
727 'rules' => Rules::is( 'builtin_doc_page', true )
728 ],
729 'docs_slug' => [
730 'name' => 'docs_slug',
731 'type' => 'text',
732 'label' => __( 'BetterDocs Root Slug', 'betterdocs' ),
733 'default' => 'docs',
734 'priority' => 5,
735 'rules' => Rules::is( 'builtin_doc_page', true )
736 ],
737 'docs_page' => [
738 'name' => 'docs_page',
739 'label' => __( 'Docs Page', 'betterdocs' ),
740 'type' => 'select',
741 'default' => 0,
742 'priority' => 6,
743 'search' => true,
744 'options' => $this->normalize_options( $this->get_pages() ),
745 'label_subtitle' => __( 'You will need to insert BetterDocs Shortcode inside the page. This page will be used as docs permalink.', 'betterdocs' ),
746 'rules' => Rules::is( 'builtin_doc_page', false )
747 ],
748
749 'category_slug' => [
750 'name' => 'category_slug',
751 'type' => 'text',
752 'label' => __( 'Custom Category Slug', 'betterdocs' ),
753 'default' => 'docs-category',
754 'priority' => 7
755 ],
756 'tag_slug' => [
757 'name' => 'tag_slug',
758 'type' => 'text',
759 'label' => __( 'Custom Tag Slug', 'betterdocs' ),
760 'default' => 'docs-tag',
761 'priority' => 8
762 ],
763 'permalink_structure' => [
764 'name' => 'permalink_structure',
765 'type' => 'permalink_structure',
766 'label' => __( 'Single Docs Permalink', 'betterdocs' ),
767 'default' => PostType::permalink_structure(),
768 'priority' => 9,
769 'tags' => $this->normalize_options( [
770 '%doc_category%' => '%doc_category%',
771 '%knowledge_base%' => '%knowledge_base%'
772 ] ),
773 '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' )
774 ],
775 'enable_glossaries' => [
776 'name' => 'enable_glossaries',
777 'type' => 'toggle',
778 'label' => __( 'Show Glossary', 'betterdocs' ),
779 'label_subtitle' => __( 'Enable the glossary feature to allow users to look up definitions for terms used within your encyclopedia or glossaries themselves.', 'betterdocs' ),
780 'enable_disable_text_active' => true,
781 'default' => false,
782 'priority' => 10,
783 'is_pro' => true
784 ],
785 'enable_encyclopedia' => [
786 'name' => 'enable_encyclopedia',
787 'type' => 'toggle',
788 'label' => __( 'Built-in Encyclopedia Page', 'betterdocs' ),
789 'enable_disable_text_active' => true,
790 'default' => false,
791 'priority' => 11,
792 'is_pro' => true
793 ],
794 'enable_faq_schema' => [
795 'name' => 'enable_faq_schema',
796 'type' => 'toggle',
797 'label' => __( 'FAQ Schema', 'betterdocs' ),
798 'enable_disable_text_active' => true,
799 'default' => '',
800 'priority' => 12
801 ],
802 'analytics_from' => [
803 'name' => 'analytics_from',
804 'type' => 'select',
805 'label' => __( 'Analytics From', 'betterdocs' ),
806 'options' => $this->normalize_options( [
807 'everyone' => __( 'Everyone', 'betterdocs' ),
808 'guests' => __( 'Guests Only', 'betterdocs' ),
809 'registered_users' => __( 'Registered Users Only', 'betterdocs' )
810 ] ),
811 'default' => 'everyone',
812 'priority' => 13,
813 'is_pro' => true
814 ],
815 'unique_visitor_count' => [
816 'name' => 'unique_visitor_count',
817 'type' => 'toggle',
818 'label' => __( 'Unique Visitor Count', 'betterdocs' ),
819 'enable_disable_text_active' => true,
820 'default' => false,
821 'priority' => 14,
822 'is_pro' => true
823 ],
824 'exclude_bot_analytics' => [
825 'name' => 'exclude_bot_analytics',
826 'type' => 'toggle',
827 'label' => __( 'Exclude Bot Analytics', 'betterdocs' ),
828 'enable_disable_text_active' => true,
829 'default' => false,
830 'priority' => 15,
831 'is_pro' => true
832 ]
833
834 ]
835 ] )
836 ]
837 ] ),
838 'tab-layout' => apply_filters( 'betterdocs_settings_tab_layout', [
839 'id' => 'tab-layout',
840 'label' => __( 'Layout', 'betterdocs' ),
841 'classes' => 'tab-layout',
842 'priority' => 20,
843 'fields' => [
844 'title-layout' => [
845 'name' => 'title-layout-tab',
846 'type' => 'section',
847 'label' => __( 'Layout Settings', 'betterdocs' ),
848 'priority' => 20,
849 'fields' => [
850 'tab-sidebar-layout' => apply_filters( 'betterdocs_settings_tab_sidebar_layout', [
851 'id' => 'tab-sidebar-layout',
852 'name' => 'tab_sidebar_layout',
853 'label' => __( 'Layout Settings', 'betterdocs' ),
854 'classes' => 'tab-layout',
855 'type' => 'tab',
856 'active' => 'layout_documentation_page',
857 'completionTrack' => true,
858 'sidebar' => false,
859 'save' => false,
860 'title' => false,
861 'config' => [
862 'active' => 'layout_documentation_page',
863 'sidebar' => false,
864 'title' => false
865 ],
866 'submit' => [
867 'show' => false
868 ],
869 'step' => [
870 'show' => false
871 ],
872 'priority' => 20,
873 'fields' => [
874 'layout_documentation_page' => [
875 'id' => 'layout_documentation_page',
876 'name' => 'layout_documentation_page',
877 'type' => 'section',
878 'label' => __( 'Documentation Page', 'betterdocs' ),
879 'priority' => 1,
880 'fields' => [
881 'tab-nested-layout-1' => [
882 'id' => 'tab-nested-layout-1',
883 'name' => 'tab_nested_layout_1',
884 'label' => __( 'Documentation Page', 'betterdocs' ),
885 'classes' => 'tab-nested-layout',
886 'type' => 'tab',
887 'active' => 'layout_documentation_page_general',
888 'completionTrack' => true,
889 'sidebar' => false,
890 'save' => false,
891 'title' => false,
892 'config' => [
893 'active' => 'layout_documentation_page_general',
894 'sidebar' => false,
895 'title' => false
896 ],
897 'submit' => [
898 'show' => false
899 ],
900 'step' => [
901 'show' => false
902 ],
903 'priority' => 1,
904 'fields' => [
905 'layout_documentation_page_general' => [
906 'id' => 'layout_documentation_page_general',
907 'name' => 'layout_documentation_page_general',
908 'type' => 'section',
909 'label' => __( 'General', 'betterdocs' ),
910 'priority' => 1,
911 'fields' => [
912 'docs_list_icon' => [
913 'name' => 'docs_list_icon',
914 'type' => 'media',
915 'value' => '',
916 'label' => __( 'Docs List Icon', 'betterdocs' ),
917 'label_subtitle' => __( 'Upload your own preferred document list icon', 'betterdocs' ),
918 'priority' => 0
919 ],
920 'category_title_link' => [
921 'name' => 'category_title_link',
922 'type' => 'toggle',
923 'label' => __( 'Category Title Link', 'betterdocs' ),
924 'label_subtitle' => __( 'This setting is applicable for category grid layout', 'betterdocs' ),
925 'enable_disable_text_active' => true,
926 'default' => false,
927 'priority' => 0
928 ],
929 'masonry_layout' => [
930 'name' => 'masonry_layout',
931 'type' => 'toggle',
932 'label' => __( 'Masonry', 'betterdocs' ),
933 'enable_disable_text_active' => true,
934 'default' => 1,
935 'priority' => 1
936 ],
937 'nested_subcategory' => [
938 'name' => 'nested_subcategory',
939 'type' => 'toggle',
940 'label' => __( 'Nested Sub Category', 'betterdocs' ),
941 'enable_disable_text_active' => true,
942 'default' => '',
943 'priority' => 2
944 ],
945 'column_number' => [
946 'name' => 'column_number',
947 'type' => 'number',
948 'label' => __( 'Number Of Columns', 'betterdocs' ),
949 'label_subtitle' => __( 'This setting is not applicable for sleek layout.', 'betterdocs' ),
950 'default' => 3,
951 'priority' => 3
952 ],
953 'posts_number' => apply_filters( 'betterdocs_posts_number', [
954 'name' => 'posts_number',
955 'type' => 'number',
956 'label' => __( 'Number Of Docs', 'betterdocs' ),
957 'label_subtitle' => __( 'This setting is not applicable for handbook layout.', 'betterdocs' ),
958 'default' => 10,
959 'priority' => 4
960 ] ),
961 'post_count' => [
962 'name' => 'post_count',
963 'type' => 'toggle',
964 'label' => __( 'Doc Count', 'betterdocs' ),
965 'enable_disable_text_active' => true,
966 'default' => 1,
967 'priority' => 5
968 ],
969 'count_text' => [
970 'name' => 'count_text',
971 'type' => 'text',
972 'label' => __( 'Count Text', 'betterdocs' ),
973 'default' => __( 'Docs', 'betterdocs' ),
974 'priority' => 6
975 ],
976 'count_text_singular' => [
977 'name' => 'count_text_singular',
978 'type' => 'text',
979 'label' => __( 'Count Text Singular', 'betterdocs' ),
980 'default' => __( 'Doc', 'betterdocs' ),
981 'priority' => 7
982 ],
983 'exploremore_btn' => [
984 'name' => 'exploremore_btn',
985 'type' => 'toggle',
986 'label' => __( 'Explore More Button', 'betterdocs' ),
987 'enable_disable_text_active' => true,
988 'default' => true,
989 'priority' => 8
990 ],
991 'exploremore_btn_txt' => [
992 'name' => 'exploremore_btn_txt',
993 'type' => 'text',
994 'label' => __( 'Explore More Button Text', 'betterdocs' ),
995 'default' => __( 'Explore More', 'betterdocs' ),
996 'priority' => 9,
997 'rules' => Rules::is( 'exploremore_btn', true )
998 ],
999 'betterdocs_popular_docs_text' => [
1000 'name' => 'betterdocs_popular_docs_text',
1001 'type' => 'text',
1002 'label' => __( 'Popular Docs Text', 'betterdocs' ),
1003 'default' => __( 'Popular Docs', 'betterdocs' ),
1004 'priority' => 10,
1005 'is_pro' => true
1006 ],
1007 'betterdocs_popular_docs_number' => [
1008 'name' => 'betterdocs_popular_docs_number',
1009 'type' => 'number',
1010 'label' => __( 'Popular Docs Number', 'betterdocs' ),
1011 'default' => 10,
1012 'priority' => 11,
1013 'is_pro' => true
1014 ]
1015 ]
1016 ],
1017 'layout_documentation_page_search' => [
1018 'id' => 'layout_documentation_page_search',
1019 'name' => 'layout_documentation_page_search',
1020 'type' => 'section',
1021 'label' => __( 'Search', 'betterdocs' ),
1022 'priority' => 2,
1023 'fields' => [
1024 'live_search' => [
1025 'name' => 'live_search',
1026 'type' => 'toggle',
1027 'label' => __( 'Live Search', 'betterdocs' ),
1028 'enable_disable_text_active' => true,
1029 'default' => 1,
1030 'priority' => 1
1031 ],
1032 'advance_search' => apply_filters( 'betterdocs_advance_search_settings', [
1033 'name' => 'advance_search',
1034 'type' => 'toggle',
1035 'label' => __( 'Advanced Search', 'betterdocs' ),
1036 'enable_disable_text_active' => true,
1037 'default' => '',
1038 'priority' => 2,
1039 'is_pro' => true
1040 ] ),
1041 'child_category_exclude' => apply_filters( 'child_category_exclude', [
1042 'name' => 'child_category_exclude',
1043 'type' => 'toggle',
1044 'label' => __( 'Exclude Child Terms In Category Search', 'betterdocs' ),
1045 'enable_disable_text_active' => true,
1046 'default' => '',
1047 'priority' => 3,
1048 'is_pro' => true
1049 ] ),
1050 'popular_keyword_limit' => apply_filters( 'betterdocs_popular_keyword_limit_settings', [
1051 'name' => 'popular_keyword_limit',
1052 'type' => 'number',
1053 'label' => __( 'Minimum amount of Keywords Search', 'betterdocs' ),
1054 'default' => 5,
1055 'priority' => 4,
1056 'is_pro' => true
1057 ] ),
1058 'search_letter_limit' => [
1059 'name' => 'search_letter_limit',
1060 'type' => 'number',
1061 'label' => __( 'Minimum Character Limit For Search Result', 'betterdocs' ),
1062 'priority' => 5,
1063 'default' => 3
1064 ],
1065 'search_placeholder' => [
1066 'name' => 'search_placeholder',
1067 'type' => 'text',
1068 'label' => __( 'Search Placeholder', 'betterdocs' ),
1069 'default' => __( 'Search..', 'betterdocs' ),
1070 'priority' => 6
1071 ],
1072 'search_button_text' => apply_filters( 'betterdocs_search_button_text', [
1073 'name' => 'search_button_text',
1074 'type' => 'text',
1075 'label' => __( 'Search Button Text', 'betterdocs' ),
1076 'priority' => 7,
1077 'default' => __( 'Search', 'betterdocs' )
1078 ] ),
1079 'search_not_found_text' => [
1080 'name' => 'search_not_found_text',
1081 'type' => 'text',
1082 'label' => __( 'Search Not Found Text', 'betterdocs' ),
1083 'default' => 'Sorry, no docs were found.',
1084 'priority' => 8
1085 ],
1086 'search_result_image' => [
1087 'name' => 'search_result_image',
1088 'type' => 'toggle',
1089 'label' => __( 'Search Result Image', 'betterdocs' ),
1090 'enable_disable_text_active' => true,
1091 'default' => 1,
1092 'priority' => 9
1093 ],
1094 'kb_based_search' => apply_filters( 'betterdocs_kb_based_search_settings', [
1095 'name' => 'kb_based_search',
1096 'type' => 'toggle',
1097 'label' => __( 'KB Based Search', 'betterdocs' ),
1098 'enable_disable_text_active' => true,
1099 'default' => '',
1100 'priority' => 10,
1101 'is_pro' => true,
1102 'rules' => Rules::is( 'multiple_kb', true )
1103 ] ),
1104 'search_modal_search_type' => [
1105 'name' => 'search_modal_search_type',
1106 'type' => 'select',
1107 'label' => __( 'Search Modal Source', 'betterdocs' ),
1108 'label_subtitle' => __( 'Choose the content type to be shown in the search modal. <br> <b>Note:</b> This is only applicable on Modal Search.', 'betterdocs' ),
1109 'default' => 'all',
1110 'options' => $this->normalize_options( [
1111 'all' => __('Both (Docs + FAQs)', 'betterdocs'),
1112 'docs' => __('Docs only', 'betterdocs'),
1113 'faq' => __('FAQs only', 'betterdocs')
1114 ] ),
1115 'priority' => 11,
1116 ]
1117 ]
1118 ],
1119 'layout_documentation_page_order_by' => [
1120 'id' => 'layout_documentation_page_order_by',
1121 'name' => 'layout_documentation_page_order_by',
1122 'type' => 'section',
1123 'label' => __( 'Order By', 'betterdocs' ),
1124 'priority' => 3,
1125 'fields' => [
1126 'terms_orderby' => [
1127 'name' => 'terms_orderby',
1128 'type' => 'select',
1129 'label' => __( 'Terms Order By', 'betterdocs' ),
1130 'default' => 'betterdocs_order',
1131 'options' => $this->normalize_options( apply_filters( 'betterdocs_terms_orderby_options', [
1132 'none' => __( 'No order', 'betterdocs' ),
1133 'name' => __( 'Name', 'betterdocs' ),
1134 'slug' => __( 'Slug', 'betterdocs' ),
1135 'term_group' => __( 'Term Group', 'betterdocs' ),
1136 'term_id' => __( 'Term ID', 'betterdocs' ),
1137 'id' => __( 'ID', 'betterdocs' ),
1138 'description' => __( 'Description', 'betterdocs' ),
1139 'parent' => __( 'Parent', 'betterdocs' ),
1140 'betterdocs_order' => __( 'BetterDocs Order', 'betterdocs' )
1141 ] ) ),
1142 'priority' => 1
1143 ],
1144 'terms_order' => [
1145 'name' => 'terms_order',
1146 'type' => 'select',
1147 'label' => __( 'Terms Order', 'betterdocs' ),
1148 'default' => 'ASC',
1149 'options' => $this->normalize_options( [
1150 'ASC' => 'Ascending',
1151 'DESC' => 'Descending'
1152 ] ),
1153 'priority' => 3,
1154 'rules' => Rules::includes( 'terms_orderby', 'betterdocs_order', true )
1155 ],
1156 'alphabetically_order_post' => [
1157 'name' => 'alphabetically_order_post',
1158 'type' => 'select',
1159 'label' => __( 'Docs Order By', 'betterdocs' ),
1160 'default' => 'betterdocs_order',
1161 'options' => $this->normalize_options( [
1162 'none' => __( 'No order', 'betterdocs' ),
1163 'ID' => __( 'Docs ID', 'betterdocs' ),
1164 'author' => __( 'Docs Author', 'betterdocs' ),
1165 'title' => __( 'Title', 'betterdocs' ),
1166 'date' => __( 'Date', 'betterdocs' ),
1167 'modified' => __( 'Last Modified Date', 'betterdocs' ),
1168 'parent' => __( 'Parent Id', 'betterdocs' ),
1169 'rand' => __( 'Random', 'betterdocs' ),
1170 'comment_count' => __( 'Comment Count', 'betterdocs' ),
1171 'menu_order' => __( 'Menu Order', 'betterdocs' ),
1172 'betterdocs_order' => __( 'BetterDocs Order', 'betterdocs' )
1173 ] ),
1174 'priority' => 4
1175 ],
1176 'docs_order' => [
1177 'name' => 'docs_order',
1178 'type' => 'select',
1179 'label' => __( 'Docs Order', 'betterdocs' ),
1180 'default' => 'ASC',
1181 'options' => $this->normalize_options( [
1182 'ASC' => 'Ascending',
1183 'DESC' => 'Descending'
1184 ] ),
1185 'priority' => 5,
1186 'rules' => Rules::includes( 'alphabetically_order_post', 'betterdocs_order', true )
1187 ]
1188 ]
1189 ]
1190 ]
1191 ]
1192 ]
1193 ],
1194 'layout_single_doc' => apply_filters( 'single_doc_setting_section', [
1195 'id' => 'layout_single_doc',
1196 'name' => 'layout_single_doc',
1197 'type' => 'section',
1198 'label' => __( 'Single Doc', 'betterdocs' ),
1199 'priority' => 2,
1200 'fields' => [
1201 'tab-nested-layout-2' => [
1202 'id' => 'tab-nested-layout-2',
1203 'name' => 'tab_nested_layout_2',
1204 'label' => __( 'Single Doc', 'betterdocs' ),
1205 'classes' => 'tab-nested-layout',
1206 'type' => 'tab',
1207 'active' => 'layout_single_doc_general',
1208 'completionTrack' => true,
1209 'sidebar' => false,
1210 'save' => false,
1211 'title' => false,
1212 'config' => [
1213 'active' => 'layout_single_doc_general',
1214 'sidebar' => false,
1215 'title' => false
1216 ],
1217 'submit' => [
1218 'show' => false
1219 ],
1220 'step' => [
1221 'show' => false
1222 ],
1223 'priority' => 20,
1224 'fields' => [
1225 'layout_single_doc_general' => [
1226 'id' => 'layout_single_doc_general',
1227 'name' => 'layout_single_doc_general',
1228 'type' => 'section',
1229 'label' => __( 'General', 'betterdocs' ),
1230 'priority' => 5,
1231 'fields' => [
1232 'enable_post_title' => [
1233 'name' => 'enable_post_title',
1234 'type' => 'toggle',
1235 'label' => __( 'Doc Title', 'betterdocs' ),
1236 'enable_disable_text_active' => true,
1237 'default' => 1,
1238 'priority' => 1
1239 ],
1240 'enable_sidebar_cat_list' => [
1241 'name' => 'enable_sidebar_cat_list',
1242 'type' => 'toggle',
1243 'label' => __( 'Sidebar Category List', 'betterdocs' ),
1244 'enable_disable_text_active' => true,
1245 'default' => 1,
1246 'priority' => 2
1247 ],
1248 'enable_print_icon' => [
1249 'name' => 'enable_print_icon',
1250 'type' => 'toggle',
1251 'label' => __( 'Print Icon', 'betterdocs' ),
1252 'enable_disable_text_active' => true,
1253 'default' => 1,
1254 'priority' => 3
1255 ],
1256 'enable_tags' => [
1257 'name' => 'enable_tags',
1258 'type' => 'toggle',
1259 'label' => __( 'Tags', 'betterdocs' ),
1260 'enable_disable_text_active' => true,
1261 'default' => 1,
1262 'priority' => 4
1263 ],
1264 'show_last_update_time' => [
1265 'name' => 'show_last_update_time',
1266 'type' => 'toggle',
1267 'label' => __( 'Last Update Time', 'betterdocs' ),
1268 'enable_disable_text_active' => true,
1269 'default' => 1,
1270 'priority' => 5
1271 ],
1272 'enable_navigation' => [
1273 'name' => 'enable_navigation',
1274 'type' => 'toggle',
1275 'label' => __( 'Navigation', 'betterdocs' ),
1276 'enable_disable_text_active' => true,
1277 'default' => 1,
1278 'priority' => 6
1279 ],
1280 'enable_comment' => [
1281 'name' => 'enable_comment',
1282 'type' => 'toggle',
1283 'label' => __( 'Comment', 'betterdocs' ),
1284 'enable_disable_text_active' => true,
1285 'default' => '',
1286 'priority' => 7
1287 ],
1288 'enable_credit' => [
1289 'name' => 'enable_credit',
1290 'type' => 'toggle',
1291 'label' => __( 'Show Powered by BetterDocs', 'betterdocs' ),
1292 'enable_disable_text_active' => true,
1293 'default' => '',
1294 'priority' => 8
1295 ],
1296 'reaction_feedback_text' => [
1297 'name' => 'reaction_feedback_text',
1298 'type' => 'text',
1299 'label' => __( 'Reaction Feedback Text', 'betterdocs' ),
1300 'default' => __( 'Thanks for your feedback.', 'betterdocs' ),
1301 'priority' => 9
1302 ],
1303 'enable_estimated_reading_time' => [
1304 'name' => 'enable_estimated_reading_time',
1305 'type' => 'toggle',
1306 'label' => __( 'Estimated Reading Time', 'betterdocs' ),
1307 'enable_disable_text_active' => true,
1308 'default' => 0,
1309 'priority' => 10
1310 ],
1311 'estimated_reading_time_title' => [
1312 'name' => 'estimated_reading_time_title',
1313 'type' => 'text',
1314 'label' => __( 'Estimated Reading Time Title', 'betterdocs' ),
1315 'default' => '',
1316 'priority' => 11,
1317 'rules' => Rules::is( 'enable_estimated_reading_time', true )
1318 ],
1319 'estimated_reading_time_text' => [
1320 'name' => 'estimated_reading_time_text',
1321 'type' => 'text',
1322 'label' => __( 'Estimated Reading Time Text', 'betterdocs' ),
1323 'default' => __( 'min read', 'betterdocs' ),
1324 'priority' => 12,
1325 'rules' => Rules::is( 'enable_estimated_reading_time', true )
1326 ],
1327 'singular_estimated_reading_time_text' => [
1328 'name' => 'singular_estimated_reading_time_text',
1329 'type' => 'text',
1330 'label' => __( 'Estimated Reading Time Text Singular', 'betterdocs' ),
1331 'default' => __( 'min read', 'betterdocs' ),
1332 'priority' => 13,
1333 'rules' => Rules::is( 'enable_estimated_reading_time', true )
1334 ]
1335 ]
1336 ],
1337 'layout_single_doc_TOC' => [
1338 'id' => 'layout_single_doc_TOC',
1339 'name' => 'layout_single_doc_TOC',
1340 'type' => 'section',
1341 'label' => __( 'TOC', 'betterdocs' ),
1342 'priority' => 5,
1343 'fields' => [
1344 'enable_toc' => [
1345 'name' => 'enable_toc',
1346 'type' => 'toggle',
1347 'label' => __( 'Table of Contents', 'betterdocs' ),
1348 'enable_disable_text_active' => true,
1349 'default' => 1,
1350 'priority' => 1
1351 ],
1352 'toc_title' => [
1353 'name' => 'toc_title',
1354 'type' => 'text',
1355 'label' => __( 'TOC Title', 'betterdocs' ),
1356 'default' => __( 'Table of Contents', 'betterdocs' ),
1357 'priority' => 2,
1358 'rules' => Rules::is( 'enable_toc', true )
1359
1360 ],
1361 'toc_hierarchy' => [
1362 'name' => 'toc_hierarchy',
1363 'type' => 'toggle',
1364 'label' => __( 'TOC Hierarchy', 'betterdocs' ),
1365 'enable_disable_text_active' => true,
1366 'default' => 1,
1367 'priority' => 3,
1368 'rules' => Rules::is( 'enable_toc', true )
1369 ],
1370 'toc_list_number' => [
1371 'name' => 'toc_list_number',
1372 'type' => 'toggle',
1373 'label' => __( 'TOC List Number', 'betterdocs' ),
1374 'enable_disable_text_active' => true,
1375 'default' => 1,
1376 'priority' => 4,
1377 'rules' => Rules::is( 'enable_toc', true )
1378 ],
1379 'toc_dynamic_title' => [
1380 'name' => 'toc_dynamic_title',
1381 'type' => 'toggle',
1382 'label' => __( 'Show TOC Title in Anchor Links', 'betterdocs' ),
1383 'enable_disable_text_active' => true,
1384 'default' => 0,
1385 'priority' => 5,
1386 'rules' => Rules::is( 'enable_toc', true )
1387 ],
1388 'enable_sticky_toc' => [
1389 'name' => 'enable_sticky_toc',
1390 'type' => 'toggle',
1391 'label' => __( 'Sticky TOC', 'betterdocs' ),
1392 'enable_disable_text_active' => true,
1393 'default' => 1,
1394 'priority' => 6,
1395 'rules' => Rules::is( 'enable_toc', true )
1396 ],
1397 'collapsible_toc_mobile' => [
1398 'name' => 'collapsible_toc_mobile',
1399 'type' => 'toggle',
1400 'label' => __( 'Collapsible TOC on small devices', 'betterdocs' ),
1401 'enable_disable_text_active' => true,
1402 'default' => '',
1403 'priority' => 7,
1404 'rules' => Rules::is( 'enable_toc', true )
1405 ],
1406 'title_link_ctc' => [
1407 'name' => 'title_link_ctc',
1408 'type' => 'toggle',
1409 'label' => __( 'Title Link Copy To Clipboard', 'betterdocs' ),
1410 'enable_disable_text_active' => true,
1411 'default' => 1,
1412 'priority' => 8
1413 ],
1414 'supported_heading_tag' => [
1415 'name' => 'supported_heading_tag',
1416 'label' => __( 'TOC Supported Heading Tag', 'betterdocs' ),
1417 'type' => 'checkbox-select',
1418 'multiple' => true,
1419 'priority' => 10,
1420 'default' => [
1421 '1',
1422 '2',
1423 '3',
1424 '4',
1425 '5',
1426 '6'
1427 ],
1428 'options' => $this->normalize_options( [
1429 '1' => 'H1',
1430 '2' => 'H2',
1431 '3' => 'H3',
1432 '4' => 'H4',
1433 '5' => 'H5',
1434 '6' => 'H6'
1435 ] ),
1436 'priority' => 9,
1437 'rules' => Rules::is( 'enable_toc', true )
1438 ],
1439 'sticky_toc_offset' => [
1440 'name' => 'sticky_toc_offset',
1441 'type' => 'number',
1442 'label' => __( 'Content Offset', 'betterdocs' ),
1443 'default' => 100,
1444 'priority' => 10,
1445 'label_subtitle' => __( 'content offset from top on scroll.', 'betterdocs' ),
1446 'rules' => Rules::is( 'enable_toc', true )
1447 ]
1448 ]
1449 ],
1450 'layout_single_doc_breadcrumb' => [
1451 'id' => 'layout_single_doc_breadcrumb',
1452 'name' => 'layout_single_doc_breadcrumb',
1453 'type' => 'section',
1454 'label' => __( 'Breadcrumb', 'betterdocs' ),
1455 'priority' => 5,
1456 'fields' => [
1457 'enable_breadcrumb' => [
1458 'name' => 'enable_breadcrumb',
1459 'type' => 'toggle',
1460 'label' => __( 'Breadcrumb', 'betterdocs' ),
1461 'enable_disable_text_active' => true,
1462 'default' => 1,
1463 'priority' => 1
1464 ],
1465 'enable_breadcrumb_home_text' => [
1466 'name' => 'enable_breadcrumb_home_text',
1467 'type' => 'toggle',
1468 'label' => __( 'Enable Breadcrumb Home Text', 'betterdocs' ),
1469 'enable_disable_text_active' => true,
1470 'default' => true,
1471 'priority' => 2,
1472 'rules' => Rules::is( 'enable_breadcrumb', true )
1473 ],
1474 'breadcrumb_home_text' => [
1475 'name' => 'breadcrumb_home_text',
1476 'type' => 'text',
1477 'label' => __( 'Breadcrumb Home Text', 'betterdocs' ),
1478 'default' => __( 'Home', 'betterdocs' ),
1479 'priority' => 3,
1480 'rules' => Rules::logicalRule(
1481 [
1482 Rules::is( 'enable_breadcrumb', true ),
1483 Rules::is( 'enable_breadcrumb_home_text', true )
1484 ],
1485 'and'
1486 )
1487 ],
1488 'breadcrumb_home_url' => [
1489 'name' => 'breadcrumb_home_url',
1490 'type' => 'text',
1491 'label' => __( 'Breadcrumb Home URL', 'betterdocs' ),
1492 'priority' => 4,
1493 'default' => get_home_url(),
1494 'rules' => Rules::is( 'enable_breadcrumb', true )
1495 ],
1496 'enable_breadcrumb_category' => [
1497 'name' => 'enable_breadcrumb_category',
1498 'type' => 'toggle',
1499 'label' => __( 'Category on Breadcrumb', 'betterdocs' ),
1500 'enable_disable_text_active' => true,
1501 'default' => 1,
1502 'priority' => 5,
1503 'rules' => Rules::is( 'enable_breadcrumb', true )
1504 ],
1505 'enable_breadcrumb_title' => [
1506 'name' => 'enable_breadcrumb_title',
1507 'type' => 'toggle',
1508 'label' => __( 'Title on Breadcrumb', 'betterdocs' ),
1509 'enable_disable_text_active' => true,
1510 'default' => 1,
1511 'priority' => 6,
1512 'rules' => Rules::is( 'enable_breadcrumb', true )
1513 ]
1514 ]
1515 ],
1516 'layout_single_doc_email_feedback' => [
1517 'id' => 'layout_single_doc_email_feedback',
1518 'name' => 'layout_single_doc_email_feedback',
1519 'type' => 'section',
1520 'label' => __( 'Email Feedback', 'betterdocs' ),
1521 'priority' => 5,
1522 'fields' => [
1523 'email_feedback' => [
1524 'name' => 'email_feedback',
1525 'type' => 'toggle',
1526 'label' => __( 'Email Feedback', 'betterdocs' ),
1527 'enable_disable_text_active' => true,
1528 'default' => 1,
1529 'priority' => 1
1530 ],
1531 'feedback_link_text' => [
1532 'name' => 'feedback_link_text',
1533 'type' => 'text',
1534 'label' => __( 'Feedback Link Text', 'betterdocs' ),
1535 'default' => __( 'Still stuck? How can we help?', 'betterdocs' ),
1536 'priority' => 2,
1537 'rules' => Rules::is( 'email_feedback', true )
1538 ],
1539 'feedback_form_title' => [
1540 'name' => 'feedback_form_title',
1541 'type' => 'text',
1542 'label' => __( 'Feedback Form Title', 'betterdocs' ),
1543 'default' => __( 'Still stuck? How can we help?', 'betterdocs' ),
1544 'priority' => 3,
1545 'rules' => Rules::is( 'email_feedback', true )
1546 ],
1547 'email_address' => [
1548 'name' => 'email_address',
1549 'type' => 'text',
1550 'label' => __( 'Email Address', 'betterdocs' ),
1551 'default' => get_option( 'admin_email' ),
1552 'priority' => 4,
1553 'label_subtitle' => __( 'The email address where the Feedback form will be sent', 'betterdocs' ),
1554 'rules' => Rules::is( 'email_feedback', true )
1555 ],
1556 'feedback_url' => [
1557 'name' => 'feedback_url',
1558 'type' => 'text',
1559 'label' => __( 'Feedback URL', 'betterdocs' ),
1560 'default' => '',
1561 'priority' => 5,
1562 'rules' => Rules::is( 'email_feedback', true )
1563 ]
1564 ]
1565 ],
1566 [
1567 'id' => 'layout_single_doc_attachments',
1568 'name' => 'layout_single_doc_attachments',
1569 'type' => 'section',
1570 'label' => __( 'Attachments', 'betterdocs' ),
1571 'priority' => 6,
1572 'fields' => apply_filters( 'betterdocs_single_doc_attachments', [
1573 'show_attachment' => [
1574 'name' => 'show_attachment',
1575 'type' => 'toggle',
1576 'is_pro' => true,
1577 'priority' => 1,
1578 'label' => __( 'Show Attachment', 'betterdocs' ),
1579 'enable_disable_text_active' => true,
1580 'default' => false
1581 ]
1582 ] )
1583 ],
1584 [
1585 'id' => 'layout_single_doc_related_docs',
1586 'name' => 'layout_single_doc_related_docs',
1587 'type' => 'section',
1588 'label' => __( 'Related Docs', 'betterdocs' ),
1589 'priority' => 7,
1590 'fields' => apply_filters( 'betterdocs_single_doc_related_docs', [
1591 'show_related_docs' => [
1592 'name' => 'show_related_docs',
1593 'type' => 'toggle',
1594 'is_pro' => true,
1595 'priority' => 1,
1596 'label' => __( 'Show Related Docs', 'betterdocs' ),
1597 'enable_disable_text_active' => true,
1598 'default' => false
1599 ]
1600 ] )
1601 ]
1602 ]
1603 ]
1604 ]
1605 ] ),
1606 'layout_archive_page' => [
1607 'id' => 'layout_archive_page',
1608 'name' => 'layout_archive_page',
1609 'type' => 'section',
1610 'label' => __( 'Archive Page', 'betterdocs' ),
1611 'priority' => 3,
1612 'fields' => [
1613 'enable_archive_sidebar' => [
1614 'name' => 'enable_archive_sidebar',
1615 'type' => 'toggle',
1616 'label' => __( 'Sidebar Category List', 'betterdocs' ),
1617 'enable_disable_text_active' => true,
1618 'default' => 1,
1619 'priority' => 31
1620 ],
1621 'archive_nested_subcategory' => [
1622 'name' => 'archive_nested_subcategory',
1623 'type' => 'toggle',
1624 'label' => __( 'Nested Subcategory', 'betterdocs' ),
1625 'enable_disable_text_active' => true,
1626 'default' => 1,
1627 'priority' => 32
1628 ],
1629 'archive_enable_pagination' => [
1630 'name' => 'archive_enable_pagination',
1631 'type' => 'toggle',
1632 'label' => __( 'Enable Pagination', 'betterdocs' ),
1633 'enable_disable_text_active' => true,
1634 'default' => false,
1635 'priority' => 33
1636 ]
1637 ]
1638 ]
1639 ]
1640 ] )
1641 ]
1642 ]
1643 ]
1644 ] ),
1645 'tab-design' => apply_filters( 'betterdocs_settings_tab_design', [
1646 'id' => 'tab-design',
1647 'label' => __( 'Design', 'betterdocs' ),
1648 'priority' => 30,
1649 'fields' => [
1650 'title-design' => [
1651 'name' => 'title-design-tab',
1652 'type' => 'section',
1653 'label' => __( 'Design', 'betterdocs' ),
1654 'priority' => 30,
1655 'fields' => $this->design_tab()
1656 ]
1657 ]
1658 ] ),
1659 'tab-shortcodes' => apply_filters( 'betterdocs_settings_tab_shortcodes', [
1660 'label' => __( 'Shortcodes', 'betterdocs' ),
1661 'id' => 'tab-shortcodes',
1662 'classes' => 'tab-shortcodes',
1663 'priority' => 40,
1664 'fields' => [
1665 'title-shortcodes' => [
1666 'name' => 'title-shortcodes-tab',
1667 'type' => 'section',
1668 'label' => __( 'Shortcodes', 'betterdocs' ),
1669 'priority' => 40,
1670 'searchable' => true,
1671 'searchPlaceholder' => __( 'Search for shortcode', 'betterdocs' ),
1672 'searchNotFoundMessage' => '<img src="' . betterdocs()->assets->icon( 'not-found.svg', true ) . '"/><p>' . __( 'No Shortcodes Found with these keywords', 'betterdocs' ) . '</p>',
1673 'fields' => apply_filters( 'betterdocs_shortcode_fields', [
1674 'search_form' => [
1675 'name' => 'search_form',
1676 'type' => 'copy-to-clipboard',
1677 'label' => __( 'Search Form', 'betterdocs' ),
1678 'default' => '[betterdocs_search_form]',
1679 'readOnly' => true,
1680 'priority' => 1,
1681 'description' => __( '[betterdocs_search_form placeholder="Search..." heading="Heading" subheading="Subheading" category_search="true" search_button="true" popular_search="true"]', 'betterdocs' ),
1682 'descriptionLabel' => __( 'Example with parameters:', 'betterdocs' ),
1683 'descriptionCopyable' => true
1684 ],
1685 'feedback_form' => [
1686 'name' => 'feedback_form',
1687 'type' => 'copy-to-clipboard',
1688 'label' => __( 'Feedback Form', 'betterdocs' ),
1689 'default' => '[betterdocs_feedback_form]',
1690 'readOnly' => true,
1691 'priority' => 2,
1692 'description' => __( '[betterdocs_feedback_form button_text="Send"]', 'betterdocs' ),
1693 'descriptionLabel' => __( 'Example with parameters:', 'betterdocs' ),
1694 'descriptionCopyable' => true
1695 ],
1696 'category_grid' => [
1697 'name' => 'category_grid',
1698 'type' => 'copy-to-clipboard',
1699 'label' => __( 'Category Grid- Layout 1', 'betterdocs' ),
1700 'default' => '[betterdocs_category_grid]',
1701 'readOnly' => true,
1702 'priority' => 3,
1703 'description' => __( '[betterdocs_category_grid show_count="true" show_icon="true" masonry="true" column="3" posts_per_page="5" nested_subcategory="true" terms="term_ID, term_ID" terms_orderby="" terms_order="" multiple_knowledge_base="" kb_slug="" title_tag="h2" orderby="" order="" ]', 'betterdocs' ),
1704 'descriptionLabel' => __( 'Example with parameters:', 'betterdocs' ),
1705 'descriptionCopyable' => true
1706 ],
1707 'category_box' => [
1708 'name' => 'category_box',
1709 'type' => 'copy-to-clipboard',
1710 'label' => __( 'Category Box- Layout 2', 'betterdocs' ),
1711 'default' => '[betterdocs_category_box]',
1712 'readOnly' => true,
1713 'priority' => 4,
1714 'description' => __( '[betterdocs_category_box orderby="" column="" nested_subcategory="" terms="" terms_orderby="" show_icon="" kb_slug="" title_tag="h2" multiple_knowledge_base="false" border_bottom="false"]', 'betterdocs' ),
1715 'descriptionLabel' => __( 'Example with parameters:', 'betterdocs' ),
1716 'descriptionCopyable' => true
1717 ],
1718 'category_list' => [
1719 'name' => 'category_list',
1720 'type' => 'copy-to-clipboard',
1721 'label' => __( 'Category List', 'betterdocs' ),
1722 'default' => '[betterdocs_category_list]',
1723 'readOnly' => true,
1724 'priority' => 5,
1725 'description' => __( '[betterdocs_category_list orderby="" order="" posts_per_page="" nested_subcategory="" terms="" terms_orderby="" terms_order="" kb_slug="" multiple_knowledge_base="false" title_tag="h2"]', 'betterdocs' ),
1726 'descriptionLabel' => __( 'Example with parameters:', 'betterdocs' ),
1727 'descriptionCopyable' => true
1728 ],
1729 'faq_modern_layout' => [
1730 'name' => 'faq_modern_layout',
1731 'type' => 'copy-to-clipboard',
1732 'label' => __( 'FAQ Layout - 1', 'betterdocs' ),
1733 'default' => '[betterdocs_faq_list_modern]',
1734 'readOnly' => true,
1735 'priority' => 13,
1736 'description' => __( '[betterdocs_faq_list_modern groups="group_id" class="" group_exclude="group_id" faq_heading="Frequently Asked Questions"]', 'betterdocs' ),
1737 'descriptionLabel' => __( 'Example with parameters:', 'betterdocs' ),
1738 'descriptionCopyable' => true
1739 ],
1740 'faq_classic_layout' => [
1741 'name' => 'faq_classic_layout',
1742 'type' => 'copy-to-clipboard',
1743 'label' => __( 'FAQ Layout - 2', 'betterdocs' ),
1744 'default' => '[betterdocs_faq_list_classic]',
1745 'readOnly' => true,
1746 'priority' => 14,
1747 'description' => __( '[betterdocs_faq_list_classic groups="group_id" class="" group_exclude="group_id" faq_heading="Frequently Asked Questions"]', 'betterdocs' ),
1748 'descriptionLabel' => __( 'Example with parameters:', 'betterdocs' ),
1749 'descriptionCopyable' => true
1750 ],
1751 'betterdocs_faq_list_layout_3' => [
1752 'name' => 'betterdocs_faq_list_layout_3',
1753 'type' => 'copy-to-clipboard',
1754 'label' => __( 'FAQ Layout - 3', 'betterdocs' ),
1755 'default' => '[betterdocs_faq_list_layout_3 class="faq-doc betterdocs-faq-layout-3"]',
1756 'readOnly' => true,
1757 'priority' => 15,
1758 'description' => __( '[betterdocs_faq_list_layout_3 class="faq-doc betterdocs-faq-layout-3" groups="group_id" class="" group_exclude="group_id" faq_heading="Frequently Asked Questions"]', 'betterdocs' ),
1759 'descriptionLabel' => __( 'Example with parameters:', 'betterdocs' ),
1760 'descriptionCopyable' => true
1761 ],
1762 'betterdocs_faq_tab' => [
1763 'name' => 'betterdocs_faq_tab',
1764 'type' => 'copy-to-clipboard',
1765 'label' => __( 'FAQ Layout - 4', 'betterdocs' ),
1766 'default' => '[betterdocs_faq_tab class="faq-doc betterdocs-faq-layout-4"]',
1767 'readOnly' => true,
1768 'priority' => 16,
1769 'description' => __( '[betterdocs_faq_tab class="faq-doc betterdocs-faq-layout-4" groups="group_id" group_exclude="group_id" faq_heading="Frequently Asked Questions"]', 'betterdocs' ),
1770 'descriptionLabel' => __( 'Example with parameters:', 'betterdocs' ),
1771 'descriptionCopyable' => true
1772 ]
1773 ] )
1774 ]
1775 ]
1776 ] ),
1777 'tab-advance-settings' => apply_filters( 'betterdocs_settings_tab_advance', [
1778 'id' => 'tab-advance-settings',
1779 'label' => __( 'Access & Restrictions', 'betterdocs' ),
1780 'classes' => 'tab-layout',
1781 'priority' => 50,
1782 'fields' => [
1783 'title_advance_settings' => [
1784 'name' => 'title-advance-settings-tab',
1785 'type' => 'section',
1786 'label' => __( 'Access & Restrictions', 'betterdocs' ),
1787 'priority' => 50,
1788 'fields' => [
1789 'tab-advanced-settings' => [
1790 'id' => 'tab-advanced-settings',
1791 'name' => 'tab-advanced-settings',
1792 'label' => __( 'Access & Restrictions', 'betterdocs' ),
1793 'classes' => 'tab-layout',
1794 'type' => 'tab',
1795 'active' => 'global_role_management',
1796 'completionTrack' => true,
1797 'sidebar' => false,
1798 'save' => false,
1799 'title' => false,
1800 'config' => [
1801 'active' => '',
1802 'sidebar' => false,
1803 'title' => false
1804 ],
1805 'submit' => [
1806 'show' => false
1807 ],
1808 'step' => [
1809 'show' => false
1810 ],
1811 'priority' => 50,
1812 'fields' => [
1813 'global_role_management' => [
1814 'id' => 'global_role_management',
1815 'name' => 'global_role_management',
1816 'type' => 'section',
1817 'label' => __( 'Global Role Management', 'betterdocs' ),
1818 'priority' => 1,
1819 'fields' => [
1820 'article_roles' => [
1821 'name' => 'article_roles',
1822 'type' => 'checkbox-select',
1823 'label' => __( 'Who Can Write Docs?', 'betterdocs' ),
1824 'priority' => 1,
1825 'multiple' => true,
1826 'search' => true,
1827 'is_pro' => true,
1828 'default' => [ 'administrator' ],
1829 'options' => $wp_roles
1830 ],
1831 'settings_roles' => [
1832 'name' => 'settings_roles',
1833 'type' => 'checkbox-select',
1834 'label' => __( 'Who Can Edit Settings?', 'betterdocs' ),
1835 'priority' => 2,
1836 'multiple' => true,
1837 'is_pro' => true,
1838 'search' => true,
1839 'default' => [ 'administrator' ],
1840 'options' => $wp_roles
1841 ],
1842 'analytics_roles' => [
1843 'name' => 'analytics_roles',
1844 'type' => 'checkbox-select',
1845 'label' => __( 'Who Can Check Analytics?', 'betterdocs' ),
1846 'priority' => 3,
1847 'multiple' => true,
1848 'is_pro' => true,
1849 'search' => true,
1850 'default' => [ 'administrator' ],
1851 'options' => $wp_roles
1852 ],
1853 'faq_roles' => [
1854 'name' => 'faq_roles',
1855 'type' => 'checkbox-select',
1856 'label' => __( 'Who Can Check FAQ Builder?', 'betterdocs' ),
1857 'priority' => 4,
1858 'multiple' => true,
1859 'is_pro' => true,
1860 'search' => true,
1861 'default' => [ 'administrator' ],
1862 'options' => $wp_roles
1863 ],
1864
1865 ]
1866 ],
1867 'internal_knowledge_base' => [
1868 'id' => 'internal_knowledge_base',
1869 'name' => 'internal_knowledge_base',
1870 'type' => 'section',
1871 'label' => __('Internal Knowledge Base', 'betterdocs'),
1872 'priority' => 1,
1873 'fields' => apply_filters('betterdocs_settings_content_restriction_fields', [
1874 'enable_content_restriction' => [
1875 'name' => 'enable_content_restriction',
1876 'type' => 'toggle',
1877 'is_pro' => true,
1878 'priority' => 5,
1879 'label' => __( 'Internal Knowledge Base', 'betterdocs' ),
1880 'enable_disable_text_active' => true,
1881 'default' => [ 'all' ]
1882 ],
1883 'internal_knowledge_base_type' => [
1884 'name' => 'internal_knowledge_base_type',
1885 'type' => 'radio-card',
1886 'label' => __( 'Choose a Rule Type', 'betterdocs' ),
1887 'label_subtitle' => __( 'Choose a rule type: apply access globally (Basic), or configure detailed restrictions (Advanced) for docs, categories, and KBs.', 'betterdocs' ),
1888 'priority' => 6,
1889 'multiple' => true,
1890 'search' => true,
1891 'default' => [ 'all' ],
1892 'placeholder' => __( 'Select any', 'betterdocs' ),
1893 'options' => [
1894 [
1895 'label' => 'Basic',
1896 'value' => 'basic'
1897 ],
1898 [
1899 'label' => 'Advanced',
1900 'value' => 'advanced'
1901 ]
1902 ],
1903 'filterValue' => 'all',
1904 'rules' => Rules::is( 'enable_content_restriction', true )
1905 ],
1906 'content_visibility' => [
1907 'name' => 'content_visibility',
1908 'type' => 'checkbox-select',
1909 'label' => __( 'Restrict Access to', 'betterdocs' ),
1910 'label_subtitle' => __( 'Only selected User Roles will be able to view your Knowledge Base', 'betterdocs' ),
1911 'is_pro' => true,
1912 'priority' => 7,
1913 'multiple' => true,
1914 'search' => true,
1915 'default' => [ 'all' ],
1916 'placeholder' => __( 'Select any', 'betterdocs' ),
1917 'options' => $roles_for_ikb,
1918 'rules' => Rules::logicalRule(
1919 [
1920 Rules::is( 'enable_content_restriction', true ),
1921 Rules::is( 'internal_knowledge_base_type', 'basic' )
1922 ],
1923 'and'
1924 ),
1925 'filterValue' => 'all'
1926 ],
1927 'restrict_template' => [
1928 'name' => 'restrict_template',
1929 'type' => 'checkbox-select',
1930 'label' => __( 'Restriction on Docs', 'betterdocs' ),
1931 'label_subtitle' => __( 'Selected Docs pages will be restricted', 'betterdocs' ),
1932 'is_pro' => true,
1933 'priority' => 8,
1934 'multiple' => true,
1935 'search' => true,
1936 'default' => [ 'all' ],
1937 'placeholder' => __( 'Select any', 'betterdocs' ),
1938 'options' => $this->get_texanomy(),
1939 'rules' => Rules::logicalRule(
1940 [
1941 Rules::is( 'enable_content_restriction', true ),
1942 Rules::is( 'internal_knowledge_base_type', 'basic' )
1943 ],
1944 'and'
1945 ),
1946 'filterValue' => 'all'
1947 ],
1948 'restrict_category' => [
1949 'name' => 'restrict_category',
1950 'type' => 'checkbox-select',
1951 'label' => __( 'Restriction on Docs Categories', 'betterdocs' ),
1952 'label_subtitle' => __( 'Selected Docs categories will be restricted', 'betterdocs' ),
1953 'is_pro' => true,
1954 'priority' => 9,
1955 'multiple' => true,
1956 'search' => true,
1957 'default' => [ 'all' ],
1958 'placeholder' => __( 'Select any', 'betterdocs' ),
1959 'options' => $this->get_terms( 'doc_category' ),
1960 'rules' => Rules::logicalRule(
1961 [
1962 Rules::is( 'enable_content_restriction', true ),
1963 Rules::is( 'internal_knowledge_base_type', 'basic' )
1964 ],
1965 'and'
1966 ),
1967 'filterValue' => 'all'
1968 ],
1969 'restricted_redirect_url' => [
1970 'name' => 'restricted_redirect_url',
1971 'type' => 'text',
1972 'label' => __( 'Redirect URL', 'betterdocs' ),
1973 'label_subtitle' => __( 'Set a custom URL to redirect users without permissions when they try to access internal knowledge base. By default, restricted content will redirect to the "404 not found" page', 'betterdocs' ),
1974 'default' => '',
1975 'placeholder' => 'https://',
1976 'is_pro' => true,
1977 'priority' => 20,
1978 'rules' => Rules::logicalRule(
1979 [
1980 Rules::is( 'enable_content_restriction', true ),
1981 ],
1982 'and'
1983 )
1984 ]
1985 ] )
1986 ]
1987 ]
1988 ]
1989 ]
1990 ]
1991 ]
1992 ] ),
1993 'tab-email-reporting' => apply_filters( 'betterdocs_settings_tab_email_reporting', [
1994 'id' => 'tab-email-reporting',
1995 'label' => __( 'Email Reporting', 'betterdocs' ),
1996 'priority' => 60,
1997 'fields' => [
1998 'title-email-reporting' => [
1999 'name' => 'title-email-reporting-tab',
2000 'type' => 'section',
2001 'label' => __( 'Email Reporting', 'betterdocs' ),
2002 'priority' => 60,
2003 'fields' => [
2004 'enable_reporting' => [
2005 'name' => 'enable_reporting',
2006 'label' => __( 'Email Reporting', 'betterdocs' ),
2007 'enable_disable_text_active' => true,
2008 'type' => 'toggle',
2009 'priority' => 1,
2010 'default' => 0
2011 ],
2012 'reporting_frequency' => apply_filters( 'betterdocs_reporting_frequency_settings', [
2013 'name' => 'reporting_frequency',
2014 'type' => 'select',
2015 'label' => __( 'Reporting Frequency', 'betterdocs' ),
2016 'default' => 'betterdocs_weekly',
2017 'priority' => 2,
2018 'is_pro' => true,
2019 'options' => $this->normalize_options( [
2020 'betterdocs_daily' => __( 'Once Daily', 'betterdocs' ),
2021 'betterdocs_weekly' => __( 'Once Weekly', 'betterdocs' ),
2022 'betterdocs_monthly' => __( 'Once Monthly', 'betterdocs' )
2023 ] ),
2024 'rules' => Rules::is( 'enable_reporting', true )
2025 ] ),
2026 'reporting_day' => [
2027 'name' => 'reporting_day',
2028 'type' => 'select',
2029 'label' => __( 'Reporting Day', 'betterdocs' ),
2030 'default' => 'monday',
2031 'rules' => Rules::logicalRule( [
2032 Rules::is( 'enable_reporting', true ),
2033 Rules::is( 'reporting_frequency', 'betterdocs_weekly' )
2034 ], 'and' ),
2035 'priority' => 3,
2036 'options' => $this->normalize_options( [
2037 'sunday' => __( 'Sunday', 'betterdocs' ),
2038 'monday' => __( 'Monday', 'betterdocs' ),
2039 'tuesday' => __( 'Tuesday', 'betterdocs' ),
2040 'wednesday' => __( 'Wednesday', 'betterdocs' ),
2041 'thursday' => __( 'Thursday', 'betterdocs' ),
2042 'friday' => __( 'Friday', 'betterdocs' ),
2043 'saturday' => __( 'Saturday', 'betterdocs' )
2044 ] ),
2045 'label_subtitle' => __( 'This is only applicable for the “Weekly” report', 'betterdocs' )
2046 ],
2047 'select_reporting_data' => apply_filters( 'betterdocs_select_reporting_data_settings', [
2048 'name' => 'select_reporting_data',
2049 'type' => 'checkbox-select',
2050 'label' => __( 'Select Reporting Data', 'betterdocs' ),
2051 'priority' => 4,
2052 'multiple' => true,
2053 'options' => $this->normalize_options( [
2054 'overview' => 'Overview',
2055 'top-docs' => 'Top Docs',
2056 'most-search' => 'Most Searched Keywords'
2057 ] ),
2058 'default' => [ 'overview', 'top-docs', 'most-search' ],
2059 'is_pro' => true,
2060 'rules' => Rules::is( 'enable_reporting', true )
2061 ] ),
2062 'reporting_email' => [
2063 'name' => 'reporting_email',
2064 'type' => 'text',
2065 'label' => __( 'Reporting Email', 'betterdocs' ),
2066 'default' => get_option( 'admin_email' ),
2067 'priority' => 5,
2068 'rules' => Rules::is( 'enable_reporting', true )
2069 ],
2070 'reporting_subject' => apply_filters( 'betterdocs_reporting_subject_settings', [
2071 'name' => 'reporting_subject',
2072 'type' => 'textarea',
2073 'label' => __( 'Reporting Email Subject', 'betterdocs' ),
2074 'default' => wp_sprintf( // Translators: %s is replaced with the website name.
2075 __( 'Your Documentation Performance of %s Website', 'betterdocs' ), get_bloginfo( 'name' ) ),
2076 'priority' => 6,
2077 'is_pro' => true,
2078 'rules' => Rules::is( 'enable_reporting', true )
2079 ] ),
2080 'test_report' => [
2081 'name' => 'test_report',
2082 'label' => __( 'Reporting Test', 'betterdocs' ),
2083 'text' => __( 'Test Report', 'betterdocs' ),
2084 'type' => 'button',
2085 'priority' => 7,
2086 'rules' => Rules::is( 'enable_reporting', true ),
2087 'ajax' => [
2088 'on' => 'click',
2089 'api' => '/betterdocs/v1/reporting-test',
2090 'data' => [
2091 'enable_reporting' => '@enable_reporting',
2092 'select_reporting_data' => '@select_reporting_data',
2093 'reporting_subject' => '@reporting_subject',
2094 'reporting_email' => '@reporting_email',
2095 'reporting_day' => '@reporting_day',
2096 'reporting_frequency' => '@reporting_frequency'
2097 ],
2098 'swal' => [
2099 'text' => __( 'Successfully Sent a Test Report in Your Email.', 'betterdocs' ),
2100 'icon' => 'success',
2101 'autoClose' => 2000
2102 ]
2103 ]
2104 ]
2105 ]
2106 ]
2107 ]
2108 ] ),
2109 'tab-github-integration' => apply_filters( 'betterdocs_settings_tab_github_integration', [
2110 'id' => 'tab-github-integration',
2111 'label' => __( 'Git Sync', 'betterdocs' ),
2112 'priority' => 60,
2113 'fields' => [
2114 'title-git-integration' => [
2115 'name' => 'title-git-integration-tab',
2116 'type' => 'section',
2117 'label' => __( 'Git Sync Settings', 'betterdocs' ),
2118 'priority' => 60,
2119 'fields' => [
2120 'enable_git_integration' => [
2121 'name' => 'enable_git_integration',
2122 'type' => 'toggle',
2123 'label' => __( 'Enable Git Sync', 'betterdocs' ),
2124 'enable_disable_text_active' => true,
2125 'default' => false,
2126 'priority' => 1,
2127 'is_pro' => true,
2128 'label_subtitle' => __( 'Enable bidirectional synchronization between BetterDocs and Git repositories', 'betterdocs' )
2129 ]
2130 ]
2131 ]
2132 ]
2133 ] ),
2134 'tab-instant-answer' => apply_filters( 'betterdocs_settings_tab_instant_answer', [
2135 'id' => 'tab-instant-answer',
2136 'name' => 'tab-instant-answer',
2137 'type' => 'section',
2138 'label' => __( 'Instant Answer', 'betterdocs' ),
2139 'save' => false,
2140 'priority' => 70,
2141 'fields' => [
2142 'title-instant-answer' => [
2143 'name' => 'title-instant-answer-tab',
2144 'type' => 'section',
2145 'label' => __( 'Instant Answer', 'betterdocs' ),
2146 'priority' => 80,
2147 'save' => false,
2148 'showSubmit' => false,
2149 'fields' => apply_filters( 'betterdocs_instant_answer_fields', [
2150 'enable_disable_wrapper' => [
2151 'name' => 'enable_disable_wrapper',
2152 'type' => 'section',
2153 'priority' => 0,
2154 'save' => false,
2155 'fields' => [
2156 'enable_disable' => [
2157 'name' => 'enable_disable',
2158 'type' => 'toggle',
2159 'priority' => 100,
2160 'description' => __( 'Enable Instant Answer', 'betterdocs' ),
2161 'enable_disable_text_active' => false,
2162 'default' => false,
2163 'is_pro' => true
2164 ]
2165 ]
2166 ]
2167 ] )
2168 ]
2169 ]
2170 ] ),
2171 'tab-betterdocs-ai' => [
2172 'id' => 'tab-betterdocs-ai',
2173 'name' => 'tab-betterdocs-ai',
2174 'type' => 'section',
2175 'label' => __( 'AI Content Suite', 'betterdocs' ),
2176 'priority' => 74,
2177 'fields' => [
2178 'sections-betterdocs-ai' => [
2179 'name' => 'sections-betterdocs-ai',
2180 'type' => 'section',
2181 'label' => __( 'AI Content Suite', 'betterdocs' ),
2182 'priority' => 10,
2183 'fields' => [
2184 'all-betterdocs-ai' => [
2185 'id' => 'all-tab-betterdocs-ai',
2186 'name' => 'all-tab-betterdocs-ai',
2187 'label' => __( 'AI Content Suite Settings', 'betterdocs' ),
2188 'classes' => 'tab-layout',
2189 'type' => 'tab',
2190 'active' => 'open-ai-settings',
2191 'completionTrack' => true,
2192 'sidebar' => false,
2193 'save' => false,
2194 'title' => false,
2195 'config' => [
2196 'active' => 'open-ai-settings',
2197 'sidebar' => false,
2198 'title' => false
2199 ],
2200 'submit' => [
2201 'show' => false
2202 ],
2203 'step' => [
2204 'show' => false
2205 ],
2206 'priority' => 20,
2207 'fields' => apply_filters(
2208 'betterdocs_migration_tab_sections',
2209 [
2210 'open-ai-settings' => [
2211 'id' => 'open-ai-settings',
2212 'name' => 'open-ai-settings',
2213 'type' => 'section',
2214 'label' => __( 'API Settings', 'betterdocs' ),
2215 'priority' => 1,
2216 'fields' => [
2217 'ai_autowrite_api_key' => [
2218 'name' => 'ai_autowrite_api_key',
2219 'type' => 'text',
2220 'label' => __( 'API Key', 'betterdocs' ),
2221 'label_subtitle' => sprintf( /* translators: %s is a link to the documentation about generating an OpenAI API key. */ __( 'Check out this <a target="_blank" href="%s">documentation</a> to find out how to generate your OpenAI API Key.', 'betterdocs' ), esc_url( 'https://betterdocs.co/docs/write-with-ai/' ) ),
2222 'default' => '',
2223 'priority' => 1
2224 ],
2225 ]
2226 ],
2227 'write-with-ai' => [
2228 'id' => 'write-with-ai',
2229 'name' => 'write-with-ai',
2230 'type' => 'section',
2231 'label' => __( 'Write with AI', 'betterdocs' ),
2232 'priority' => 5,
2233 'fields' => [
2234 'enable_write_with_ai' => [
2235 'name' => 'enable_write_with_ai',
2236 'type' => 'toggle',
2237 'priority' => 0,
2238 'label' => __( 'Write Docs with AI', 'betterdocs' ),
2239 'label_subtitle' => __( 'Generate AI based Documentation in your Gutenberg Editor', 'betterdocs' ),
2240 'enable_disable_text_active' => true,
2241 'default' => true
2242 ],
2243 'enable_faq_write_with_ai' => [
2244 'name' => 'enable_faq_write_with_ai',
2245 'type' => 'toggle',
2246 'priority' => 5,
2247 'label' => __( 'Write FAQ with AI', 'betterdocs' ),
2248 'label_subtitle' => __( 'Generate AI based FAQ in your Editor', 'betterdocs' ),
2249 'enable_disable_text_active' => true,
2250 'default' => true
2251 ],
2252 'write_with_ai_model' => [
2253 'name' => 'write_with_ai_model',
2254 'type' => 'select',
2255 'label' => __( 'OpenAI Model*', 'betterdocs' ),
2256 'priority' => 20,
2257 'multiple' => false,
2258 'default' => 'gpt-4o-mini',
2259 'options' => GlobalFields::normalize_fields( [
2260 'gpt-4o-mini' => 'GPT-4o Mini',
2261 'gpt-4o' => 'GPT-4o',
2262 ] ),
2263 ],
2264 'ai_autowrite_max_token' => [
2265 'name' => 'ai_autowrite_max_token',
2266 'type' => 'number',
2267 'label' => __( 'Set Max Tokens', 'betterdocs' ),
2268 'label_subtitle' => sprintf( // translators: %s is a link to more information about token limits.
2269 __( 'Documentation will be generated based on the Token Limits you have set. For more information on Token Limits, you can check out this <a target="_blank" href="%s">link</a>.', 'betterdocs' ), esc_url( 'https://platform.openai.com/account/limits' ) ),
2270 'default' => 1500,
2271 'priority' => 10
2272 ],
2273 ]
2274 ],
2275 'article-summary' => [
2276 'id' => 'article-summary',
2277 'name' => 'article-summary',
2278 'type' => 'section',
2279 'label' => __( 'AI Doc Summarizer', 'betterdocs' ),
2280 'priority' => 10,
2281 'fields' => [
2282 'enable_article_summary' => [
2283 'name' => 'enable_article_summary',
2284 'type' => 'toggle',
2285 'priority' => 1,
2286 'label' => __( 'AI Powered Doc Summarizer', 'betterdocs' ),
2287 'label_subtitle' => __( 'Enable AI-powered article summaries on single doc pages. Requires OpenAI API key.', 'betterdocs' ),
2288 'enable_disable_text_active' => true,
2289 'default' => false
2290 ],
2291 'article_summary_max_token' => [
2292 'name' => 'article_summary_max_token',
2293 'type' => 'number',
2294 'label' => __( 'Set Max Tokens', 'betterdocs' ),
2295 'label_subtitle' => sprintf( // translators: %s is a link to more information about token limits.
2296 __( 'Single Doc summarizer will be generated based on the token limits you have set. For more information on Token Limits, you can check out this <a target="_blank" href="%s">link</a>.', 'betterdocs' ), esc_url( 'https://platform.openai.com/account/limits' ) ),
2297 'default' => 1500,
2298 'priority' => 5
2299 ],
2300 'article_summary_model' => [
2301 'name' => 'article_summary_model',
2302 'type' => 'select',
2303 'label' => __( 'OpenAI Model*', 'betterdocs' ),
2304 'priority' => 10,
2305 'multiple' => false,
2306 'default' => 'gpt-4o-mini',
2307 'options' => GlobalFields::normalize_fields( [
2308 'gpt-4o-mini' => 'GPT-4o Mini',
2309 'gpt-4o' => 'GPT-4o',
2310 ] ),
2311 ],
2312 ]
2313 ],
2314 ]
2315 )
2316 ]
2317 ]
2318 ]
2319 ],
2320 ],
2321 'tab-ai-chatbot' => apply_filters( 'betterdocs_settings_tab_ai_chatbot', [
2322 'id' => 'tab-ai-chatbot',
2323 'name' => 'tab-ai-chatbot',
2324 'type' => 'section',
2325 'label' => __( 'AI Chatbot', 'betterdocs' ),
2326 'submit' => [
2327 'show' => false
2328 ],
2329 'save' => false,
2330 'priority' => 75,
2331 'fields' => [
2332 'title-ai-chatbot-tab' => [
2333 'name' => 'title-ai-chatbot-tab',
2334 'type' => 'section',
2335 'label' => __( 'AI Chatbot', 'betterdocs' ),
2336 'priority' => 80,
2337 'submit' => [
2338 'show' => false
2339 ],
2340 'save' => false,
2341 'fields' => apply_filters( 'betterdocs_ai_chatbot_fields', [
2342 'ai_chatbot_fields' => [
2343 'name' => 'ai_chatbot_fields',
2344 'type' => 'section',
2345 'priority' => 0,
2346 'fields' => [
2347 'enable_ai_chatbot' => [
2348 'name' => 'enable_ai_chatbot',
2349 'label' => __( 'AI Chatbot', 'betterdocs' ),
2350 'description' => __( 'Enable AI Chatbot', 'betterdocs' ),
2351 'type' => 'toggle',
2352 'priority' => 5,
2353 'default' => 0,
2354 'is_pro' => true,
2355 'is_license_active' => false,
2356 'disabled' => ! betterdocs()->is_pro_active() || ! defined( 'BETTERDOCS_CHATBOT_FILE' )
2357 ],
2358 ]
2359 ]
2360 ] )
2361 ]
2362 ]
2363 ] ),
2364 ] ),
2365 'TAB_AI_CHATBOT' => get_option( 'enable_ai_chatbot' ),
2366 'CHATBOT_LICENSE' => get_option( 'betterdocs_chatbot_software__license_status' ),
2367 'PRO_ACTIVE' => is_plugin_active( 'betterdocs-pro/betterdocs-pro.php' ),
2368 'PRO_LICENSE' => get_option( 'betterdocs_pro_software__license_status' ),
2369 ];
2370
2371 $settings = array_merge( $settings, $this->chatbot_active_localize() );
2372
2373 return apply_filters( 'betterdocs_settings_args', $settings );
2374 }
2375
2376 /**
2377 * @return array
2378 */
2379 public function chatbot_active_localize() {
2380 $chatbot_active = is_plugin_active( 'betterdocs-ai-chatbot/betterdocs-ai-chatbot.php' );
2381 $chatbot_license_valid = get_option( 'betterdocs_chatbot_software__license_status' ) === 'valid';
2382 $chatbot_enabled = $this->get( 'enable_ai_chatbot', false );
2383
2384 // AI Search Suggestions are enabled if all conditions are met
2385 $ai_search_suggestions_enabled = betterdocs()->helper->is_ai_chatbot_enabled();
2386
2387 return [
2388 'CHATBOT_ACTIVE' => $chatbot_active,
2389 'CHATBOT_LICENSE_VALID' => $chatbot_license_valid,
2390 'CHATBOT_ENABLED' => $chatbot_enabled,
2391 'AI_SEARCH_SUGGESTIONS_ENABLED' => $ai_search_suggestions_enabled
2392 ];
2393 }
2394
2395 /**
2396 * Call This Function As Helper, When Pro Is Deactivated, To Be Used As Settings Default Values, When Betterdocs Pro Is Deactivated
2397 *
2398 * @return array
2399 */
2400 public function pro_settings_default_values() {
2401 return [
2402 'multiple_kb' => false,
2403 'enable_glossaries' => false,
2404 'enable_encyclopedia' => false,
2405 'analytics_from' => false,
2406 'unique_visitor_count' => false,
2407 'exclude_bot_analytics' => false,
2408 'show_attachment' => false,
2409 'show_related_docs' => false,
2410 'advance_search' => false,
2411 'child_category_exclude' => false,
2412 'kb_based_search' => false,
2413 'enable_disable' => false,
2414 'enable_content_restriction' => false
2415 ];
2416 }
2417
2418 public function import_export_settings( $settings ) {
2419 if ( ! current_user_can( 'import' ) ) {
2420 return $settings;
2421 }
2422
2423 $settings['tab-import-export'] = apply_filters( 'betterdocs_settings_tab_import_export', [
2424 'id' => 'tab-import-export',
2425 'name' => 'tab-import-export',
2426 'classes' => 'tab-import-export',
2427 'label' => __( 'Import / Export', 'betterdocs' ),
2428 'priority' => 80,
2429 'fields' => [
2430 'sections-import-export' => [
2431 'name' => 'sections-import-export',
2432 'type' => 'section',
2433 'label' => __( 'Import / Export', 'betterdocs' ),
2434 'priority' => 30,
2435 'fields' => [
2436 'all-tab-import-export' => [
2437 'id' => 'all-tab-import-export',
2438 'name' => 'all-tab-import-export',
2439 'label' => __( 'Import Export Settings', 'betterdocs' ),
2440 'classes' => 'tab-layout',
2441 'type' => 'tab',
2442 'active' => 'import',
2443 'completionTrack' => true,
2444 'sidebar' => false,
2445 'save' => false,
2446 'title' => false,
2447 'config' => [
2448 'active' => 'import',
2449 'sidebar' => false,
2450 'title' => false
2451 ],
2452 'submit' => [
2453 'show' => false
2454 ],
2455 'step' => [
2456 'show' => false
2457 ],
2458 'priority' => 20,
2459 'fields' => [
2460 'import' => [
2461 'id' => 'import',
2462 'name' => 'import',
2463 'type' => 'section',
2464 'label' => __( 'Import', 'betterdocs' ),
2465 'priority' => 1,
2466 'fields' => [
2467 'import_tab_nested' => [
2468 'id' => 'import_tab_nested',
2469 'name' => 'import_tab_nested',
2470 'label' => __( 'Import', 'betterdocs' ),
2471 'classes' => 'tab-nested-layout',
2472 'type' => 'tab',
2473 'active' => 'import_docs_nested',
2474 'completionTrack' => true,
2475 'sidebar' => false,
2476 'save' => false,
2477 'title' => false,
2478 'config' => [
2479 'active' => 'import_docs_nested',
2480 'sidebar' => false,
2481 'title' => false
2482 ],
2483 'submit' => [
2484 'show' => false
2485 ],
2486 'step' => [
2487 'show' => false
2488 ],
2489 'priority' => 1,
2490 'fields' => [
2491 'import_docs_nested' => [
2492 'id' => 'import_docs_nested',
2493 'name' => 'import_docs_nested',
2494 'type' => 'section',
2495 'label' => __( 'Import Docs', 'betterdocs' ),
2496 'priority' => 1,
2497 'fields' => [
2498 'import_docs' => [
2499 'name' => 'import_docs',
2500 'type' => 'importerupload',
2501 'label' => __( 'Import Docs', 'betterdocs' ),
2502 'label_subtitle' => wp_sprintf( // Translators: %1$s is a link to download a sample CSV file.
2503 __( 'To import your Docs, please upload the .xml / .csv file here. <a href="%1$s">Download sample csv file</a>', 'betterdocs' ), betterdocs()->assets->icon( 'BetterDocs-sample-data.csv', true ) ),
2504 'text' => [
2505 'normal' => __( 'Proceed', 'betterdocs' ),
2506 'saved' => __( 'Proceed', 'betterdocs' ),
2507 'loading' => __( 'Importing...', 'betterdocs' ),
2508 'exists_notice' => __( 'It seems like documentations with same slugs already exist on your website. What would you like to do?', 'betterdocs' )
2509 ],
2510 'ajax' => [
2511 'on' => 'click',
2512 'api' => '/betterdocs/v1/import-docs',
2513 'swal' => [
2514 'text' => __( 'Import completed successfully.', 'betterdocs' ),
2515 'icon' => 'success',
2516 'autoClose' => 2000
2517 ]
2518 ],
2519 'file_type' => '.xml, .csv',
2520 'priority' => 1
2521 ]
2522 ]
2523 ],
2524
2525 'import_settings_nested' => [
2526 'id' => 'import_settings_nested',
2527 'name' => 'import_settings_nested',
2528 'type' => 'section',
2529 'label' => __( 'Import Settings', 'betterdocs' ),
2530 'priority' => 1,
2531 'fields' => [
2532 'settings_importer' => [
2533 'name' => 'settings_importer',
2534 'type' => 'settingsuploader',
2535 'label' => __( 'Import Settings', 'betterdocs' ),
2536 'label_subtitle' => __( 'To import BetterDocs Settings, please upload BetterDocs settings you have exported from another website in .json format', 'betterdocs' ),
2537 'reset' => __( 'Change', 'betterdocs' ),
2538 'priority' => 1
2539 ],
2540 'import_settings' => [
2541 'name' => 'import_settings',
2542 'type' => 'button',
2543 'rules' => Rules::is( 'settings_importer', null, true ),
2544 'text' => [
2545 'normal' => __( 'Proceed', 'betterdocs' ),
2546 'saved' => __( 'Proceed', 'betterdocs' ),
2547 'loading' => __( 'Importing...', 'betterdocs' )
2548 ],
2549 'ajax' => [
2550 'on' => 'click',
2551 'api' => '/betterdocs/v1/import-settings',
2552 'data' => [
2553 'settings' => '@settings_importer'
2554 ],
2555 'swal' => [
2556 'text' => __( 'Import completed successfully.', 'betterdocs' ),
2557 'icon' => 'success',
2558 'autoClose' => 1000
2559 ],
2560 'reload' => true
2561 ],
2562 'priority' => 2
2563 ]
2564 ]
2565 ]
2566 ]
2567 ]
2568 ]
2569 ],
2570 'export' => [
2571 'id' => 'export',
2572 'name' => 'export',
2573 'type' => 'section',
2574 'label' => __( 'Export', 'betterdocs' ),
2575 'priority' => 1,
2576 'fields' => [
2577 'export_tab_nested' => [
2578 'id' => 'export_tab_nested',
2579 'name' => 'export_tab_nested',
2580 'label' => __( 'Export', 'betterdocs' ),
2581 'classes' => 'tab-nested-layout',
2582 'type' => 'tab',
2583 'active' => 'export_docs_nested',
2584 'completionTrack' => true,
2585 'sidebar' => false,
2586 'save' => false,
2587 'title' => false,
2588 'config' => [
2589 'active' => 'export_docs_nested',
2590 'sidebar' => false,
2591 'title' => false
2592 ],
2593 'submit' => [
2594 'show' => false
2595 ],
2596 'step' => [
2597 'show' => false
2598 ],
2599 'priority' => 1,
2600 'fields' => [
2601 'export_docs_nested' => [
2602 'id' => 'export_docs_nested',
2603 'name' => 'export_docs_nested',
2604 'type' => 'section',
2605 'label' => __( 'Export Docs', 'betterdocs' ),
2606 'priority' => 1,
2607 'fields' => apply_filters( 'betterdocs_export_fields', [
2608 'export_type' => [
2609 'name' => 'export_type',
2610 'label' => __( 'Select Docs Type', 'betterdocs' ),
2611 'label_subtitle' => __( 'Choose an export type: All Docs, a specific Knowledge Base, or a Doc Category', 'betterdocs' ),
2612 'type' => 'select',
2613 'default' => 'docs',
2614 'priority' => 3,
2615 'search' => true,
2616 'options' => $this->normalize_options( apply_filters( 'betterdocs_export_type_options', [
2617 'docs' => __( 'Docs', 'betterdocs' ),
2618 'doc_category' => __( 'Docs Category', 'betterdocs' ),
2619 'glossaries' => __( 'Glossaries', 'betterdocs' )
2620 ] ) )
2621 ],
2622 'export_docs' => [
2623 'name' => 'export_docs',
2624 'type' => 'checkbox-select',
2625 'label' => __( 'Select Docs', 'betterdocs' ),
2626 'label_subtitle' => __( 'Selected docs will be included in the export.', 'betterdocs' ),
2627 'priority' => 4,
2628 'multiple' => true,
2629 'search' => true,
2630 'default' => [ 'all' ],
2631 'placeholder' => __( 'Select any', 'betterdocs' ),
2632 'options' => array_merge( [
2633 [
2634 'value' => 'all',
2635 'label' => 'All'
2636 ]
2637 ], $this->docs() ),
2638 'filterValue' => 'all',
2639 'rules' => Rules::is( 'export_type', 'docs' )
2640 ],
2641 'export_categories' => [
2642 'name' => 'export_categories',
2643 'type' => 'checkbox-select',
2644 'label' => __( 'Select Categories', 'betterdocs' ),
2645 'label_subtitle' => __( 'Selected categories and its docs will be included in the export.', 'betterdocs' ),
2646 'priority' => 6,
2647 'multiple' => true,
2648 'search' => true,
2649 'default' => [ 'all' ],
2650 'placeholder' => __( 'Select any', 'betterdocs' ),
2651 'options' => $this->get_terms( 'doc_category', false ),
2652 'filterValue' => 'all',
2653 'rules' => Rules::is( 'export_type', 'doc_category' )
2654 ],
2655 'export_glossaries' => [
2656 'name' => 'export_glossaries',
2657 'type' => 'checkbox-select',
2658 'label' => __( 'Select Glossaries', 'betterdocs' ),
2659 'label_subtitle' => __( 'Selected glossary terms will be exported.', 'betterdocs' ),
2660 'priority' => 7,
2661 'multiple' => true,
2662 'search' => true,
2663 'default' => [ 'all' ],
2664 'placeholder' => __( 'Select any', 'betterdocs' ),
2665 'options' => $this->get_terms( 'glossaries' ),
2666 'filterValue' => 'all',
2667 'rules' => Rules::is( 'export_type', 'glossaries' )
2668 ],
2669 'file_type' => [
2670 'name' => 'file_type',
2671 'label' => __( 'Select File Type', 'betterdocs' ),
2672 'label_subtitle' => __( 'Choose a file type', 'betterdocs' ),
2673 'type' => 'select',
2674 'default' => 'xml',
2675 'priority' => 8,
2676 'search' => true,
2677 'options' => $this->normalize_options( apply_filters( 'betterdocs_export_file_type_options', [
2678 'xml' => __( '.xml', 'betterdocs' ),
2679 'csv' => __( '.csv', 'betterdocs' )
2680 ] ) )
2681 ],
2682 'enable_export_faq' => [
2683 'name' => 'enable_export_faq',
2684 'type' => 'toggle',
2685 'priority' => 9,
2686 'label' => __( 'Export FAQ', 'betterdocs' ),
2687 'label_subtitle' => __( 'Export FAQ Related Terms & Posts', 'betterdocs' ),
2688 'enable_disable_text_active' => true,
2689 'default' => true,
2690 'rules' => Rules::is( 'export_type', 'glossaries', true )
2691 ],
2692 'export_docs_btn' => [
2693 'name' => 'export_docs_btn',
2694 'text' => [
2695 'normal' => __( 'Proceed', 'betterdocs' ),
2696 'saved' => __( 'Proceed', 'betterdocs' ),
2697 'loading' => __( 'Exporting...', 'betterdocs' )
2698 ],
2699 'type' => 'button',
2700 'priority' => 10,
2701 'ajax' => [
2702 'on' => 'click',
2703 'api' => '/betterdocs/v1/export-docs',
2704 'data' => [
2705 'export_type' => '@export_type',
2706 'export_docs' => '@export_docs',
2707 'export_kbs' => '@export_kbs',
2708 'export_categories' => '@export_categories',
2709 'export_glossaries' => '@export_glossaries',
2710 'file_type' => '@file_type',
2711 'enable_export_faq' => '@enable_export_faq'
2712 ],
2713 'swal' => [
2714 'text' => __( 'Exported Successfully.', 'betterdocs' ),
2715 'icon' => 'success',
2716 'autoClose' => 2000
2717 ]
2718 ]
2719 ]
2720 ] )
2721 ],
2722
2723 'export_settings_nested' => [
2724 'id' => 'export_settings_nested',
2725 'name' => 'export_settings_nested',
2726 'type' => 'section',
2727 'label' => __( 'Export Settings', 'betterdocs' ),
2728 'priority' => 1,
2729 'fields' => [
2730 'export_settings' => [
2731 'name' => 'export_settings',
2732 'label' => __( 'Export Settings', 'betterdocs' ),
2733 'label_subtitle' => __( 'Simply click on “Export Settings” button to download your BetterDocs settings in .json format', 'betterdocs' ),
2734 'text' => [
2735 'normal' => __( 'Export Settings', 'betterdocs' ),
2736 'saved' => __( 'Export Settings', 'betterdocs' ),
2737 'loading' => __( 'Exporting...', 'betterdocs' )
2738 ],
2739 'type' => 'button',
2740 'priority' => 8,
2741 'ajax' => [
2742 'on' => 'click',
2743 'api' => '/betterdocs/v1/export-settings',
2744 'data' => [
2745 'betterdocs_settings' => get_option( 'betterdocs_settings' )
2746 ],
2747 'swal' => [
2748 'text' => __( 'File downloaded successfully.', 'betterdocs' ),
2749 'icon' => 'success',
2750 'autoClose' => 2000
2751 ]
2752 ]
2753 ]
2754 ]
2755 ]
2756 ]
2757 ]
2758 ]
2759 ]
2760 ]
2761 ]
2762 ]
2763 ]
2764 ]
2765 ] );
2766
2767 return $settings;
2768 }
2769
2770 public function maybe_remove_git_tab( $tabs ) {
2771 $pro_active = is_plugin_active( 'betterdocs-pro/betterdocs-pro.php' );
2772 $pro_has_git = apply_filters( 'betterdocs_pro_has_git_integration', false );
2773
2774 if ( $pro_active && ! $pro_has_git ) {
2775 unset( $tabs['tab-github-integration'] );
2776 }
2777
2778 return $tabs;
2779 }
2780
2781 public function normalize_options( $options ) {
2782 return GlobalFields::normalize_fields( $options );
2783 }
2784
2785 public function get_texanomy() {
2786 $docs_tax = $this->database->get_cache( 'betterdocs::settings::taxonomies' );
2787
2788 if ( $docs_tax ) {
2789 return $docs_tax;
2790 }
2791
2792 $taxonomies = get_taxonomies( [
2793 'object_type' => [ 'docs' ]
2794 ], 'objects' );
2795
2796 $docs_tax = [
2797 'all' => 'All Docs Archive',
2798 'docs' => 'Docs Page'
2799 ];
2800 foreach ( $taxonomies as $key => $value ) {
2801 $docs_tax[ $key ] = $value->label;
2802 }
2803 unset( $docs_tax['doc_tag'] );
2804
2805 $docs_tax = $this->normalize_options( $docs_tax );
2806 if ( count( $docs_tax ) > 2 ) {
2807 $this->database->set_cache( 'betterdocs::settings::taxonomies', $docs_tax );
2808 }
2809
2810 return $docs_tax;
2811 }
2812
2813 public function get_terms( $taxonomy, $hide_empty = true ) {
2814 $_cache_key = 'betterdocs::settings::terms::' . trim( $taxonomy );
2815 $docs_tax = $this->database->get_cache( $_cache_key );
2816
2817 if ( $docs_tax ) {
2818 return $docs_tax;
2819 }
2820
2821 $get_terms = get_terms( [
2822 'taxonomy' => $taxonomy,
2823 'hide_empty' => $hide_empty
2824 ] );
2825
2826 $terms = [
2827 'all' => 'All'
2828 ];
2829
2830 if ( ! empty( $get_terms ) && ! is_wp_error( $get_terms ) ) {
2831 foreach ( $get_terms as $value ) {
2832 if ( isset( $value->slug ) && isset( $value->name ) ) {
2833 $terms[ $value->slug ] = $value->name;
2834 }
2835 }
2836 }
2837
2838 $terms = $this->normalize_options( $terms );
2839 if ( count( $terms ) > 1 ) {
2840 $this->database->set_cache( $_cache_key, $terms );
2841 }
2842
2843 return $terms;
2844 }
2845
2846 public function get_terms_with_ids( $taxonomy ) {
2847 $_cache_key = 'betterdocs::settings::terms::ids' . trim( $taxonomy );
2848 $docs_tax = $this->database->get_cache( $_cache_key );
2849
2850 if ( $docs_tax ) {
2851 return $docs_tax;
2852 }
2853
2854 $get_terms = get_terms( [
2855 'taxonomy' => $taxonomy,
2856 'hide_empty' => false,
2857 'suppress_filter' => true,
2858 ] );
2859
2860 $terms = [];
2861
2862 if ( ! empty( $get_terms ) && ! is_wp_error( $get_terms ) ) {
2863 foreach ( $get_terms as $value ) {
2864 if ( isset( $value->term_id ) && isset( $value->name ) ) {
2865 $terms[ $value->term_id ] = $value->name;
2866 }
2867 }
2868 }
2869
2870 $terms = $this->normalize_options( $terms );
2871 if ( count( $terms ) > 1 ) {
2872 $this->database->set_cache( $_cache_key, $terms );
2873 }
2874
2875 return $terms;
2876 }
2877
2878 /**
2879 * Get all docs
2880 */
2881 public function docs() {
2882 $docs = $this->database->get_cache( 'betterdocs::settings::all_docs' );
2883
2884 if ( $docs ) {
2885 return $docs;
2886 }
2887
2888 $docs = [];
2889
2890 $_docs = get_posts( [
2891 'post_type' => 'docs',
2892 'numberposts' => - 1,
2893 'posts_per_page' => - 1
2894 ] );
2895
2896 if ( ! empty( $_docs ) ) {
2897 foreach ( $_docs as $doc ) {
2898 $docs[ $doc->ID ] = betterdocs()->template_helper->kses( $doc->post_title );
2899 }
2900 $docs = GlobalFields::normalize_fields( $docs );
2901 $this->database->set_cache( 'betterdocs::settings::all_docs', $docs );
2902 }
2903
2904 return $docs;
2905 }
2906
2907 public function hide_roles_management( $tabData = [] ) {
2908 global $current_user;
2909
2910 if ( $current_user instanceof WP_User && ! in_array( 'administrator', $current_user->roles ) ) {
2911 unset( $tabData['fields']['title-advance-settings']['fields']['article_roles'] );
2912 unset( $tabData['fields']['title-advance-settings']['fields']['settings_roles'] );
2913 unset( $tabData['fields']['title-advance-settings']['fields']['analytics_roles'] );
2914 unset( $tabData['fields']['title-advance-settings']['fields']['faq_roles'] );
2915 }
2916
2917 return $tabData;
2918 }
2919 }
2920