/var/www/html_it/wp-content/plugins/query-monitor/collectors/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
<?php declare(strict_types 1);
/**
 * Hooks and actions collector.
 *
 * @package query-monitor
 */

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

/**
 * @extends QM_DataCollector<QM_Data_Hooks>
 */
class QM_Collector_Hooks extends QM_DataCollector {

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

    
/**
     * @var bool
     */
    
protected static $hide_core;

    public function 
get_storage(): QM_Data {
        return new 
QM_Data_Hooks();
    }

    
/**
     * @return void
     */
    
public function process() {
        
/**
         * @var array<string, int> $wp_actions
         * @var array<string, WP_Hook> $wp_filter
         */
        
global $wp_actions$wp_filter;

        
self::$hide_qm self::hide_qm();
        
self::$hide_core = ( defined'QM_HIDE_CORE_ACTIONS' ) && QM_HIDE_CORE_ACTIONS );

        
$hooks = array();
        
$all_parts = array();
        
$components = array();

        if ( 
has_action'all' ) ) {
            
$hooks[] = QM_Hook::process'all''action'$wp_filterself::$hide_qmself::$hide_core );
        }

        
$this->data->all_hooks defined'QM_SHOW_ALL_HOOKS' ) && QM_SHOW_ALL_HOOKS;

        if ( 
$this->data->all_hooks ) {
            
// Show all hooks
            
$hook_names array_keys$wp_filter );
        } else {
            
// Only show action hooks that have been called at least once
            
$hook_names array_keys$wp_actions );
        }

        foreach ( 
$hook_names as $name ) {
            
$type 'action';

            if ( 
$this->data->all_hooks ) {
                
$type array_key_exists$name$wp_actions ) ? 'action' 'filter';
            }

            
$hook QM_Hook::process$name$type$wp_filterself::$hide_qmself::$hide_core );
            
$hooks[] = $hook;

            
$all_parts array_merge$all_parts$hook['parts'] );
            
$components array_merge$components$hook['components'] );

        }

        
$this->data->hooks $hooks;
        
$this->data->parts array_uniquearray_filter$all_parts ) );
        
$this->data->components array_uniquearray_filter$components ) );

        
usort$this->data->parts'strcasecmp' );
        
usort$this->data->components'strcasecmp' );
    }

}

# Load early to catch all hooks
QM_Collectors::add( new QM_Collector_Hooks() );