| @@ -177,8 +177,13 @@ | ||
| 177 | 177 | if ( is_string( $saved_version ) && version_compare( $saved_version, '3.0.0', '<' ) ) { |
| 178 | 178 | update_option( 'cartflows-legacy-admin', 'enable' ); |
| 179 | 179 | } |
| 180 | 180 | |
| 181 | + // Knowledge Base docs were stored autoloaded, adding hundreds of KB to every request. | |
| 182 | + if ( is_string( $saved_version ) && version_compare( $saved_version, '3.2.1', '<' ) ) { | |
| 183 | + $this->migrate_knowledge_base_docs_storage(); | |
| 184 | + } | |
| 185 | + | |
| 181 | 186 | // Update auto saved version number. |
| 182 | 187 | update_option( 'cartflows-version', CARTFLOWS_VER ); |
| 183 | 188 | |
| 184 | 189 | // Update cartflows asset version to regenerate the dynamic css. We are using the time() function to add the random number. |
| @@ -416,8 +421,47 @@ | ||
| 416 | 421 | } |
| 417 | 422 | } |
| 418 | 423 | |
| 419 | 424 | return $migrated; |
| 425 | + } | |
| 426 | + | |
| 427 | + /** | |
| 428 | + * Stop the Knowledge Base docs option from being autoloaded on every request. | |
| 429 | + * Only the legacy admin renders the screen that reads it, so the new UI drops it entirely. | |
| 430 | + * | |
| 431 | + * @since x.x.x | |
| 432 | + * @return void | |
| 433 | + */ | |
| 434 | + public function migrate_knowledge_base_docs_storage() { | |
| 435 | + | |
| 436 | + // Earlier blocks in init() rewrite this option, so CARTFLOWS_LEGACY_ADMIN is stale here — see class-cartflows-loader.php:158 for the allowlist. | |
| 437 | + $legacy_admin_saved = get_option( 'cartflows-legacy-admin', false ); | |
| 438 | + $is_legacy_admin = in_array( $legacy_admin_saved, array( true, 1, '1', 'enable', 'yes' ), true ); | |
| 439 | + | |
| 440 | + if ( ! $is_legacy_admin ) { | |
| 441 | + delete_option( 'cartflows_docs_data' ); | |
| 442 | + | |
| 443 | + if ( function_exists( 'as_unschedule_all_actions' ) ) { | |
| 444 | + as_unschedule_all_actions( 'cartflows_update_knowledge_base_data' ); | |
| 445 | + } | |
| 446 | + | |
| 447 | + return; | |
| 448 | + } | |
| 449 | + | |
| 450 | + if ( false === get_option( 'cartflows_docs_data', false ) ) { | |
| 451 | + return; | |
| 452 | + } | |
| 453 | + | |
| 454 | + // wp_set_option_autoload() landed in WP 6.4 and we still support 5.8. | |
| 455 | + if ( function_exists( 'wp_set_option_autoload' ) ) { | |
| 456 | + wp_set_option_autoload( 'cartflows_docs_data', false ); | |
| 457 | + return; | |
| 458 | + } | |
| 459 | + | |
| 460 | + $docs_data = get_option( 'cartflows_docs_data' ); | |
| 461 | + | |
| 462 | + delete_option( 'cartflows_docs_data' ); | |
| 463 | + add_option( 'cartflows_docs_data', $docs_data, '', false ); | |
| 420 | 464 | } |
| 421 | 465 | |
| 422 | 466 | /** |
| 423 | 467 | * Migrate old combined custom script meta to separate JS and CSS meta fields. |