Skip to content

Commit 1c75ec3

Browse files
committed
Update Query Monitor plugin from 3.19.0 to 3.20.0
1 parent 479ca79 commit 1c75ec3

64 files changed

Lines changed: 1059 additions & 484 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

wp-content/plugins/query-monitor/SECURITY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44

55
[You can report security bugs through the official Query Monitor Vulnerability Disclosure Program on Patchstack](https://patchstack.com/database/vdp/query-monitor). The Patchstack team helps validate, triage, and handle any security vulnerabilities.
66

7-
Do not report security issues on GitHub or the WordPress.org support forums. Thank you.
7+
Do not report security issues on GitHub, on the WordPress.org support forums, or via email. Thank you.

wp-content/plugins/query-monitor/classes/Backtrace.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ public function get_component() {
222222
$component = self::get_frame_component( $frame );
223223

224224
if ( $component ) {
225-
if ( 'plugin' === $component->type ) {
225+
if ( $component->is_plugin() ) {
226226
// If the component is a plugin then it can't be anything else,
227227
// so short-circuit and return early.
228228
$this->component = $component;
@@ -234,7 +234,7 @@ public function get_component() {
234234
}
235235

236236
$file_dirs = QM_Util::get_file_dirs();
237-
$file_dirs['dropin'] = WP_CONTENT_DIR;
237+
$file_dirs[ QM_Component::TYPE_DROPIN ] = WP_CONTENT_DIR;
238238

239239
foreach ( $file_dirs as $type => $dir ) {
240240
if ( isset( $components[ $type ] ) ) {
@@ -243,12 +243,7 @@ public function get_component() {
243243
}
244244
}
245245

246-
$component = new QM_Component();
247-
$component->type = 'unknown';
248-
$component->name = __( 'Unknown', 'query-monitor' );
249-
$component->context = 'unknown';
250-
251-
return $component;
246+
return QM_Component::from( QM_Component::TYPE_UNKNOWN, 'unknown' );
252247
}
253248

254249
/**
@@ -314,9 +309,12 @@ public function get_display_trace() {
314309
/**
315310
* @return array<int, array<string, mixed>>
316311
* @phpstan-return list<array{
312+
* id: string,
313+
* display: string,
314+
* calling_file: string,
315+
* calling_line: int,
317316
* file: string,
318317
* line: int,
319-
* display: string,
320318
* }>
321319
*/
322320
public function get_filtered_trace() {
@@ -427,7 +425,7 @@ public function filter_trace( array $frame ) {
427425
/**
428426
* Filters which namespaces to ignore when constructing user-facing call stacks.
429427
*
430-
* @since 3.18.1
428+
* @since 3.19.0
431429
*
432430
* @param array<string, bool> $ignore_namespace Array of namespace names to ignore. The array keys are namespace names to ignore,
433431
* the array values are whether to ignore the namespace (usually true).

wp-content/plugins/query-monitor/classes/Collector.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,20 +83,22 @@ protected function log_type( $type ) {
8383
* @return void
8484
*/
8585
protected function log_component( $component, $ltime, $type ) {
86-
if ( ! isset( $this->data->component_times[ $component->name ] ) ) {
87-
$this->data->component_times[ $component->name ] = array(
88-
'component' => $component->name,
86+
$key = $component->get_id();
87+
88+
if ( ! isset( $this->data->component_times[ $key ] ) ) {
89+
$this->data->component_times[ $key ] = array(
90+
'component' => $component,
8991
'ltime' => 0,
9092
'types' => array(),
9193
);
9294
}
9395

94-
$this->data->component_times[ $component->name ]['ltime'] += $ltime;
96+
$this->data->component_times[ $key ]['ltime'] += $ltime;
9597

96-
if ( isset( $this->data->component_times[ $component->name ]['types'][ $type ] ) ) {
97-
$this->data->component_times[ $component->name ]['types'][ $type ]++;
98+
if ( isset( $this->data->component_times[ $key ]['types'][ $type ] ) ) {
99+
$this->data->component_times[ $key ]['types'][ $type ]++;
98100
} else {
99-
$this->data->component_times[ $component->name ]['types'][ $type ] = 1;
101+
$this->data->component_times[ $key ]['types'][ $type ] = 1;
100102
}
101103

102104
}

wp-content/plugins/query-monitor/classes/Collector_Assets.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -283,13 +283,13 @@ protected static function get_script_modules(): ?array {
283283
$reflector = new ReflectionClass( $modules );
284284

285285
$get_marked_for_enqueue = $reflector->getMethod( 'get_marked_for_enqueue' );
286-
$get_marked_for_enqueue->setAccessible( true );
286+
( \PHP_VERSION_ID < 80100 ) && $get_marked_for_enqueue->setAccessible( true );
287287

288288
$get_dependencies = $reflector->getMethod( 'get_dependencies' );
289-
$get_dependencies->setAccessible( true );
289+
( \PHP_VERSION_ID < 80100 ) && $get_dependencies->setAccessible( true );
290290

291291
$get_src = $reflector->getMethod( 'get_src' );
292-
$get_src->setAccessible( true );
292+
( \PHP_VERSION_ID < 80100 ) && $get_src->setAccessible( true );
293293

294294
/**
295295
* @var array<string, array<string, mixed>> $enqueued
@@ -365,9 +365,9 @@ protected static function get_script_modules(): ?array {
365365
}
366366

367367
// @todo check isPrivate before changing visibility back
368-
$get_marked_for_enqueue->setAccessible( false );
369-
$get_dependencies->setAccessible( false );
370-
$get_src->setAccessible( false );
368+
( \PHP_VERSION_ID < 80100 ) && $get_marked_for_enqueue->setAccessible( false );
369+
( \PHP_VERSION_ID < 80100 ) && $get_dependencies->setAccessible( false );
370+
( \PHP_VERSION_ID < 80100 ) && $get_src->setAccessible( false );
371371

372372
return $sources;
373373
}

wp-content/plugins/query-monitor/classes/Component.php

Lines changed: 132 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,31 @@
55
* @package query-monitor
66
*/
77

8-
class QM_Component {
8+
/**
9+
* @phpstan-type QM_Component_Array array{
10+
* type: string,
11+
* name: string,
12+
* context: string,
13+
* }
14+
* @property-read string $name
15+
*/
16+
class QM_Component implements JsonSerializable {
17+
public const TYPE_ALTIS_VENDOR = 'altis-vendor';
18+
public const TYPE_CORE = 'core';
19+
public const TYPE_DROPIN = 'dropin';
20+
public const TYPE_MU_PLUGIN = 'mu-plugin';
21+
public const TYPE_MU_VENDOR = 'mu-vendor';
22+
public const TYPE_OTHER = 'other';
23+
public const TYPE_PHP = 'php';
24+
public const TYPE_PLUGIN = 'plugin';
25+
public const TYPE_STYLESHEET = 'stylesheet';
26+
public const TYPE_TEMPLATE = 'template';
27+
public const TYPE_THEME = 'theme';
28+
public const TYPE_UNKNOWN = 'unknown';
29+
public const TYPE_VIP_CLIENT_MU_PLUGIN = 'vip-client-mu-plugin';
30+
public const TYPE_VIP_PLUGIN = 'vip-plugin';
31+
public const TYPE_VIP_SHARED_PLUGIN = 'vip-shared-plugin';
32+
933
/**
1034
* @var string
1135
*/
@@ -14,10 +38,115 @@ class QM_Component {
1438
/**
1539
* @var string
1640
*/
17-
public $name;
41+
public $context;
1842

1943
/**
2044
* @var string
2145
*/
22-
public $context;
46+
public $file;
47+
48+
public function __construct( string $context, string $file = '', string $type = '' ) {
49+
$this->context = $context;
50+
$this->file = $file;
51+
$this->type = $type;
52+
}
53+
54+
public function get_name(): string {
55+
if ( isset( $this->name ) ) {
56+
return $this->name;
57+
}
58+
59+
return sprintf(
60+
$this->type,
61+
$this->context
62+
);
63+
}
64+
65+
final public function get_id(): string {
66+
return "{$this->type}-{$this->context}";
67+
}
68+
69+
final public function is_plugin(): bool {
70+
return ( $this->type === self::TYPE_PLUGIN );
71+
}
72+
73+
final public function is_core(): bool {
74+
return ( $this->type === self::TYPE_CORE );
75+
}
76+
77+
/**
78+
* @param QM_Component[] $components
79+
*/
80+
final public static function has_non_core( array $components ): bool {
81+
foreach ( $components as $component ) {
82+
if ( ! $component->is_core() ) {
83+
return true;
84+
}
85+
}
86+
87+
return false;
88+
}
89+
90+
final public static function from( string $type, string $context = '', string $file = '' ): QM_Component {
91+
switch ( $type ) {
92+
case self::TYPE_ALTIS_VENDOR:
93+
return new QM_Component_Altis_Vendor( $context, $file, $type );
94+
case self::TYPE_PLUGIN:
95+
return new QM_Component_Plugin( $context, $file, $type );
96+
case self::TYPE_MU_PLUGIN:
97+
return new QM_Component_MU_Plugin( $context, $file, $type );
98+
case self::TYPE_MU_VENDOR:
99+
return new QM_Component_MU_Vendor( $context, $file, $type );
100+
case self::TYPE_VIP_SHARED_PLUGIN:
101+
case self::TYPE_VIP_PLUGIN:
102+
case self::TYPE_VIP_CLIENT_MU_PLUGIN:
103+
return new QM_Component_VIP_Plugin( $context, $file, $type );
104+
case self::TYPE_STYLESHEET:
105+
return new QM_Component_Stylesheet( $context, $file, $type );
106+
case self::TYPE_TEMPLATE:
107+
return new QM_Component_Template( $context, $file, $type );
108+
case self::TYPE_OTHER:
109+
return new QM_Component_Other( $context, $file, $type );
110+
case self::TYPE_CORE:
111+
return new QM_Component_Core( $context, $file, $type );
112+
case self::TYPE_DROPIN:
113+
return new QM_Component_Dropin( $context, $file, $type );
114+
case self::TYPE_PHP:
115+
return new QM_Component_PHP( $context, $file, $type );
116+
}
117+
118+
return new QM_Component_Unknown( $context, $file, $type );
119+
}
120+
121+
/**
122+
* @return mixed
123+
*/
124+
public function __get( string $key ) {
125+
if ( 'name' === $key ) {
126+
return $this->get_name();
127+
}
128+
}
129+
130+
/**
131+
* @phpstan-return QM_Component_Array
132+
* @return array<string, string>
133+
*/
134+
public function toArray(): array {
135+
return array(
136+
'type' => $this->type,
137+
'name' => $this->name,
138+
'context' => $this->context,
139+
);
140+
}
141+
/**
142+
* @phpstan-return QM_Component_Array
143+
* @return array<string, string>
144+
*/
145+
public function jsonSerialize(): array {
146+
return $this->toArray();
147+
}
148+
149+
public static function sort( QM_Component $a, QM_Component $b ): int {
150+
return strcasecmp( $a->get_name(), $b->get_name() );
151+
}
23152
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php declare(strict_types = 1);
2+
/**
3+
* Class representing an Altis vendor dependency component.
4+
*
5+
* @package query-monitor
6+
*/
7+
8+
class QM_Component_Altis_Vendor extends QM_Component {
9+
public function get_name(): string {
10+
return sprintf(
11+
/* translators: %s: Dependency name */
12+
__( 'Dependency: %s', 'query-monitor' ),
13+
$this->context
14+
);
15+
}
16+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php declare(strict_types = 1);
2+
/**
3+
* Class representing the WordPress core component.
4+
*
5+
* @package query-monitor
6+
*/
7+
8+
class QM_Component_Core extends QM_Component {
9+
public function get_name(): string {
10+
return __( 'WordPress Core', 'query-monitor' );
11+
}
12+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php declare(strict_types = 1);
2+
/**
3+
* Class representing a drop-in plugin component.
4+
*
5+
* @package query-monitor
6+
*/
7+
8+
class QM_Component_Dropin extends QM_Component {
9+
public function get_name(): string {
10+
return sprintf(
11+
/* translators: %s: Drop-in plugin file name */
12+
__( 'Drop-in: %s', 'query-monitor' ),
13+
$this->context
14+
);
15+
}
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php declare(strict_types = 1);
2+
/**
3+
* Class representing a mu-plugin component.
4+
*
5+
* @package query-monitor
6+
*/
7+
8+
class QM_Component_MU_Plugin extends QM_Component {
9+
public function get_name(): string {
10+
return sprintf(
11+
/* translators: %s: Plugin name */
12+
__( 'MU Plugin: %s', 'query-monitor' ),
13+
$this->context
14+
);
15+
}
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php declare(strict_types = 1);
2+
/**
3+
* Class representing a mu-plugins/vendor dependency.
4+
*
5+
* @package query-monitor
6+
*/
7+
8+
class QM_Component_MU_Vendor extends QM_Component {
9+
public function get_name(): string {
10+
return sprintf(
11+
/* translators: %s: Plugin name */
12+
__( 'MU Plugin: %s', 'query-monitor' ),
13+
$this->context
14+
);
15+
}
16+
}

0 commit comments

Comments
 (0)