PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 3.8.9
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v3.8.9
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
← All changes | includes/Core/Admin.php +278 -535 4.5.63.8.9 View file →
@@ -1,22 +1,16 @@
1 1 <?php
2 +
2 3 namespace WPDeveloper\BetterDocs\Core;
3 4
4 -if ( ! defined( 'ABSPATH' ) ) {
5 - exit;
6 -}
7 -
8 -
9 5 use Exception;
10 6 use PriyoMukul\WPNotice\Notices;
11 -use WPDeveloper\BetterDocs\Admin\NoticePointers;
12 7 use WPDeveloper\BetterDocs\Utils\Base;
13 8 use PriyoMukul\WPNotice\Utils\CacheBank;
14 9 use WPDeveloper\BetterDocs\Utils\Helper;
15 10 use WPDeveloper\BetterDocs\Utils\Enqueue;
16 -use WPDeveloper\BetterDocs\Insights\Insights;
11 +use WPDeveloper\BetterDocs\Utils\Insights;
17 12 use PriyoMukul\WPNotice\Utils\NoticeRemover;
18 -use WPDeveloper\BetterDocs\Core\PluginInstaller;
19 13 use WPDeveloper\BetterDocs\Dependencies\DI\Container;
20 14
21 15 class Admin extends Base {
22 16 /**
@@ -24,12 +18,11 @@
24 18 */
25 19 private static $cache_bank;
26 20 /**
27 21 * Admin Root Menu Slug
28 - *
29 22 * @var string
30 23 */
31 - private $slug = 'betterdocs-dashboard';
24 + private $slug = 'betterdocs-admin';
32 25 /**
33 26 * Insights
34 27 *
35 28 * @var Insights
@@ -58,19 +51,14 @@
58 51 private $kbmigration;
59 52
60 53 /**
61 54 * Enqueue
62 - *
63 55 * @var Enqueue
64 56 */
65 57 private $assets;
66 58
67 - // modules
68 - protected $installer;
69 -
70 59 /**
71 60 * FAQBuilder
72 - *
73 61 * @var FAQBuilder
74 62 */
75 63 private $faq_builder;
76 64 private $glossaries;
@@ -79,12 +67,11 @@
79 67 $this->container = $container;
80 68 $this->assets = $assets;
81 69 $this->settings = $settings;
82 70 $this->kbmigration = $kbmigration;
83 - $this->slug = 'betterdocs-dashboard';
71 + $this->slug = 'betterdocs-admin';
84 72
85 - add_action( 'init', array( $type, 'register' ), 9 );
86 - add_action( 'rest_api_init', array( $this, 'order_terms_in_wp_terms_admin_table' ) );
73 + add_action( 'init', [ $type, 'register' ], 9 );
87 74
88 75 $type->init();
89 76 $type->admin_init();
90 77
@@ -90,63 +77,51 @@
90 77
91 78 $this->faq_builder = $this->container->get( FAQBuilder::class );
92 79 $this->glossaries = $this->container->get( Glossaries::class );
93 80
94 - /**
95 - * Register usage tracking (including the daily `put_do_weekly_action` cron
96 - * handler) on every request — WP-Cron runs with is_admin() === false, so
97 - * this MUST sit above the admin guard or the cron send never fires. The
98 - * admin-only UI hooks inside Insights::init() (deactivation form, footer
99 - * scripts, plugin_action_links) are context-specific and simply never run
100 - * outside wp-admin.
101 - */
102 - $this->plugin_insights();
103 -
104 81 if ( ! is_admin() ) {
105 82 return;
106 83 }
107 84
108 - $this->installer = new PluginInstaller();
109 -
110 - add_action( 'admin_notices', array( $this, 'compatibility_notices' ) );
85 + $this->plugin_insights();
86 + add_action( 'admin_notices', [ $this, 'compatibility_notices' ] );
111 87 // add_action( 'admin_init', [$this, 'notices'], 9 );
112 - add_filter( 'admin_init', array( $this, 'save_admin_page' ), 99 );
88 + add_filter( 'admin_init', [ $this, 'save_admin_page' ], 99 );
113 89
114 - add_action( 'admin_menu', array( $this, 'menus' ) );
115 - add_action( 'admin_menu', array( $this, 'reset_submenu' ) );
116 - add_action( 'admin_head', array( $this, 'add_custom_classes_to_menu_items' ) );
117 - add_filter( 'plugin_action_links_' . BETTERDOCS_PLUGIN_BASENAME, array( $this, 'insert_plugin_links' ) );
90 + add_action( 'admin_menu', [ $this, 'menus' ] );
91 + add_action( 'admin_menu', [ $this, 'reset_submenu' ] );
92 + add_action( 'admin_head', [ $this, 'add_custom_classes_to_menu_items' ] );
93 + add_filter( 'plugin_action_links_' . BETTERDOCS_PLUGIN_BASENAME, [ $this, 'insert_plugin_links' ] );
118 94
119 95 // $this->container->get( SetupWizard::class )->init();
120 96
121 - add_action( 'admin_enqueue_scripts', array( $this, 'styles' ) );
122 - add_action( 'admin_enqueue_scripts', array( $this, 'scripts' ) );
123 - // add_action( 'betterdocs_listing_header', [ $this, 'header' ], 10, 1 );
124 - add_action( 'admin_bar_menu', array( $this, 'toolbar_menu' ), 32 );
97 + add_action( 'admin_enqueue_scripts', [ $this, 'styles' ] );
98 + add_action( 'admin_enqueue_scripts', [ $this, 'scripts' ] );
99 + //add_action( 'betterdocs_listing_header', [ $this, 'header' ], 10, 1 );
100 + add_action( 'admin_bar_menu', [ $this, 'toolbar_menu' ], 32 );
125 101
126 - add_filter( 'admin_body_class', array( $this, 'body_classes' ) );
127 - add_filter( 'parent_file', array( $type, 'highlight_admin_menu' ) );
128 - add_filter( 'submenu_file', array( $type, 'highlight_admin_submenu' ), 10, 2 );
129 - add_filter( 'betterdocs_admin_menu', array( $this, 'quick_setup_menu' ), 10, 1 );
102 + add_filter( 'admin_body_class', [ $this, 'body_classes' ] );
103 + add_filter( 'parent_file', [ $type, 'highlight_admin_menu' ] );
104 + add_filter( 'submenu_file', [ $type, 'highlight_admin_submenu' ], 10, 2 );
105 + add_filter( 'betterdocs_admin_menu', [ $this, 'quick_setup_menu' ], 10, 1 );
130 106
131 107 /**
132 108 * Remove Comments Column from List Table.
133 109 */
134 - add_filter( 'manage_docs_posts_columns', array( $this, 'set_custom_edit_action_columns' ) );
135 - add_filter( 'manage_docs_posts_custom_column', array( $this, 'manage_custom_columns' ), 10, 2 );
110 + add_filter( 'manage_docs_posts_columns', [ $this, 'set_custom_edit_action_columns' ] );
111 + add_filter( 'manage_docs_posts_custom_column', [ $this, 'manage_custom_columns' ], 10, 2 );
136 112
137 113 /**
138 114 * Add New Column
139 115 */
140 - add_filter( 'manage_users_columns', array( $this, 'add_users_total_docs_column' ), 10, 1 );
141 - add_filter( 'manage_users_custom_column', array( $this, 'popular_users_docs_data' ), 10, 3 );
116 + add_filter( 'manage_users_columns', [ $this, 'add_users_total_docs_column' ], 10, 1 );
117 + add_filter( 'manage_users_custom_column', [ $this, 'popular_users_docs_data' ], 10, 3 );
142 118 if ( is_plugin_active( 'betterdocs-pro/betterdocs-pro.php' ) ) {
143 119 add_action( 'admin_footer-plugins.php', array( $this, 'disable_deactivation' ) );
144 120 }
145 121
146 122 if ( $this->settings->get( 'enable_estimated_reading_time' ) ) {
147 - // Hook into unified metabox instead of creating separate metabox
148 - add_action( 'betterdocs_reading_time_tab_content', array( $this, 'render_estimated_time_markup' ) );
123 + add_action( 'add_meta_boxes', [ $this, 'reading_meta_box_' ], 10 );
149 124 }
150 125
151 126 self::$cache_bank = CacheBank::get_instance();
152 127
@@ -157,30 +132,10 @@
157 132 $this->notices();
158 133 } catch ( Exception $e ) {
159 134 unset( $e );
160 135 }
161 -
162 - // Initialize Black Friday Pointer
163 - $this->init_black_friday_pointer();
164 -
165 - // Register AJAX handler for pointer dismissal
166 - add_action( 'wp_ajax_betterdocs_dismiss_black_friday_pointer', array( $this, 'ajax_dismiss_black_friday_pointer' ) );
167 136 }
168 137
169 - public function order_terms_in_wp_terms_admin_table() {
170 - // order the terms correctly to be shown on the admin panel categories menu with betterdocs order
171 - add_action(
172 - 'rest_insert_doc_category',
173 - function ( $term, $request, $bool ) {
174 - $max_order = Helper::get_max_doc_category_order_from_term_meta() ?? 0;
175 - $next_order = $max_order + 1;
176 - update_term_meta( $term->term_id, 'doc_category_order', $next_order );
177 - },
178 - 10,
179 - 3
180 - );
181 - }
182 -
183 138 public function disable_deactivation() {
184 139 $tooltip_text = esc_html__( 'Deactivate BetterDocs Pro First', 'betterdocs' );
185 140 ?>
186 141 <style type="text/css">
@@ -225,17 +180,17 @@
225 180 <?php
226 181 }
227 182
228 183 public function add_users_total_docs_column( $columns ) {
229 - $new_column = array(
230 - 'docs' => __( 'Docs', 'betterdocs' ),
231 - );
184 + $new_column = [
185 + 'docs' => __( 'Docs', 'betterdocs' )
186 + ];
232 187 $columns = array_merge( $columns, $new_column );
233 188 return $columns;
234 189 }
235 190
236 191 public function popular_users_docs_data( $output, $column_name, $user_id ) {
237 - if ( 'docs' == $column_name ) {
192 + if ( $column_name == 'docs' ) {
238 193 $total_count = count_user_posts( $user_id, 'docs', true );
239 194 return '<a href="edit.php?post_type=docs&author=' . $user_id . '" class="edit"><span aria-hidden="true">' . $total_count . '</span></a>';
240 195 }
241 196 return $output;
@@ -240,8 +195,20 @@
240 195 }
241 196 return $output;
242 197 }
243 198
199 + public function reading_meta_box_() {
200 + add_meta_box(
201 + 'betterdocs_estimated_time_metabox',
202 + __( 'Estimated Reading Time', 'betterdocs' ),
203 + [
204 + $this,
205 + 'render_estimated_time_markup'
206 + ],
207 + 'docs'
208 + );
209 + }
210 +
244 211 public function render_estimated_time_markup() {
245 212 betterdocs()->views->get( 'admin/metabox/estimated-reading-box' );
246 213 }
247 214
@@ -253,9 +220,9 @@
253 220 if ( isset( $plugin_data['Version'] ) && version_compare( $plugin_data['Version'], '2.5.0', '>=' ) ) {
254 221 return;
255 222 }
256 223
257 - betterdocs()->views->get( 'admin/notices/compatibility', array( 'version' => $plugin_data['Version'] ) );
224 + betterdocs()->views->get( 'admin/notices/compatibility', [ 'version' => $plugin_data['Version'] ] );
258 225 }
259 226 }
260 227
261 228 public function plugin_insights( $prevent_init = false ) {
@@ -260,20 +227,20 @@
260 227
261 228 public function plugin_insights( $prevent_init = false ) {
262 229 $this->insights = Insights::get_instance(
263 230 BETTERDOCS_PLUGIN_FILE,
264 - array(
231 + [
265 232 'opt_in' => true,
266 233 'goodbye_form' => true,
267 - 'item_id' => 'c7b16777b4f1b83f6083',
268 - )
234 + 'item_id' => 'c7b16777b4f1b83f6083'
235 + ]
269 236 );
270 237
271 238 $this->insights->set_notice_options(
272 - array(
239 + [
273 240 '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' ),
274 - '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' ),
275 - )
241 + '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' )
242 + ]
276 243 );
277 244
278 245 if ( ! $prevent_init ) {
279 246 $this->insights->init();
@@ -289,77 +256,76 @@
289 256 * @throws Exception
290 257 */
291 258 public function notices() {
292 259 $notices = new Notices(
293 - array(
260 + [
294 261 'id' => 'betterdocs',
295 262 'storage_key' => 'notices',
296 263 'lifetime' => 3,
297 264 'stylesheet_url' => $this->assets->asset_url( 'admin/css/notices.css' ),
298 265 'styles' => $this->assets->asset_url( 'admin/css/notices.css' ),
299 - 'priority' => 4,
300 - )
266 + 'priority' => 4
267 + ]
301 268 );
302 269
303 270 /**
304 - * Review Notice
305 - *
306 - * @var mixed $message
307 - */
271 + * Review Notice
272 + * @var mixed $message
273 + */
308 274
309 275 $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' );
310 276
311 - $_review_notice = array(
277 + $_review_notice = [
312 278 'thumbnail' => $this->assets->icon( 'betterdocs-logo.svg', true ),
313 279 'html' => '<p>' . $message . '</p>',
314 - 'links' => array(
315 - 'later' => array(
280 + 'links' => [
281 + 'later' => [
316 282 'link' => 'https://wordpress.org/plugins/betterdocs/#reviews',
317 283 'target' => '_blank',
318 284 'label' => __( 'Sure, you deserve it!', 'betterdocs' ),
319 - 'icon_class' => 'dashicons dashicons-external',
320 - ),
321 - 'allready' => array(
285 + 'icon_class' => 'dashicons dashicons-external'
286 + ],
287 + 'allready' => [
322 288 'label' => __( 'I already did', 'betterdocs' ),
323 289 'icon_class' => 'dashicons dashicons-smiley',
324 - 'attributes' => array(
325 - 'data-dismiss' => true,
326 - ),
327 - ),
328 - 'maybe_later' => array(
290 + 'attributes' => [
291 + 'data-dismiss' => true
292 + ]
293 + ],
294 + 'maybe_later' => [
329 295 'label' => __( 'Maybe Later', 'betterdocs' ),
330 296 'icon_class' => 'dashicons dashicons-calendar-alt',
331 - 'attributes' => array(
297 + 'attributes' => [
332 298 'data-later' => true,
333 - 'class' => 'dismiss-btn',
334 - ),
335 - ),
336 - 'support' => array(
299 + 'class' => 'dismiss-btn'
300 + ]
301 + ],
302 + 'support' => [
337 303 'link' => 'https://wpdeveloper.com/support',
338 - 'attributes' => array(
339 - 'target' => '_blank',
340 - ),
304 + 'attributes' => [
305 + 'target' => '_blank'
306 + ],
341 307 'label' => __( 'I need help', 'betterdocs' ),
342 - 'icon_class' => 'dashicons dashicons-sos',
343 - ),
344 - 'never_show_again' => array(
308 + 'icon_class' => 'dashicons dashicons-sos'
309 + ],
310 + 'never_show_again' => [
345 311 'label' => __( 'Never show again', 'betterdocs' ),
346 312 'icon_class' => 'dashicons dashicons-dismiss',
347 - 'attributes' => array(
348 - 'data-dismiss' => true,
349 - ),
350 - ),
351 - ),
352 - );
313 + 'attributes' => [
314 + 'data-dismiss' => true
315 + ]
316 + ]
317 + ]
318 + ];
353 319
354 320 $notices->add(
355 321 'review',
356 322 $_review_notice,
357 - array(
323 + [
358 324 'start' => $notices->strtotime( '+10 days' ),
359 325 'recurrence' => 30,
360 - 'dismissible' => true,
361 - )
326 + 'dismissible' => true
327 + ]
362 328 );
363 329
364 330 if ( $this->kbmigration->existing_plugins && ! in_array( $this->kbmigration->existing_plugins[0][0], $this->kbmigration->migrated_plugins ) ) {
365 331 $plugin_name = '<strong>' . esc_html( $this->kbmigration->existing_plugins[0][1] ) . '</strong>';
@@ -364,9 +330,9 @@
364 330 if ( $this->kbmigration->existing_plugins && ! in_array( $this->kbmigration->existing_plugins[0][0], $this->kbmigration->migrated_plugins ) ) {
365 331 $plugin_name = '<strong>' . esc_html( $this->kbmigration->existing_plugins[0][1] ) . '</strong>';
366 332
367 333 $message = sprintf(
368 - /* translators: %s is the name of the existing knowledge base plugin. */
334 + /* translators: %s is the name of the existing knowledge base plugin. */
369 335 __( 'Already using %s? Power up your Knowledge Base by migrating all your docs and settings to BetterDocs with just 1 click.', 'betterdocs' ),
370 336 esc_html( $plugin_name )
371 337 );
372 338
@@ -376,51 +342,50 @@
376 342 esc_url( admin_url( 'admin.php?page=betterdocs-settings&tab=tab-migration' ) ),
377 343 esc_html__( 'Start Migration', 'betterdocs' )
378 344 );
379 345
380 - $_migration_notice = array(
346 + $_migration_notice = [
381 347 'thumbnail' => '',
382 348 'html' => $migration_message,
383 - 'links' => array(
384 - 'maybe_later' => array(
349 + 'links' => [
350 + 'maybe_later' => [
385 351 'label' => __( 'Maybe Later', 'betterdocs' ),
386 352 'icon_class' => 'dashicons dashicons-calendar-alt',
387 - 'attributes' => array(
353 + 'attributes' => [
388 354 'data-later' => true,
389 - 'class' => 'dismiss-btn',
390 - ),
391 - ),
392 - 'never_show_again' => array(
355 + 'class' => 'dismiss-btn'
356 + ]
357 + ],
358 + 'never_show_again' => [
393 359 'label' => __( 'Never show again', 'betterdocs' ),
394 360 'icon_class' => 'dashicons dashicons-dismiss',
395 - 'attributes' => array(
396 - 'data-dismiss' => true,
397 - ),
398 - ),
399 - ),
400 - );
361 + 'attributes' => [
362 + 'data-dismiss' => true
363 + ]
364 + ]
365 + ]
366 + ];
401 367
402 368 $notices->add(
403 369 'migration',
404 370 $_migration_notice,
405 - array(
371 + [
406 372 'start' => $notices->time(),
407 373 'recurrence' => false,
408 - 'dismissible' => true,
409 - )
374 + 'dismissible' => true
375 + ]
410 376 );
411 377 }
412 378
413 379 /**
414 - *
415 380 * Opt-In Notice
416 381 */
417 382 $allow_tracking = get_option( 'wpins_allow_tracking' );
418 - if ( null != $this->insights && ! isset( $allow_tracking['betterdocs'] ) ) {
383 + if ( $this->insights != null && ! isset( $allow_tracking['betterdocs'] ) ) {
419 384 $notices->add(
420 385 'opt_in',
421 - array( $this->insights, 'notice' ),
422 - array(
386 + [ $this->insights, 'notice' ],
387 + [
423 388 'classes' => 'updated put-dismiss-notice',
424 389 'start' => $notices->time(),
425 390 'refresh' => BETTERDOCS_VERSION,
426 391 'dismissible' => true,
@@ -425,57 +390,19 @@
425 390 'refresh' => BETTERDOCS_VERSION,
426 391 'dismissible' => true,
427 392 'do_action' => 'wpdeveloper_notice_clicked_for_betterdocs',
428 393 'display_if' => ! function_exists( 'betterdocs_pro' ),
429 - 'screens' => array( 'dashboard' ),
430 - )
394 + 'screens' => [ 'dashboard' ]
395 + ]
431 396 );
432 397 }
433 398
434 - $summer_campaign_message = '<div class="betterdocs-summer-notice-body"><p style="margin-top: 0; margin-bottom: 0;">🏖️ <strong>Summer Savings:</strong> Build AI-powered Knowledge Bases & FAQs to cut support tickets and improve user experience – now <strong>up to $100 OFF!</strong></p></div>';
435 - $_summer_campaign_notice = array(
436 - 'thumbnail' => $this->assets->icon( 'betterdocs-logo.svg', true ),
437 - 'html' => $summer_campaign_message,
438 - 'links' => array(
439 - 'support' => array(
440 - 'link' => 'https://betterdocs.co/summer2026-admin-notice',
441 - 'attributes' => array(
442 - 'target' => '_blank',
443 - 'class' => 'offer-button',
444 - ),
445 - 'label' => __( 'Upgrade To PRO Now', 'betterdocs' ),
446 - ),
447 - 'maybe_later' => array(
448 - 'label' => __( 'I’ll Grab It Later', 'betterdocs' ),
449 - 'attributes' => array(
450 - 'target' => '_blank',
451 - 'data-later' => true,
452 - 'class' => 'dismiss-btn',
453 - ),
454 - ),
455 - ),
456 - );
457 -
458 - $notices->add(
459 - 'summer-campaign-26',
460 - $_summer_campaign_notice,
461 - array(
462 - 'start' => $notices->time(),
463 - 'recurrence' => false,
464 - 'dismissible' => true,
465 - 'refresh' => BETTERDOCS_VERSION,
466 - 'expire' => strtotime( '11:59:59pm June 25, 2026' ),
467 - 'display_if' => ! is_plugin_active( 'betterdocs-pro/betterdocs-pro.php' ),
468 - )
469 - );
470 -
471 399 self::$cache_bank->create_account( $notices );
472 400 self::$cache_bank->calculate_deposits( $notices );
473 401 if ( method_exists( self::$cache_bank, 'clear_notices_in_' ) ) {
474 402 self::$cache_bank->clear_notices_in_(
475 - array(
476 - 'toplevel_page_betterdocs-dashboard',
477 - 'admin_page_betterdocs-admin',
403 + [
404 + 'toplevel_page_betterdocs-admin',
478 405 'betterdocs_page_betterdocs-admin',
479 406 'betterdocs_page_betterdocs-settings',
480 407 'betterdocs_page_betterdocs-faq',
481 408 'betterdocs_page_betterdocs-analytics',
@@ -481,10 +408,10 @@
481 408 'betterdocs_page_betterdocs-analytics',
482 409 'betterdocs_page_betterdocs-glossaries',
483 410 'betterdocs_page_betterdocs-ai-chatbot',
484 411 'edit-doc_category',
485 - 'edit-doc_tag',
486 - ),
412 + 'edit-doc_tag'
413 + ],
487 414 $notices,
488 415 true
489 416 );
490 417 }
@@ -493,27 +420,26 @@
493 420 public function body_classes( $classes ) {
494 421 $saved_settings = get_option( 'betterdocs_settings', false );
495 422 $dark_mode = isset( $saved_settings['dark_mode'] ) ? $saved_settings['dark_mode'] : false;
496 423 $dark_mode = ! empty( $dark_mode ) ? boolval( $dark_mode ) : false;
497 - $current_screen_id = get_current_screen() != null ? str_replace( 'betterdocs_page_', '', str_replace( 'toplevel_page_', '', str_replace( 'admin_page_', '', get_current_screen()->id ) ) ) : '';
498 - $registered_screens = array(
499 - 'betterdocs-settings',
500 - 'betterdocs-admin',
501 - 'betterdocs-dashboard',
502 - 'betterdocs-analytics',
503 - 'betterdocs-glossaries',
504 - 'betterdocs-faq',
505 - 'edit-doc_category',
506 - 'edit-doc_tag',
507 - 'edit-knowledge_base',
508 - 'betterdocs-ai-chatbot',
509 - );
424 + $current_screen_id = get_current_screen() != null ? str_replace( 'betterdocs_page_', '', str_replace( 'toplevel_page_', '', get_current_screen()->id ) ) : '';
425 + $registered_screens = [
426 + 'betterdocs-settings',
427 + 'betterdocs-admin',
428 + 'betterdocs-analytics',
429 + 'betterdocs-glossaries',
430 + 'betterdocs-faq',
431 + 'edit-doc_category',
432 + 'edit-doc_tag',
433 + 'edit-knowledge_base',
434 + 'betterdocs-ai-chatbot'
435 + ];
510 436
511 - if ( in_array( $current_screen_id, $registered_screens ) ) {
512 - $classes .= ' betterdocs-admin ';
513 - }
437 + if( in_array( $current_screen_id, $registered_screens ) ) {
438 + $classes .= ' betterdocs-admin ';
439 + }
514 440
515 - if ( true === $dark_mode && in_array( $current_screen_id, $registered_screens ) ) {
441 + if ( $dark_mode === true && in_array( $current_screen_id, $registered_screens ) ) {
516 442 $classes .= ' betterdocs-dark-mode ';
517 443 }
518 444
519 445 return $classes;
@@ -528,11 +454,11 @@
528 454 * @since 1.0.0
529 455 */
530 456 public function set_custom_edit_action_columns( $columns ) {
531 457 unset( $columns['comments'] );
532 - $new_columns = array();
458 + $new_columns = [];
533 459 foreach ( $columns as $key => $value ) {
534 - if ( 'date' == $key ) {
460 + if ( $key == 'date' ) {
535 461 $new_columns['betterdocs_word_count'] = __( 'Word Count', 'betterdocs' ); // put the tags column before it
536 462 $new_columns['betterdocs_reaction'] = __( 'Reactions', 'betterdocs' );
537 463 }
538 464 $new_columns[ $key ] = $value;
@@ -544,29 +470,26 @@
544 470 public function manage_custom_columns( $column, $post_id ) {
545 471 global $wpdb;
546 472 switch ( $column ) {
547 473 case 'betterdocs_word_count':
548 - $content_without_html_tags = trim( wp_strip_all_tags( get_post_field( 'post_content', $post_id ) ) );
474 + $content_without_html_tags = trim( strip_tags( get_post_field( 'post_content', $post_id ) ) );
549 475 preg_match_all( '/<[^>]*>|[\p{L}\p{M}]+/u', $content_without_html_tags, $matches );
550 - $total_words = ! empty( $matches[0] ) ? count( $matches[0] ) : count( array() );
476 + $total_words = ! empty( $matches[0] ) ? count( $matches[0] ) : count( [] );
551 477 $word_count = $total_words;
552 478 echo '<span>' . esc_html( intval( $word_count ) ) . '</span>';
553 479 break;
554 480 case 'betterdocs_reaction':
555 - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- per-post analytics aggregation rendered in admin list table; cache would mask live reactions.
481 + $where = "WHERE post_id='" . esc_sql( $post_id ) . "'";
556 482 $analytics = $wpdb->get_results(
557 - $wpdb->prepare(
558 - "SELECT
559 - sum(impressions) as totalViews,
560 - sum(unique_visit) as totalUniqueViews,
561 - sum(happy + sad + normal) as totalReactions,
562 - sum(happy) as totalHappy,
563 - sum(normal) as totalNormal,
564 - sum(sad) as totalSad
565 - FROM {$wpdb->prefix}betterdocs_analytics
566 - WHERE post_id = %d",
567 - $post_id
568 - )
483 + "SELECT
484 + sum(impressions) as totalViews,
485 + sum(unique_visit) as totalUniqueViews,
486 + sum(happy + sad + normal) as totalReactions,
487 + sum(happy) as totalHappy,
488 + sum(normal) as totalNormal,
489 + sum(sad) as totalSad
490 + FROM {$wpdb->prefix}betterdocs_analytics
491 + $where"
569 492 );
570 493
571 494 echo '<ul class="reactions-count">
572 495 <li>
@@ -622,22 +545,22 @@
622 545 * @return void
623 546 * @since 1.0.0
624 547 */
625 548 public function styles( $hook ) {
626 - $this->assets->enqueue( 'betterdocs-global', 'admin/css/global.css', array(), 'all' );
549 + $this->assets->enqueue( 'betterdocs-global', 'admin/css/global.css', [], 'all' );
627 550
628 551 if ( ! betterdocs()->is_betterdocs_screen( $hook ) ) {
629 552 return;
630 553 }
631 554
632 - $this->assets->enqueue( 'betterdocs-select2', 'vendor/css/select2.min.css', array(), 'all' );
633 - $this->assets->enqueue( 'betterdocs-daterangepicker', 'vendor/css/daterangepicker.css', array(), 'all' );
634 - $this->assets->enqueue( 'betterdocs-old', 'admin/css/betterdocs.css', array(), 'all' );
555 + $this->assets->enqueue( 'betterdocs-select2', 'vendor/css/select2.min.css', [], 'all' );
556 + $this->assets->enqueue( 'betterdocs-daterangepicker', 'vendor/css/daterangepicker.css', [], 'all' );
557 + $this->assets->enqueue( 'betterdocs-old', 'admin/css/betterdocs.css', [], 'all' );
635 558
636 559 /**
637 - * This scripts enqueued for Dashboard App.
638 - */
639 - $this->assets->enqueue( 'betterdocs', 'admin/css/dashboard.css', array( 'betterdocs-old' ), '', BETTERDOCS_VERSION );
560 + * This scripts enqueued for Dashboard App.
561 + */
562 + $this->assets->enqueue( 'betterdocs', 'admin/css/dashboard.css', [ 'betterdocs-old' ] );
640 563 $this->assets->enqueue( 'betterdocs-icons', 'admin/btd-icon/style.css' );
641 564 }
642 565
643 566 /**
@@ -648,26 +571,26 @@
648 571 * @return void
649 572 * @since 1.0.0
650 573 */
651 574 public function scripts( $hook ) {
652 - if ( ( 'edit.php' === $hook ) && get_post_type() == 'docs' ) {
575 + if ( ( $hook === 'edit.php' ) && get_post_type() == 'docs' ) {
653 576 $this->assets->enqueue(
654 577 'betterdocs-switcher',
655 578 'admin/js/switcher.js',
656 - array(
657 - 'jquery',
658 - )
579 + [
580 + 'jquery'
581 + ]
659 582 );
660 583
661 584 $this->assets->localize(
662 585 'betterdocs-switcher',
663 586 'betterdocsSwitcher',
664 - array(
587 + [
665 588 'menu_title' => __( 'Switch to BetterDocs UI', 'betterdocs' ),
666 589 'site_address' => get_bloginfo( 'url' ),
667 590 'betterdocs_pro_plugin' => betterdocs()->is_pro_active(),
668 - 'betterdocs_pro_version' => betterdocs()->pro_version(),
669 - )
591 + 'betterdocs_pro_version' => betterdocs()->pro_version()
592 + ]
670 593 );
671 594
672 595 return;
673 596 }
@@ -677,9 +600,8 @@
677 600 if ( ! betterdocs()->is_betterdocs_screen( $hook ) ) {
678 601 return;
679 602 }
680 603
681 - wp_enqueue_media(); // load early to fix problems with media upload issues on settings for WordPress 6.0.9
682 604 $this->assets->register( 'betterdocs-admin', 'admin/js/dashboard.js' );
683 605
684 606 $saved_settings = get_option( 'betterdocs_settings', false );
685 607 $dark_mode = $saved_settings['dark_mode'] ?? false;
@@ -686,55 +608,50 @@
686 608 $dark_mode = ! empty( $dark_mode ) && boolval( $dark_mode );
687 609 $this->assets->localize(
688 610 'betterdocs-admin',
689 611 'betterdocs_admin',
690 - array(
612 + [
691 613 'ajaxurl' => admin_url( 'admin-ajax.php' ),
692 614 'doc_cat_order_nonce' => wp_create_nonce( 'doc_cat_order_nonce' ),
693 615 'knowledge_base_order_nonce' => wp_create_nonce( 'knowledge_base_order_nonce' ),
694 - 'paged' => isset( $_GET['paged'] ) ? absint( wp_unslash( $_GET['paged'] ) ) : 0, // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- pagination read from URL.
695 - 'per_page_id' => 'edit_doc_category_per_page',
696 - 'menu_title' => __( 'Switch to BetterDocs UI', 'betterdocs' ),
697 - 'dark_mode' => $dark_mode,
698 - 'text' => __( 'Copied!', 'betterdocs' ),
699 - 'test_report' => __( 'Test Report!', 'betterdocs' ),
700 - 'sending' => __( 'Sending...', 'betterdocs' ),
701 - 'dir_url' => BETTERDOCS_ABSURL,
702 - 'rest_url' => esc_url_raw( rest_url() ),
703 - 'free_version' => betterdocs()->version,
704 - 'generate_data_url' => get_rest_url( null, '/betterdocs/v1/create-sample-docs' ),
705 - 'nonce' => wp_create_nonce( 'wp_rest' ),
706 - 'sync_nonce' => wp_create_nonce( 'ai_chatbot_embed' ),
707 - 'count_all_docs' => array_sum( (array) wp_count_posts( 'docs' ) ),
708 - 'count_all_faq' => array_sum( (array) wp_count_posts( 'betterdocs_faq' ) ),
709 - 'count_new_docs' => $this->get_not_synced_docs_count(),
710 - 'admin_url' => admin_url(),
711 - 'ia_preview' => betterdocs()->settings->get( 'ia_enable_preview', false ),
712 - 'multiple_kb' => betterdocs()->settings->get( 'multiple_kb' ),
713 - 'previewMode' => betterdocs()->settings->get( 'ia_enable_preview', false ),
714 - 'dashboard_mode' => get_option( 'dashboard_mode' ),
715 - 'betterdocs_pro_plugin' => betterdocs()->is_pro_active(),
716 - 'betterdocs_pro_version' => betterdocs()->pro_version(),
717 - 'analytics_older' => version_compare( betterdocs()->pro_version(), '3.3.4', '<=' ),
718 - 'disabled_embed_model_option' => get_option( 'disabled_embed_model_option' ),
719 - 'betterdocs_ChatBot_plugin' => is_plugin_active( 'betterdocs-ai-chatbot/betterdocs-ai-chatbot.php' ),
720 - 'total_doc_category_terms' => wp_count_terms( 'doc_category' ),
721 - 'current_admin_language' => Helper::get_current_admin_language(),
722 - 'is_multilingual' => Helper::is_multilingual_active(),
723 - )
616 + 'paged' => isset( $_GET['paged'] ) ? absint( wp_unslash( $_GET['paged'] ) ) : 0, // phpcs:ignore WordPress.Security.NonceVerification.Missing
617 + 'per_page_id' => 'edit_doc_category_per_page',
618 + 'menu_title' => __( 'Switch to BetterDocs UI', 'betterdocs' ),
619 + 'dark_mode' => $dark_mode,
620 + 'text' => __( 'Copied!', 'betterdocs' ),
621 + 'test_report' => __( 'Test Report!', 'betterdocs' ),
622 + 'sending' => __( 'Sending...', 'betterdocs' ),
623 + 'dir_url' => BETTERDOCS_ABSURL,
624 + 'rest_url' => esc_url_raw( rest_url() ),
625 + 'free_version' => betterdocs()->version,
626 + 'generate_data_url' => get_rest_url( null, '/betterdocs/v1/create-sample-docs' ),
627 + 'nonce' => wp_create_nonce( 'wp_rest' ),
628 + 'sync_nonce' => wp_create_nonce( 'ai_chatbot_embed' ),
629 + 'count_all_docs' => wp_count_posts('docs')->publish,
630 + 'count_new_docs' => count(get_option('saved_docs_post_ids', [])),
631 + 'admin_url' => admin_url(),
632 + 'ia_preview' => betterdocs()->settings->get( 'ia_enable_preview', false ),
633 + 'multiple_kb' => betterdocs()->settings->get( 'multiple_kb' ),
634 + 'previewMode' => betterdocs()->settings->get( 'ia_enable_preview', false ),
635 + 'dashboard_mode' => get_option( 'dashboard_mode' ),
636 + 'betterdocs_pro_plugin' => betterdocs()->is_pro_active(),
637 + 'betterdocs_pro_version' => betterdocs()->pro_version(),
638 + 'analytics_older' => version_compare( betterdocs()->pro_version(), '3.3.4', '<=' ),
639 + 'disabled_embed_model_option'=> get_option('disabled_embed_model_option'),
640 + ]
724 641 );
725 642
726 643 // If wp-date (which includes moment.js) is not registered, enqueue your custom moment.js
727 644 if ( ! wp_script_is( 'wp-date', 'registered' ) ) {
728 - $this->assets->enqueue( 'moment', 'vendor/js/moment.min.js', array() );
645 + $this->assets->enqueue( 'moment', 'vendor/js/moment.min.js', [] );
729 646 }
730 647 wp_enqueue_script( 'betterdocs-admin' );
731 648
732 649 /**
733 - * Duplicate Codes Need to Be Removed From Here Onwards
734 - */
650 + * Duplicate Codes Need to Be Removed From Here Onwards
651 + */
735 652
736 - // FAQ Builder Related Localization
653 + //FAQ Builder Related Localization
737 654 betterdocs()->assets->enqueue( 'betterdocs-admin-faq', 'admin/css/faq.css' );
738 655 betterdocs()->assets->enqueue( 'betterdocs-admin-faq', 'admin/js/faq.js' );
739 656
740 657 // removing emoji support
@@ -740,28 +657,21 @@
740 657 // removing emoji support
741 658 remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
742 659 remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
743 660
744 - // Get settings and remove unnecessary keys
745 - $betterdocs_settings = get_option( 'betterdocs_settings', false );
746 - if ( is_array( $betterdocs_settings ) && ! current_user_can( 'edit_docs_settings' ) ) {
747 - unset( $betterdocs_settings['ai_autowrite_api_key'] );
748 - unset( $betterdocs_settings['ai_chatbot_api_key'] );
749 - }
750 -
751 661 betterdocs()->assets->localize(
752 662 'betterdocs-admin-faq',
753 663 'betterdocsFaq',
754 - array(
664 + [
755 665 'dir_url' => BETTERDOCS_ABSURL,
756 666 'rest_url' => esc_url_raw( rest_url() ),
757 667 'free_version' => betterdocs()->version,
758 668 'nonce' => wp_create_nonce( 'wp_rest' ),
759 - 'betterdocs_settings' => $betterdocs_settings,
760 - )
669 + 'betterdocs_settings' => get_option( 'betterdocs_settings', false )
670 + ]
761 671 );
762 672
763 - // Glossaries Related Localization
673 + //Glossaries Related Localization
764 674 betterdocs()->assets->enqueue( 'betterdocs-admin-glossaries', 'admin/css/faq.css' );
765 675
766 676 betterdocs()->assets->enqueue( 'betterdocs-admin-glossaries', 'admin/js/glossaries.js' );
767 677
@@ -767,15 +677,15 @@
767 677
768 678 betterdocs()->assets->localize(
769 679 'betterdocs-admin-glossaries',
770 680 'betterdocsGlossary',
771 - array(
681 + [
772 682 'dir_url' => BETTERDOCS_ABSURL,
773 683 'rest_url' => esc_url_raw( rest_url() ),
774 684 'free_version' => betterdocs()->version,
775 685 'nonce' => wp_create_nonce( 'wp_rest' ),
776 - 'betterdocs_settings' => $betterdocs_settings,
777 - )
686 + 'betterdocs_settings' => get_option( 'betterdocs_settings', false )
687 + ]
778 688 );
779 689 }
780 690
781 691 /**
@@ -784,31 +694,31 @@
784 694 * @return void
785 695 * @since 1.0.0
786 696 */
787 697 public function header( $admin_tab_name ) {
788 - $quick_links = array(
698 + $quick_links = [
789 699 'switch_view' => sprintf(
790 700 '<a href="%s" class="betterdocs-button betterdocs-button-secondary">%s</a>',
791 701 add_query_arg(
792 - array(
702 + [
793 703 'post_type' => 'docs',
794 - 'bdocs_view' => 'classic',
795 - ),
704 + 'bdocs_view' => 'classic'
705 + ],
796 706 'edit.php'
797 707 ),
798 708 __( 'Switch to Classic UI', 'betterdocs' )
799 709 ),
800 - 'add_new_doc' => sprintf( '<a href="%s" class="betterdocs-button betterdocs-button-primary">%s</a>', add_query_arg( array( 'post_type' => 'docs' ), 'post-new.php' ), __( 'Add New Doc', 'betterdocs' ) ),
801 - );
710 + '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' ) )
711 + ];
802 712
803 713 $quick_links = apply_filters( 'betterdocs_quick_links', $quick_links );
804 714
805 715 betterdocs()->views->get(
806 716 'admin/header',
807 - array(
717 + [
808 718 'quick_links' => $quick_links,
809 - 'active_tab' => $admin_tab_name,
810 - )
719 + 'active_tab' => $admin_tab_name
720 + ]
811 721 );
812 722 }
813 723
814 724 /**
@@ -816,77 +726,37 @@
816 726 *
817 727 * @return void
818 728 * @since 1.0.0
819 729 */
730 +
820 731 public function menus() {
821 - $default_args = array(
732 + $default_args = [
822 733 'page_title' => 'BetterDocs',
823 734 'menu_title' => 'BetterDocs',
824 - 'capability' => 'edit_docs', // Unified capability
735 + 'capability' => 'edit_posts',
825 736 'menu_slug' => $this->slug,
826 - 'callback' => array( $this, 'output' ),
737 + 'callback' => [ $this, 'output' ],
827 738 'icon_url' => betterdocs()->assets->icon( 'betterdocs-icon-white.svg', true ),
828 - 'position' => 5,
829 - );
739 + 'position' => 5
740 + ];
830 741
831 742 $_menu_position = 5;
832 - global $submenu;
833 743
834 - // Always register both UI endpoints
835 - $this->register_modern_ui_fallback();
836 -
837 744 foreach ( $this->menu_list() as $key => $value ) {
838 - if ( 'betterdocs' === $key ) {
745 + if ( $key === 'betterdocs' ) {
839 746 $callable = 'add_menu_page';
840 747 $value = wp_parse_args( $value, $default_args );
841 - call_user_func_array( $callable, $value );
842 748 } else {
843 - $is_core_page = strpos( $value['menu_slug'], '?' ) !== false;
844 -
845 - if ( $is_core_page ) {
846 - // Add classic UI directly
847 - $submenu[ $this->slug ][] = array(
848 - $value['menu_title'],
849 - $value['capability'],
850 - $value['menu_slug'],
851 - $value['page_title'],
852 - );
853 - } else {
854 - // Add modern UI through WordPress API
855 - add_submenu_page(
856 - $this->slug,
857 - $value['page_title'],
858 - $value['menu_title'],
859 - $value['capability'],
860 - $value['menu_slug'],
861 - $value['callback']
862 - );
863 - }
864 - ++$_menu_position;
749 + $callable = 'add_submenu_page';
750 + $default_args['callback'] = '';
751 + $default_args['position'] = $_menu_position;
752 + unset( $default_args['icon_url'] );
753 + $value = wp_parse_args( $value, array_merge( [ 'parent_slug' => $this->slug ], $default_args ) );
865 754 }
866 - }
867 - }
868 755
869 - private function register_modern_ui_fallback() {
870 - // Add the submenu with valid parent slug
871 - add_submenu_page(
872 - 'betterdocs', // Valid parent slug
873 - __( 'All Docs', 'betterdocs' ),
874 - '', // Empty menu title hides it
875 - 'edit_docs',
876 - 'betterdocs-admin',
877 - array( $this, 'output' )
878 - );
756 + ++$_menu_position;
879 757
880 - // Hide the menu item from appearing in the admin sidebar
881 - global $submenu;
882 - if ( isset( $submenu['betterdocs'] ) ) {
883 - foreach ( $submenu['betterdocs'] as $key => $item ) {
884 - if ( 'betterdocs-admin' === $item[2] ) {
885 - unset( $submenu['betterdocs'][ $key ] );
886 - break;
887 - }
888 - }
758 + call_user_func_array( $callable, $value );
889 759 }
890 760 }
891 761
892 762 /**
@@ -896,17 +766,17 @@
896 766 * @since 1.0.0
897 767 */
898 768 public function output() {
899 769 if ( betterdocs()->is_pro_active()
900 - && version_compare( betterdocs()->pro_version(), '3.3.4', '<=' )
901 - && get_current_screen()->id == 'betterdocs_page_betterdocs-analytics' ) {
770 + && version_compare( betterdocs()->pro_version(), '3.3.4', '<=' )
771 + && get_current_screen()->id == 'betterdocs_page_betterdocs-analytics' ) {
902 772 betterdocs_pro()->views->get( 'admin/analytics-pro' );
903 773 } else {
904 774 betterdocs()->views->get(
905 775 'admin/main',
906 - array(
907 - 'admin_ui' => 'dnd',
908 - )
776 + [
777 + 'admin_ui' => 'dnd'
778 + ]
909 779 );
910 780 }
911 781 }
912 782
@@ -919,10 +789,11 @@
919 789 * @param array $callback
920 790 *
921 791 * @return array
922 792 * @since 2.5.0
793 + *
923 794 */
924 - private function normalize_menu( $title, $slug, $cap = 'edit_docs', $callback = null, $optional = array() ) {
795 + private function normalize_menu( $title, $slug, $cap = 'edit_docs', $callback = null, $optional = [] ) {
925 796 return Helper::normalize_menu( $title, $slug, $cap, $callback, $optional );
926 797 }
927 798
928 799 /**
@@ -931,58 +802,32 @@
931 802 * @return array
932 803 * @since 1.0.0
933 804 */
934 805 private function menu_list() {
935 - $parent_slug = array();
806 + $parent_slug = [];
936 807
937 - $betterdocs_admin_pages = array(
938 - 'betterdocs' => array(
808 + $betterdocs_admin_pages = [
809 + 'betterdocs' => [
939 810 'menu_slug' => $this->slug,
940 811 'page_title' => 'BetterDocs',
941 812 'menu_title' => 'BetterDocs',
942 813 'capability' => 'edit_docs',
943 - 'callback' => array( $this, 'output' ),
814 + 'callback' => [ $this, 'output' ],
944 815 'icon_url' => betterdocs()->assets->icon( 'betterdocs-icon-white.svg', true ),
945 - 'position' => 5,
946 - ),
947 - 'dashboard' => $this->normalize_menu(
948 - __( 'Dashboard', 'betterdocs' ),
949 - 'betterdocs-dashboard',
950 - 'edit_docs',
951 - array(
952 - $this,
953 - 'output',
954 - )
955 - ),
956 - 'all_docs' => $this->normalize_menu(
957 - __( 'All Docs', 'betterdocs' ),
958 - $this->ui_slug(),
959 - 'edit_docs',
960 - array( $this, 'output' ),
961 - $parent_slug
962 - ),
963 - 'add_new' => $this->normalize_menu(
964 - __( 'Add New', 'betterdocs' ),
965 - 'post-new.php?post_type=docs'
966 - ),
967 - 'categories' => $this->normalize_menu(
968 - __( 'Categories', 'betterdocs' ),
969 - 'edit-tags.php?taxonomy=doc_category&post_type=docs',
970 - 'manage_doc_terms'
971 - ),
972 - 'tags' => $this->normalize_menu(
973 - __( 'Tags', 'betterdocs' ),
974 - 'edit-tags.php?taxonomy=doc_tag&post_type=docs',
975 - 'manage_doc_terms'
976 - ),
816 + 'position' => 5
817 + ],
818 + 'all_docs' => $this->normalize_menu( __( 'All Docs', 'betterdocs' ), $this->ui_slug() ),
819 + 'add_new' => $this->normalize_menu( __( 'Add New', 'betterdocs' ), 'post-new.php?post_type=docs' ),
820 + 'categories' => $this->normalize_menu( __( 'Categories', 'betterdocs' ), 'edit-tags.php?taxonomy=doc_category&post_type=docs', 'manage_doc_terms' ),
821 + 'tags' => $this->normalize_menu( __( 'Tags', 'betterdocs' ), 'edit-tags.php?taxonomy=doc_tag&post_type=docs', 'manage_doc_terms' ),
977 822 'settings' => $this->normalize_menu(
978 823 __( 'Settings', 'betterdocs' ),
979 824 'betterdocs-settings',
980 825 'edit_docs_settings',
981 - array(
826 + [
982 827 $this,
983 - 'output',
984 - ),
828 + 'output'
829 + ],
985 830 $parent_slug
986 831 ),
987 832 'analytics' => $this->normalize_menu(
988 833 __( 'Analytics', 'betterdocs' ),
@@ -987,25 +832,25 @@
987 832 'analytics' => $this->normalize_menu(
988 833 __( 'Analytics', 'betterdocs' ),
989 834 'betterdocs-analytics',
990 835 'read_docs_analytics',
991 - array(
836 + [
992 837 $this,
993 - 'output',
994 - ),
838 + 'output'
839 + ],
995 840 $parent_slug
996 841 ),
997 842 'faq' => $this->normalize_menu(
998 843 __( 'FAQ Builder', 'betterdocs' ),
999 844 'betterdocs-faq',
1000 - 'read_faq_builder',
1001 - array(
845 + 'read_docs_analytics',
846 + [
1002 847 $this,
1003 - 'output',
1004 - ),
848 + 'output'
849 + ],
1005 850 $parent_slug
1006 - ),
1007 - );
851 + )
852 + ];
1008 853
1009 854 if ( betterdocs()->is_pro_active() && betterdocs()->settings->get( 'enable_glossaries' ) == true ) {
1010 855 $betterdocs_admin_pages['glossaries'] = $this->normalize_menu(
1011 856 __( 'Glossaries', 'betterdocs' ),
@@ -1010,36 +855,24 @@
1010 855 $betterdocs_admin_pages['glossaries'] = $this->normalize_menu(
1011 856 __( 'Glossaries', 'betterdocs' ),
1012 857 'betterdocs-glossaries',
1013 858 'read_docs_analytics',
1014 - array(
859 + [
1015 860 $this,
1016 - 'output',
1017 - ),
861 + 'output'
862 + ],
1018 863 $parent_slug
1019 864 );
1020 865 }
1021 866
1022 - if ( ! betterdocs()->is_chatbot_active() ) {
1023 - $betterdocs_admin_pages['ai_chatbot'] = $this->normalize_menu(
1024 - __( 'AI Chatbot', 'betterdocs' ),
1025 - 'betterdocs-ai-chatbot',
1026 - 'edit_docs_settings',
1027 - array(
1028 - $this,
1029 - 'output',
1030 - ),
1031 - $parent_slug
1032 - );
1033 - }
867 + return apply_filters( 'betterdocs_admin_menu', $betterdocs_admin_pages, [$this, 'output'], $parent_slug);
1034 868
1035 - return apply_filters( 'betterdocs_admin_menu', $betterdocs_admin_pages, array( $this, 'output' ), $parent_slug );
1036 - }
869 + }
1037 870
1038 871 public function add_custom_classes_to_menu_items() {
1039 872 global $menu, $submenu;
1040 873
1041 - $menu_items = array(
874 + $menu_items = [
1042 875 'betterdocs' => 'betterdocs',
1043 876 'betterdocs_page_all_docs' => 'betterdocs-all-docs',
1044 877 'betterdocs_page_add_new' => 'betterdocs-add-new',
1045 878 'edit-tags.php?taxonomy=doc_category&post_type=docs' => 'betterdocs-categories',
@@ -1048,10 +881,10 @@
1048 881 'betterdocs-analytics' => 'betterdocs-analytics',
1049 882 'betterdocs-faq' => 'betterdocs-faq',
1050 883 'betterdocs-glossaries' => 'betterdocs-glossaries',
1051 884 'betterdocs-ai-chatbot' => 'betterdocs-ai-chatbot',
1052 - 'edit-tags.php?taxonomy=knowledge_base&post_type=docs' => 'betterdocs-multiplekb',
1053 - );
885 + 'edit-tags.php?taxonomy=knowledge_base&post_type=docs' => 'betterdocs-multiplekb'
886 + ];
1054 887
1055 888 foreach ( $menu as &$item ) {
1056 889 if ( isset( $menu_items[ $item[2] ] ) ) {
1057 890 if ( ! isset( $item[4] ) ) {
@@ -1081,12 +914,12 @@
1081 914 $menus['quick_setup'] = $this->normalize_menu(
1082 915 __( 'Quick Setup', 'betterdocs' ),
1083 916 'betterdocs-setup',
1084 917 'delete_users',
1085 - array(
918 + [
1086 919 $this->container->get( SetupWizard::class ),
1087 - 'views',
1088 - )
920 + 'views'
921 + ]
1089 922 );
1090 923 }
1091 924
1092 925 return $menus;
@@ -1094,12 +927,8 @@
1094 927
1095 928 public function insert_plugin_links( $links ) {
1096 929 $links[] = '<a href="admin.php?page=betterdocs-settings">' . __( 'Settings', 'betterdocs' ) . '</a>';
1097 930
1098 - if ( ! is_plugin_active( 'betterdocs-pro/betterdocs-pro.php' ) ) {
1099 - $links[] = '<a href="https://betterdocs.co/upgrade-to-pro-plugins-wp" target="_blank" style="color: #000; font-weight: bold;">' . __( 'Upgrade to Pro', 'betterdocs' ) . '</a>';
1100 - }
1101 -
1102 931 return $links;
1103 932 }
1104 933
1105 934 public function toolbar_menu( $admin_bar ) {
@@ -1126,22 +955,17 @@
1126 955 }
1127 956
1128 957 $slug = $this->settings->get( 'encyclopedia_root_slug' );
1129 958
1130 - global $wp_rewrite;
1131 - if ( $wp_rewrite->using_index_permalinks() ) {
1132 - $slug = $wp_rewrite->index . '/' . $slug;
1133 - }
1134 -
1135 959 $encyclopedia_url = home_url( $slug );
1136 960
1137 961 $admin_bar->add_node(
1138 - array(
962 + [
1139 963 'parent' => 'site-name',
1140 964 'id' => 'view-docs',
1141 965 'title' => __( 'Visit Documentation', 'betterdocs' ),
1142 - 'href' => $docs_url,
1143 - )
966 + 'href' => $docs_url
967 + ]
1144 968 );
1145 969
1146 970 $is_enable_encyclopedia = betterdocs()->settings->get( 'enable_encyclopedia' );
1147 971
@@ -1146,14 +970,14 @@
1146 970 $is_enable_encyclopedia = betterdocs()->settings->get( 'enable_encyclopedia' );
1147 971
1148 972 if ( $is_enable_encyclopedia && betterdocs()->is_pro_active() ) {
1149 973 $admin_bar->add_node(
1150 - array(
974 + [
1151 975 'parent' => 'site-name',
1152 976 'id' => 'view-encyclopedia',
1153 977 'title' => __( 'Visit Encyclopedia', 'betterdocs' ),
1154 - 'href' => $encyclopedia_url,
1155 - )
978 + 'href' => $encyclopedia_url
979 + ]
1156 980 );
1157 981 }
1158 982 }
1159 983
@@ -1160,20 +984,14 @@
1160 984 /**
1161 985 * Save last visited admin ui
1162 986 *
1163 987 * @since 3.0.1
988 + *
1164 989 */
1165 990 public function save_admin_page() {
1166 - // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only screen detection.
1167 - $post_type = isset( $_GET['post_type'] ) ? sanitize_text_field( wp_unslash( $_GET['post_type'] ) ) : '';
1168 - // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only screen detection.
1169 - $bdocs_view = isset( $_GET['bdocs_view'] ) ? sanitize_text_field( wp_unslash( $_GET['bdocs_view'] ) ) : '';
1170 - // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only screen detection.
1171 - $page = isset( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : '';
1172 -
1173 - if ( 'docs' === $post_type && 'classic' === $bdocs_view ) {
991 + if ( isset( $_GET['post_type'] ) && $_GET['post_type'] === 'docs' && isset( $_GET['bdocs_view'] ) && $_GET['bdocs_view'] === 'classic' ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
1174 992 update_user_meta( get_current_user_id(), 'last_visited_docs_admin_page', 'classic_ui' );
1175 - } elseif ( 'betterdocs-admin' === $page ) {
993 + } elseif ( isset( $_GET['page'] ) && $_GET['page'] === 'betterdocs-admin' ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
1176 994 update_user_meta( get_current_user_id(), 'last_visited_docs_admin_page', 'modern_ui' );
1177 995 }
1178 996 }
1179 997
@@ -1184,19 +1002,23 @@
1184 1002 * @since 3.0.1
1185 1003 */
1186 1004 public function ui_slug() {
1187 1005 $last_visited = get_user_meta( get_current_user_id(), 'last_visited_docs_admin_page', true );
1188 - $docs_exist = get_posts(
1189 - array(
1006 + $docs = get_posts(
1007 + [
1190 1008 'post_type' => 'docs',
1191 1009 'post_status' => 'any',
1192 - 'numberposts' => 1,
1193 - )
1010 + 'numberposts' => 2
1011 + ]
1194 1012 );
1195 1013
1196 - return ( 'modern_ui' === $last_visited || empty( $docs_exist ) )
1197 - ? 'betterdocs-admin'
1198 - : 'edit.php?post_type=docs&bdocs_view=classic';
1014 + if ( $last_visited === 'modern_ui' || count( $docs ) == 0 ) {
1015 + $slug = 'betterdocs-admin';
1016 + } else {
1017 + $slug = admin_url( 'edit.php?post_type=docs&bdocs_view=classic' );
1018 + }
1019 +
1020 + return $slug;
1199 1021 }
1200 1022
1201 1023 /**
1202 1024 * Resets a duplicate submenu in WordPress if the parent main menu and the first submenu permalink are not the same.
@@ -1206,9 +1028,9 @@
1206 1028 */
1207 1029 public function reset_submenu() {
1208 1030 global $submenu;
1209 1031
1210 - $docs = get_posts( array( 'post_type' => 'docs' ) );
1032 + $docs = get_posts( [ 'post_type' => 'docs' ] );
1211 1033 if ( count( $docs ) == 0 ) {
1212 1034 return;
1213 1035 }
1214 1036
@@ -1213,89 +1035,10 @@
1213 1035 }
1214 1036
1215 1037 $last_visited = get_user_meta( get_current_user_id(), 'last_visited_docs_admin_page', true );
1216 1038
1217 - if ( 'classic_ui' === $last_visited && isset( $submenu['betterdocs-admin'] ) && in_array( 'betterdocs-admin', $submenu['betterdocs-admin'][0] ) ) {
1039 + if ( $last_visited === 'classic_ui' && isset( $submenu['betterdocs-admin'] ) && in_array( 'betterdocs-admin', $submenu['betterdocs-admin'][0] ) ) {
1218 1040 unset( $submenu['betterdocs-admin'][0] );
1219 1041 $submenu['betterdocs-admin'] = array_values( $submenu['betterdocs-admin'] );
1220 1042 }
1221 - }
1222 -
1223 - /**
1224 - * Initialize Black Friday Pointer
1225 - *
1226 - * @return void
1227 - * @since 3.7.0
1228 - */
1229 - private function init_black_friday_pointer() {
1230 - // Only initialize if conditions are met
1231 - if ( NoticePointers::should_display_notice() ) {
1232 - new NoticePointers();
1233 - }
1234 - }
1235 -
1236 - /**
1237 - * AJAX handler for dismissing Black Friday pointer
1238 - *
1239 - * @return void
1240 - * @since 3.7.0
1241 - */
1242 - public function ajax_dismiss_black_friday_pointer() {
1243 - // Verify nonce
1244 - $nonce = isset( $_POST['nonce'] ) ? sanitize_text_field( wp_unslash( $_POST['nonce'] ) ) : '';
1245 - if ( ! wp_verify_nonce( $nonce, 'betterdocs_dismiss_pointer' ) ) {
1246 - wp_send_json_error( array( 'message' => __( 'Invalid nonce', 'betterdocs' ) ) );
1247 - }
1248 -
1249 - // Check if user has permission
1250 - if ( ! current_user_can( 'manage_options' ) && ! current_user_can( 'edit_docs' ) ) {
1251 - wp_send_json_error( array( 'message' => __( 'Permission denied', 'betterdocs' ) ) );
1252 - }
1253 -
1254 - // Get the introduction key
1255 - $introduction_key = isset( $_POST['introduction_key'] ) ? sanitize_text_field( wp_unslash( $_POST['introduction_key'] ) ) : '';
1256 -
1257 - if ( empty( $introduction_key ) ) {
1258 - wp_send_json_error( array( 'message' => __( 'Invalid introduction key', 'betterdocs' ) ) );
1259 - }
1260 -
1261 - // Set the introduction as viewed
1262 - NoticePointers::set_introduction_viewed( $introduction_key );
1263 -
1264 - // Clear the priority option so other plugins can set their priority
1265 - delete_option( '_wpdeveloper_plugin_pointer_priority' );
1266 -
1267 - wp_send_json_success( array( 'message' => __( 'Pointer dismissed successfully', 'betterdocs' ) ) );
1268 - }
1269 -
1270 - /**
1271 - * Get count of docs that are not yet synced
1272 - * Similar to Helper::get_not_synced_post_ids() in betterdocs-ai-chatbot plugin
1273 - *
1274 - * @return int
1275 - * @since 3.7.0
1276 - */
1277 - private function get_not_synced_docs_count() {
1278 - $new_post_ids = get_option( 'saved_docs_post_ids', array() );
1279 - $error_posts_data = get_option( 'betterdocs_ai_chatbot_error_posts', array() );
1280 -
1281 - // Extract post IDs from error posts (handle both old and new formats)
1282 - $error_post_ids = array();
1283 - if ( is_array( $error_posts_data ) && ! empty( $error_posts_data ) ) {
1284 - foreach ( $error_posts_data as $key => $value ) {
1285 - if ( is_numeric( $key ) && is_numeric( $value ) ) {
1286 - // Old format: numeric key with post ID as value
1287 - $error_post_ids[] = $value;
1288 - } elseif ( is_numeric( $key ) && is_array( $value ) && isset( $value['post_id'] ) ) {
1289 - // New format: post ID as key with structured data
1290 - $error_post_ids[] = $key;
1291 - } elseif ( is_numeric( $key ) ) {
1292 - // New format: post ID as key
1293 - $error_post_ids[] = $key;
1294 - }
1295 - }
1296 - }
1297 -
1298 - // Merge both arrays and remove duplicates, then count
1299 - return count( array_unique( array_merge( $new_post_ids, $error_post_ids ) ) );
1300 1043 }
1301 1044 }