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
|
<?php declare(strict_types = 1); /** * Multisite collector, used for monitoring use of `switch_to_blog()` and `restore_current_blog()`. * * @package query-monitor */
if ( ! defined( 'ABSPATH' ) ) { exit; }
/** * @extends QM_DataCollector<QM_Data_Multisite> */ class QM_Collector_Multisite extends QM_DataCollector { public $id = 'multisite';
public function __construct() { parent::__construct();
$this->data->switches = array();
add_action( 'switch_blog', array( $this, 'action_switch_blog' ), 10, 3 ); }
public function get_storage(): QM_Data { return new QM_Data_Multisite(); }
/** * Fires when the blog is switched. * * @param int $new_blog_id New blog ID. * @param int $prev_blog_id Previous blog ID. * @param string $context Additional context. Accepts 'switch' when called from switch_to_blog() * or 'restore' when called from restore_current_blog(). * @return void */ public function action_switch_blog( $new_blog_id, $prev_blog_id, $context ) { if ( intval( $new_blog_id ) === intval( $prev_blog_id ) ) { return; }
$this->data->switches[] = array( 'new' => $new_blog_id, 'prev' => $prev_blog_id, 'to' => ( 'switch' === $context ), 'trace' => new QM_Backtrace( array( 'ignore_hook' => array( 'switch_blog' => true, ), 'ignore_func' => array( 'switch_to_blog' => true, 'restore_current_blog' => true, ), ) ), ); } }
if ( is_multisite() ) { # Load early to detect as many happenings during the bootstrap process as possible QM_Collectors::add( new QM_Collector_Multisite() ); }
|