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