From c49c89a41af1c4a9bd79255fcb968414f2c8b5e7 Mon Sep 17 00:00:00 2001 From: David Binovec Date: Wed, 19 Apr 2017 12:06:35 +0000 Subject: [PATCH 1/2] Add attachment_url_to_postid to restricted functions - wpcom_vip_attachment_url_to_postid should be used instead Fixes #67 --- .../Sniffs/VIP/RestrictedFunctionsSniff.php | 7 +++++++ .../Tests/VIP/RestrictedFunctionsUnitTest.inc | 6 +++++- .../Tests/VIP/RestrictedFunctionsUnitTest.php | 1 + ruleset_test.inc | 4 +++- ruleset_test.php | 1 + 5 files changed, 17 insertions(+), 2 deletions(-) diff --git a/WordPressVIPMinimum/Sniffs/VIP/RestrictedFunctionsSniff.php b/WordPressVIPMinimum/Sniffs/VIP/RestrictedFunctionsSniff.php index 173a0162..2248fab3 100644 --- a/WordPressVIPMinimum/Sniffs/VIP/RestrictedFunctionsSniff.php +++ b/WordPressVIPMinimum/Sniffs/VIP/RestrictedFunctionsSniff.php @@ -46,6 +46,13 @@ public function getGroups() { 'flush_rewrite_rules', ), ), + 'attachment_url_to_postid' => array( + 'type' => 'error', + 'message' => '%s() is prohibited, please use wpcom_vip_attachment_url_to_postid() instead.', + 'functions' => array( + 'attachment_url_to_postid' + ) + ), ); return array_merge( $original_groups, $new_groups ); diff --git a/WordPressVIPMinimum/Tests/VIP/RestrictedFunctionsUnitTest.inc b/WordPressVIPMinimum/Tests/VIP/RestrictedFunctionsUnitTest.inc index d7311b23..97a23f2f 100644 --- a/WordPressVIPMinimum/Tests/VIP/RestrictedFunctionsUnitTest.inc +++ b/WordPressVIPMinimum/Tests/VIP/RestrictedFunctionsUnitTest.inc @@ -8,4 +8,8 @@ wp_cache_get_multi(); // Bad. get_super_admins(); // Bad. -flush_rewrite_rules(); // Bad. \ No newline at end of file +flush_rewrite_rules(); // Bad. + +attachment_url_to_postid(); // Bad. + +wpcom_vip_attachment_url_to_postid(); // OK. \ No newline at end of file diff --git a/WordPressVIPMinimum/Tests/VIP/RestrictedFunctionsUnitTest.php b/WordPressVIPMinimum/Tests/VIP/RestrictedFunctionsUnitTest.php index e68c8522..58742809 100644 --- a/WordPressVIPMinimum/Tests/VIP/RestrictedFunctionsUnitTest.php +++ b/WordPressVIPMinimum/Tests/VIP/RestrictedFunctionsUnitTest.php @@ -23,6 +23,7 @@ public function getErrorList() { 7 => 1, 9 => 1, 11 => 1, + 13 => 1, ); } diff --git a/ruleset_test.inc b/ruleset_test.inc index 14821a02..f3c693c7 100644 --- a/ruleset_test.inc +++ b/ruleset_test.inc @@ -126,4 +126,6 @@ eval(); // Bad. Error. // WordPressVIPMinimum.VIP.RestrictedFunctions wpcom_vip_irc(); // Bad. Error. -get_children(); // Bad. Warning. Message. \ No newline at end of file +get_children(); // Bad. Warning. Message. + +attachment_url_to_postid(); // Bad. Error. \ No newline at end of file diff --git a/ruleset_test.php b/ruleset_test.php index dd362f32..3b251dbb 100644 --- a/ruleset_test.php +++ b/ruleset_test.php @@ -43,6 +43,7 @@ 124 => 1, 127 => 1, 129 => 1, + 131 => 1, ), 'warnings' => array( 9 => 1, From bf05e53e4dcb708b17a2984483bb6598a2f3f91d Mon Sep 17 00:00:00 2001 From: David Binovec Date: Wed, 19 Apr 2017 13:05:59 +0000 Subject: [PATCH 2/2] Addressing PHPCS issues --- WordPressVIPMinimum/Sniffs/VIP/RestrictedFunctionsSniff.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WordPressVIPMinimum/Sniffs/VIP/RestrictedFunctionsSniff.php b/WordPressVIPMinimum/Sniffs/VIP/RestrictedFunctionsSniff.php index 2248fab3..0e118687 100644 --- a/WordPressVIPMinimum/Sniffs/VIP/RestrictedFunctionsSniff.php +++ b/WordPressVIPMinimum/Sniffs/VIP/RestrictedFunctionsSniff.php @@ -50,8 +50,8 @@ public function getGroups() { 'type' => 'error', 'message' => '%s() is prohibited, please use wpcom_vip_attachment_url_to_postid() instead.', 'functions' => array( - 'attachment_url_to_postid' - ) + 'attachment_url_to_postid', + ), ), );