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/Plugin.php +348 -422 4.7.03.8.9 View file →
@@ -2,9 +2,9 @@
2 2
3 3 namespace WPDeveloper\BetterDocs;
4 4
5 5 if ( ! defined( 'ABSPATH' ) ) {
6 - exit; // Exit if accessed directly
6 + exit; // Exit if accessed directly
7 7 }
8 8
9 9 use WPDeveloper\BetterDocs\Admin\Analytics;
10 10 use WPDeveloper\BetterDocs\Admin\Customizer\Customizer;
@@ -10,10 +10,8 @@
10 10 use WPDeveloper\BetterDocs\Admin\Customizer\Customizer;
11 11 use WPDeveloper\BetterDocs\Admin\HelpScoutMigration;
12 12 use WPDeveloper\BetterDocs\Admin\ReportEmail;
13 13 use WPDeveloper\BetterDocs\Core\Admin;
14 -use WPDeveloper\BetterDocs\Core\AnalyticsTracker;
15 -use WPDeveloper\BetterDocs\Core\AnalyticsRetention;
16 14 use WPDeveloper\BetterDocs\Core\BaseAPI;
17 15 use WPDeveloper\BetterDocs\Core\Install;
18 16 use WPDeveloper\BetterDocs\Core\KBMigration;
19 17 use WPDeveloper\BetterDocs\Core\Query;
@@ -23,19 +21,13 @@
23 21 use WPDeveloper\BetterDocs\Core\Scripts;
24 22 use WPDeveloper\BetterDocs\Core\Settings;
25 23 use WPDeveloper\BetterDocs\Core\ShortcodeFactory;
26 24 use WPDeveloper\BetterDocs\Core\WriteWithAI;
27 -use WPDeveloper\BetterDocs\Core\ArticleSummary;
28 -use WPDeveloper\BetterDocs\Core\ArticleQualityScore;
29 -use WPDeveloper\BetterDocs\Core\UnifiedMetabox;
30 -use WPDeveloper\BetterDocs\Core\DocsAISuite;
31 25 use WPDeveloper\BetterDocs\Dependencies\DI\Container;
32 26 use WPDeveloper\BetterDocs\Dependencies\DI\ContainerBuilder;
33 27 use WPDeveloper\BetterDocs\Editors\Editor;
34 28 use WPDeveloper\BetterDocs\FrontEnd\FrontEnd;
35 -use WPDeveloper\BetterDocs\FrontEnd\SearchExtender;
36 29 use WPDeveloper\BetterDocs\FrontEnd\TemplateTags;
37 -use WPDeveloper\BetterDocs\FrontEnd\WooProductFAQ;
38 30 use WPDeveloper\BetterDocs\Modules\StyleHandler as ModulesStyleHandler;
39 31 use WPDeveloper\BetterDocs\Utils\Database;
40 32 use WPDeveloper\BetterDocs\Utils\Enqueue;
41 33 use WPDeveloper\BetterDocs\Utils\Helper;
@@ -41,480 +33,414 @@
41 33 use WPDeveloper\BetterDocs\Utils\Helper;
42 34 use WPDeveloper\BetterDocs\Utils\Views;
43 35
44 36 final class Plugin {
45 - private static $_instance = null;
46 - /**
47 - * Assets manager
48 - *
49 - * @var Enqueue
50 - */
51 - public $assets;
52 - /**
53 - * View manager
54 - *
55 - * @var Views
56 - */
57 - public $views;
58 - /**
59 - * Container Manager
60 - *
61 - * @var Container
62 - */
63 - public $container;
64 - /**
65 - * Editor Manager
66 - * @var Editor
67 - */
68 - public $editor;
69 - /**
70 - * Helper class
71 - * @var Helper
72 - */
73 - public $helper;
74 - /**
75 - * KBMigration class
76 - * @var KBMigration
77 - */
78 - public $kbmigration;
79 - /**
80 - * KBMigration class
81 - * @var Admin
82 - */
83 - public $admin;
84 - /**
85 - * Helper class
86 - * @var Database
87 - */
88 - public $database;
89 - /**
90 - * Helper class
91 - * @var Settings
92 - */
93 - public $settings;
94 - /**
95 - * Helper class
96 - * @var TemplateTags
97 - */
98 - public $template_helper;
99 - /**
100 - * Article Summary class
101 - * @var ArticleSummary
102 - */
103 - public $article_summary;
104 - /**
105 - * Customizer class
106 - * @var Customizer
107 - */
108 - public $customizer;
109 - /**
110 - * Query class
111 - * @var Query
112 - */
113 - public $query;
114 - /**
115 - * Rewrite Class
116 - * @var Rewrite
117 - */
118 - public $rewrite;
119 - /**
120 - * Request Class
121 - * @var Request
122 - */
123 - public $request;
124 - /**
125 - * Analytics Class
126 - * @var Analytics
127 - */
128 - public $analytics;
129 - /**
130 - * Plugin Version
131 - * @var string
132 - */
133 - public $version = '4.7.0';
37 + private static $_instance = null;
38 + /**
39 + * Assets manager
40 + *
41 + * @var Enqueue
42 + */
43 + public $assets;
44 + /**
45 + * View manager
46 + *
47 + * @var Views
48 + */
49 + public $views;
50 + /**
51 + * Container Manager
52 + *
53 + * @var Container
54 + */
55 + public $container;
56 + /**
57 + * Editor Manager
58 + * @var Editor
59 + */
60 + public $editor;
61 + /**
62 + * Helper class
63 + * @var Helper
64 + */
65 + public $helper;
66 + /**
67 + * KBMigration class
68 + * @var KBMigration
69 + */
70 + public $kbmigration;
71 + /**
72 + * KBMigration class
73 + * @var Admin
74 + */
75 + public $admin;
76 + /**
77 + * Helper class
78 + * @var Database
79 + */
80 + public $database;
81 + /**
82 + * Helper class
83 + * @var Settings
84 + */
85 + public $settings;
86 + /**
87 + * Helper class
88 + * @var TemplateTags
89 + */
90 + public $template_helper;
91 + /**
92 + * Customizer class
93 + * @var Customizer
94 + */
95 + public $customizer;
96 + /**
97 + * Query class
98 + * @var Query
99 + */
100 + public $query;
101 + /**
102 + * Rewrite Class
103 + * @var Rewrite
104 + */
105 + public $rewrite;
106 + /**
107 + * Request Class
108 + * @var Request
109 + */
110 + public $request;
111 + /**
112 + * Analytics Class
113 + * @var Analytics
114 + */
115 + public $analytics;
116 + /**
117 + * Plugin Version
118 + * @var string
119 + */
120 + public $version = '3.8.9';
134 121
135 - /**
136 - * WriteWithAI Class
137 - * @var string
138 - */
139 - public $ai_autowrtie;
140 - public $backgroundProccessor;
122 + /**
123 + * WriteWithAI Class
124 + * @var string
125 + */
126 + public $ai_autowrtie;
127 + public $backgroundProccessor;
141 128
142 - /**
143 - * ArticleQualityScore Class
144 - * @var ArticleQualityScore
145 - */
146 - public $article_quality_score;
129 + /**
130 + * Plugin DB Version
131 + * @var string
132 + */
133 + public $db_version = '1.0.1';
147 134
148 - /**
149 - * Plugin DB Version
150 - * @var string
151 - */
152 - public $db_version = '1.0.2';
135 + public function __construct() {
136 + $this->define_constants();
153 137
154 - public function __construct() {
155 - $this->define_constants();
138 + do_action( 'betterdocs_init_before' );
156 139
157 - do_action( 'betterdocs_init_before' );
140 + $this->setup_container();
141 + /**
142 + * Register activation and deactivation hooks
143 + * and version updates check
144 + */
145 + $this->container->get( Install::class );
158 146
159 - $this->setup_container();
160 - /**
161 - * Register activation and deactivation hooks
162 - * and version updates check
163 - */
164 - $this->container->get( Install::class );
147 + add_action( 'init', [ $this, 'initialize' ], 0 );
165 148
166 - add_action( 'init', array( $this, 'initialize' ), 0 );
149 + /**
150 + * Initialize API
151 + */
152 + add_action( 'rest_api_init', [ $this, 'api_initialization' ] );
167 153
168 - /**
169 - * Initialize API
170 - */
171 - add_action( 'rest_api_init', array( $this, 'api_initialization' ) );
154 + /**
155 + * For admin only
156 + */
157 + add_action( 'admin_init', [ $this, 'admin_init' ], 0 );
172 158
173 - /**
174 - * For admin only
175 - */
176 - add_action( 'admin_init', array( $this, 'admin_init' ), 0 );
159 + /**
160 + * For AJAX only
161 + */
162 + $this->ajax();
177 163
178 - /**
179 - * For AJAX only
180 - */
181 - $this->ajax();
164 + /**
165 + * Style Handler For Parsing and Saving Styles as file.
166 + */
167 + ModulesStyleHandler::init();
168 + }
182 169
183 - /**
184 - * Style Handler For Parsing and Saving Styles as file.
185 - */
186 - ModulesStyleHandler::init();
187 - }
170 + private function define_constants() {
171 + $this->define( 'BETTERDOCS_VERSION', $this->version );
172 + $this->define( 'BETTERDOCS_DB_VERSION', $this->db_version );
173 + $this->define( 'BETTERDOCS_ABSPATH', dirname( BETTERDOCS_PLUGIN_FILE ) . '/' );
174 + $this->define( 'BETTERDOCS_ABSURL', plugin_dir_url( BETTERDOCS_PLUGIN_FILE ) );
175 + $this->define( 'BETTERDOCS_PLUGIN_BASENAME', plugin_basename( BETTERDOCS_PLUGIN_FILE ) );
176 + $this->define( 'BETTERDOCS_BLOCKS_DIRECTORY', BETTERDOCS_ABSPATH . 'assets/blocks/' );
177 + $this->define( 'BETTERDOCS_ROOT_DIR_PATH', plugin_dir_path( BETTERDOCS_PLUGIN_FILE ) );
178 + $this->define( 'BETTERDOCS_FSE_TEMPLATES_PATH', BETTERDOCS_ROOT_DIR_PATH . 'views/templates/fse' );
188 179
189 - private function define_constants() {
190 - $this->define( 'BETTERDOCS_VERSION', $this->version );
191 - $this->define( 'BETTERDOCS_DB_VERSION', $this->db_version );
192 - $this->define( 'BETTERDOCS_ABSPATH', dirname( BETTERDOCS_PLUGIN_FILE ) . '/' );
193 - $this->define( 'BETTERDOCS_ABSURL', plugin_dir_url( BETTERDOCS_PLUGIN_FILE ) );
194 - $this->define( 'BETTERDOCS_PLUGIN_BASENAME', plugin_basename( BETTERDOCS_PLUGIN_FILE ) );
195 - $this->define( 'BETTERDOCS_BLOCKS_DIRECTORY', BETTERDOCS_ABSPATH . 'assets/blocks/' );
196 - $this->define( 'BETTERDOCS_ROOT_DIR_PATH', plugin_dir_path( BETTERDOCS_PLUGIN_FILE ) );
197 - $this->define( 'BETTERDOCS_FSE_TEMPLATES_PATH', BETTERDOCS_ROOT_DIR_PATH . 'views/templates/fse' );
180 + /**
181 + * Third Party Constants
182 + * @since 2.5.0
183 + *
184 + * WPML compatibility with Polylang
185 + */
186 + if ( Helper::is_plugin_active( 'polylang/polylang.php' ) ) {
187 + define( 'PLL_WPML_COMPAT', false );
188 + }
189 + }
198 190
199 - /**
200 - * Third Party Constants
201 - * @since 2.5.0
202 - *
203 - * WPML compatibility with Polylang
204 - */
205 - if ( Helper::is_plugin_active( 'polylang/polylang.php' ) ) {
206 - // Polylang's documented integration constant — must use the upstream-defined name.
207 - // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedConstantFound
208 - define( 'PLL_WPML_COMPAT', false );
209 - }
210 - }
191 + /**
192 + * Define constant if not already set.
193 + *
194 + * @param string $name Constant name.
195 + * @param string|bool $value Constant value.
196 + */
197 + private function define( $name, $value ) {
198 + if ( ! defined( $name ) ) {
199 + define( $name, $value );
200 + }
201 + }
211 202
212 - /**
213 - * Define constant if not already set.
214 - *
215 - * @param string $name Constant name.
216 - * @param string|bool $value Constant value.
217 - */
218 - private function define( $name, $value ) {
219 - if ( ! defined( $name ) ) {
220 - // Caller passes plugin-prefixed names (BETTERDOCS_*); $name comes from a controlled internal allowlist.
221 - // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.VariableConstantNameFound
222 - define( $name, $value );
223 - }
224 - }
203 + public function setup_container() {
204 + $config_array = require_once BETTERDOCS_ABSPATH . 'includes/config.php';
205 + $config = apply_filters( 'betterdocs_container_config', $config_array );
206 + $builder = new ContainerBuilder();
225 207
226 - public function setup_container() {
227 - $config_array = require_once BETTERDOCS_ABSPATH . 'includes/config.php';
228 - $config = apply_filters( 'betterdocs_container_config', $config_array );
229 - $builder = new ContainerBuilder();
208 + $builder->addDefinitions( $config );
209 + $this->container = $builder->build();
210 + }
230 211
231 - $builder->addDefinitions( $config );
232 - $this->container = $builder->build();
233 - }
212 + public function initialize() {
234 213
235 - public function initialize() {
214 + /**
215 + * Setup localization.
216 + */
217 + $this->load_plugin_textdomain();
236 218
237 - /**
238 - * Setup localization.
239 - */
240 - $this->load_plugin_textdomain();
219 + $this->container->get( Scripts::class );
220 + $this->rewrite = $this->container->get( Rewrite::class );
221 + $this->request = $this->container->get( Request::class );
222 + $this->query = $this->container->get( Query::class );
241 223
242 - $this->container->get( Scripts::class );
243 - $this->rewrite = $this->container->get( Rewrite::class );
244 - $this->request = $this->container->get( Request::class );
245 - $this->query = $this->container->get( Query::class );
224 + // Initialize background process
225 + $this->backgroundProccessor = $this->container->get( HelpScoutMigration::class );
246 226
247 - // Initialize background process
248 - $this->backgroundProccessor = $this->container->get( HelpScoutMigration::class );
227 + $this->rewrite->init();
228 + $this->request->init();
249 229
250 - $this->rewrite->init();
251 - $this->request->init();
230 + $this->assets = $this->container->get( Enqueue::class );
231 + $this->views = $this->container->get( Views::class );
232 + $this->helper = $this->container->get( Helper::class );
233 + $this->kbmigration = $this->container->get( KBMigration::class );
234 + $this->admin = $this->container->get( Admin::class );
235 + $this->database = $this->container->get( Database::class );
236 + $this->settings = $this->container->get( Settings::class );
237 + $this->analytics = $this->container->get( Analytics::class );
252 238
253 - $this->assets = $this->container->get( Enqueue::class );
254 - $this->views = $this->container->get( Views::class );
255 - $this->helper = $this->container->get( Helper::class );
256 - $this->kbmigration = $this->container->get( KBMigration::class );
257 - $this->admin = $this->container->get( Admin::class );
258 - $this->database = $this->container->get( Database::class );
259 - $this->settings = $this->container->get( Settings::class );
260 - $this->analytics = $this->container->get( Analytics::class );
261 - // Free analytics collectors: the frontend view/scroll tracker and the
262 - // daily retention purge. Each self-registers its hooks on construct.
263 - $this->container->get( AnalyticsTracker::class );
264 - $this->container->get( AnalyticsRetention::class );
239 + $this->template_helper = $this->container->get( TemplateTags::class );
240 + $this->customizer = $this->container->get( Customizer::class );
241 + $this->editor = $this->container->get( Editor::class );
242 + $this->ai_autowrtie = $this->container->get( WriteWithAI::class );
265 243
266 - $this->template_helper = $this->container->get( TemplateTags::class );
267 - $this->customizer = $this->container->get( Customizer::class );
268 - $this->editor = $this->container->get( Editor::class );
269 - $this->ai_autowrtie = $this->container->get( WriteWithAI::class );
270 - $this->article_summary = $this->container->get( ArticleSummary::class );
244 + $this->container->get( Admin::class );
245 + $this->container->get( Roles::class );
246 + $this->container->get( ReportEmail::class );
271 247
272 - // Initialize unified metabox before individual features
273 - $this->container->get( UnifiedMetabox::class );
274 - $this->article_quality_score = $this->container->get( ArticleQualityScore::class );
248 + /**
249 + * Initialize Shortcode
250 + * Make sure you have listed out all shortcode in shortcode factory.
251 + */
252 + $this->container->get( ShortcodeFactory::class )->init();
275 253
276 - // Editor "Suggest Categories / Tags / Glossaries" AI actions on the docs
277 - // post type (gated by enable_docs_ai_suite + an OpenAI key inside the class).
278 - $this->container->get( DocsAISuite::class );
254 + $this->container->get( FrontEnd::class );
279 255
280 - $this->container->get( Admin::class );
281 - $this->container->get( Roles::class );
282 - $this->container->get( ReportEmail::class );
283 - // Usage-analytics collector. Registered here (runs on every request, incl.
284 - // WP-Cron) rather than in Admin so its `betterdocs_insights_data` filter
285 - // callback is present whenever the tracking payload is built.
286 - $this->container->get( \WPDeveloper\BetterDocs\Insights\Collector::class );
287 - /**
288 - * Initialize Shortcode
289 - * Make sure you have listed out all shortcode in shortcode factory.
290 - */
291 - $this->container->get( ShortcodeFactory::class )->init();
256 + do_action( 'betterdocs_init' );
292 257
293 - $this->container->get( FrontEnd::class );
294 - $this->container->get( SearchExtender::class );
258 + $this->editor->init();
259 + }
295 260
296 - /**
297 - * Single-product FAQ rendering (WooCommerce). The class itself bails when
298 - * WooCommerce is inactive or the feature is disabled.
299 - */
300 - $this->container->get( WooProductFAQ::class );
261 + /**
262 + * Load plugins textdomain `betterdocs` into actions.
263 + * @return void
264 + */
265 + public function load_plugin_textdomain( $textdomain = 'betterdocs', $plugin_file = BETTERDOCS_PLUGIN_FILE ) {
266 + $locale = determine_locale();
301 267
302 - do_action( 'betterdocs_init' );
268 + /**
269 + * Filter to adjust the BetterDocs locale to use for translations.
270 + */
271 + $locale = apply_filters( 'plugin_locale', $locale, $textdomain );
303 272
304 - $this->editor->init();
305 - }
273 + if ( file_exists( WP_LANG_DIR . "/$textdomain-" . $locale . '.mo' ) ) {
274 + unload_textdomain( $textdomain );
275 + load_textdomain( $textdomain, WP_LANG_DIR . "/$textdomain-" . $locale . '.mo' );
276 + }
306 277
307 - /**
308 - * Load plugins textdomain `betterdocs` into actions.
309 - * @return void
310 - */
311 - public function load_plugin_textdomain( $textdomain = 'betterdocs', $plugin_file = BETTERDOCS_PLUGIN_FILE ) {
312 - $locale = determine_locale();
278 + load_plugin_textdomain( $textdomain, false, plugin_basename( dirname( $plugin_file ) ) . '/languages' );
279 + }
313 280
314 - /**
315 - * Filter to adjust the BetterDocs locale to use for translations.
316 - */
317 - // 'plugin_locale' is a WP-core filter; using its documented name is required.
318 - // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
319 - $locale = apply_filters( 'plugin_locale', $locale, $textdomain );
281 + /**
282 + * For AJAX Only
283 + * @return void
284 + */
285 + public function ajax() {
286 + }
320 287
321 - if ( file_exists( WP_LANG_DIR . "/$textdomain-" . $locale . '.mo' ) ) {
322 - unload_textdomain( $textdomain );
323 - load_textdomain( $textdomain, WP_LANG_DIR . "/$textdomain-" . $locale . '.mo' );
324 - }
325 - }
288 + /**
289 + * Create a plugin instance.
290 + *
291 + * @param mixed ...$args
292 + *
293 + * @return static
294 + *
295 + * @suppress PHP0441
296 + * @since 2.5.0
297 + */
298 + public static function get_instance() {
299 + if ( self::$_instance == null ) {
300 + self::$_instance = new self();
326 301
327 - /**
328 - * For AJAX Only
329 - * @return void
330 - */
331 - public function ajax() {
332 - }
302 + do_action( 'betterdocs_loaded' );
303 + }
333 304
334 - /**
335 - * Create a plugin instance.
336 - *
337 - * @param mixed ...$args
338 - *
339 - * @return static
340 - *
341 - * @suppress PHP0441
342 - * @since 2.5.0
343 - */
344 - public static function get_instance() {
345 - if ( null == self::$_instance ) {
346 - self::$_instance = new self();
305 + return self::$_instance;
306 + }
347 307
348 - do_action( 'betterdocs_loaded' );
349 - }
308 + /**
309 + * Hooked with `admin_init` action.
310 + * @return void
311 + */
312 + public function admin_init() {
313 + /**
314 + * Maybe Redirect
315 + * for setup related settings.
316 + */
317 + $this->maybe_redirect();
318 + }
350 319
351 - return self::$_instance;
352 - }
320 + /**
321 + * Summary of maybe_redirect
322 + * @return void
323 + */
324 + public function maybe_redirect() {
325 + // Bail if no activation transient is set.
326 + if ( ! $this->database->get_transient( 'betterdocs_maybe_redirect' ) ) {
327 + return;
328 + }
353 329
354 - /**
355 - * Hooked with `admin_init` action.
356 - * @return void
357 - */
358 - public function admin_init() {
359 - /**
360 - * Maybe Redirect
361 - * for setup related settings.
362 - */
363 - $this->maybe_redirect();
364 - }
330 + // Delete the activation transient.
331 + $this->database->delete_transient( 'betterdocs_maybe_redirect' );
365 332
366 - /**
367 - * Summary of maybe_redirect
368 - * @return void
369 - */
370 - public function maybe_redirect() {
371 - // Bail if no activation transient is set.
372 - if ( ! $this->database->get_transient( 'betterdocs_maybe_redirect' ) ) {
373 - return;
374 - }
333 + if ( ! is_multisite() ) {
334 + $betterdocs_settings = get_option( 'betterdocs_settings' );
335 + if ( $betterdocs_settings ) {
336 + wp_safe_redirect( add_query_arg( [ 'page' => 'betterdocs-settings' ], admin_url( 'admin.php' ) ) );
337 + } else {
338 + wp_safe_redirect( add_query_arg( [ 'page' => 'betterdocs-setup' ], admin_url( 'admin.php' ) ) );
339 + }
340 + }
341 + }
375 342
376 - // Delete the activation transient.
377 - $this->database->delete_transient( 'betterdocs_maybe_redirect' );
343 + /**
344 + * Is Pro Plugin Is Installed?
345 + * @return bool
346 + */
347 + public function is_pro_installed() {
348 + return $this->helper->get_plugins( 'betterdocs-pro/betterdocs-pro.php' );
349 + }
378 350
379 - if ( ! is_multisite() ) {
380 - $betterdocs_settings = get_option( 'betterdocs_settings' );
381 - if ( $betterdocs_settings ) {
382 - wp_safe_redirect( add_query_arg( array( 'page' => 'betterdocs-settings' ), admin_url( 'admin.php' ) ) );
383 - } else {
384 - wp_safe_redirect( add_query_arg( array( 'page' => 'betterdocs-setup' ), admin_url( 'admin.php' ) ) );
385 - }
386 - }
387 - }
351 + /**
352 + * Is Pro Plugin Is Active?
353 + * @return bool
354 + */
355 + public function pro_file() {
356 + return WP_PLUGIN_DIR . '/betterdocs-pro/betterdocs-pro.php';
357 + }
388 358
389 - /**
390 - * Is Pro Plugin Is Installed?
391 - * @return bool
392 - */
393 - public function is_pro_installed() {
394 - return $this->helper->get_plugins( 'betterdocs-pro/betterdocs-pro.php' );
395 - }
359 + public function is_pro_active() {
360 + if ( file_exists( $this->pro_file() ) ) {
361 + return $this->helper->is_plugin_active( 'betterdocs-pro/betterdocs-pro.php' );
362 + }
396 363
397 - /**
398 - * Is Pro Plugin Is Active?
399 - * @return bool
400 - */
401 - public function pro_file() {
402 - return WP_PLUGIN_DIR . '/betterdocs-pro/betterdocs-pro.php';
403 - }
364 + return false;
365 + }
404 366
405 - public function is_pro_active() {
406 - if ( file_exists( $this->pro_file() ) ) {
407 - return $this->helper->is_plugin_active( 'betterdocs-pro/betterdocs-pro.php' );
408 - }
367 + public function pro_version() {
368 + if ( ! $this->is_pro_active() ) {
369 + return false;
370 + }
409 371
410 - return false;
411 - }
372 + if ( ! function_exists( 'get_plugin_data' ) ) {
373 + require_once ABSPATH . 'wp-admin/includes/plugin.php';
374 + }
412 375
413 - public function chatbot_file() {
414 - return WP_PLUGIN_DIR . '/betterdocs-ai-chatbot/betterdocs-ai-chatbot.php';
415 - }
376 + $plugin_data = get_plugin_data( $this->pro_file() );
416 377
417 - public function is_chatbot_active() {
418 - if ( file_exists( $this->chatbot_file() ) ) {
419 - return $this->helper->is_plugin_active( 'betterdocs-ai-chatbot/betterdocs-ai-chatbot.php' );
420 - }
378 + return $plugin_data['Version'];
379 + }
421 380
422 - return false;
423 - }
381 + /**
382 + * Get all the API initialized.
383 + * @return void
384 + */
385 + public function api_initialization() {
386 + $_api_classes = scandir( __DIR__ . DIRECTORY_SEPARATOR . 'REST' );
424 387
425 - public function pro_version() {
426 - if ( ! $this->is_pro_active() ) {
427 - return false;
428 - }
388 + if ( ! empty( $_api_classes ) && is_array( $_api_classes ) ) {
389 + foreach ( $_api_classes as $class ) {
390 + if ( $class == '.' || $class == '..' || strpos( $class, '.' ) === 0 ) {
391 + continue;
392 + }
429 393
430 - if ( ! function_exists( 'get_plugin_data' ) ) {
431 - require_once ABSPATH . 'wp-admin/includes/plugin.php';
432 - }
394 + $classname = basename( $class, '.php' );
395 + $classname = '\\' . __NAMESPACE__ . "\\REST\\$classname";
396 + $_api_class = $this->container->get( $classname );
433 397
434 - $plugin_data = get_plugin_data( $this->pro_file() );
398 + if ( $_api_class instanceof BaseAPI ) {
399 + $_api_class->register();
400 + }
401 + }
402 + }
403 + }
435 404
436 - return $plugin_data[ 'Version' ];
437 - }
405 + public function is_betterdocs_screen( $hook, $admin_check = true ): bool {
406 + $screens = [
407 + 'betterdocs_page_betterdocs-settings',
408 + 'toplevel_page_betterdocs-admin',
409 + 'betterdocs_page_betterdocs-analytics',
410 + 'betterdocs_page_betterdocs-faq',
411 + 'betterdocs_page_betterdocs-glossaries',
412 + 'betterdocs_page_betterdocs-ai-chatbot',
438 413
439 - /**
440 - * Get all the API initialized.
441 - * @return void
442 - */
443 - public function api_initialization() {
444 - $_api_classes = scandir( __DIR__ . DIRECTORY_SEPARATOR . 'REST' );
414 + ];
445 415
446 - if ( ! empty( $_api_classes ) && is_array( $_api_classes ) ) {
447 - foreach ( $_api_classes as $class ) {
448 - if ( '.' == $class || '..' == $class || strpos( $class, '.' ) === 0 ) {
449 - continue;
450 - }
416 + if ( $admin_check ) {
417 + if ( in_array( $hook, $screens ) ) {
418 + return true;
419 + }
451 420
452 - $classname = basename( $class, '.php' );
453 - $classname = '\\' . __NAMESPACE__ . "\\REST\\$classname";
454 - $_api_class = $this->container->get( $classname );
421 + return false;
422 + }
455 423
456 - if ( $_api_class instanceof BaseAPI ) {
457 - $_api_class->register();
458 - }
459 - }
460 - }
461 - }
424 + return false;
425 + }
462 426
463 - public function is_betterdocs_screen( $hook, $admin_check = true ): bool {
464 - /**
465 - * Filter the list of admin screen hook suffixes treated as BetterDocs
466 - * screens (controls whether the React admin bundle + styles load).
467 - * Pro/add-ons can register their own React pages here, e.g. the
468 - * Knowledge Base admin page.
469 - *
470 - * @param string[] $screens Full hook suffixes (e.g. betterdocs_page_betterdocs-foo).
471 - */
472 - $screens = apply_filters( 'betterdocs_admin_screens', array(
473 - 'toplevel_page_betterdocs-dashboard',
474 - 'toplevel_page_betterdocs-admin',
475 - 'admin_page_betterdocs-admin',
476 - 'betterdocs_page_betterdocs-admin',
477 - 'betterdocs_page_betterdocs-analytics',
478 - 'betterdocs_page_betterdocs-settings',
479 - 'betterdocs_page_betterdocs-faq',
480 - 'betterdocs_page_betterdocs-glossaries',
427 + public function get_betterdocs_screen() {
428 + $registered_screens = [
429 + 'toplevel_page_betterdocs-admin',
430 + 'betterdocs_page_betterdocs-settings',
431 + 'betterdocs_page_betterdocs-analytics',
432 + 'betterdocs_page_betterdocs-faq',
433 + 'betterdocs_page_betterdocs-glossaries',
481 434 'betterdocs_page_betterdocs-ai-chatbot',
482 - 'betterdocs_page_betterdocs-doc-categories',
483 - 'betterdocs_page_betterdocs-doc-tags',
484 - ) );
485 435
486 - if ( $admin_check ) {
487 - if ( in_array( $hook, $screens ) ) {
488 - return true;
489 - }
436 + ];
490 437
491 - return false;
492 - }
438 + $current_screen_id = get_current_screen() != null ? get_current_screen()->id : '';
493 439
494 - return false;
495 - }
440 + if ( in_array( $current_screen_id, $registered_screens ) ) {
441 + return $current_screen_id;
442 + }
496 443
497 - public function get_betterdocs_screen() {
498 - $registered_screens = array(
499 - 'toplevel_page_betterdocs-dashboard',
500 - 'admin_page_betterdocs-admin',
501 - 'betterdocs_page_betterdocs-admin',
502 - 'betterdocs_page_betterdocs-settings',
503 - 'betterdocs_page_betterdocs-analytics',
504 - 'betterdocs_page_betterdocs-faq',
505 - 'betterdocs_page_betterdocs-glossaries',
506 - 'betterdocs_page_betterdocs-ai-chatbot',
507 - 'betterdocs_page_betterdocs-doc-categories',
508 - 'betterdocs_page_betterdocs-doc-tags',
509 - 'edit-docs'
510 - );
511 -
512 - $current_screen_id = get_current_screen() != null ? get_current_screen()->id : '';
513 -
514 - if ( in_array( $current_screen_id, $registered_screens ) ) {
515 - return $current_screen_id;
516 - }
517 -
518 - return false;
519 - }
444 + return false;
445 + }
520 446 }