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