| @@ -10,8 +10,10 @@ | ||
| 10 | 10 | use WPDeveloper\BetterDocs\Admin\Customizer\Customizer; |
| 11 | 11 | use WPDeveloper\BetterDocs\Admin\HelpScoutMigration; |
| 12 | 12 | use WPDeveloper\BetterDocs\Admin\ReportEmail; |
| 13 | 13 | use WPDeveloper\BetterDocs\Core\Admin; |
| 14 | +use WPDeveloper\BetterDocs\Core\AnalyticsTracker; | |
| 15 | +use WPDeveloper\BetterDocs\Core\AnalyticsRetention; | |
| 14 | 16 | use WPDeveloper\BetterDocs\Core\BaseAPI; |
| 15 | 17 | use WPDeveloper\BetterDocs\Core\Install; |
| 16 | 18 | use WPDeveloper\BetterDocs\Core\KBMigration; |
| 17 | 19 | use WPDeveloper\BetterDocs\Core\Query; |
| @@ -24,15 +26,19 @@ | ||
| 24 | 26 | use WPDeveloper\BetterDocs\Core\WriteWithAI; |
| 25 | 27 | use WPDeveloper\BetterDocs\Core\ArticleSummary; |
| 26 | 28 | use WPDeveloper\BetterDocs\Core\ArticleQualityScore; |
| 27 | 29 | use WPDeveloper\BetterDocs\Core\UnifiedMetabox; |
| 30 | +use WPDeveloper\BetterDocs\Core\DocsAISuite; | |
| 28 | 31 | use WPDeveloper\BetterDocs\Dependencies\DI\Container; |
| 29 | 32 | use WPDeveloper\BetterDocs\Dependencies\DI\ContainerBuilder; |
| 30 | 33 | use WPDeveloper\BetterDocs\Editors\Editor; |
| 31 | 34 | use WPDeveloper\BetterDocs\FrontEnd\FrontEnd; |
| 35 | +use WPDeveloper\BetterDocs\FrontEnd\PrintTemplate; | |
| 32 | 36 | use WPDeveloper\BetterDocs\FrontEnd\SearchExtender; |
| 33 | 37 | use WPDeveloper\BetterDocs\FrontEnd\TemplateTags; |
| 34 | 38 | use WPDeveloper\BetterDocs\FrontEnd\WooProductFAQ; |
| 39 | +use WPDeveloper\BetterDocs\Abilities\AbilitiesRegistrar; | |
| 40 | +use WPDeveloper\BetterDocs\Mcp\MCPManager; | |
| 35 | 41 | use WPDeveloper\BetterDocs\Modules\StyleHandler as ModulesStyleHandler; |
| 36 | 42 | use WPDeveloper\BetterDocs\Utils\Database; |
| 37 | 43 | use WPDeveloper\BetterDocs\Utils\Enqueue; |
| 38 | 44 | use WPDeveloper\BetterDocs\Utils\Helper; |
| @@ -126,9 +132,9 @@ | ||
| 126 | 132 | /** |
| 127 | 133 | * Plugin Version |
| 128 | 134 | * @var string |
| 129 | 135 | */ |
| 130 | - public $version = '4.6.1'; | |
| 136 | + public $version = '4.9.3'; | |
| 131 | 137 | |
| 132 | 138 | /** |
| 133 | 139 | * WriteWithAI Class |
| 134 | 140 | * @var string |
| @@ -145,9 +151,9 @@ | ||
| 145 | 151 | /** |
| 146 | 152 | * Plugin DB Version |
| 147 | 153 | * @var string |
| 148 | 154 | */ |
| 149 | - public $db_version = '1.0.1'; | |
| 155 | + public $db_version = '1.0.3'; | |
| 150 | 156 | |
| 151 | 157 | public function __construct() { |
| 152 | 158 | $this->define_constants(); |
| 153 | 159 | |
| @@ -159,8 +165,21 @@ | ||
| 159 | 165 | * and version updates check |
| 160 | 166 | */ |
| 161 | 167 | $this->container->get( Install::class ); |
| 162 | 168 | |
| 169 | + /** | |
| 170 | + * Abilities API registrar. | |
| 171 | + * | |
| 172 | + * Resolved here, at plugin load, and not from initialize(): both the | |
| 173 | + * bundled Abilities API and WordPress core's build their registry as a | |
| 174 | + * lazy singleton and fire `wp_abilities_api_init` from it, at or after | |
| 175 | + * `init`, the first time anything reads the registry. Our listeners | |
| 176 | + * therefore have to be attached before that first read, whenever it | |
| 177 | + * happens — and a container resolve on `init` would already be too late | |
| 178 | + * for a plugin that reads the registry earlier in the same hook. | |
| 179 | + */ | |
| 180 | + $this->container->get( AbilitiesRegistrar::class ); | |
| 181 | + | |
| 163 | 182 | add_action( 'init', array( $this, 'initialize' ), 0 ); |
| 164 | 183 | |
| 165 | 184 | /** |
| 166 | 185 | * Initialize API |
| @@ -188,9 +207,11 @@ | ||
| 188 | 207 | $this->define( 'BETTERDOCS_DB_VERSION', $this->db_version ); |
| 189 | 208 | $this->define( 'BETTERDOCS_ABSPATH', dirname( BETTERDOCS_PLUGIN_FILE ) . '/' ); |
| 190 | 209 | $this->define( 'BETTERDOCS_ABSURL', plugin_dir_url( BETTERDOCS_PLUGIN_FILE ) ); |
| 191 | 210 | $this->define( 'BETTERDOCS_PLUGIN_BASENAME', plugin_basename( BETTERDOCS_PLUGIN_FILE ) ); |
| 192 | - $this->define( 'BETTERDOCS_BLOCKS_DIRECTORY', BETTERDOCS_ABSPATH . 'assets/blocks/' ); | |
| 211 | + // Compiled block metadata lives under assets/build/ since the Node 24 asset | |
| 212 | + // restructure; register_block_type() fails silently if this path is wrong. | |
| 213 | + $this->define( 'BETTERDOCS_BLOCKS_DIRECTORY', BETTERDOCS_ABSPATH . 'assets/build/blocks/' ); | |
| 193 | 214 | $this->define( 'BETTERDOCS_ROOT_DIR_PATH', plugin_dir_path( BETTERDOCS_PLUGIN_FILE ) ); |
| 194 | 215 | $this->define( 'BETTERDOCS_FSE_TEMPLATES_PATH', BETTERDOCS_ROOT_DIR_PATH . 'views/templates/fse' ); |
| 195 | 216 | |
| 196 | 217 | /** |
| @@ -254,8 +275,12 @@ | ||
| 254 | 275 | $this->admin = $this->container->get( Admin::class ); |
| 255 | 276 | $this->database = $this->container->get( Database::class ); |
| 256 | 277 | $this->settings = $this->container->get( Settings::class ); |
| 257 | 278 | $this->analytics = $this->container->get( Analytics::class ); |
| 279 | + // Free analytics collectors: the frontend view/scroll tracker and the | |
| 280 | + // daily retention purge. Each self-registers its hooks on construct. | |
| 281 | + $this->container->get( AnalyticsTracker::class ); | |
| 282 | + $this->container->get( AnalyticsRetention::class ); | |
| 258 | 283 | |
| 259 | 284 | $this->template_helper = $this->container->get( TemplateTags::class ); |
| 260 | 285 | $this->customizer = $this->container->get( Customizer::class ); |
| 261 | 286 | $this->editor = $this->container->get( Editor::class ); |
| @@ -265,10 +290,23 @@ | ||
| 265 | 290 | // Initialize unified metabox before individual features |
| 266 | 291 | $this->container->get( UnifiedMetabox::class ); |
| 267 | 292 | $this->article_quality_score = $this->container->get( ArticleQualityScore::class ); |
| 268 | 293 | |
| 294 | + // Editor "Suggest Categories / Tags / Glossaries" AI actions on the docs | |
| 295 | + // post type (gated by enable_docs_ai_suite + an OpenAI key inside the class). | |
| 296 | + $this->container->get( DocsAISuite::class ); | |
| 297 | + | |
| 269 | 298 | $this->container->get( Admin::class ); |
| 270 | 299 | $this->container->get( Roles::class ); |
| 300 | + | |
| 301 | + /** | |
| 302 | + * MCP transport: rewrite rules, the pretty endpoint, OAuth discovery | |
| 303 | + * and every REST route. Resolved here rather than at plugin load | |
| 304 | + * (where the abilities registrar has to be) because its earliest hook | |
| 305 | + * is `init`, which is what this method already runs on. | |
| 306 | + */ | |
| 307 | + $this->container->get( MCPManager::class ); | |
| 308 | + | |
| 271 | 309 | $this->container->get( ReportEmail::class ); |
| 272 | 310 | // Usage-analytics collector. Registered here (runs on every request, incl. |
| 273 | 311 | // WP-Cron) rather than in Admin so its `betterdocs_insights_data` filter |
| 274 | 312 | // callback is present whenever the tracking payload is built. |
| @@ -281,8 +319,13 @@ | ||
| 281 | 319 | |
| 282 | 320 | $this->container->get( FrontEnd::class ); |
| 283 | 321 | $this->container->get( SearchExtender::class ); |
| 284 | 322 | |
| 323 | + // Running logo header / page footer for the browser's own Print command. | |
| 324 | + // Registered unconditionally: it covers every front-end page, including | |
| 325 | + // the ones that carry no BetterDocs print button. | |
| 326 | + $this->container->get( PrintTemplate::class ); | |
| 327 | + | |
| 285 | 328 | /** |
| 286 | 329 | * Single-product FAQ rendering (WooCommerce). The class itself bails when |
| 287 | 330 | * WooCommerce is inactive or the feature is disabled. |
| 288 | 331 | */ |
| @@ -371,8 +414,12 @@ | ||
| 371 | 414 | wp_safe_redirect( add_query_arg( array( 'page' => 'betterdocs-settings' ), admin_url( 'admin.php' ) ) ); |
| 372 | 415 | } else { |
| 373 | 416 | wp_safe_redirect( add_query_arg( array( 'page' => 'betterdocs-setup' ), admin_url( 'admin.php' ) ) ); |
| 374 | 417 | } |
| 418 | + // This runs at `admin_init` priority 0. Without exiting, the rest of | |
| 419 | + // admin_init still executes and can mutate the very state the redirect | |
| 420 | + // target depends on before the browser ever follows the Location header. | |
| 421 | + exit; | |
| 375 | 422 | } |
| 376 | 423 | } |
| 377 | 424 | |
| 378 | 425 | /** |
| @@ -410,8 +457,122 @@ | ||
| 410 | 457 | |
| 411 | 458 | return false; |
| 412 | 459 | } |
| 413 | 460 | |
| 461 | + /** | |
| 462 | + * Whether Pro provides the real API Documentation screen. | |
| 463 | + * | |
| 464 | + * Pro flips this via `betterdocs_pro_has_api_docs`; the class_exists() default | |
| 465 | + * keeps the gate correct against a Pro build that predates that filter. | |
| 466 | + * | |
| 467 | + * @return bool | |
| 468 | + */ | |
| 469 | + public function has_api_docs() { | |
| 470 | + return (bool) apply_filters( | |
| 471 | + 'betterdocs_pro_has_api_docs', | |
| 472 | + class_exists( '\\WPDeveloper\\BetterDocsPro\\Core\\ApiReferences' ) | |
| 473 | + ); | |
| 474 | + } | |
| 475 | + | |
| 476 | + /** | |
| 477 | + * Whether Free should show its locked API Docs teaser. | |
| 478 | + * | |
| 479 | + * Only without Pro. An older Pro has already paid, so they get nothing here — | |
| 480 | + * they need a plugin update, not an upsell. | |
| 481 | + * | |
| 482 | + * @return bool | |
| 483 | + */ | |
| 484 | + public function show_api_docs_teaser() { | |
| 485 | + return ! $this->is_pro_active() && ! $this->has_api_docs(); | |
| 486 | + } | |
| 487 | + | |
| 488 | + /** | |
| 489 | + * Whether the real Glossaries screen is available (i.e. Pro is providing it). | |
| 490 | + * | |
| 491 | + * Glossaries now lives in Pro (moved out of Free), so — like Content | |
| 492 | + * Intelligence and API Docs — there is a concrete Pro class to detect. The | |
| 493 | + * class_exists() default keeps the gate correct against a Pro build that | |
| 494 | + * predates the move (that Pro is active but does NOT ship the manager, so | |
| 495 | + * this must be false, not simply `is_pro_active()`); the filter lets Pro/add-ons | |
| 496 | + * flip it explicitly. | |
| 497 | + * | |
| 498 | + * @return bool | |
| 499 | + */ | |
| 500 | + public function has_glossaries() { | |
| 501 | + return (bool) apply_filters( | |
| 502 | + 'betterdocs_pro_has_glossaries', | |
| 503 | + class_exists( '\\WPDeveloper\\BetterDocsPro\\Core\\GlossaryTaxonomy' ) | |
| 504 | + ); | |
| 505 | + } | |
| 506 | + | |
| 507 | + /** | |
| 508 | + * Whether Free should render its locked Glossaries screen instead of the real | |
| 509 | + * manager. | |
| 510 | + * | |
| 511 | + * True whenever the Pro manager is not available — i.e. Pro is off (a genuine | |
| 512 | + * upsell) OR an older Pro that predates the glossaries move is active (it can no | |
| 513 | + * longer provide the manager, so the slot must not be left blank). Only a Pro new | |
| 514 | + * enough to ship GlossaryTaxonomy hides this and takes over the route. | |
| 515 | + * | |
| 516 | + * @return bool | |
| 517 | + */ | |
| 518 | + public function show_glossary_teaser() { | |
| 519 | + return ! $this->has_glossaries(); | |
| 520 | + } | |
| 521 | + | |
| 522 | + /** | |
| 523 | + * Whether the locked Glossaries screen is showing because an *outdated* Pro | |
| 524 | + * is active (as opposed to no Pro at all). | |
| 525 | + * | |
| 526 | + * Glossaries moved into Pro, so a Pro that predates the move is active but no | |
| 527 | + * longer provides the manager. That user already owns Pro, so the locked | |
| 528 | + * screen must ask them to UPDATE Pro rather than upsell "get Pro". Mirrors the | |
| 529 | + * has_glossaries() capability check. | |
| 530 | + * | |
| 531 | + * @return bool | |
| 532 | + */ | |
| 533 | + public function glossaries_needs_pro_update() { | |
| 534 | + return $this->is_pro_active() && ! $this->has_glossaries(); | |
| 535 | + } | |
| 536 | + | |
| 537 | + /** | |
| 538 | + * The BetterDocs Pro version that first ships the Glossaries manager, shown in | |
| 539 | + * the "please update Pro" copy. Filterable so the target can move with Pro. | |
| 540 | + * | |
| 541 | + * @return string | |
| 542 | + */ | |
| 543 | + public function glossaries_min_pro_version() { | |
| 544 | + return (string) apply_filters( 'betterdocs_glossaries_min_pro_version', '4.3.1' ); | |
| 545 | + } | |
| 546 | + | |
| 547 | + /** | |
| 548 | + * Whether Pro provides the real Content Intelligence screen. | |
| 549 | + * | |
| 550 | + * Pro flips this via `betterdocs_pro_has_content_intelligence`; the | |
| 551 | + * class_exists() default keeps the gate correct against a Pro build that | |
| 552 | + * predates that filter. | |
| 553 | + * | |
| 554 | + * @return bool | |
| 555 | + */ | |
| 556 | + public function has_content_intelligence() { | |
| 557 | + return (bool) apply_filters( | |
| 558 | + 'betterdocs_pro_has_content_intelligence', | |
| 559 | + class_exists( '\\WPDeveloper\\BetterDocsPro\\Core\\ContentIntelligenceService' ) | |
| 560 | + ); | |
| 561 | + } | |
| 562 | + | |
| 563 | + /** | |
| 564 | + * Whether Free should show its locked Content Intelligence teaser. | |
| 565 | + * | |
| 566 | + * Only without Pro. An older Pro has already paid, so they get nothing here — | |
| 567 | + * they need a plugin update, not an upsell. | |
| 568 | + * | |
| 569 | + * @return bool | |
| 570 | + */ | |
| 571 | + public function show_content_intelligence_teaser() { | |
| 572 | + return ! $this->is_pro_active() && ! $this->has_content_intelligence(); | |
| 573 | + } | |
| 574 | + | |
| 414 | 575 | public function pro_version() { |
| 415 | 576 | if ( ! $this->is_pro_active() ) { |
| 416 | 577 | return false; |
| 417 | 578 | } |
| @@ -463,12 +624,15 @@ | ||
| 463 | 624 | 'toplevel_page_betterdocs-admin', |
| 464 | 625 | 'admin_page_betterdocs-admin', |
| 465 | 626 | 'betterdocs_page_betterdocs-admin', |
| 466 | 627 | 'betterdocs_page_betterdocs-analytics', |
| 628 | + 'betterdocs_page_betterdocs-content-iq', | |
| 467 | 629 | 'betterdocs_page_betterdocs-settings', |
| 630 | + 'betterdocs_page_betterdocs-mcp', | |
| 468 | 631 | 'betterdocs_page_betterdocs-faq', |
| 469 | 632 | 'betterdocs_page_betterdocs-glossaries', |
| 470 | 633 | 'betterdocs_page_betterdocs-ai-chatbot', |
| 634 | + 'betterdocs_page_betterdocs-api-docs', | |
| 471 | 635 | 'betterdocs_page_betterdocs-doc-categories', |
| 472 | 636 | 'betterdocs_page_betterdocs-doc-tags', |
| 473 | 637 | ) ); |
| 474 | 638 | |
| @@ -488,12 +652,14 @@ | ||
| 488 | 652 | 'toplevel_page_betterdocs-dashboard', |
| 489 | 653 | 'admin_page_betterdocs-admin', |
| 490 | 654 | 'betterdocs_page_betterdocs-admin', |
| 491 | 655 | 'betterdocs_page_betterdocs-settings', |
| 656 | + 'betterdocs_page_betterdocs-mcp', | |
| 492 | 657 | 'betterdocs_page_betterdocs-analytics', |
| 493 | 658 | 'betterdocs_page_betterdocs-faq', |
| 494 | 659 | 'betterdocs_page_betterdocs-glossaries', |
| 495 | 660 | 'betterdocs_page_betterdocs-ai-chatbot', |
| 661 | + 'betterdocs_page_betterdocs-api-docs', | |
| 496 | 662 | 'betterdocs_page_betterdocs-doc-categories', |
| 497 | 663 | 'betterdocs_page_betterdocs-doc-tags', |
| 498 | 664 | 'edit-docs' |
| 499 | 665 | ); |