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 -204 4.7.03.5.3 View file →
@@ -5,42 +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\Modules\StyleHandler as ModulesStyleHandler;
39 -use WPDeveloper\BetterDocs\Utils\Database;
40 -use WPDeveloper\BetterDocs\Utils\Enqueue;
41 -use WPDeveloper\BetterDocs\Utils\Helper;
42 -use WPDeveloper\BetterDocs\Utils\Views;
31 +use WPDeveloper\BetterDocs\Admin\Customizer\Customizer;
32 +use WPDeveloper\BetterDocs\Dependencies\DI\ContainerBuilder;
43 33
44 34 final class Plugin {
45 35 private static $_instance = null;
46 36 /**
@@ -96,13 +86,8 @@
96 86 * @var TemplateTags
97 87 */
98 88 public $template_helper;
99 89 /**
100 - * Article Summary class
101 - * @var ArticleSummary
102 - */
103 - public $article_summary;
104 - /**
105 90 * Customizer class
106 91 * @var Customizer
107 92 */
108 93 public $customizer;
@@ -129,9 +114,9 @@
129 114 /**
130 115 * Plugin Version
131 116 * @var string
132 117 */
133 - public $version = '4.7.0';
118 + public $version = '3.5.3';
134 119
135 120 /**
136 121 * WriteWithAI Class
137 122 * @var string
@@ -136,27 +121,19 @@
136 121 * WriteWithAI Class
137 122 * @var string
138 123 */
139 124 public $ai_autowrtie;
140 - public $backgroundProccessor;
141 125
142 126 /**
143 - * ArticleQualityScore Class
144 - * @var ArticleQualityScore
145 - */
146 - public $article_quality_score;
147 -
148 - /**
149 127 * Plugin DB Version
150 128 * @var string
151 129 */
152 - public $db_version = '1.0.2';
130 + public $db_version = '1.0.1';
153 131
154 132 public function __construct() {
155 133 $this->define_constants();
156 134
157 135 do_action( 'betterdocs_init_before' );
158 -
159 136 $this->setup_container();
160 137 /**
161 138 * Register activation and deactivation hooks
162 139 * and version updates check
@@ -162,29 +139,21 @@
162 139 * and version updates check
163 140 */
164 141 $this->container->get( Install::class );
165 142
166 - add_action( 'init', array( $this, 'initialize' ), 0 );
143 + $this->initialize();
167 144
168 - /**
169 - * Initialize API
170 - */
171 - add_action( 'rest_api_init', array( $this, 'api_initialization' ) );
145 + add_action( 'init', [ $this, 'init' ], 0 );
172 146
173 147 /**
174 148 * For admin only
175 149 */
176 - add_action( 'admin_init', array( $this, 'admin_init' ), 0 );
150 + add_action( 'admin_init', [ $this, 'admin_init' ], 0 );
177 151
178 152 /**
179 153 * For AJAX only
180 154 */
181 155 $this->ajax();
182 -
183 - /**
184 - * Style Handler For Parsing and Saving Styles as file.
185 - */
186 - ModulesStyleHandler::init();
187 156 }
188 157
189 158 private function define_constants() {
190 159 $this->define( 'BETTERDOCS_VERSION', $this->version );
@@ -202,10 +171,8 @@
202 171 *
203 172 * WPML compatibility with Polylang
204 173 */
205 174 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 175 define( 'PLL_WPML_COMPAT', false );
209 176 }
210 177 }
211 178
@@ -211,15 +178,13 @@
211 178
212 179 /**
213 180 * Define constant if not already set.
214 181 *
215 - * @param string $name Constant name.
182 + * @param string $name Constant name.
216 183 * @param string|bool $value Constant value.
217 184 */
218 185 private function define( $name, $value ) {
219 186 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 187 define( $name, $value );
223 188 }
224 189 }
225 190
@@ -232,59 +197,58 @@
232 197 $this->container = $builder->build();
233 198 }
234 199
235 200 public function initialize() {
236 -
237 - /**
238 - * Setup localization.
239 - */
240 - $this->load_plugin_textdomain();
241 -
242 201 $this->container->get( Scripts::class );
243 202 $this->rewrite = $this->container->get( Rewrite::class );
244 203 $this->request = $this->container->get( Request::class );
245 204 $this->query = $this->container->get( Query::class );
246 205
247 - // Initialize background process
248 - $this->backgroundProccessor = $this->container->get( HelpScoutMigration::class );
249 -
250 206 $this->rewrite->init();
251 207 $this->request->init();
252 208
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 );
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 );
265 217
266 218 $this->template_helper = $this->container->get( TemplateTags::class );
267 219 $this->customizer = $this->container->get( Customizer::class );
268 220 $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 );
221 + $this->ai_autowrtie = $this->container->get( WriteWithAI::class );
271 222
272 - // Initialize unified metabox before individual features
273 - $this->container->get( UnifiedMetabox::class );
274 - $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' ] );
275 228
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 );
229 + /**
230 + * Initialize API
231 + */
232 + add_action( 'rest_api_init', [ $this, 'api_initialization' ] );
233 + }
279 234
235 + /**
236 + * Initialize the BetterDocs Plugin
237 + *
238 + * @return void
239 + * @since 2.5.0
240 + */
241 + public function init() {
242 + /**
243 + * Setup localization.
244 + */
245 + $this->load_plugin_textdomain();
246 +
280 247 $this->container->get( Admin::class );
281 248 $this->container->get( Roles::class );
282 249 $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 );
250 +
287 251 /**
288 252 * Initialize Shortcode
289 253 * Make sure you have listed out all shortcode in shortcode factory.
290 254 */
@@ -290,19 +254,10 @@
290 254 */
291 255 $this->container->get( ShortcodeFactory::class )->init();
292 256
293 257 $this->container->get( FrontEnd::class );
294 - $this->container->get( SearchExtender::class );
295 258
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 );
301 -
302 259 do_action( 'betterdocs_init' );
303 -
304 - $this->editor->init();
305 260 }
306 261
307 262 /**
308 263 * Load plugins textdomain `betterdocs` into actions.
@@ -313,16 +268,13 @@
313 268
314 269 /**
315 270 * Filter to adjust the BetterDocs locale to use for translations.
316 271 */
317 - // 'plugin_locale' is a WP-core filter; using its documented name is required.
318 - // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
319 272 $locale = apply_filters( 'plugin_locale', $locale, $textdomain );
320 273
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 - }
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' );
325 277 }
326 278
327 279 /**
328 280 * For AJAX Only
@@ -341,15 +293,15 @@
341 293 * @suppress PHP0441
342 294 * @since 2.5.0
343 295 */
344 296 public static function get_instance() {
345 - if ( null == self::$_instance ) {
346 - self::$_instance = new self();
297 + if ( static::$_instance == null ) {
298 + static::$_instance = new self();
347 299
348 300 do_action( 'betterdocs_loaded' );
349 301 }
350 302
351 - return self::$_instance;
303 + return static::$_instance;
352 304 }
353 305
354 306 /**
355 307 * Hooked with `admin_init` action.
@@ -376,13 +328,13 @@
376 328 // Delete the activation transient.
377 329 $this->database->delete_transient( 'betterdocs_maybe_redirect' );
378 330
379 331 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' ) ) );
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' ) ) );
383 335 } else {
384 - 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' ) ) );
385 337 }
386 338 }
387 339 }
388 340
@@ -397,46 +349,12 @@
397 349 /**
398 350 * Is Pro Plugin Is Active?
399 351 * @return bool
400 352 */
401 - public function pro_file() {
402 - return WP_PLUGIN_DIR . '/betterdocs-pro/betterdocs-pro.php';
403 - }
404 -
405 353 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 - }
409 -
410 - return false;
354 + return $this->helper->is_plugin_active( 'betterdocs-pro/betterdocs-pro.php' );
411 355 }
412 356
413 - public function chatbot_file() {
414 - return WP_PLUGIN_DIR . '/betterdocs-ai-chatbot/betterdocs-ai-chatbot.php';
415 - }
416 -
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 - }
421 -
422 - return false;
423 - }
424 -
425 - public function pro_version() {
426 - if ( ! $this->is_pro_active() ) {
427 - return false;
428 - }
429 -
430 - if ( ! function_exists( 'get_plugin_data' ) ) {
431 - require_once ABSPATH . 'wp-admin/includes/plugin.php';
432 - }
433 -
434 - $plugin_data = get_plugin_data( $this->pro_file() );
435 -
436 - return $plugin_data[ 'Version' ];
437 - }
438 -
439 357 /**
440 358 * Get all the API initialized.
441 359 * @return void
442 360 */
@@ -444,9 +362,9 @@
444 362 $_api_classes = scandir( __DIR__ . DIRECTORY_SEPARATOR . 'REST' );
445 363
446 364 if ( ! empty( $_api_classes ) && is_array( $_api_classes ) ) {
447 365 foreach ( $_api_classes as $class ) {
448 - if ( '.' == $class || '..' == $class || strpos( $class, '.' ) === 0 ) {
366 + if ( $class == '.' || $class == '..' || strpos( $class, '.' ) === 0) {
449 367 continue;
450 368 }
451 369
452 370 $classname = basename( $class, '.php' );
@@ -457,64 +375,6 @@
457 375 $_api_class->register();
458 376 }
459 377 }
460 378 }
461 - }
462 -
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',
481 - 'betterdocs_page_betterdocs-ai-chatbot',
482 - 'betterdocs_page_betterdocs-doc-categories',
483 - 'betterdocs_page_betterdocs-doc-tags',
484 - ) );
485 -
486 - if ( $admin_check ) {
487 - if ( in_array( $hook, $screens ) ) {
488 - return true;
489 - }
490 -
491 - return false;
492 - }
493 -
494 - return false;
495 - }
496 -
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 379 }
520 380 }