Skip to main content

SupportMode

\Benecaster\Admin\SupportMode

Class Free

Owns the state of Support Mode, the switch on Settings → Tools that raises the debug log’s verbosity and unlocks the “Send diagnostic log” button. State is two options, a boolean flag and the Unix timestamp at which the mode switches itself off, plus one single-shot WP-Cron event that does the switching off. Enabling it sends nothing anywhere: log data leaves the site only when an admin clicks the send button.

The methods are instance methods, not static. The plugin registers one shared instance in its service container. Add-on code that only needs to know whether Support Mode is on can read it with \Benecaster\Plugin::instance()->container()->make( \Benecaster\Admin\SupportMode::class )->is_active(). There is no public benecaster_* function for it. To toggle Support Mode from code, send support_mode_enabled (true or false) to POST /benecaster/v1/tools/settings, which calls enable() or disable(). To react when it changes, hook benecaster_support_mode_enabled and benecaster_support_mode_disabled rather than calling the class.

Methods

Method Visibility Since Description
register(): void Public — Attaches auto_disable() to the benecaster_support_mode_auto_disable cron hook. The plugin calls this once at boot; there is no reason to call it again.
is_active(): bool Public — Returns true when the benecaster_support_mode_enabled option holds a truthy value. This is the check the Send diagnostic log button makes before it will send, and the option DebugLog reads directly to decide whether to record info and warning entries.
get_auto_disable_at(): ?int Public — Returns the Unix timestamp at which Support Mode will switch itself off, or null when no positive timestamp is stored, which is the case whenever Support Mode is off.
enable(): void Public — Turns Support Mode on. Stores the flag and a switch-off time seven days from now, clears any previously scheduled auto-disable event, schedules a new single event at the new time, then fires benecaster_support_mode_enabled with the switch-off timestamp. Safe to call when already enabled: the seven-day window restarts from the moment of the call rather than keeping the original expiry, and the action fires again.
disable(): void Public — Turns Support Mode off. Deletes both options, clears the scheduled auto-disable event, then fires benecaster_support_mode_disabled with the reason 'manual'. Safe to call when already off; the action still fires.
auto_disable(): void Public — The WP-Cron callback for the seven-day timer. Deletes both options and fires benecaster_support_mode_disabled with the reason 'auto', so listeners can tell a timed switch-off from a manual one. It does not clear the cron hook, because the single event has already run. Not intended to be called directly.

Constants

Name Value Description
OPTION_ENABLED 'benecaster_support_mode_enabled' Option holding the on/off flag. It is stored with autoload off.
OPTION_AUTO_DISABLE 'benecaster_support_mode_auto_disable_at' Option holding the Unix timestamp of the scheduled switch-off, stored with autoload off.
CRON_HOOK 'benecaster_support_mode_auto_disable' WP-Cron hook name for the single auto-disable event.
AUTO_DISABLE_DURATION 7 * DAY_IN_SECONDS How long Support Mode stays on before it switches itself off: seven days, 604800 seconds.

Hooks Fired

Notes

The switch-off relies on WP-Cron. On a site where cron does not run, the option stays set past the timestamp until something triggers the event, so is_active() can return true after get_auto_disable_at() has passed. Code that needs the mode to have truly lapsed should compare the timestamp to the current time as well.