PluginProbe
Remote Website Management by Watchful / trunk
Remote Website Management by Watchful vtrunk
v2.0.17 v2.0.16 v2.0.15 v2.0.14 v2.0.13 v2.0.12 v2.0.11 trunk v1.2.11 v1.2.12 v1.2.13 v1.2.14 v1.2.17 v1.2.19 v1.2.20 v1.2.9 v1.3.0 v1.3.1 v1.3.2 v1.4.1 v1.4.10 v1.4.11 v1.4.12 v1.4.2 v1.4.3 All 72 releases
watchful / lib / ShutdownHandler.php

ShutdownHandler.php in Remote Website Management by Watchful trunk, at lib/ShutdownHandler.php

50 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Handle unexpected shutdown.
4 *
5 * @version 2016-12-20 11:41 UTC+01
6 * @package watchful
7 * @author Watchful
8 * @authorUrl https://watchful.net
9 * @copyright Copyright (c) 2020 watchful.net
10 * @license GNU/GPL
11 */
12
13 namespace Watchful;
14
15 if (!defined('ABSPATH')) {
16 exit; // Exit if accessed directly.
17 }
18
19
20 use Watchful\Helpers\ResponseFormatter;
21
22 /**
23 * Class for handling unexpected shutdowns.
24 */
25 class ShutdownHandler
26 {
27
28 public function __construct()
29 {
30 add_action('shutdown', array($this, 'shutdown'), 99);
31 }
32
33 public function shutdown()
34 {
35 $error = error_get_last();
36 if (empty($error) || $error['type'] !== E_ERROR) {
37 return;
38 }
39 $response = array(
40 'error' => 1,
41 'code' => $error['type'],
42 'message' => $error['message'],
43 'details' => $error,
44 );
45
46 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- output is JSON-encoded; HTML escaping would corrupt the payload.
47 echo ResponseFormatter::add_response_delimiters(wp_json_encode($response));
48 }
49 }
50