/var/www/html_de/wp-content/plugins/query-monitor/output/html/hooks.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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
<?php declare(strict_types 1);
/**
 * Hooks and actions output for HTML pages.
 *
 * @package query-monitor
 */

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

class 
QM_Output_Html_Hooks extends QM_Output_Html {

    
/**
     * Collector instance.
     *
     * @var QM_Collector_Hooks Collector.
     */
    
protected $collector;

    public function 
__constructQM_Collector $collector ) {
        
parent::__construct$collector );
        
add_filter'qm/output/menus', array( $this'admin_menu' ), 80 );
    }

    
/**
     * @return string
     */
    
public function name() {
        
/** @var QM_Data_Hooks */
        
$data $this->collector->get_data();

        
$name __'Hooks & Actions''query-monitor' );

        if ( 
$data->all_hooks ) {
            
$name __'Hooks, Actions, & Filters''query-monitor' );
        }

        return 
$name;
    }

    
/**
     * @return void
     */
    
public function output() {
        
/** @var QM_Data_Hooks */
        
$data $this->collector->get_data();

        if ( empty( 
$data->hooks ) ) {
            return;
        }

        
$this->before_tabular_output();

        
$callback_label __'Action''query-monitor' );
        
$th_type '';

        if ( 
$data->all_hooks ) {
            
$callback_label __'Callback''query-monitor' );
            
$th_type '<th scope="col" class="qm-filterable-column">' $this->build_filter'type', array(
                
'action' => __'Action''query-monitor' ),
                
'filter' => __'Filter''query-monitor' ),
            ), 
__'Type''query-monitor' ) ) . '</th>';
        }

        echo 
'<thead>';
        echo 
'<tr>';
        echo 
'<th scope="col" class="qm-filterable-column">';
        echo 
$this->build_filter'name'$data->parts__'Hook''query-monitor' ) ); // WPCS: XSS ok.
        
echo '</th>';
        echo 
$th_type// WPCS: XSS ok.
        
echo '<th scope="col">' esc_html__'Priority''query-monitor' ) . '</th>';
        echo 
'<th scope="col">' esc_html$callback_label ) . '</th>';
        echo 
'<th scope="col" class="qm-filterable-column">';
        echo 
$this->build_filter'component'$data->components__'Component''query-monitor' ), array(
            
'highlight' => 'subject',
        ) ); 
// WPCS: XSS ok.
        
echo '</th>';
        echo 
'</tr>';
        echo 
'</thead>';

        echo 
'<tbody>';
        
self::output_hook_table$data->hooks$data->all_hooks );
        echo 
'</tbody>';

        
$this->after_tabular_output();
    }

    
/**
     * @param array<int, mixed[]> $hooks
     * @param bool                $all_hooks
     * @return void
     */
    
public static function output_hook_table( array $hooksbool $all_hooks ) {
        
$core __'WordPress Core''query-monitor' );

        foreach ( 
$hooks as $hook ) {
            
$row_attr = array();
            
$row_attr['data-qm-name'] = implode' '$hook['parts'] );
            
$row_attr['data-qm-component'] = implode' '$hook['components'] );
            
$row_attr['data-qm-type'] = $hook['type'];

            if ( ! empty( 
$row_attr['data-qm-component'] ) && $core !== $row_attr['data-qm-component'] ) {
                
$row_attr['data-qm-component'] .= ' non-core';
            }

            
$attr '';

            if ( ! empty( 
$hook['actions'] ) ) {
                
$rowspan count$hook['actions'] );
            } else {
                
$rowspan 1;
            }

            foreach ( 
$row_attr as $a => $v ) {
                
$attr .= ' ' $a '="' esc_attr$v ) . '"';
            }

            if ( ! empty( 
$hook['actions'] ) ) {

                
$first true;

                foreach ( 
$hook['actions'] as $action ) {
                    
$component '';
                    
$subject '';

                    if ( isset( 
$action['callback']['component'] ) ) {
                        
$component $action['callback']['component']->name;
                        
$subject $component;
                    }

                    if ( 
$core !== $component ) {
                        
$subject .= ' non-core';
                    }

                    
printf// WPCS: XSS ok.
                        
'<tr data-qm-subject="%s" %s>',
                        
esc_attr$subject ),
                        
$attr
                    
);

                    if ( 
$first ) {

                        echo 
'<th scope="row" rowspan="' intval$rowspan ) . '" class="qm-nowrap qm-ltr"><span class="qm-sticky">';
                        echo 
'<code>' esc_html$hook['name'] ) . '</code>';
                        if ( 
'all' === $hook['name'] ) {
                            
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
                            
echo '<br><span class="qm-warn">' QueryMonitor::icon'warning' );
                            
printf(
                                
/* translators: %s: Action name */
                                
esc_html__'Warning: The %s action is extremely resource intensive. Try to avoid using it.''query-monitor' ),
                                
'<code>all</code>'
                            
);
                            echo 
'</span>';
                        }
                        echo 
'</span></th>';

                        if ( 
$all_hooks ) {
                            
$type = ( 'action' === $hook['type'] ) ? __'Action''query-monitor' ) : __'Filter''query-monitor' );
                            echo 
'<td rowspan="' intval$rowspan ) . '" class="qm-nowrap qm-ltr"><span class="qm-sticky">' esc_html$type ) . '</td>';
                        }
                    }

                    if ( isset( 
$action['callback']['error'] ) ) {
                        
$class ' qm-warn';
                    } else {
                        
$class '';
                    }

                    echo 
'<td class="qm-num' esc_attr$class ) . '">';

                    echo 
esc_html$action['priority'] );

                    if ( 
PHP_INT_MAX === $action['priority'] ) {
                        echo 
' <span class="qm-info">(PHP_INT_MAX)</span>';
                    } elseif ( 
PHP_INT_MIN === $action['priority'] ) {
                        echo 
' <span class="qm-info">(PHP_INT_MIN)</span>';
                    } elseif ( -
PHP_INT_MAX === $action['priority'] ) {
                        echo 
' <span class="qm-info">(-PHP_INT_MAX)</span>';
                    }

                    echo 
'</td>';

                    if ( isset( 
$action['callback']['file'] ) ) {
                        if ( 
self::has_clickable_links() ) {
                            echo 
'<td class="qm-nowrap qm-ltr' esc_attr$class ) . '">';
                            echo 
self::output_filename$action['callback']['name'], $action['callback']['file'], $action['callback']['line'] ); // WPCS: XSS ok.
                            
echo '</td>';
                        } else {
                            echo 
'<td class="qm-nowrap qm-ltr qm-has-toggle' esc_attr$class ) . '">';
                            echo 
self::build_toggler(); // WPCS: XSS ok;
                            
echo '<ol>';
                            echo 
'<li>';
                            echo 
self::output_filename$action['callback']['name'], $action['callback']['file'], $action['callback']['line'] ); // WPCS: XSS ok.
                            
echo '</li>';
                            echo 
'</ol></td>';
                        }
                    } else {
                        echo 
'<td class="qm-ltr qm-nowrap' esc_attr$class ) . '">';
                        echo 
'<code>' esc_html$action['callback']['name'] ) . '</code>';

                        if ( isset( 
$action['callback']['error'] ) ) {
                            
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
                            
echo '<br>' QueryMonitor::icon'warning' );
                            echo 
esc_htmlsprintf(
                                
/* translators: %s: Error message text */
                                
__'Error: %s''query-monitor' ),
                                
$action['callback']['error']->get_error_message()
                            ) );
                        }

                        echo 
'</td>';
                    }

                    echo 
'<td class="qm-nowrap' esc_attr$class ) . '">';
                    echo 
esc_html$component );
                    echo 
'</td>';
                    echo 
'</tr>';
                    
$first false;
                }
            } else {
                echo 
"<tr{$attr}>"// WPCS: XSS ok.
                
echo '<th scope="row" class="qm-ltr">';
                echo 
'<code>' esc_html$hook['name'] ) . '</code>';
                echo 
'</th>';
                echo 
'<td></td>';
                echo 
'<td></td>';
                echo 
'<td></td>';

                if ( 
$all_hooks ) {
                    echo 
'<td></td>';
                }

                echo 
'</tr>';
            }
        }

    }

}

/**
 * @param array<string, QM_Output> $output
 * @param QM_Collectors $collectors
 * @return array<string, QM_Output>
 */
function register_qm_output_html_hooks( array $outputQM_Collectors $collectors ) {
    
$collector QM_Collectors::get'hooks' );
    if ( 
$collector ) {
        
$output['hooks'] = new QM_Output_Html_Hooks$collector );
    }
    return 
$output;
}

add_filter'qm/outputter/html''register_qm_output_html_hooks'80);