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