PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 3.5.3
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v3.5.3
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 +64 -265 4.9.03.5.3 View file →
@@ -5,44 +5,32 @@
5 5 if ( ! defined( 'ABSPATH' ) ) {
6 6 exit; // Exit if accessed directly
7 7 }
8 8
9 -use WPDeveloper\BetterDocs\Admin\Analytics;
10 -use WPDeveloper\BetterDocs\Admin\Customizer\Customizer;
11 -use WPDeveloper\BetterDocs\Admin\HelpScoutMigration;
12 -use WPDeveloper\BetterDocs\Admin\ReportEmail;
13 9 use WPDeveloper\BetterDocs\Core\Admin;
14 -use WPDeveloper\BetterDocs\Core\AnalyticsTracker;
15 -use WPDeveloper\BetterDocs\Core\AnalyticsRetention;
10 +use WPDeveloper\BetterDocs\Core\Query;
11 +use WPDeveloper\BetterDocs\Core\Roles;
12 +use WPDeveloper\BetterDocs\Core\WriteWithAI;
13 +use WPDeveloper\BetterDocs\Dependencies\DI\Container;
14 +use WPDeveloper\BetterDocs\Utils\Views;
16 15 use WPDeveloper\BetterDocs\Core\BaseAPI;
17 16 use WPDeveloper\BetterDocs\Core\Install;
18 -use WPDeveloper\BetterDocs\Core\KBMigration;
19 -use WPDeveloper\BetterDocs\Core\Query;
20 17 use WPDeveloper\BetterDocs\Core\Request;
21 18 use WPDeveloper\BetterDocs\Core\Rewrite;
22 -use WPDeveloper\BetterDocs\Core\Roles;
23 19 use WPDeveloper\BetterDocs\Core\Scripts;
20 +use WPDeveloper\BetterDocs\Utils\Helper;
24 21 use WPDeveloper\BetterDocs\Core\Settings;
25 -use WPDeveloper\BetterDocs\Core\ShortcodeFactory;
26 -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 -use WPDeveloper\BetterDocs\Dependencies\DI\Container;
32 -use WPDeveloper\BetterDocs\Dependencies\DI\ContainerBuilder;
22 +use WPDeveloper\BetterDocs\Core\KBMigration;
23 +use WPDeveloper\BetterDocs\Utils\Enqueue;
33 24 use WPDeveloper\BetterDocs\Editors\Editor;
25 +use WPDeveloper\BetterDocs\Utils\Database;
26 +use WPDeveloper\BetterDocs\Admin\Analytics;
27 +use WPDeveloper\BetterDocs\Admin\ReportEmail;
34 28 use WPDeveloper\BetterDocs\FrontEnd\FrontEnd;
35 -use WPDeveloper\BetterDocs\FrontEnd\SearchExtender;
29 +use WPDeveloper\BetterDocs\Core\ShortcodeFactory;
36 30 use WPDeveloper\BetterDocs\FrontEnd\TemplateTags;
37 -use WPDeveloper\BetterDocs\FrontEnd\WooProductFAQ;
38 -use WPDeveloper\BetterDocs\Abilities\AbilitiesRegistrar;
39 -use WPDeveloper\BetterDocs\Mcp\MCPManager;
40 -use WPDeveloper\BetterDocs\Modules\StyleHandler as ModulesStyleHandler;
41 -use WPDeveloper\BetterDocs\Utils\Database;
42 -use WPDeveloper\BetterDocs\Utils\Enqueue;
43 -use WPDeveloper\BetterDocs\Utils\Helper;
44 -use WPDeveloper\BetterDocs\Utils\Views;
31 +use WPDeveloper\BetterDocs\Admin\Customizer\Customizer;
32 +use WPDeveloper\BetterDocs\Dependencies\DI\ContainerBuilder;
45 33
46 34 final class Plugin {
47 35 private static $_instance = null;
48 36 /**
@@ -98,13 +86,8 @@
98 86 * @var TemplateTags
99 87 */
100 88 public $template_helper;
101 89 /**
102 - * Article Summary class
103 - * @var ArticleSummary
104 - */
105 - public $article_summary;
106 - /**
107 90 * Customizer class
108 91 * @var Customizer
109 92 */
110 93 public $customizer;
@@ -131,9 +114,9 @@
131 114 /**
132 115 * Plugin Version
133 116 * @var string
134 117 */
135 - public $version = '4.9.0';
118 + public $version = '3.5.3';
136 119
137 120 /**
138 121 * WriteWithAI Class
139 122 * @var string
@@ -138,27 +121,19 @@
138 121 * WriteWithAI Class
139 122 * @var string
140 123 */
141 124 public $ai_autowrtie;
142 - public $backgroundProccessor;
143 125
144 126 /**
145 - * ArticleQualityScore Class
146 - * @var ArticleQualityScore
147 - */
148 - public $article_quality_score;
149 -
150 - /**
151 127 * Plugin DB Version
152 128 * @var string
153 129 */
154 - public $db_version = '1.0.2';
130 + public $db_version = '1.0.1';
155 131
156 132 public function __construct() {
157 133 $this->define_constants();
158 134
159 135 do_action( 'betterdocs_init_before' );
160 -
161 136 $this->setup_container();
162 137 /**
163 138 * Register activation and deactivation hooks
164 139 * and version updates check
@@ -164,42 +139,21 @@
164 139 * and version updates check
165 140 */
166 141 $this->container->get( Install::class );
167 142
168 - /**
169 - * Abilities API registrar.
170 - *
171 - * Resolved here, at plugin load, and not from initialize(): both the
172 - * bundled Abilities API and WordPress core's build their registry as a
173 - * lazy singleton and fire `wp_abilities_api_init` from it, at or after
174 - * `init`, the first time anything reads the registry. Our listeners
175 - * therefore have to be attached before that first read, whenever it
176 - * happens — and a container resolve on `init` would already be too late
177 - * for a plugin that reads the registry earlier in the same hook.
178 - */
179 - $this->container->get( AbilitiesRegistrar::class );
143 + $this->initialize();
180 144
181 - add_action( 'init', array( $this, 'initialize' ), 0 );
145 + add_action( 'init', [ $this, 'init' ], 0 );
182 146
183 147 /**
184 - * Initialize API
185 - */
186 - add_action( 'rest_api_init', array( $this, 'api_initialization' ) );
187 -
188 - /**
189 148 * For admin only
190 149 */
191 - add_action( 'admin_init', array( $this, 'admin_init' ), 0 );
150 + add_action( 'admin_init', [ $this, 'admin_init' ], 0 );
192 151
193 152 /**
194 153 * For AJAX only
195 154 */
196 155 $this->ajax();
197 -
198 - /**
199 - * Style Handler For Parsing and Saving Styles as file.
200 - */
201 - ModulesStyleHandler::init();
202 156 }
203 157
204 158 private function define_constants() {
205 159 $this->define( 'BETTERDOCS_VERSION', $this->version );
@@ -206,11 +160,9 @@
206 160 $this->define( 'BETTERDOCS_DB_VERSION', $this->db_version );
207 161 $this->define( 'BETTERDOCS_ABSPATH', dirname( BETTERDOCS_PLUGIN_FILE ) . '/' );
208 162 $this->define( 'BETTERDOCS_ABSURL', plugin_dir_url( BETTERDOCS_PLUGIN_FILE ) );
209 163 $this->define( 'BETTERDOCS_PLUGIN_BASENAME', plugin_basename( BETTERDOCS_PLUGIN_FILE ) );
210 - // Compiled block metadata lives under assets/build/ since the Node 24 asset
211 - // restructure; register_block_type() fails silently if this path is wrong.
212 - $this->define( 'BETTERDOCS_BLOCKS_DIRECTORY', BETTERDOCS_ABSPATH . 'assets/build/blocks/' );
164 + $this->define( 'BETTERDOCS_BLOCKS_DIRECTORY', BETTERDOCS_ABSPATH . 'assets/blocks/' );
213 165 $this->define( 'BETTERDOCS_ROOT_DIR_PATH', plugin_dir_path( BETTERDOCS_PLUGIN_FILE ) );
214 166 $this->define( 'BETTERDOCS_FSE_TEMPLATES_PATH', BETTERDOCS_ROOT_DIR_PATH . 'views/templates/fse' );
215 167
216 168 /**
@@ -219,10 +171,8 @@
219 171 *
220 172 * WPML compatibility with Polylang
221 173 */
222 174 if ( Helper::is_plugin_active( 'polylang/polylang.php' ) ) {
223 - // Polylang's documented integration constant — must use the upstream-defined name.
224 - // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedConstantFound
225 175 define( 'PLL_WPML_COMPAT', false );
226 176 }
227 177 }
228 178
@@ -228,15 +178,13 @@
228 178
229 179 /**
230 180 * Define constant if not already set.
231 181 *
232 - * @param string $name Constant name.
182 + * @param string $name Constant name.
233 183 * @param string|bool $value Constant value.
234 184 */
235 185 private function define( $name, $value ) {
236 186 if ( ! defined( $name ) ) {
237 - // Caller passes plugin-prefixed names (BETTERDOCS_*); $name comes from a controlled internal allowlist.
238 - // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.VariableConstantNameFound
239 187 define( $name, $value );
240 188 }
241 189 }
242 190
@@ -249,68 +197,58 @@
249 197 $this->container = $builder->build();
250 198 }
251 199
252 200 public function initialize() {
253 -
254 - /**
255 - * Setup localization.
256 - */
257 - $this->load_plugin_textdomain();
258 -
259 201 $this->container->get( Scripts::class );
260 202 $this->rewrite = $this->container->get( Rewrite::class );
261 203 $this->request = $this->container->get( Request::class );
262 204 $this->query = $this->container->get( Query::class );
263 205
264 - // Initialize background process
265 - $this->backgroundProccessor = $this->container->get( HelpScoutMigration::class );
266 -
267 206 $this->rewrite->init();
268 207 $this->request->init();
269 208
270 - $this->assets = $this->container->get( Enqueue::class );
271 - $this->views = $this->container->get( Views::class );
272 - $this->helper = $this->container->get( Helper::class );
273 - $this->kbmigration = $this->container->get( KBMigration::class );
274 - $this->admin = $this->container->get( Admin::class );
275 - $this->database = $this->container->get( Database::class );
276 - $this->settings = $this->container->get( Settings::class );
277 - $this->analytics = $this->container->get( Analytics::class );
278 - // Free analytics collectors: the frontend view/scroll tracker and the
279 - // daily retention purge. Each self-registers its hooks on construct.
280 - $this->container->get( AnalyticsTracker::class );
281 - $this->container->get( AnalyticsRetention::class );
209 + $this->assets = $this->container->get( Enqueue::class );
210 + $this->views = $this->container->get( Views::class );
211 + $this->helper = $this->container->get( Helper::class );
212 + $this->kbmigration = $this->container->get( KBMigration::class );
213 + $this->admin = $this->container->get( Admin::class );
214 + $this->database = $this->container->get( Database::class );
215 + $this->settings = $this->container->get( Settings::class );
216 + $this->analytics = $this->container->get( Analytics::class );
282 217
283 218 $this->template_helper = $this->container->get( TemplateTags::class );
284 219 $this->customizer = $this->container->get( Customizer::class );
285 220 $this->editor = $this->container->get( Editor::class );
286 - $this->ai_autowrtie = $this->container->get( WriteWithAI::class );
287 - $this->article_summary = $this->container->get( ArticleSummary::class );
221 + $this->ai_autowrtie = $this->container->get( WriteWithAI::class );
288 222
289 - // Initialize unified metabox before individual features
290 - $this->container->get( UnifiedMetabox::class );
291 - $this->article_quality_score = $this->container->get( ArticleQualityScore::class );
223 + /**
224 + * Initialize all editors.
225 + * Elementor, Gutenberg/BlockEditor
226 + */
227 + add_action( 'init', [ $this->editor, 'init' ] );
292 228
293 - // Editor "Suggest Categories / Tags / Glossaries" AI actions on the docs
294 - // post type (gated by enable_docs_ai_suite + an OpenAI key inside the class).
295 - $this->container->get( DocsAISuite::class );
229 + /**
230 + * Initialize API
231 + */
232 + add_action( 'rest_api_init', [ $this, 'api_initialization' ] );
233 + }
296 234
297 - $this->container->get( Admin::class );
298 - $this->container->get( Roles::class );
299 -
235 + /**
236 + * Initialize the BetterDocs Plugin
237 + *
238 + * @return void
239 + * @since 2.5.0
240 + */
241 + public function init() {
300 242 /**
301 - * MCP transport: rewrite rules, the pretty endpoint, OAuth discovery
302 - * and every REST route. Resolved here rather than at plugin load
303 - * (where the abilities registrar has to be) because its earliest hook
304 - * is `init`, which is what this method already runs on.
243 + * Setup localization.
305 244 */
306 - $this->container->get( MCPManager::class );
245 + $this->load_plugin_textdomain();
307 246
247 + $this->container->get( Admin::class );
248 + $this->container->get( Roles::class );
308 249 $this->container->get( ReportEmail::class );
309 - // Usage-analytics collector. Registered here (runs on every request, incl.
310 - // WP-Cron) rather than in Admin so its `betterdocs_insights_data` filter
311 - // callback is present whenever the tracking payload is built.
312 - $this->container->get( \WPDeveloper\BetterDocs\Insights\Collector::class );
250 +
313 251 /**
314 252 * Initialize Shortcode
315 253 * Make sure you have listed out all shortcode in shortcode factory.
316 254 */
@@ -316,19 +254,10 @@
316 254 */
317 255 $this->container->get( ShortcodeFactory::class )->init();
318 256
319 257 $this->container->get( FrontEnd::class );
320 - $this->container->get( SearchExtender::class );
321 258
322 - /**
323 - * Single-product FAQ rendering (WooCommerce). The class itself bails when
324 - * WooCommerce is inactive or the feature is disabled.
325 - */
326 - $this->container->get( WooProductFAQ::class );
327 -
328 259 do_action( 'betterdocs_init' );
329 -
330 - $this->editor->init();
331 260 }
332 261
333 262 /**
334 263 * Load plugins textdomain `betterdocs` into actions.
@@ -339,16 +268,13 @@
339 268
340 269 /**
341 270 * Filter to adjust the BetterDocs locale to use for translations.
342 271 */
343 - // 'plugin_locale' is a WP-core filter; using its documented name is required.
344 - // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
345 272 $locale = apply_filters( 'plugin_locale', $locale, $textdomain );
346 273
347 - if ( file_exists( WP_LANG_DIR . "/$textdomain-" . $locale . '.mo' ) ) {
348 - unload_textdomain( $textdomain );
349 - load_textdomain( $textdomain, WP_LANG_DIR . "/$textdomain-" . $locale . '.mo' );
350 - }
274 + unload_textdomain( $textdomain );
275 + load_textdomain( $textdomain, WP_LANG_DIR . "/$textdomain-" . $locale . '.mo' );
276 + load_plugin_textdomain( $textdomain, false, plugin_basename( dirname( $plugin_file ) ) . '/languages' );
351 277 }
352 278
353 279 /**
354 280 * For AJAX Only
@@ -367,15 +293,15 @@
367 293 * @suppress PHP0441
368 294 * @since 2.5.0
369 295 */
370 296 public static function get_instance() {
371 - if ( null == self::$_instance ) {
372 - self::$_instance = new self();
297 + if ( static::$_instance == null ) {
298 + static::$_instance = new self();
373 299
374 300 do_action( 'betterdocs_loaded' );
375 301 }
376 302
377 - return self::$_instance;
303 + return static::$_instance;
378 304 }
379 305
380 306 /**
381 307 * Hooked with `admin_init` action.
@@ -402,18 +328,14 @@
402 328 // Delete the activation transient.
403 329 $this->database->delete_transient( 'betterdocs_maybe_redirect' );
404 330
405 331 if ( ! is_multisite() ) {
406 - $betterdocs_settings = get_option( 'betterdocs_settings' );
407 - if ( $betterdocs_settings ) {
408 - wp_safe_redirect( add_query_arg( array( 'page' => 'betterdocs-settings' ), admin_url( 'admin.php' ) ) );
332 + $betterdocs_settings = get_option('betterdocs_settings');
333 + if ( $betterdocs_settings) {
334 + wp_safe_redirect( add_query_arg( [ 'page' => 'betterdocs-settings' ], admin_url( 'admin.php' ) ) );
409 335 } else {
410 - wp_safe_redirect( add_query_arg( array( 'page' => 'betterdocs-setup' ), admin_url( 'admin.php' ) ) );
336 + wp_safe_redirect( add_query_arg( [ 'page' => 'betterdocs-setup' ], admin_url( 'admin.php' ) ) );
411 337 }
412 - // This runs at `admin_init` priority 0. Without exiting, the rest of
413 - // admin_init still executes and can mutate the very state the redirect
414 - // target depends on before the browser ever follows the Location header.
415 - exit;
416 338 }
417 339 }
418 340
419 341 /**
@@ -427,74 +349,13 @@
427 349 /**
428 350 * Is Pro Plugin Is Active?
429 351 * @return bool
430 352 */
431 - public function pro_file() {
432 - return WP_PLUGIN_DIR . '/betterdocs-pro/betterdocs-pro.php';
433 - }
434 -
435 353 public function is_pro_active() {
436 - if ( file_exists( $this->pro_file() ) ) {
437 - return $this->helper->is_plugin_active( 'betterdocs-pro/betterdocs-pro.php' );
438 - }
439 -
440 - return false;
354 + return $this->helper->is_plugin_active( 'betterdocs-pro/betterdocs-pro.php' );
441 355 }
442 356
443 - public function chatbot_file() {
444 - return WP_PLUGIN_DIR . '/betterdocs-ai-chatbot/betterdocs-ai-chatbot.php';
445 - }
446 -
447 - public function is_chatbot_active() {
448 - if ( file_exists( $this->chatbot_file() ) ) {
449 - return $this->helper->is_plugin_active( 'betterdocs-ai-chatbot/betterdocs-ai-chatbot.php' );
450 - }
451 -
452 - return false;
453 - }
454 -
455 357 /**
456 - * Whether Pro provides the real API Documentation screen.
457 - *
458 - * Pro flips this via `betterdocs_pro_has_api_docs`; the class_exists() default
459 - * keeps the gate correct against a Pro build that predates that filter.
460 - *
461 - * @return bool
462 - */
463 - public function has_api_docs() {
464 - return (bool) apply_filters(
465 - 'betterdocs_pro_has_api_docs',
466 - class_exists( '\\WPDeveloper\\BetterDocsPro\\Core\\ApiReferences' )
467 - );
468 - }
469 -
470 - /**
471 - * Whether Free should show its locked API Docs teaser.
472 - *
473 - * Only without Pro. An older Pro has already paid, so they get nothing here —
474 - * they need a plugin update, not an upsell.
475 - *
476 - * @return bool
477 - */
478 - public function show_api_docs_teaser() {
479 - return ! $this->is_pro_active() && ! $this->has_api_docs();
480 - }
481 -
482 - public function pro_version() {
483 - if ( ! $this->is_pro_active() ) {
484 - return false;
485 - }
486 -
487 - if ( ! function_exists( 'get_plugin_data' ) ) {
488 - require_once ABSPATH . 'wp-admin/includes/plugin.php';
489 - }
490 -
491 - $plugin_data = get_plugin_data( $this->pro_file() );
492 -
493 - return $plugin_data[ 'Version' ];
494 - }
495 -
496 - /**
497 358 * Get all the API initialized.
498 359 * @return void
499 360 */
500 361 public function api_initialization() {
@@ -501,9 +362,9 @@
501 362 $_api_classes = scandir( __DIR__ . DIRECTORY_SEPARATOR . 'REST' );
502 363
503 364 if ( ! empty( $_api_classes ) && is_array( $_api_classes ) ) {
504 365 foreach ( $_api_classes as $class ) {
505 - if ( '.' == $class || '..' == $class || strpos( $class, '.' ) === 0 ) {
366 + if ( $class == '.' || $class == '..' || strpos( $class, '.' ) === 0) {
506 367 continue;
507 368 }
508 369
509 370 $classname = basename( $class, '.php' );
@@ -514,68 +375,6 @@
514 375 $_api_class->register();
515 376 }
516 377 }
517 378 }
518 - }
519 -
520 - public function is_betterdocs_screen( $hook, $admin_check = true ): bool {
521 - /**
522 - * Filter the list of admin screen hook suffixes treated as BetterDocs
523 - * screens (controls whether the React admin bundle + styles load).
524 - * Pro/add-ons can register their own React pages here, e.g. the
525 - * Knowledge Base admin page.
526 - *
527 - * @param string[] $screens Full hook suffixes (e.g. betterdocs_page_betterdocs-foo).
528 - */
529 - $screens = apply_filters( 'betterdocs_admin_screens', array(
530 - 'toplevel_page_betterdocs-dashboard',
531 - 'toplevel_page_betterdocs-admin',
532 - 'admin_page_betterdocs-admin',
533 - 'betterdocs_page_betterdocs-admin',
534 - 'betterdocs_page_betterdocs-analytics',
535 - 'betterdocs_page_betterdocs-settings',
536 - 'betterdocs_page_betterdocs-mcp',
537 - 'betterdocs_page_betterdocs-faq',
538 - 'betterdocs_page_betterdocs-glossaries',
539 - 'betterdocs_page_betterdocs-ai-chatbot',
540 - 'betterdocs_page_betterdocs-api-docs',
541 - 'betterdocs_page_betterdocs-doc-categories',
542 - 'betterdocs_page_betterdocs-doc-tags',
543 - ) );
544 -
545 - if ( $admin_check ) {
546 - if ( in_array( $hook, $screens ) ) {
547 - return true;
548 - }
549 -
550 - return false;
551 - }
552 -
553 - return false;
554 - }
555 -
556 - public function get_betterdocs_screen() {
557 - $registered_screens = array(
558 - 'toplevel_page_betterdocs-dashboard',
559 - 'admin_page_betterdocs-admin',
560 - 'betterdocs_page_betterdocs-admin',
561 - 'betterdocs_page_betterdocs-settings',
562 - 'betterdocs_page_betterdocs-mcp',
563 - 'betterdocs_page_betterdocs-analytics',
564 - 'betterdocs_page_betterdocs-faq',
565 - 'betterdocs_page_betterdocs-glossaries',
566 - 'betterdocs_page_betterdocs-ai-chatbot',
567 - 'betterdocs_page_betterdocs-api-docs',
568 - 'betterdocs_page_betterdocs-doc-categories',
569 - 'betterdocs_page_betterdocs-doc-tags',
570 - 'edit-docs'
571 - );
572 -
573 - $current_screen_id = get_current_screen() != null ? get_current_screen()->id : '';
574 -
575 - if ( in_array( $current_screen_id, $registered_screens ) ) {
576 - return $current_screen_id;
577 - }
578 -
579 - return false;
580 379 }
581 380 }