/var/www/html_nl/wp-content/plugins/query-monitor/dispatchers/WP_Die.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<?php declare(strict_types 1);
/**
 * Dispatcher for output that gets added to `wp_die()` calls.
 *
 * @package query-monitor
 */

if ( ! defined'ABSPATH' ) ) {
    exit;
}

class 
QM_Dispatcher_WP_Die extends QM_Dispatcher {

    
/**
     * @var string
     */
    
public $id 'wp_die';

    
/**
     * @var QM_Backtrace|null
     */
    
public $trace null;

    public function 
__constructQM_Plugin $qm ) {
        
add_action'shutdown', array( $this'dispatch' ), );

        
add_filter'wp_die_handler', array( $this'filter_wp_die_handler' ) );

        
parent::__construct$qm );
    }

    
/**
     * @param callable $handler
     * @return callable
     */
    
public function filter_wp_die_handler$handler ) {
        
$this->trace = new QM_Backtrace( array(
            
'ignore_hook' => array(
                
current_filter() => true,
            ),
        ) );

        return 
$handler;
    }

    
/**
     * @return void
     */
    
public function dispatch() {
        if ( ! 
$this->should_dispatch() ) {
            return;
        }

        
$switched_locale self::switch_to_localeget_user_locale() );
        
$stack = array();
        
$filtered_trace $this->trace->get_filtered_trace();
        
$component $this->trace->get_component();

        foreach ( 
$filtered_trace as $i => $item ) {
            
$stack[] = QM_Output_Html::output_filename$item['display'], $item['file'], $item['line'] );
        }

        
?>
        <style>
            #query-monitor {
                position: absolute;
                margin: 4em 0 1em -2em;
                border: 1px solid #ccd0d4;
                box-shadow: 0 1px 1px rgb( 0 0 0 / 4% );
                background: #fff;
                padding-top: 1em;
                max-width: 700px;
                z-index: -1;
            }

            #query-monitor h2 {
                font-size: 12px;
                font-weight: normal;
                padding: 7px;
                background: #f3f3f3;
                margin: 0;
                border-top: 1px solid #ddd;
            }

            #query-monitor ol,
            #query-monitor p {
                font-size: 12px;
                padding: 0;
                margin: 1em 2.5em;
            }

            #query-monitor ol {
                padding: 0 0 1em 0;
            }

            #query-monitor li {
                margin: 0 0 0.7em;
                list-style: none;
            }

            #query-monitor .qm-info {
                color: #666;
            }

            #query-monitor a.qm-edit-link svg {
                display: none !important;
            }

        </style>
        <?php

        
echo '<div id="query-monitor">';

        echo 
'<p>';

        if ( 
'unknown' !== $component->type ) {
            
$name = ( 'plugin' === $component->type ) ? $component->context $component->name;
            
printf(
                
/* translators: %s: Plugin or theme name */
                
esc_html__'This message was triggered by %s.''query-monitor' ),
                
'<b>' esc_html$name ) . '</b>'
            
);
        }

        echo 
'</p>';

        echo 
'<p>' esc_html__'Call stack:''query-monitor' ) . '</p>';
        echo 
'<ol>';
        echo 
'<li>' implode'</li><li>'$stack ) . '</li>'// WPCS: XSS ok.
        
echo '</ol>';

        echo 
'<h2>' esc_html__'Query Monitor''query-monitor' ) . '</h2>';

        echo 
'</div>';

        if ( 
$switched_locale ) {
            
self::restore_previous_locale();
        }
    }

    
/**
     * @return bool
     */
    
public function is_active() {
        if ( ! 
$this->trace ) {
            return 
false;
        }

        if ( ! 
self::user_can_view() ) {
            return 
false;
        }

        return 
true;
    }

}

/**
 * @param array<string, QM_Dispatcher> $dispatchers
 * @param QM_Plugin $qm
 * @return array<string, QM_Dispatcher>
 */
function register_qm_dispatcher_wp_die( array $dispatchersQM_Plugin $qm ) {
    
$dispatchers['wp_die'] = new QM_Dispatcher_WP_Die$qm );
    return 
$dispatchers;
}

add_filter'qm/dispatchers''register_qm_dispatcher_wp_die'10);