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
|
<?php declare(strict_types = 1); /** * Template conditionals collector. * * @package query-monitor */
if ( ! defined( 'ABSPATH' ) ) { exit; }
/** * @extends QM_DataCollector<QM_Data_Conditionals> */ class QM_Collector_Conditionals extends QM_DataCollector {
public $id = 'conditionals';
public function get_storage(): QM_Data { return new QM_Data_Conditionals(); }
/** * @return void */ public function process() {
/** * Allows users to filter the names of conditional functions that are exposed by QM. * * @since 2.7.0 * * @param array<int, string> $conditionals The list of conditional function names. */ $conds = apply_filters( 'qm/collect/conditionals', array( 'is_404', 'is_admin', 'is_archive', 'is_attachment', 'is_author', 'is_blog_admin', 'is_category', 'is_comment_feed', 'is_customize_preview', 'is_date', 'is_day', 'is_embed', 'is_favicon', 'is_feed', 'is_front_page', 'is_home', 'is_login', 'is_main_network', 'is_main_site', 'is_month', 'is_network_admin', 'is_page', 'is_page_template', 'is_paged', 'is_post_type_archive', 'is_preview', 'is_privacy_policy', 'is_robots', 'is_rtl', 'is_search', 'is_single', 'is_singular', 'is_ssl', 'is_sticky', 'is_tag', 'is_tax', 'is_time', 'is_trackback', 'is_user_admin', 'is_year', ) );
/** * This filter is deprecated. Please use `qm/collect/conditionals` instead. * * @since 2.7.0 * * @param array<int, string> $conditionals The list of conditional function names. */ $conds = apply_filters( 'query_monitor_conditionals', $conds );
$true = array(); $false = array(); $na = array();
foreach ( $conds as $cond ) { if ( function_exists( $cond ) ) { $id = null; if ( ( 'is_sticky' === $cond ) && ! get_post( $id ) ) { # Special case for is_sticky to prevent PHP notices $false[] = $cond; } elseif ( ! is_multisite() && in_array( $cond, array( 'is_main_network', 'is_main_site' ), true ) ) { # Special case for multisite conditionals to prevent them from being annoying on single site installations $na[] = $cond; } else { if ( call_user_func( $cond ) ) { $true[] = $cond; } else { $false[] = $cond; } } } else { $na[] = $cond; } } $this->data->conds = compact( 'true', 'false', 'na' );
}
}
/** * @param array<string, QM_Collector> $collectors * @param QueryMonitor $qm * @return array<string, QM_Collector> */ function register_qm_collector_conditionals( array $collectors, QueryMonitor $qm ) { $collectors['conditionals'] = new QM_Collector_Conditionals(); return $collectors; }
add_filter( 'qm/collectors', 'register_qm_collector_conditionals', 10, 2 );
|