WordPress Hook Suspension: Why LearnDash Imports Crash and How to Fix It
LearnDash and BuddyBoss hooks trigger template rendering during CLI bulk post creation, crashing the import process. The fix: suspend dangerous hooks during import with targeted hook removal and restoration.
The crash: template rendering in CLI context
When you programmatically create LearnDash course posts via WP-CLI or a PHP script, WordPress fires the same hooks as if a post were being created in the admin. LearnDash and BuddyBoss register hooks on save_post and the_content that trigger template rendering — which tries to load frontend assets that don't exist in a CLI context. Fatal error, import dies.
The fix: suspend_template_hooks() and restore_template_hooks()
We wrote two methods for the importer: suspend_template_hooks() removes the dangerous action and filter callbacks before bulk post creation begins, and restore_template_hooks() puts them back after. This is targeted hook removal — we only suspend the specific callbacks that cause CLI crashes, not all WordPress hooks.
Which hooks to suspend
The main offenders are LearnDash's learndash_content filter on the_content, BuddyBoss's template loading on wp_head and wp_footer, and any theme-level hooks that assume a frontend request context. The specific callbacks vary by theme and plugin combination — inspect with the WordPress Hook Inspector or simply dump the $wp_filter global before and after your import.