PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 4.9.3
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v4.9.3
4.9.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 All 201 releases
← All changes | includes/Admin/Importer/WPImport.php +29 -2 4.9.1 → 4.9.3 View file →
@@ -372,8 +372,16 @@
372 372
373 373 wp_defer_term_counting( true );
374 374 wp_defer_comment_counting( true );
375 375
376 + // Safety net for an aborted run: a PHP timeout, memory limit, fatal, or a
377 + // cut-off request can end the import before import_end() runs, which would
378 + // strand wp_defer_term_counting(true) and a stale {taxonomy}_children cache
379 + // and silently drop nested-category counts site-wide. A shutdown handler
380 + // guarantees the restore runs on the way out; it is idempotent, so the normal
381 + // import_end() path (which also calls it) makes this a no-op. (#167)
382 + register_shutdown_function( array( $this, 'restore_counting_and_hierarchy' ) );
383 +
376 384 do_action( 'import_start', $this );
377 385
378 386 return true;
379 387 }
@@ -385,8 +393,29 @@
385 393 wp_import_cleanup( $this->id );
386 394
387 395 wp_cache_flush();
388 396
397 + $this->restore_counting_and_hierarchy();
398 +
399 + do_action( 'import_end' );
400 + }
401 +
402 + /**
403 + * Turn term/comment counting back on and rebuild the term hierarchy.
404 + *
405 + * import_start() registers this as a shutdown handler so an aborted run (timeout,
406 + * memory, fatal, cut-off request) that never reaches import_end() cannot strand
407 + * wp_defer_term_counting(true) or a stale {taxonomy}_children cache. Idempotent,
408 + * so it is safe to call from both import_end() and the shutdown handler. (#167)
409 + */
410 + public function restore_counting_and_hierarchy() {
411 + static $restored = false;
412 +
413 + if ( $restored ) {
414 + return;
415 + }
416 + $restored = true;
417 +
389 418 foreach ( get_taxonomies() as $tax ) {
390 419 delete_option( "{$tax}_children" );
391 420 _get_term_hierarchy( $tax );
392 421 }
@@ -392,10 +421,8 @@
392 421 }
393 422
394 423 wp_defer_term_counting( false );
395 424 wp_defer_comment_counting( false );
396 -
397 - do_action( 'import_end' );
398 425 }
399 426
400 427 /**
401 428 * Retrieve authors from parsed WXR data and set it to `$this->>authors`.