PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 3.3.2
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v3.3.2
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 / Admin.php

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

628 lines 22.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 Exception;
6 use PriyoMukul\WPNotice\Notices;
7 use PriyoMukul\WPNotice\Utils\CacheBank;
8 use PriyoMukul\WPNotice\Utils\NoticeRemover;
9 use WPDeveloper\BetterDocs\Admin\Analytics;
10 use WPDeveloper\BetterDocs\Dependencies\DI\Container;
11 use WPDeveloper\BetterDocs\Utils\Base;
12 use WPDeveloper\BetterDocs\Utils\Enqueue;
13 use WPDeveloper\BetterDocs\Utils\Helper;
14 use WPDeveloper\BetterDocs\Utils\Insights;
15
16 class Admin extends Base {
17 /**
18 * @var CacheBank
19 */
20 private static $cache_bank;
21 /**
22 * Admin Root Menu Slug
23 * @var string
24 */
25 private $slug = 'betterdocs-admin';
26 /**
27 * Insights
28 *
29 * @var Insights
30 */
31 private $insights = null;
32
33 /**
34 * DI\Container
35 *
36 * @var Container
37 */
38 private $container;
39
40 /**
41 * Database Wrapper
42 *
43 * @var Settings
44 */
45 private $settings;
46
47 /**
48 * Enqueue
49 * @var Enqueue
50 */
51 private $assets;
52
53 /**
54 * FAQBuilder
55 * @var FAQBuilder
56 */
57 private $faq_builder;
58
59 public function __construct( Container $container, PostType $type, Enqueue $assets, Settings $settings ) {
60 $this->container = $container;
61 $this->assets = $assets;
62 $this->settings = $settings;
63 $this->slug = 'betterdocs-admin';
64
65 add_action( 'init', [ $type, 'register' ], 9 );
66
67 $type->init();
68 $type->admin_init();
69
70 $this->faq_builder = $this->container->get( FAQBuilder::class );
71
72 if ( ! is_admin() ) {
73 return;
74 }
75
76 $this->plugin_insights();
77 add_action( 'admin_notices', [$this, 'compatibility_notices'] );
78 // add_action( 'admin_init', [$this, 'notices'], 9 );
79 add_filter( 'admin_init', [$this, 'save_admin_page'], 99 );
80
81 add_action( 'admin_menu', [$this, 'menus'] );
82 add_action( 'admin_menu', [$this, 'reset_submenu'] );
83 add_filter( 'plugin_action_links_' . BETTERDOCS_PLUGIN_BASENAME, [$this, 'insert_plugin_links'] );
84
85 // $this->container->get( SetupWizard::class )->init();
86
87 add_action( 'admin_enqueue_scripts', [ $this, 'styles' ] );
88 add_action( 'admin_enqueue_scripts', [ $this, 'scripts' ] );
89 add_action( 'betterdocs_listing_header', [ $this, 'header' ], 10, 1 );
90 add_action( 'admin_bar_menu', [ $this, 'toolbar_menu' ], 32 );
91
92 add_filter( 'admin_body_class', [ $this, 'body_classes' ] );
93 add_filter( 'parent_file', [ $type, 'highlight_admin_menu' ] );
94 add_filter( 'submenu_file', [ $type, 'highlight_admin_submenu' ], 10, 2 );
95 add_filter( 'betterdocs_admin_menu', [ $this, 'quick_setup_menu' ], 10, 1 );
96
97 /**
98 * Remove Comments Column from List Table.
99 */
100 add_filter( 'manage_docs_posts_columns', [ $this, 'set_custom_edit_action_columns' ] );
101 add_filter( 'manage_docs_posts_custom_column', [ $this, 'manage_custom_columns' ], 10, 2 );
102
103 self::$cache_bank = CacheBank::get_instance();
104 try {
105 $this->notices();
106 } catch ( Exception $e ) {
107 unset( $e );
108 }
109 // Remove OLD notice from 1.0.0 (if other WPDeveloper plugin has notice)
110 NoticeRemover::get_instance( '1.0.0' );
111 }
112
113 public function compatibility_notices() {
114 if ( betterdocs()->is_pro_active() ) {
115 $plugins = Helper::get_plugins();
116 $plugin_data = $plugins['betterdocs-pro/betterdocs-pro.php'];
117
118 if ( isset( $plugin_data['Version'] ) && version_compare( $plugin_data['Version'], '2.5.0', '>=' ) ) {
119 return;
120 }
121
122 betterdocs()->views->get( 'admin/notices/compatibility', [ 'version' => $plugin_data['Version'] ] );
123 }
124 }
125
126 public function plugin_insights( $prevent_init = false ) {
127 $this->insights = Insights::get_instance( BETTERDOCS_PLUGIN_FILE, [
128 'opt_in' => true,
129 'goodbye_form' => true,
130 'item_id' => 'c7b16777b4f1b83f6083'
131 ] );
132
133 $this->insights->set_notice_options( [
134 'notice' => __( 'Want to help make <strong>BetterDocs</strong> even more awesome? You can get a <strong>10% discount coupon</strong> for Premium extensions if you allow us to track the usage.', 'betterdocs' ),
135 'extra_notice' => __( 'We collect non-sensitive diagnostic data and plugin usage information. Your site URL, WordPress & PHP version, plugins & themes and email address to send you the discount coupon. This data lets us make sure this plugin always stays compatible with the most popular plugins and themes. No spam, I promise.', 'betterdocs' )
136 ] );
137
138 if ( ! $prevent_init ) {
139 $this->insights->init();
140 }
141
142 return $this->insights;
143 }
144
145 /**
146 * Admin notices for Review and others.
147 *
148 * @return void
149 * @throws Exception
150 */
151 public function notices() {
152 $notices = new Notices( [
153 'id' => 'betterdocs',
154 'storage_key' => 'notices',
155 'lifetime' => 3,
156 'stylesheet_url' => $this->assets->asset_url( 'admin/css/notices.css' ),
157 'styles' => $this->assets->asset_url( 'admin/css/notices.css' ),
158 'priority' => 4
159 ] );
160
161 /**
162 * Review Notice
163 * @var mixed $message
164 */
165
166 $message = __( 'We hope you\'re enjoying BetterDocs! Could you please do us a BIG favor and give it a 5-star rating on WordPress to help us spread the word and boost our motivation?', 'betterdocs' );
167
168 $_review_notice = [
169 'thumbnail' => $this->assets->icon( 'betterdocs-logo.svg', true ),
170 'html' => '<p>' . $message . '</p>',
171 'links' => [
172 'later' => [
173 'link' => 'https://wordpress.org/plugins/betterdocs/#reviews',
174 'target' => '_blank',
175 'label' => __( 'Sure, you deserve it!', 'betterdocs' ),
176 'icon_class' => 'dashicons dashicons-external'
177 ],
178 'allready' => [
179 'label' => __( 'I already did', 'betterdocs' ),
180 'icon_class' => 'dashicons dashicons-smiley',
181 'attributes' => [
182 'data-dismiss' => true
183 ]
184 ],
185 'maybe_later' => [
186 'label' => __( 'Maybe Later', 'betterdocs' ),
187 'icon_class' => 'dashicons dashicons-calendar-alt',
188 'attributes' => [
189 'data-later' => true,
190 'class' => 'dismiss-btn'
191 ]
192 ],
193 'support' => [
194 'link' => 'https://wpdeveloper.com/support',
195 'attributes' => [
196 'target' => '_blank'
197 ],
198 'label' => __( 'I need help', 'betterdocs' ),
199 'icon_class' => 'dashicons dashicons-sos'
200 ],
201 'never_show_again' => [
202 'label' => __( 'Never show again', 'betterdocs' ),
203 'icon_class' => 'dashicons dashicons-dismiss',
204 'attributes' => [
205 'data-dismiss' => true
206 ]
207 ]
208 ]
209 ];
210
211 $notices->add( 'review', $_review_notice, [
212 'start' => $notices->strtotime( '+10 days' ),
213 'recurrence' => 30,
214 'dismissible' => true
215 // 'screens' => [
216 // 'dashboard', 'plugins', 'themes', 'edit-page',
217 // 'edit-post', 'users', 'tools', 'options-general',
218 // 'nav-menus', 'toplevel_page_betterdocs-admin', 'betterdocs_page_betterdocs-settings', 'betterdocs_page_betterdocs-analytics', 'betterdocs_page_betterdocs-faq', 'edit-doc_tag', 'edit-doc_category'
219 // ]
220 ] );
221
222 /**
223 * Opt-In Notice
224 */
225 if ( $this->insights != null ) {
226 $notices->add( 'opt_in', [ $this->insights, 'notice' ], [
227 'classes' => 'updated put-dismiss-notice',
228 'start' => $notices->strtotime( '+20 days' ),
229 'dismissible' => true,
230 'do_action' => 'wpdeveloper_notice_clicked_for_betterdocs',
231 'display_if' => ! function_exists( 'betterdocs_pro' )
232 ] );
233 }
234
235 $b_message = '<p style="margin-top: 0; margin-bottom: 10px;">Black Friday Sale: Enjoy 40% off & unlock <strong>premium features to streamline customer support</strong> & knowledge base 🎁</p><a class="button button-primary" href="https://wpdeveloper.com/upgrade/betterdocs-bfcm" target="_blank">Upgrade to pro</a> <button data-dismiss="true" class="dismiss-btn button button-link">I don’t want to save money</button>';
236 $_black_friday_notice = [
237 'thumbnail' => $this->assets->icon( 'betterdocs-logo.svg', true ),
238 'html' => $b_message,
239 ];
240
241 $notices->add( 'black_friday_notice', $_black_friday_notice, [
242 'start' => $notices->time(),
243 'recurrence' => false,
244 'dismissible' => true,
245 'refresh' => BETTERDOCS_VERSION,
246 "expire" => strtotime( '11:59:59pm 2nd December, 2023' ),
247 'display_if' => ! is_plugin_active( 'betterdocs-pro/betterdocs-pro.php' )
248 ] );
249
250 self::$cache_bank->create_account( $notices );
251 self::$cache_bank->calculate_deposits( $notices );
252 }
253
254 public function body_classes( $classes ) {
255 $saved_settings = get_option( 'betterdocs_settings', false );
256 $dark_mode = isset( $saved_settings['dark_mode'] ) ? $saved_settings['dark_mode'] : false;
257 $dark_mode = ! empty( $dark_mode ) ? boolval( $dark_mode ) : false;
258
259 if ( $dark_mode === true ) {
260 $classes .= ' betterdocs-dark-mode ';
261 }
262
263 return $classes;
264 }
265
266 /**
267 * Remove Comments Column From List Table
268 *
269 * @param array $columns
270 *
271 * @return array
272 * @since 1.0.0
273 */
274 public function set_custom_edit_action_columns( $columns ) {
275 unset( $columns['comments'] );
276 $new_columns = [];
277 foreach ( $columns as $key => $value ) {
278 if ( $key == 'date' ) {
279 $new_columns['betterdocs_word_count'] = __( 'Word Count', 'betterdocs' ); // put the tags column before it
280 }
281 $new_columns[ $key ] = $value;
282 }
283
284 return $new_columns;
285 }
286
287 public function manage_custom_columns( $column, $post_id ) {
288 switch ( $column ) {
289 case 'betterdocs_word_count':
290 $word_count = str_word_count( trim( strip_tags( get_post_field( 'post_content', $post_id ) ) ) );
291 echo '<span>' . $word_count . '</span>';
292 break;
293 }
294 }
295
296 /**
297 * Enqueue Assets for Admin ( Styles )
298 *
299 * @param string $hook
300 *
301 * @return void
302 * @since 1.0.0
303 */
304 public function styles( $hook ) {
305 $this->assets->enqueue( 'betterdocs-global', 'admin/css/global.css', [], 'all' );
306
307 if ( ! in_array( $hook, [
308 'toplevel_page_betterdocs-admin',
309 'betterdocs_page_betterdocs-settings',
310 'betterdocs_page_betterdocs-analytics'
311 ] ) ) {
312 return;
313 }
314
315 $this->assets->enqueue( 'betterdocs-select2', 'vendor/css/select2.min.css', [], 'all' );
316 $this->assets->enqueue( 'betterdocs-daterangepicker', 'vendor/css/daterangepicker.css', [], 'all' );
317 $this->assets->enqueue( 'betterdocs', 'admin/css/betterdocs.css', [], 'all' );
318 }
319
320 /**
321 * Enqueue Assets for Admin ( Scripts )
322 *
323 * @param string $hook
324 *
325 * @return void
326 * @since 1.0.0
327 */
328 public function scripts( $hook ) {
329 $this->assets->register( 'betterdocs-admin', 'admin/js/betterdocs.js', [ 'jquery', 'jquery-ui-sortable' ] );
330
331 $saved_settings = get_option( 'betterdocs_settings', false );
332 $dark_mode = isset( $saved_settings['dark_mode'] ) ? $saved_settings['dark_mode'] : false;
333 $dark_mode = ! empty( $dark_mode ) ? boolval( $dark_mode ) : false;
334 $this->assets->localize( 'betterdocs-admin', 'betterdocs_admin', [
335 'ajaxurl' => admin_url( 'admin-ajax.php' ),
336 'doc_cat_order_nonce' => wp_create_nonce( 'doc_cat_order_nonce' ),
337 'knowledge_base_order_nonce' => wp_create_nonce( 'knowledge_base_order_nonce' ),
338 'paged' => isset( $_GET['paged'] ) ? absint( wp_unslash( $_GET['paged'] ) ) : 0,
339 'per_page_id' => "edit_doc_category_per_page",
340 'menu_title' => __( 'Switch to BetterDocs UI', 'betterdocs' ),
341 'dark_mode' => ! empty( $dark_mode ) ? boolval( $dark_mode ) : false,
342 'text' => __( 'Copied!', 'betterdocs' ),
343 'test_report' => __( 'Test Report!', 'betterdocs' ),
344 'sending' => __( 'Sending...', 'betterdocs' )
345 ] );
346
347 if ( ( $hook === 'edit.php' || $hook === 'toplevel_page_betterdocs-admin' ) && get_post_type() == 'docs' ) {
348 $this->assets->enqueue( 'betterdocs-switcher', 'admin/js/switcher.js', [
349 'jquery'
350 ] );
351
352 $this->assets->localize( 'betterdocs-switcher', 'betterdocsSwitcher', [
353 'menu_title' => __( 'Switch to BetterDocs UI', 'betterdocs' ),
354 'site_address' => get_bloginfo( 'url' ),
355 'betterdocs_pro_plugin' => betterdocs()->is_pro_active()
356 ] );
357 }
358
359 if ( ! in_array( $hook, [ 'toplevel_page_betterdocs-admin', 'betterdocs_page_betterdocs-analytics' ] ) ) {
360 return;
361 }
362
363 wp_enqueue_script( 'wp-color-picker' );
364
365 $this->assets->enqueue( 'betterdocs-select2', 'vendor/js/select2.min.js', [] );
366 $this->assets->enqueue( 'betterdocs-sweetalert', 'vendor/js/sweetalert.min.js', [] );
367 $this->assets->enqueue( 'moment', 'vendor/js/moment.min.js', [] );
368 $this->assets->enqueue( 'betterdocs-daterangepicker', 'vendor/js/daterangepicker.min.js', [] );
369 wp_enqueue_script( 'betterdocs-admin' );
370 }
371
372 /**
373 * All admin pages header
374 *
375 * @return void
376 * @since 1.0.0
377 */
378 public function header( $admin_tab_name ) {
379 $quick_links = [
380 'switch_view' => sprintf( '<a href="%s" class="betterdocs-button betterdocs-button-secondary">%s</a>', add_query_arg( [
381 'post_type' => 'docs',
382 'bdocs_view' => 'classic'
383 ], 'edit.php' ), __( 'Switch to Classic UI', 'betterdocs' ) ),
384 'add_new_doc' => sprintf( '<a href="%s" class="betterdocs-button betterdocs-button-primary">%s</a>', add_query_arg( [ 'post_type' => 'docs' ], 'post-new.php' ), __( 'Add New Doc', 'betterdocs' ) )
385 ];
386
387 $quick_links = apply_filters( 'betterdocs_quick_links', $quick_links );
388
389 betterdocs()->views->get( 'admin/header', [
390 'quick_links' => $quick_links,
391 'active_tab' => $admin_tab_name
392 ] );
393 }
394
395 /**
396 * Register all the menus for BetterDocs
397 *
398 * @return void
399 * @since 1.0.0
400 */
401 // public function menus() {
402 // add_menu_page(
403 // 'BetterDocs',
404 // 'BetterDocs',
405 // 'edit_posts',
406 // $this->slug,
407 // [$this, 'output'],
408 // betterdocs()->assets->icon( 'betterdocs-icon-white.svg', true ),
409 // 5 // Position on the menu (use a unique number)
410 // );
411 // }
412
413 public function menus() {
414 $default_args = [
415 'page_title' => 'BetterDocs',
416 'menu_title' => 'BetterDocs',
417 'capability' => 'edit_posts',
418 'menu_slug' => $this->slug,
419 'callback' => [ $this, 'output' ],
420 'icon_url' => betterdocs()->assets->icon( 'betterdocs-icon-white.svg', true ),
421 'position' => 5
422 ];
423
424 $_menu_position = 5;
425
426 foreach ( $this->menu_list() as $key => $value ) {
427 if ( $key === 'betterdocs' ) {
428 $callable = 'add_menu_page';
429 $value = wp_parse_args( $value, $default_args );
430 } else {
431 $callable = 'add_submenu_page';
432 $default_args['callback'] = '';
433 $default_args['position'] = $_menu_position;
434 unset( $default_args['icon_url'] );
435 $value = wp_parse_args( $value, array_merge( [ 'parent_slug' => $this->slug ], $default_args ) );
436 }
437
438 $_menu_position++;
439
440 call_user_func_array( $callable, $value );
441 }
442 }
443
444 /**
445 * BetterDocs Admin Page Output
446 *
447 * @return void
448 * @since 1.0.0
449 */
450 public function output() {
451 betterdocs()->views->get( 'admin/main', [
452 'admin_ui' => 'dnd'
453 ] );
454 }
455
456 /**
457 * Menu creator helper
458 *
459 * @param string $title
460 * @param string $slug
461 * @param string $cap
462 * @param array $callback
463 *
464 * @return array
465 * @since 2.5.0
466 *
467 */
468 private function normalize_menu( $title, $slug, $cap = 'edit_docs', $callback = null ) {
469 return Helper::normalize_menu( $title, $slug, $cap, $callback );
470 }
471
472 /**
473 * BetterDocs Menu List
474 *
475 * @return array
476 * @since 1.0.0
477 */
478 private function menu_list() {
479 $betterdocs_admin_pages = [
480 'betterdocs' => [
481 'menu_slug' => $this->slug,
482 'page_title' => 'BetterDocs',
483 'menu_title' => 'BetterDocs',
484 'capability' => 'edit_docs',
485 'callback' => [ $this, 'output' ],
486 'icon_url' => betterdocs()->assets->icon( 'betterdocs-icon-white.svg', true ),
487 'position' => 5
488 ],
489 'all_docs' => $this->normalize_menu( __( 'All Docs', 'betterdocs' ), $this->ui_slug() ),
490 'add_new' => $this->normalize_menu( __( 'Add New', 'betterdocs' ), 'post-new.php?post_type=docs' ),
491 'categories' => $this->normalize_menu(
492 __( 'Categories', 'betterdocs' ),
493 'edit-tags.php?taxonomy=doc_category&post_type=docs',
494 'manage_doc_terms'
495 ),
496 'tags' => $this->normalize_menu(
497 __( 'Tags', 'betterdocs' ),
498 'edit-tags.php?taxonomy=doc_tag&post_type=docs',
499 'manage_doc_terms'
500 ),
501 'settings' => $this->normalize_menu(
502 __( 'Settings', 'betterdocs' ),
503 'betterdocs-settings',
504 'edit_docs_settings',
505 [$this->container->get( Settings::class ), 'views']
506 ),
507 'analytics' => $this->normalize_menu(
508 __( 'Analytics', 'betterdocs' ),
509 'betterdocs-analytics',
510 'read_docs_analytics',
511 [$this->container->get( Analytics::class ), 'views']
512 ),
513 'faq' => $this->normalize_menu(
514 __( 'FAQ Builder', 'betterdocs' ),
515 'betterdocs-faq',
516 'read_docs_analytics',
517 [$this->faq_builder, 'output']
518 )
519 ];
520
521 return apply_filters( 'betterdocs_admin_menu', $betterdocs_admin_pages );
522 }
523
524 public function quick_setup_menu( $menus ) {
525 $betterdocs_settings = get_option( 'betterdocs_settings' );
526 if ( $betterdocs_settings ) {
527 return $menus;
528 } else {
529 $menus['quick_setup'] = $this->normalize_menu( __( 'Quick Setup', 'betterdocs' ), 'betterdocs-setup', 'delete_users', [
530 $this->container->get( SetupWizard::class ),
531 'views'
532 ] );
533 }
534
535 return $menus;
536 }
537
538 public function insert_plugin_links( $links ) {
539 $links[] = '<a href="admin.php?page=betterdocs-settings">' . __( 'Settings', 'betterdocs' ) . '</a>';
540
541 return $links;
542 }
543
544 public function toolbar_menu( $admin_bar ) {
545 if ( ! is_admin() || ! is_admin_bar_showing() ) {
546 return;
547 }
548
549 // Show only when the user is a member of this site, or they're a super admin.
550 if ( ! is_user_member_of_blog() && ! is_super_admin() ) {
551 return;
552 }
553
554 $docs_url = '';
555
556 if ( $this->settings->get( 'builtin_doc_page' ) ) {
557 $docs_url = get_post_type_archive_link( 'docs' );
558 } elseif ( intval( $docs_page = $this->settings->get( 'docs_page' ) ) ) {
559 $docs_url = ! empty( $docs_page ) ? get_page_link( $docs_page ) : false;
560 }
561
562 if ( ! $docs_url ) {
563 return;
564 }
565
566 $admin_bar->add_node( [
567 'parent' => 'site-name',
568 'id' => 'view-docs',
569 'title' => __( 'Visit Documentation', 'betterdocs' ),
570 'href' => $docs_url
571 ] );
572 }
573 /**
574 * Save last visited admin ui
575 *
576 * @since 3.0.1
577 *
578 */
579 public function save_admin_page() {
580 if (isset($_GET['post_type']) && $_GET['post_type'] === 'docs' && isset($_GET['bdocs_view']) && $_GET['bdocs_view'] === 'classic') {
581 update_user_meta( get_current_user_id(), 'last_visited_docs_admin_page', 'classic_ui' );
582 } elseif (isset($_GET['page']) && $_GET['page'] === 'betterdocs-admin') {
583 update_user_meta( get_current_user_id(), 'last_visited_docs_admin_page', 'modern_ui' );
584 }
585 }
586
587 /**
588 * Return last visited admin ui slug
589 *
590 * @since 3.0.1
591 * @return string
592 */
593 public function ui_slug() {
594 $last_visited = get_user_meta( get_current_user_id(), 'last_visited_docs_admin_page', true);
595 $docs = get_posts( ['post_type' => 'docs', 'post_status' => 'any', 'numberposts' => -1] );
596
597 if ($last_visited === 'modern_ui' || count($docs) == 0 ) {
598 $slug = 'betterdocs-admin';
599 } else {
600 $slug = admin_url('edit.php?post_type=docs&bdocs_view=classic');
601 }
602
603 return $slug;
604 }
605
606 /**
607 * Resets a duplicate submenu in WordPress if the parent main menu and the first submenu permalink are not the same.
608 *
609 * @since 3.0.1
610 * @return string
611 */
612 public function reset_submenu() {
613 global $submenu;
614
615 $docs = get_posts( ['post_type' => 'docs'] );
616 if ( count($docs) == 0 ) {
617 return;
618 }
619
620 $last_visited = get_user_meta( get_current_user_id(), 'last_visited_docs_admin_page', true);
621
622 if ( $last_visited === 'classic_ui' && in_array( "betterdocs-admin", $submenu['betterdocs-admin'][0] ) ) {
623 unset($submenu['betterdocs-admin'][0]);
624 $submenu['betterdocs-admin'] = array_values($submenu['betterdocs-admin']);
625 }
626 }
627 }
628