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.2 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 All 200 releases
← All changes | includes/Plugin.php +64 -174 4.5.63.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.6';
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,51 +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 );
271 - // Usage-analytics collector. Registered here (runs on every request, incl.
272 - // WP-Cron) rather than in Admin so its `betterdocs_insights_data` filter
273 - // callback is present whenever the tracking payload is built.
274 - $this->container->get( \WPDeveloper\BetterDocs\Insights\Collector::class );
250 +
275 251 /**
276 252 * Initialize Shortcode
277 253 * Make sure you have listed out all shortcode in shortcode factory.
278 254 */
@@ -278,13 +254,10 @@
278 254 */
279 255 $this->container->get( ShortcodeFactory::class )->init();
280 256
281 257 $this->container->get( FrontEnd::class );
282 - $this->container->get( SearchExtender::class );
283 258
284 259 do_action( 'betterdocs_init' );
285 -
286 - $this->editor->init();
287 260 }
288 261
289 262 /**
290 263 * Load plugins textdomain `betterdocs` into actions.
@@ -295,16 +268,13 @@
295 268
296 269 /**
297 270 * Filter to adjust the BetterDocs locale to use for translations.
298 271 */
299 - // 'plugin_locale' is a WP-core filter; using its documented name is required.
300 - // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound
301 272 $locale = apply_filters( 'plugin_locale', $locale, $textdomain );
302 273
303 - if ( file_exists( WP_LANG_DIR . "/$textdomain-" . $locale . '.mo' ) ) {
304 - unload_textdomain( $textdomain );
305 - load_textdomain( $textdomain, WP_LANG_DIR . "/$textdomain-" . $locale . '.mo' );
306 - }
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' );
307 277 }
308 278
309 279 /**
310 280 * For AJAX Only
@@ -323,15 +293,15 @@
323 293 * @suppress PHP0441
324 294 * @since 2.5.0
325 295 */
326 296 public static function get_instance() {
327 - if ( null == self::$_instance ) {
328 - self::$_instance = new self();
297 + if ( static::$_instance == null ) {
298 + static::$_instance = new self();
329 299
330 300 do_action( 'betterdocs_loaded' );
331 301 }
332 302
333 - return self::$_instance;
303 + return static::$_instance;
334 304 }
335 305
336 306 /**
337 307 * Hooked with `admin_init` action.
@@ -358,13 +328,13 @@
358 328 // Delete the activation transient.
359 329 $this->database->delete_transient( 'betterdocs_maybe_redirect' );
360 330
361 331 if ( ! is_multisite() ) {
362 - $betterdocs_settings = get_option( 'betterdocs_settings' );
363 - if ( $betterdocs_settings ) {
364 - 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' ) ) );
365 335 } else {
366 - 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' ) ) );
367 337 }
368 338 }
369 339 }
370 340
@@ -379,46 +349,12 @@
379 349 /**
380 350 * Is Pro Plugin Is Active?
381 351 * @return bool
382 352 */
383 - public function pro_file() {
384 - return WP_PLUGIN_DIR . '/betterdocs-pro/betterdocs-pro.php';
385 - }
386 -
387 353 public function is_pro_active() {
388 - if ( file_exists( $this->pro_file() ) ) {
389 - return $this->helper->is_plugin_active( 'betterdocs-pro/betterdocs-pro.php' );
390 - }
391 -
392 - return false;
354 + return $this->helper->is_plugin_active( 'betterdocs-pro/betterdocs-pro.php' );
393 355 }
394 356
395 - public function chatbot_file() {
396 - return WP_PLUGIN_DIR . '/betterdocs-ai-chatbot/betterdocs-ai-chatbot.php';
397 - }
398 -
399 - public function is_chatbot_active() {
400 - if ( file_exists( $this->chatbot_file() ) ) {
401 - return $this->helper->is_plugin_active( 'betterdocs-ai-chatbot/betterdocs-ai-chatbot.php' );
402 - }
403 -
404 - return false;
405 - }
406 -
407 - public function pro_version() {
408 - if ( ! $this->is_pro_active() ) {
409 - return false;
410 - }
411 -
412 - if ( ! function_exists( 'get_plugin_data' ) ) {
413 - require_once ABSPATH . 'wp-admin/includes/plugin.php';
414 - }
415 -
416 - $plugin_data = get_plugin_data( $this->pro_file() );
417 -
418 - return $plugin_data[ 'Version' ];
419 - }
420 -
421 357 /**
422 358 * Get all the API initialized.
423 359 * @return void
424 360 */
@@ -426,9 +362,9 @@
426 362 $_api_classes = scandir( __DIR__ . DIRECTORY_SEPARATOR . 'REST' );
427 363
428 364 if ( ! empty( $_api_classes ) && is_array( $_api_classes ) ) {
429 365 foreach ( $_api_classes as $class ) {
430 - if ( '.' == $class || '..' == $class || strpos( $class, '.' ) === 0 ) {
366 + if ( $class == '.' || $class == '..' || strpos( $class, '.' ) === 0) {
431 367 continue;
432 368 }
433 369
434 370 $classname = basename( $class, '.php' );
@@ -439,52 +375,6 @@
439 375 $_api_class->register();
440 376 }
441 377 }
442 378 }
443 - }
444 -
445 - public function is_betterdocs_screen( $hook, $admin_check = true ): bool {
446 - $screens = array(
447 - 'toplevel_page_betterdocs-dashboard',
448 - 'toplevel_page_betterdocs-admin',
449 - 'admin_page_betterdocs-admin',
450 - 'betterdocs_page_betterdocs-admin',
451 - 'betterdocs_page_betterdocs-analytics',
452 - 'betterdocs_page_betterdocs-settings',
453 - 'betterdocs_page_betterdocs-faq',
454 - 'betterdocs_page_betterdocs-glossaries',
455 - 'betterdocs_page_betterdocs-ai-chatbot'
456 - );
457 -
458 - if ( $admin_check ) {
459 - if ( in_array( $hook, $screens ) ) {
460 - return true;
461 - }
462 -
463 - return false;
464 - }
465 -
466 - return false;
467 - }
468 -
469 - public function get_betterdocs_screen() {
470 - $registered_screens = array(
471 - 'toplevel_page_betterdocs-dashboard',
472 - 'admin_page_betterdocs-admin',
473 - 'betterdocs_page_betterdocs-admin',
474 - 'betterdocs_page_betterdocs-settings',
475 - 'betterdocs_page_betterdocs-analytics',
476 - 'betterdocs_page_betterdocs-faq',
477 - 'betterdocs_page_betterdocs-glossaries',
478 - 'betterdocs_page_betterdocs-ai-chatbot',
479 - 'edit-docs'
480 - );
481 -
482 - $current_screen_id = get_current_screen() != null ? get_current_screen()->id : '';
483 -
484 - if ( in_array( $current_screen_id, $registered_screens ) ) {
485 - return $current_screen_id;
486 - }
487 -
488 - return false;
489 379 }
490 380 }