Skip to content

Commit 0c9df2a

Browse files
authored
Merge pull request #649 from Automattic/switch_to_blog_messaging
RestrictedFunctionsSniff: Change default message of switch_to_blog()
2 parents 0ea8b1a + 8b2ae7d commit 0c9df2a

File tree

7 files changed

+6
-11
lines changed

7 files changed

+6
-11
lines changed

WordPress-VIP-Go/ruleset-test.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,9 +331,6 @@
331331
196 => [
332332
'Stylesheets should be registered/enqueued via `wp_enqueue_style`. This can improve the site\'s performance due to styles concatenation.',
333333
],
334-
269 => [
335-
'Switch to blog may not work as expected since it only changes the database context for the blog and does not load the plugins or theme of that site. This means that filters or hooks that the blog you are switching to uses will not run.',
336-
],
337334
],
338335
];
339336

WordPress-VIP-Go/ruleset.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,7 @@
241241
<severity>1</severity>
242242
</rule>
243243
<rule ref="WordPressVIPMinimum.Functions.RestrictedFunctions.switch_to_blog_switch_to_blog">
244-
<type>warning</type>
245244
<severity>3</severity>
246-
<message>Switch to blog may not work as expected since it only changes the database context for the blog and does not load the plugins or theme of that site. This means that filters or hooks that the blog you are switching to uses will not run.</message>
247245
</rule>
248246
<rule ref="WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn">
249247
<severity>3</severity>

WordPressVIPMinimum/Sniffs/Functions/RestrictedFunctionsSniff.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ public function getGroups() {
8383
],
8484
// @link https://docs.wpvip.com/technical-references/code-review/vip-notices/#h-switch_to_blog
8585
'switch_to_blog' => [
86-
'type' => 'error',
87-
'message' => '%s() is not something you should ever need to do in a VIP theme context. Instead use an API (XML-RPC, REST) to interact with other sites if needed.',
86+
'type' => 'warning',
87+
'message' => '%s() may not work as expected since it only changes the database context for the blog and does not load the plugins or theme of that site. Filters or hooks on the blog you are switching to will not run.',
8888
'functions' => [
8989
'switch_to_blog',
9090
],

WordPressVIPMinimum/Tests/Functions/RestrictedFunctionsUnitTest.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ db_delta(); // Ok - similarly-named function to dbDelta().
5353
dbDelta(); // Error.
5454

5555
switch_blog(); // Ok - similarly-named function to switch_to_blog().
56-
switch_to_blog( $blogid ); // Error.
56+
switch_to_blog( $blogid ); // Warning.
5757

5858
wpcom_vip_get_page_by_title(); // Ok - VIP recommended version of get_page_by_title().
5959
get_page_by_title( $page_title ); // Error.

WordPressVIPMinimum/Tests/Functions/RestrictedFunctionsUnitTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ public function getErrorList() {
3838
46 => 1,
3939
50 => 1,
4040
53 => 1,
41-
56 => 1,
4241
59 => 1,
4342
62 => 1,
4443
75 => 1,
@@ -114,6 +113,7 @@ public function getErrorList() {
114113
*/
115114
public function getWarningList() {
116115
return [
116+
56 => 1,
117117
110 => 1,
118118
111 => 1,
119119
114 => 1,

WordPressVIPMinimum/ruleset-test.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ flush_rewrite_rules(); // Error.
321321
$wp_rewrite->flush_rules(); // Error.
322322
attachment_url_to_postid( $url ); // Error.
323323
dbDelta(); // Error.
324-
switch_to_blog( $blogid ); // Error.
324+
switch_to_blog( $blogid ); // Warning.
325325
get_page_by_title( $page_title ); // Error.
326326
url_to_postid( $url ); // Error.
327327
\add_role(); // Error.

WordPressVIPMinimum/ruleset-test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@
9393
321 => 1,
9494
322 => 1,
9595
323 => 1,
96-
324 => 1,
9796
325 => 1,
9897
326 => 1,
9998
327 => 1,
@@ -255,6 +254,7 @@
255254
288 => 1,
256255
293 => 1,
257256
294 => 1,
257+
324 => 1,
258258
396 => 1,
259259
397 => 1,
260260
398 => 1,

0 commit comments

Comments
 (0)