PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 3.4.0
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v3.4.0
4.9.1 4.9.0 4.8.2 4.8.1 4.8.0 4.7.0 4.6.2 4.6.1 4.6.0 4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 4.5.1 4.5.0 4.4.1 4.4.0 3.3.4 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.5.2 All 199 releases
betterdocs / includes / Core / Admin.php

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

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