@@ -157,7 +157,6 @@ public function url($args)
157
157
{
158
158
$ data = array (
159
159
Router::ACTION => Core::ACTION_QS_PURGE ,
160
- Router::VALIDATE_PURGE => Router::get_hash (Router::VALIDATE_PURGE ),
161
160
);
162
161
$ url = $ args [0 ];
163
162
$ deconstructed = wp_parse_url ($ url );
@@ -167,9 +166,30 @@ public function url($args)
167
166
}
168
167
169
168
if (is_multisite ()) {
170
- $ data ['switch_blog ' ] = get_current_blog_id ();
171
-
172
- if (get_blog_id_from_url ($ deconstructed ['host ' ], '/ ' ) === 0 ) {
169
+ $ current_blog = get_current_blog_id ();
170
+ $ path = '/ ' ;
171
+ // If subfolder install test if we can identify the blog from url.
172
+ // If subdomain install: $path needs to remain '/'.
173
+ if (!SUBDOMAIN_INSTALL ){
174
+ // Get subfolder blog link. Try to match to a blog id.
175
+ $ temp_path = explode ('/ ' , $ deconstructed ['path ' ]);
176
+ if (!empty ($ temp_path [1 ])){
177
+ $ path = '/ ' .$ temp_path [1 ].'/ ' ; // need / at beginning and end.
178
+ }
179
+ }
180
+
181
+ // Attempt to get blog id from URL.
182
+ $ url_blog = get_blog_id_from_url ($ deconstructed ['host ' ], $ path );
183
+ if ($ url_blog && $ url_blog !== $ current_blog ){
184
+ // If blog found will switch to it.
185
+ switch_to_blog ($ url_blog );
186
+ }
187
+ else {
188
+ $ path = '/ ' ;
189
+ }
190
+
191
+ // Test if link can be found.
192
+ if (get_blog_id_from_url ($ deconstructed ['host ' ], $ path ) === 0 ) {
173
193
WP_CLI ::error ('Multisite url passed in is invalid. ' );
174
194
return ;
175
195
}
@@ -180,6 +200,8 @@ public function url($args)
180
200
return ;
181
201
}
182
202
}
203
+ // Create security hash.
204
+ $ data [Router::VALIDATE_PURGE ] = Router::get_hash (Router::VALIDATE_PURGE );
183
205
184
206
WP_CLI ::debug ('url is ' . $ url );
185
207
0 commit comments