run:R W Run
DIR
2026-03-11 16:18:51
R W Run
DIR
2026-03-11 16:18:52
R W Run
DIR
2026-03-11 16:18:51
R W Run
DIR
2026-03-11 16:18:52
R W Run
DIR
2026-03-11 16:18:52
R W Run
DIR
2026-03-11 16:18:51
R W Run
DIR
2026-03-11 16:18:51
R W Run
DIR
2026-03-11 16:18:51
R W Run
DIR
2026-03-11 16:18:51
R W Run
DIR
2026-03-11 16:18:52
R W Run
DIR
2026-03-11 16:18:52
R W Run
DIR
2026-03-11 16:18:52
R W Run
DIR
2026-03-11 16:18:51
R W Run
DIR
2026-03-11 16:18:52
R W Run
DIR
2026-03-11 16:18:52
R W Run
DIR
2026-03-11 16:18:51
R W Run
DIR
2026-03-11 16:18:52
R W Run
DIR
2026-03-11 16:18:51
R W Run
DIR
2026-03-11 16:18:51
R W Run
DIR
2026-03-11 16:18:51
R W Run
DIR
2026-03-11 16:18:52
R W Run
DIR
2026-03-11 16:18:52
R W Run
DIR
2026-03-11 16:18:52
R W Run
DIR
2026-03-11 16:18:52
R W Run
DIR
2026-03-11 16:18:51
R W Run
DIR
2026-03-11 16:18:52
R W Run
DIR
2026-03-11 16:18:52
R W Run
DIR
2026-03-11 16:18:51
R W Run
DIR
2026-03-11 16:18:51
R W Run
23.8 KB
2026-03-11 16:18:51
R W Run
7.8 KB
2026-03-11 16:18:52
R W Run
36.1 KB
2026-03-11 16:18:51
R W Run
11.9 KB
2026-03-11 16:18:52
R W Run
18.94 KB
2026-03-11 16:18:52
R W Run
7.35 KB
2026-03-11 16:18:52
R W Run
28.6 KB
2026-03-11 16:18:51
R W Run
316 By
2026-03-11 16:18:51
R W Run
12.9 KB
2026-03-11 16:18:51
R W Run
61.02 KB
2026-03-11 16:18:52
R W Run
15 KB
2026-03-11 16:18:51
R W Run
112.05 KB
2026-03-11 16:18:51
R W Run
12.47 KB
2026-03-11 16:18:51
R W Run
15.07 KB
2026-03-11 16:18:52
R W Run
9.84 KB
2026-03-11 16:18:52
R W Run
13.17 KB
2026-03-11 16:18:52
R W Run
33.83 KB
2026-03-11 16:18:51
R W Run
42.63 KB
2026-03-11 16:18:51
R W Run
55.71 KB
2026-03-11 16:18:52
R W Run
12.53 KB
2026-03-11 16:18:51
R W Run
2.55 KB
2026-03-11 16:18:52
R W Run
28.92 KB
2026-03-11 16:18:52
R W Run
539 By
2026-03-11 16:18:51
R W Run
367 By
2026-03-11 16:18:52
R W Run
42.65 KB
2026-03-11 16:18:51
R W Run
401 By
2026-03-11 16:18:51
R W Run
6.61 KB
2026-03-11 16:18:51
R W Run
664 By
2026-03-11 16:18:52
R W Run
20.63 KB
2026-03-11 16:18:51
R W Run
2.18 KB
2026-03-11 16:18:52
R W Run
453 By
2026-03-11 16:18:52
R W Run
457 By
2026-03-11 16:18:51
R W Run
36.83 KB
2026-03-11 16:18:52
R W Run
2.41 KB
2026-03-11 16:18:52
R W Run
8.28 KB
2026-03-11 16:18:51
R W Run
13.89 KB
2026-03-11 16:18:51
R W Run
11.76 KB
2026-03-11 16:18:51
R W Run
2.65 KB
2026-03-11 16:18:51
R W Run
7.43 KB
2026-03-11 16:18:51
R W Run
17.46 KB
2026-03-11 16:18:51
R W Run
5.14 KB
2026-03-11 16:18:52
R W Run
16.7 KB
2026-03-11 16:18:51
R W Run
8.28 KB
2026-03-11 16:18:52
R W Run
2.92 KB
2026-03-11 16:18:52
R W Run
1.32 KB
2026-03-11 16:18:51
R W Run
4.6 KB
2026-03-11 16:18:52
R W Run
11.62 KB
2026-03-11 16:18:52
R W Run
2.5 KB
2026-03-11 16:18:51
R W Run
1.97 KB
2026-03-11 16:18:51
R W Run
11.25 KB
2026-03-11 16:18:52
R W Run
5.32 KB
2026-03-11 16:18:51
R W Run
10.99 KB
2026-03-11 16:18:52
R W Run
68.32 KB
2026-03-11 16:18:51
R W Run
6.34 KB
2026-03-11 16:18:51
R W Run
5.49 KB
2026-03-11 16:18:51
R W Run
1.99 KB
2026-03-11 16:18:52
R W Run
7.02 KB
2026-03-11 16:18:51
R W Run
4.91 KB
2026-03-11 16:18:52
R W Run
16.86 KB
2026-03-11 16:18:51
R W Run
24.23 KB
2026-03-11 16:18:51
R W Run
3.97 KB
2026-03-11 16:18:51
R W Run
47.66 KB
2026-03-11 16:18:51
R W Run
9.22 KB
2026-03-11 16:18:51
R W Run
25.51 KB
2026-03-11 16:18:51
R W Run
198.38 KB
2026-03-11 16:18:52
R W Run
56.65 KB
2026-03-11 16:18:51
R W Run
10.46 KB
2026-03-11 16:18:51
R W Run
10.95 KB
2026-03-11 16:18:52
R W Run
29.26 KB
2026-03-11 16:18:51
R W Run
70.91 KB
2026-03-11 16:18:52
R W Run
35.3 KB
2026-03-11 16:18:52
R W Run
16.61 KB
2026-03-11 16:18:52
R W Run
2.57 KB
2026-03-11 16:18:52
R W Run
39.83 KB
2026-03-11 16:18:51
R W Run
70.64 KB
2026-03-11 16:18:51
R W Run
15.56 KB
2026-03-11 16:18:52
R W Run
7.33 KB
2026-03-11 16:18:52
R W Run
253 By
2026-03-11 16:18:51
R W Run
7.96 KB
2026-03-11 16:18:52
R W Run
3.23 KB
2026-03-11 16:18:52
R W Run
969 By
2026-03-11 16:18:52
R W Run
16.28 KB
2026-03-11 16:18:51
R W Run
7.22 KB
2026-03-11 16:18:51
R W Run
12.95 KB
2026-03-11 16:18:51
R W Run
6.53 KB
2026-03-11 16:18:51
R W Run
3.42 KB
2026-03-11 16:18:52
R W Run
5.84 KB
2026-03-11 16:18:51
R W Run
1.97 KB
2026-03-11 16:18:51
R W Run
4.3 KB
2026-03-11 16:18:52
R W Run
2.91 KB
2026-03-11 16:18:51
R W Run
16.46 KB
2026-03-11 16:18:52
R W Run
40.6 KB
2026-03-11 16:18:51
R W Run
20.22 KB
2026-03-11 16:18:51
R W Run
36.11 KB
2026-03-11 16:18:52
R W Run
17.01 KB
2026-03-11 16:18:51
R W Run
7.27 KB
2026-03-11 16:18:52
R W Run
6.62 KB
2026-03-11 16:18:52
R W Run
16.49 KB
2026-03-11 16:18:52
R W Run
1.79 KB
2026-03-11 16:18:52
R W Run
29.82 KB
2026-03-11 16:18:51
R W Run
6.67 KB
2026-03-11 16:18:52
R W Run
8.98 KB
2026-03-11 16:18:52
R W Run
19.42 KB
2026-03-11 16:18:51
R W Run
12.01 KB
2026-03-11 16:18:51
R W Run
17.11 KB
2026-03-11 16:18:51
R W Run
6.74 KB
2026-03-11 16:18:52
R W Run
30.93 KB
2026-03-11 16:18:51
R W Run
4.99 KB
2026-03-11 16:18:51
R W Run
4.25 KB
2026-03-11 16:18:51
R W Run
24.72 KB
2026-03-11 16:18:51
R W Run
29.96 KB
2026-03-11 16:18:52
R W Run
6.41 KB
2026-03-11 16:18:51
R W Run
160 KB
2026-03-11 16:18:51
R W Run
6.72 KB
2026-03-11 16:18:52
R W Run
10.92 KB
2026-03-11 16:18:51
R W Run
4.77 KB
2026-03-11 16:18:51
R W Run
3.38 KB
2026-03-11 16:18:51
R W Run
11.18 KB
2026-03-11 16:18:51
R W Run
62.19 KB
2026-03-11 16:18:51
R W Run
2.46 KB
2026-03-11 16:18:51
R W Run
9.17 KB
2026-03-11 16:18:51
R W Run
32.15 KB
2026-03-11 16:18:51
R W Run
34.05 KB
2026-03-11 16:18:52
R W Run
7.15 KB
2026-03-11 16:18:51
R W Run
3.47 KB
2026-03-11 16:18:52
R W Run
1.87 KB
2026-03-11 16:18:52
R W Run
30.91 KB
2026-03-11 16:18:51
R W Run
7.29 KB
2026-03-11 16:18:52
R W Run
7.35 KB
2026-03-11 16:18:51
R W Run
12.54 KB
2026-03-11 16:18:51
R W Run
19.12 KB
2026-03-11 16:18:51
R W Run
18.12 KB
2026-03-11 16:18:52
R W Run
39.99 KB
2026-03-11 16:18:52
R W Run
5.17 KB
2026-03-11 16:18:52
R W Run
979 By
2026-03-11 16:18:51
R W Run
18.44 KB
2026-03-11 16:18:52
R W Run
10.24 KB
2026-03-11 16:18:51
R W Run
1.77 KB
2026-03-11 16:18:52
R W Run
34.9 KB
2026-03-11 16:18:51
R W Run
7.19 KB
2026-03-11 16:18:52
R W Run
160.5 KB
2026-03-11 16:18:51
R W Run
64.27 KB
2026-03-11 16:18:51
R W Run
27.95 KB
2026-03-11 16:18:51
R W Run
4.69 KB
2026-03-11 16:18:51
R W Run
2.94 KB
2026-03-11 16:18:51
R W Run
43.13 KB
2026-03-11 16:18:52
R W Run
2.25 KB
2026-03-11 16:18:52
R W Run
22.5 KB
2026-03-11 16:18:51
R W Run
13.01 KB
2026-03-11 16:18:52
R W Run
3.27 KB
2026-03-11 16:18:51
R W Run
18 KB
2026-03-11 16:18:51
R W Run
210.4 KB
2026-03-11 16:18:52
R W Run
25.86 KB
2026-03-11 16:18:52
R W Run
115.85 KB
2026-03-11 16:18:51
R W Run
373 By
2026-03-11 16:18:52
R W Run
343 By
2026-03-11 16:18:52
R W Run
338 By
2026-03-11 16:18:51
R W Run
100.73 KB
2026-03-11 16:18:52
R W Run
130.93 KB
2026-03-11 16:18:51
R W Run
19.1 KB
2026-03-11 16:18:51
R W Run
17.41 KB
2026-03-11 16:18:52
R W Run
41.98 KB
2026-03-11 16:18:52
R W Run
400 By
2026-03-11 16:18:52
R W Run
11.1 KB
2026-03-11 16:18:52
R W Run
37.02 KB
2026-03-11 16:18:51
R W Run
2.24 KB
2026-03-11 16:18:51
R W Run
188.13 KB
2026-03-11 16:18:51
R W Run
338 By
2026-03-11 16:18:51
R W Run
38 KB
2026-03-11 16:18:51
R W Run
4.02 KB
2026-03-11 16:18:52
R W Run
5.38 KB
2026-03-11 16:18:51
R W Run
3.05 KB
2026-03-11 16:18:52
R W Run
2.61 KB
2026-03-11 16:18:51
R W Run
1.16 KB
2026-03-11 16:18:52
R W Run
4.04 KB
2026-03-11 16:18:51
R W Run
3.71 KB
2026-03-11 16:18:51
R W Run
24.6 KB
2026-03-11 16:18:51
R W Run
9.56 KB
2026-03-11 16:18:51
R W Run
346.43 KB
2026-03-11 16:18:52
R W Run
281.84 KB
2026-03-11 16:18:52
R W Run
14.95 KB
2026-03-11 16:18:51
R W Run
8.44 KB
2026-03-11 16:18:52
R W Run
168.95 KB
2026-03-11 16:18:52
R W Run
20.71 KB
2026-03-11 16:18:52
R W Run
25.27 KB
2026-03-11 16:18:51
R W Run
5.72 KB
2026-03-11 16:18:51
R W Run
4.63 KB
2026-03-11 16:18:52
R W Run
81.73 KB
2026-03-11 16:18:51
R W Run
67.18 KB
2026-03-11 16:18:51
R W Run
156.36 KB
2026-03-11 16:18:52
R W Run
55.19 KB
2026-03-11 16:18:51
R W Run
162 By
2026-03-11 16:18:51
R W Run
61.72 KB
2026-03-11 16:18:51
R W Run
216.06 KB
2026-03-11 16:18:52
R W Run
65.09 KB
2026-03-11 16:18:51
R W Run
25.24 KB
2026-03-11 16:18:52
R W Run
4.81 KB
2026-03-11 16:18:51
R W Run
6.48 KB
2026-03-11 16:18:52
R W Run
21.25 KB
2026-03-11 16:18:51
R W Run
2.79 KB
2026-03-11 16:18:52
R W Run
89.69 KB
2026-03-11 16:18:52
R W Run
19.42 KB
2026-03-11 16:18:52
R W Run
3.69 KB
2026-03-11 16:18:52
R W Run
4.11 KB
2026-03-11 16:18:51
R W Run
40.74 KB
2026-03-11 16:18:51
R W Run
25.38 KB
2026-03-11 16:18:51
R W Run
43.31 KB
2026-03-11 16:18:52
R W Run
102.57 KB
2026-03-11 16:18:52
R W Run
6.18 KB
2026-03-11 16:18:51
R W Run
124.47 KB
2026-03-11 16:18:52
R W Run
35.65 KB
2026-03-11 16:18:52
R W Run
6.94 KB
2026-03-11 16:18:52
R W Run
67.04 KB
2026-03-11 16:18:52
R W Run
10.62 KB
2026-03-11 16:18:51
R W Run
289.35 KB
2026-03-11 16:18:52
R W Run
36.23 KB
2026-03-11 16:18:51
R W Run
200 By
2026-03-11 16:18:52
R W Run
200 By
2026-03-11 16:18:52
R W Run
98.29 KB
2026-03-11 16:18:52
R W Run
30.02 KB
2026-03-11 16:18:52
R W Run
19.03 KB
2026-03-11 16:18:52
R W Run
5.06 KB
2026-03-11 16:18:52
R W Run
255 By
2026-03-11 16:18:51
R W Run
22.66 KB
2026-03-11 16:18:52
R W Run
154.63 KB
2026-03-11 16:18:51
R W Run
9.68 KB
2026-03-11 16:18:51
R W Run
258 By
2026-03-11 16:18:51
R W Run
23.49 KB
2026-03-11 16:18:51
R W Run
3.16 KB
2026-03-11 16:18:51
R W Run
8.4 KB
2026-03-11 16:18:52
R W Run
441 By
2026-03-11 16:18:51
R W Run
7.39 KB
2026-03-11 16:18:51
R W Run
173 KB
2026-03-11 16:18:52
R W Run
544 By
2026-03-11 16:18:52
R W Run
4.17 KB
2026-03-11 16:18:51
R W Run
35.97 KB
2026-03-11 16:18:52
R W Run
1.69 KB
2026-03-11 16:18:51
R W Run
2.84 KB
2026-03-11 16:18:52
R W Run
6.09 KB
2026-03-11 16:18:51
R W Run
8.71 KB
2026-03-11 16:18:51
R W Run
131.84 KB
2026-03-11 16:18:51
R W Run
37.45 KB
2026-03-11 16:18:51
R W Run
173.89 KB
2026-03-11 16:18:51
R W Run
7.09 KB
2026-03-11 16:18:51
R W Run
6.41 KB
2026-03-11 16:18:51
R W Run
1.08 KB
2026-03-11 16:18:51
R W Run
69.46 KB
2026-03-11 16:18:52
R W Run
445 By
2026-03-11 16:18:51
R W Run
799 By
2026-03-11 16:18:52
R W Run
error_log
📄class-wp-network.php
1<?php
2/**
3 * Network API: WP_Network class
4 *
5 * @package WordPress
6 * @subpackage Multisite
7 * @since 4.4.0
8 */
9
10/**
11 * Core class used for interacting with a multisite network.
12 *
13 * This class is used during load to populate the `$current_site` global and
14 * setup the current network.
15 *
16 * This class is most useful in WordPress multi-network installations where the
17 * ability to interact with any network of sites is required.
18 *
19 * @since 4.4.0
20 *
21 * @property int $id
22 * @property int $site_id
23 */
24#[AllowDynamicProperties]
25class WP_Network {
26
27 /**
28 * Network ID.
29 *
30 * @since 4.4.0
31 * @since 4.6.0 Converted from public to private to explicitly enable more intuitive
32 * access via magic methods. As part of the access change, the type was
33 * also changed from `string` to `int`.
34 * @var int
35 */
36 private $id;
37
38 /**
39 * Domain of the network.
40 *
41 * @since 4.4.0
42 * @var string
43 */
44 public $domain = '';
45
46 /**
47 * Path of the network.
48 *
49 * @since 4.4.0
50 * @var string
51 */
52 public $path = '';
53
54 /**
55 * The ID of the network's main site.
56 *
57 * Named "blog" vs. "site" for legacy reasons. A main site is mapped to
58 * the network when the network is created.
59 *
60 * A numeric string, for compatibility reasons.
61 *
62 * @since 4.4.0
63 * @var string
64 */
65 private $blog_id = '0';
66
67 /**
68 * Domain used to set cookies for this network.
69 *
70 * @since 4.4.0
71 * @var string
72 */
73 public $cookie_domain = '';
74
75 /**
76 * Name of this network.
77 *
78 * Named "site" vs. "network" for legacy reasons.
79 *
80 * @since 4.4.0
81 * @var string
82 */
83 public $site_name = '';
84
85 /**
86 * Retrieves a network from the database by its ID.
87 *
88 * @since 4.4.0
89 *
90 * @global wpdb $wpdb WordPress database abstraction object.
91 *
92 * @param int $network_id The ID of the network to retrieve.
93 * @return WP_Network|false The network's object if found. False if not.
94 */
95 public static function get_instance( $network_id ) {
96 global $wpdb;
97
98 $network_id = (int) $network_id;
99 if ( ! $network_id ) {
100 return false;
101 }
102
103 $_network = wp_cache_get( $network_id, 'networks' );
104
105 if ( false === $_network ) {
106 $_network = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->site} WHERE id = %d LIMIT 1", $network_id ) );
107
108 if ( empty( $_network ) || is_wp_error( $_network ) ) {
109 $_network = -1;
110 }
111
112 wp_cache_add( $network_id, $_network, 'networks' );
113 }
114
115 if ( is_numeric( $_network ) ) {
116 return false;
117 }
118
119 return new WP_Network( $_network );
120 }
121
122 /**
123 * Creates a new WP_Network object.
124 *
125 * Will populate object properties from the object provided and assign other
126 * default properties based on that information.
127 *
128 * @since 4.4.0
129 *
130 * @param WP_Network|object $network A network object.
131 */
132 public function __construct( $network ) {
133 foreach ( get_object_vars( $network ) as $key => $value ) {
134 $this->__set( $key, $value );
135 }
136
137 $this->_set_site_name();
138 $this->_set_cookie_domain();
139 }
140
141 /**
142 * Getter.
143 *
144 * Allows current multisite naming conventions when getting properties.
145 *
146 * @since 4.6.0
147 *
148 * @param string $key Property to get.
149 * @return mixed Value of the property. Null if not available.
150 */
151 public function __get( $key ) {
152 switch ( $key ) {
153 case 'id':
154 return (int) $this->id;
155 case 'blog_id':
156 return (string) $this->get_main_site_id();
157 case 'site_id':
158 return $this->get_main_site_id();
159 }
160
161 return null;
162 }
163
164 /**
165 * Isset-er.
166 *
167 * Allows current multisite naming conventions when checking for properties.
168 *
169 * @since 4.6.0
170 *
171 * @param string $key Property to check if set.
172 * @return bool Whether the property is set.
173 */
174 public function __isset( $key ) {
175 switch ( $key ) {
176 case 'id':
177 case 'blog_id':
178 case 'site_id':
179 return true;
180 }
181
182 return false;
183 }
184
185 /**
186 * Setter.
187 *
188 * Allows current multisite naming conventions while setting properties.
189 *
190 * @since 4.6.0
191 *
192 * @param string $key Property to set.
193 * @param mixed $value Value to assign to the property.
194 */
195 public function __set( $key, $value ) {
196 switch ( $key ) {
197 case 'id':
198 $this->id = (int) $value;
199 break;
200 case 'blog_id':
201 case 'site_id':
202 $this->blog_id = (string) $value;
203 break;
204 default:
205 $this->$key = $value;
206 }
207 }
208
209 /**
210 * Returns the main site ID for the network.
211 *
212 * Internal method used by the magic getter for the 'blog_id' and 'site_id'
213 * properties.
214 *
215 * @since 4.9.0
216 *
217 * @return int The ID of the main site.
218 */
219 private function get_main_site_id() {
220 /**
221 * Filters the main site ID.
222 *
223 * Returning a positive integer will effectively short-circuit the function.
224 *
225 * @since 4.9.0
226 *
227 * @param int|null $main_site_id If a positive integer is returned, it is interpreted as the main site ID.
228 * @param WP_Network $network The network object for which the main site was detected.
229 */
230 $main_site_id = (int) apply_filters( 'pre_get_main_site_id', null, $this );
231
232 if ( 0 < $main_site_id ) {
233 return $main_site_id;
234 }
235
236 if ( 0 < (int) $this->blog_id ) {
237 return (int) $this->blog_id;
238 }
239
240 if ( ( defined( 'DOMAIN_CURRENT_SITE' ) && defined( 'PATH_CURRENT_SITE' )
241 && DOMAIN_CURRENT_SITE === $this->domain && PATH_CURRENT_SITE === $this->path )
242 || ( defined( 'SITE_ID_CURRENT_SITE' ) && (int) SITE_ID_CURRENT_SITE === $this->id )
243 ) {
244 if ( defined( 'BLOG_ID_CURRENT_SITE' ) ) {
245 $this->blog_id = (string) BLOG_ID_CURRENT_SITE;
246
247 return (int) $this->blog_id;
248 }
249
250 if ( defined( 'BLOGID_CURRENT_SITE' ) ) { // Deprecated.
251 $this->blog_id = (string) BLOGID_CURRENT_SITE;
252
253 return (int) $this->blog_id;
254 }
255 }
256
257 $site = get_site();
258 if ( $site->domain === $this->domain && $site->path === $this->path ) {
259 $main_site_id = (int) $site->id;
260 } else {
261
262 $main_site_id = get_network_option( $this->id, 'main_site' );
263 if ( false === $main_site_id ) {
264 $_sites = get_sites(
265 array(
266 'fields' => 'ids',
267 'number' => 1,
268 'domain' => $this->domain,
269 'path' => $this->path,
270 'network_id' => $this->id,
271 )
272 );
273 $main_site_id = ! empty( $_sites ) ? array_shift( $_sites ) : 0;
274
275 update_network_option( $this->id, 'main_site', $main_site_id );
276 }
277 }
278
279 $this->blog_id = (string) $main_site_id;
280
281 return (int) $this->blog_id;
282 }
283
284 /**
285 * Sets the site name assigned to the network if one has not been populated.
286 *
287 * @since 4.4.0
288 */
289 private function _set_site_name() {
290 if ( ! empty( $this->site_name ) ) {
291 return;
292 }
293
294 $default = ucfirst( $this->domain );
295 $this->site_name = get_network_option( $this->id, 'site_name', $default );
296 }
297
298 /**
299 * Sets the cookie domain based on the network domain if one has
300 * not been populated.
301 *
302 * @todo What if the domain of the network doesn't match the current site?
303 *
304 * @since 4.4.0
305 */
306 private function _set_cookie_domain() {
307 if ( ! empty( $this->cookie_domain ) ) {
308 return;
309 }
310 $domain = parse_url( $this->domain, PHP_URL_HOST );
311 $this->cookie_domain = is_string( $domain ) ? $domain : $this->domain;
312 if ( str_starts_with( $this->cookie_domain, 'www.' ) ) {
313 $this->cookie_domain = substr( $this->cookie_domain, 4 );
314 }
315 }
316
317 /**
318 * Retrieves the closest matching network for a domain and path.
319 *
320 * This will not necessarily return an exact match for a domain and path. Instead, it
321 * breaks the domain and path into pieces that are then used to match the closest
322 * possibility from a query.
323 *
324 * The intent of this method is to match a network during bootstrap for a
325 * requested site address.
326 *
327 * @since 4.4.0
328 *
329 * @param string $domain Domain to check.
330 * @param string $path Path to check.
331 * @param int|null $segments Path segments to use. Defaults to null, or the full path.
332 * @return WP_Network|false Network object if successful. False when no network is found.
333 */
334 public static function get_by_path( $domain = '', $path = '', $segments = null ) {
335 $domains = array( $domain );
336 $pieces = explode( '.', $domain );
337
338 /*
339 * It's possible one domain to search is 'com', but it might as well
340 * be 'localhost' or some other locally mapped domain.
341 */
342 while ( array_shift( $pieces ) ) {
343 if ( ! empty( $pieces ) ) {
344 $domains[] = implode( '.', $pieces );
345 }
346 }
347
348 /*
349 * If we've gotten to this function during normal execution, there is
350 * more than one network installed. At this point, who knows how many
351 * we have. Attempt to optimize for the situation where networks are
352 * only domains, thus meaning paths never need to be considered.
353 *
354 * This is a very basic optimization; anything further could have
355 * drawbacks depending on the setup, so this is best done per-installation.
356 */
357 $using_paths = true;
358 if ( wp_using_ext_object_cache() ) {
359 $using_paths = get_networks(
360 array(
361 'number' => 1,
362 'count' => true,
363 'path__not_in' => '/',
364 )
365 );
366 }
367
368 $paths = array();
369 if ( $using_paths ) {
370 $path_segments = array_filter( explode( '/', trim( $path, '/' ) ) );
371
372 /**
373 * Filters the number of path segments to consider when searching for a site.
374 *
375 * @since 3.9.0
376 *
377 * @param int|null $segments The number of path segments to consider. WordPress by default looks at
378 * one path segment. The function default of null only makes sense when you
379 * know the requested path should match a network.
380 * @param string $domain The requested domain.
381 * @param string $path The requested path, in full.
382 */
383 $segments = apply_filters( 'network_by_path_segments_count', $segments, $domain, $path );
384
385 if ( ( null !== $segments ) && count( $path_segments ) > $segments ) {
386 $path_segments = array_slice( $path_segments, 0, $segments );
387 }
388
389 while ( count( $path_segments ) ) {
390 $paths[] = '/' . implode( '/', $path_segments ) . '/';
391 array_pop( $path_segments );
392 }
393
394 $paths[] = '/';
395 }
396
397 /**
398 * Determines a network by its domain and path.
399 *
400 * This allows one to short-circuit the default logic, perhaps by
401 * replacing it with a routine that is more optimal for your setup.
402 *
403 * Return null to avoid the short-circuit. Return false if no network
404 * can be found at the requested domain and path. Otherwise, return
405 * an object from wp_get_network().
406 *
407 * @since 3.9.0
408 *
409 * @param null|false|WP_Network $network Network value to return by path. Default null
410 * to continue retrieving the network.
411 * @param string $domain The requested domain.
412 * @param string $path The requested path, in full.
413 * @param int|null $segments The suggested number of paths to consult.
414 * Default null, meaning the entire path was to be consulted.
415 * @param string[] $paths Array of paths to search for, based on `$path` and `$segments`.
416 */
417 $pre = apply_filters( 'pre_get_network_by_path', null, $domain, $path, $segments, $paths );
418 if ( null !== $pre ) {
419 return $pre;
420 }
421
422 if ( ! $using_paths ) {
423 $networks = get_networks(
424 array(
425 'number' => 1,
426 'orderby' => array(
427 'domain_length' => 'DESC',
428 ),
429 'domain__in' => $domains,
430 )
431 );
432
433 if ( ! empty( $networks ) ) {
434 return array_shift( $networks );
435 }
436
437 return false;
438 }
439
440 $networks = get_networks(
441 array(
442 'orderby' => array(
443 'domain_length' => 'DESC',
444 'path_length' => 'DESC',
445 ),
446 'domain__in' => $domains,
447 'path__in' => $paths,
448 )
449 );
450
451 /*
452 * Domains are sorted by length of domain, then by length of path.
453 * The domain must match for the path to be considered. Otherwise,
454 * a network with the path of / will suffice.
455 */
456 $found = false;
457 foreach ( $networks as $network ) {
458 if ( ( $network->domain === $domain ) || ( "www.{$network->domain}" === $domain ) ) {
459 if ( in_array( $network->path, $paths, true ) ) {
460 $found = true;
461 break;
462 }
463 }
464 if ( '/' === $network->path ) {
465 $found = true;
466 break;
467 }
468 }
469
470 if ( true === $found ) {
471 return $network;
472 }
473
474 return false;
475 }
476}
477
Ui Ux Design – Teachers Night Out

Get in Touch

© 2024 Teachers Night Out. All Rights Reserved.