dimayakovlev / getsimple-cms-extended

GetSimple CMS Extended
https://github.com/dimayakovlev/getsimple-cms-extended
GNU General Public License v3.0
1 stars 0 forks source link

Handle errors while exec actions in admin panel #67

Open dimayakovlev opened 2 years ago

dimayakovlev commented 2 years ago

This will prevent losing access to administration panel on errors in actions PHP code.

dimayakovlev commented 2 years ago

Example of updated function exec_action().

function exec_action($a) {
    global $plugins;
    foreach ($plugins as $hook) {
        if ($hook['hook'] == $a) {
            if (is_frontend()) {
                call_user_func_array($hook['function'], $hook['args']);
            } else {
                try {
                    call_user_func_array($hook['function'], $hook['args']);
                } catch (Throwable $e) {
                    if (error_reporting() !== 0) {
                        error_log($e);
                        if (filter_var(ini_get('display_errors'), FILTER_VALIDATE_BOOLEAN)) echo $e;
                        if (isDebug()) debugLog($e);
                    }
                }
            }
        }
    }
}