Skip to content

Commit 0ea8b1a

Browse files
authored
Merge pull request #652 from Automattic/fix/614-remove-user-meta-related-errors
RestrictedFunctions/RestrictedVariables: remove usermeta related errors
2 parents 1af6b37 + fda4656 commit 0ea8b1a

File tree

10 files changed

+27
-63
lines changed

10 files changed

+27
-63
lines changed

WordPress-VIP-Go/ruleset-test.inc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -284,20 +284,20 @@ if ( isset( $_GET['migSource'] ) && wp_verify_nonce( sanitize_text_field( $_GET[
284284
$test = sanitize_text_field( $_GET['migSource'] ); // Ok.
285285
}
286286

287-
// WordPressVIPMinimum.Functions.RestrictedFunctions.user_meta_add_user_meta
288-
add_user_meta( 123, $foo, $bar ); // Ok.
289287

290-
// WordPressVIPMinimum.Functions.RestrictedFunctions.user_meta_delete_user_meta
291-
delete_user_meta( $foo, $bar, '123' ); // Ok.
292288

293-
// WordPressVIPMinimum.Functions.RestrictedFunctions.user_meta_get_user_meta
294-
get_user_meta(); // Ok.
295289

296-
// WordPressVIPMinimum.Functions.RestrictedFunctions.user_meta_update_user_meta
297-
update_user_meta( $bar, '123', $foo ); // Ok.
298290

299-
// WordPressVIPMinimum.Variables.RestrictedVariables.user_meta__wpdb__usermeta
300-
$query = "SELECT * FROM $wpdb->usermeta"; // Ok.
291+
292+
293+
294+
295+
296+
297+
298+
299+
300+
301301

302302
// WordPressVIPMinimum.Functions.RestrictedFunctions.site_option_delete_site_option
303303
delete_site_option( $foo ); // Ok.

WordPress-VIP-Go/ruleset.xml

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -261,21 +261,6 @@
261261
<!-- We are silencing this one because VIP Go does not use Batcache-->
262262
<severity>0</severity>
263263
</rule>
264-
<rule ref="WordPressVIPMinimum.Functions.RestrictedFunctions.user_meta_add_user_meta">
265-
<severity>0</severity>
266-
</rule>
267-
<rule ref="WordPressVIPMinimum.Functions.RestrictedFunctions.user_meta_delete_user_meta">
268-
<severity>0</severity>
269-
</rule>
270-
<rule ref="WordPressVIPMinimum.Functions.RestrictedFunctions.user_meta_get_user_meta">
271-
<severity>0</severity>
272-
</rule>
273-
<rule ref="WordPressVIPMinimum.Functions.RestrictedFunctions.user_meta_update_user_meta">
274-
<severity>0</severity>
275-
</rule>
276-
<rule ref="WordPressVIPMinimum.Variables.RestrictedVariables.user_meta__wpdb__usermeta">
277-
<severity>0</severity>
278-
</rule>
279264
<rule ref="Generic.PHP.DisallowShortOpenTag.EchoFound">
280265
<severity>0</severity>
281266
</rule>

WordPressVIPMinimum/Sniffs/Functions/RestrictedFunctionsSniff.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,16 +111,6 @@ public function getGroups() {
111111
'add_role',
112112
],
113113
],
114-
'user_meta' => [
115-
'type' => 'error',
116-
'message' => '%s() usage is highly discouraged on WordPress.com VIP due to it being a multisite, please see https://lobby.vip.wordpress.com/wordpress-com-documentation/code-review-what-we-look-for/#wp_users-and-user_meta.',
117-
'functions' => [
118-
'get_user_meta',
119-
'update_user_meta',
120-
'delete_user_meta',
121-
'add_user_meta',
122-
],
123-
],
124114
'term_exists' => [
125115
'type' => 'error',
126116
'message' => '%s() is highly discouraged due to not being cached; please use wpcom_vip_term_exists() instead.',

WordPressVIPMinimum/Sniffs/Variables/RestrictedVariablesSniff.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,9 @@ public function getGroups() {
3939
return [
4040
'user_meta' => [
4141
'type' => 'error',
42-
'message' => 'Usage of users/usermeta tables is highly discouraged in VIP context, For storing user additional user metadata, you should look at User Attributes.',
42+
'message' => 'Usage of users tables is highly discouraged in VIP context',
4343
'object_vars' => [
4444
'$wpdb->users',
45-
'$wpdb->usermeta',
4645
],
4746
],
4847
'session' => [

WordPressVIPMinimum/Tests/Functions/RestrictedFunctionsUnitTest.inc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,14 @@ $y = Bar::add_role(); // Ok - calling static function of another class and not a
7575
add_role( 'test' ); // Error.
7676
\add_role(); // Error.
7777

78-
get_post_meta( 123, 'test' ); // Ok - not using get_user_meta().
79-
update_post_meta( 1234, 'test', $test ); // Ok - not using update_user_meta().
80-
delete_post_meta( $int, $test ); // Ok - not using delete_user_meta().
81-
add_post_meta( $int, $test, $test ); // Ok - not using add_user_meta().
82-
get_user_meta(); // Error.
83-
update_user_meta(); // Error.
84-
delete_user_meta(); // Error.
85-
add_user_meta(); // Error.
78+
79+
80+
81+
82+
83+
84+
85+
8686

8787
wpcom_vip_term_exists(); // Ok - VIP recommended version of term_exists().
8888
term_exists(); // Error.

WordPressVIPMinimum/Tests/Functions/RestrictedFunctionsUnitTest.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@ public function getErrorList() {
4343
62 => 1,
4444
75 => 1,
4545
76 => 1,
46-
82 => 1,
47-
83 => 1,
48-
84 => 1,
49-
85 => 1,
5046
88 => 1,
5147
91 => 1,
5248
94 => 1,

WordPressVIPMinimum/Tests/Variables/RestrictedVariablesUnitTest.inc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ $query = "SELECT * FROM $wpdb->users"; // Error.
44

55
$wp_db->update( $wpdb->users, array( 'displayname' => 'Kanobe!' ), array( 'ID' => 1 ) ); // Error.
66

7-
$query = "SELECT * FROM $wpdb->usermeta"; // Error.
87

9-
$wp_db->update( $wpdb->usermeta, array( 'meta_value' => 'bar!' ), array( 'user_id' => 1, 'meta_key' => 'foo' ) ); // Error.
8+
9+
1010

1111
$query = "SELECT * FROM $wpdb->posts"; // Ok.
1212

@@ -20,7 +20,7 @@ $y = $_SERVER['REQUEST_URI']; // Ok.
2020

2121
// Error.
2222
$query = <<<EOD
23-
SELECT * FROM $wpdb->usermeta
23+
SELECT * FROM $wpdb->users
2424
EOD;
2525

2626
// Warning
@@ -29,7 +29,7 @@ Your user-agent is {$_SERVER['HTTP_USER_AGENT']}
2929
EOD;
3030

3131
// phpcs:set WordPressVIPMinimum.Variables.RestrictedVariables exclude[] user_meta
32-
$query = "SELECT * FROM $wpdb->usermeta"; // Ok, excluded.
32+
$query = "SELECT * FROM $wpdb->users"; // Ok, excluded.
3333

3434
// phpcs:set WordPressVIPMinimum.Functions.RestrictedFunctions exclude[]
3535

WordPressVIPMinimum/Tests/Variables/RestrictedVariablesUnitTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ public function getErrorList() {
3030
return [
3131
3 => 1,
3232
5 => 1,
33-
7 => 1,
34-
9 => 1,
3533
23 => 1,
3634
36 => 1,
3735
37 => 1,

WordPressVIPMinimum/ruleset-test.inc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,10 +325,10 @@ switch_to_blog( $blogid ); // Error.
325325
get_page_by_title( $page_title ); // Error.
326326
url_to_postid( $url ); // Error.
327327
\add_role(); // Error.
328-
get_user_meta(); // Error.
329-
update_user_meta(); // Error.
330-
delete_user_meta(); // Error.
331-
add_user_meta(); // Error.
328+
329+
330+
331+
332332
term_exists(); // Error.
333333
count_user_posts(); // Error.
334334
wp_old_slug_redirect(); // Error.

WordPressVIPMinimum/ruleset-test.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,6 @@
9797
325 => 1,
9898
326 => 1,
9999
327 => 1,
100-
328 => 1,
101-
329 => 1,
102-
330 => 1,
103-
331 => 1,
104100
332 => 1,
105101
333 => 1,
106102
334 => 1,

0 commit comments

Comments
 (0)