NaveenCodes Safe Mode
NaveenCodes Safe Mode helps restore access after fatal plugin or theme crashes. It detects fatal PHP shutdown errors, identifies whether the source is a plugin or theme, performs the configured recovery action, records detailed logs, stores recovery history, shows persistent admin notices, and emails administrators.
The plugin does not modify, rewrite, or repair user code. Version 1 is focused only on detection, disabling, recovery, logging, and notification.
Version 1 Architecture
- Namespace:
NaveenCodes\SafeMode - Prefix:
ncsm_ - Text domain:
naveencodes-safe-mode - Bootstrap:
naveencodes-safe-mode.php - Autoloading: lightweight PSR-4 style autoloader for
includes/ - Composition root:
includes/Core/Plugin.php - Service boundaries:
Core: activation, deactivation, settings, plugin bootstrappingDatabase: custom table schemaRecovery: shutdown detection, source detection, queueing, plugin/theme recovery, notificationsLogging: error logs and recovery history persistenceAdmin: dashboard, logs, history, settings, notices, coming soon UIHelpers: focused WordPress helper utilitiesInterfaces: shared service contracts
Database Schema
wp_ncsm_logs
idtimestamperror_typeerror_messagefile_pathline_numbersource_typesource_nameaction_taken-
recovery_statuswp_ncsm_recovery_history
-
id timestampsource_typesource_namerecovery_actionrecovery_result
Recovery Workflow
- Register a shutdown function early on
plugins_loaded. - Inspect
error_get_last()on shutdown. - Continue only for fatal, parse, compile, core, user, or recoverable fatal errors.
- Detect source from the error file path:
wp-content/plugins/...becomes a plugin source.wp-content/themes/...becomes a theme source.- Anything else is stored as Unknown Source.
- Check recovery queue attempts for the source.
- If the source is a plugin and plugin auto-disable is enabled, deactivate the faulty plugin.
- If the source is the active theme and theme recovery is enabled, switch to the configured fallback theme.
- Log the error and recovery action.
- Store recovery history.
- Add a persistent admin notice.
- Send an administrator email when enabled.
WordPress Hooks
plugins_loadedboots the plugin.register_shutdown_function()detects fatal shutdown errors.admin_menuregisters the admin pages.admin_enqueue_scriptsloads admin assets.admin_noticesrenders persistent recovery notices.admin_post_ncsm_save_settingssaves settings.admin_post_ncsm_export_logsexports logs.admin_post_ncsm_dismiss_noticedismisses recovery notices.
Admin Pages
- Dashboard: protection status, statistics, and recovery workflow.
- Error Logs: fatal error log table, filters, and CSV export.
- Recovery History: source, action, result, and timestamp.
- Settings: recovery toggles, notifications, fallback theme, retention, maximum attempts.
- Coming Soon: Version 2 feature previews only.
Settings
- Enable Recovery
- Enable Plugin Auto Disable
- Enable Theme Recovery
- Enable Email Notifications
- Fallback Theme Selector
- Log Retention Period
- Maximum Recovery Attempts
Coming Soon
The following features are displayed as UI-only cards and are not implemented in Version 1:
- Automatic Rollback
- Update Sandbox Testing
- Code Snippet Protection
- AI Error Analysis
- Slack Notifications
- Cloud Backups
- Uptime Monitoring
- One Click Restore
Security
Version 1 uses capability checks, nonces, sanitization, escaping, WordPress database APIs, and prepared SQL for dynamic values. It performs no tracking, no hidden data collection, no remote code execution, and no unsafe file rewriting.
