Toggle an add-on’s verbose logging or extra diagnostics in lock-step with core Support Mode
Core’s Support Mode bumps DebugLog verbosity for the next 7 days and auto-disables on a one-shot WP-Cron event. Add-ons that have their own logger or diagnostic recorder should mirror that lifecycle so a customer who enables Support Mode also gets full add-on context in the bug report. $reason in the disabled action is 'manual' or 'auto'. Read the current state via SupportMode::is_active() or get_option( 'benecaster_support_mode_enabled' ).
Code
<?php
add_action(
'benecaster_support_mode_enabled',
function ( int $auto_disable_at ): void {
update_option( 'my_addon_verbose_logging', true, false );
// Optional: schedule a parallel cleanup so the add-on never logs past
// the same cutoff core uses, even if core's cron is rescheduled.
wp_clear_scheduled_hook( 'my_addon_support_mode_cleanup' );
wp_schedule_single_event( $auto_disable_at, 'my_addon_support_mode_cleanup' );
}
);
add_action(
'benecaster_support_mode_disabled',
function ( string $reason ): void {
// $reason is 'manual' when the admin toggled off, 'auto' when the
// 7-day cron fired. Tear down regardless.
update_option( 'my_addon_verbose_logging', false, false );
wp_clear_scheduled_hook( 'my_addon_support_mode_cleanup' );
}
);
Hooks Used
-
benecaster_support_mode_enabled -
benecaster_support_mode_disabled