From 15a1cd96a9a7ccb398c00df25f5c928e6dbce039 Mon Sep 17 00:00:00 2001 From: Rebecca Hum <16962021+rebeccahum@users.noreply.github.com> Date: Thu, 30 Jan 2020 17:17:54 -0700 Subject: [PATCH] RestrictedFunctions: Add stats_get_csv() along with unit tests --- WordPressVIPMinimum/Sniffs/Files/IncludingFileSniff.php | 1 - .../Sniffs/Functions/RestrictedFunctionsSniff.php | 7 +++++++ .../Tests/Functions/RestrictedFunctionsUnitTest.inc | 3 +++ .../Tests/Functions/RestrictedFunctionsUnitTest.php | 1 + 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/WordPressVIPMinimum/Sniffs/Files/IncludingFileSniff.php b/WordPressVIPMinimum/Sniffs/Files/IncludingFileSniff.php index c99aa535..2b6efd09 100644 --- a/WordPressVIPMinimum/Sniffs/Files/IncludingFileSniff.php +++ b/WordPressVIPMinimum/Sniffs/Files/IncludingFileSniff.php @@ -31,7 +31,6 @@ class IncludingFileSniff extends AbstractFunctionRestrictionsSniff { 'get_stylesheet_directory', 'get_template_directory', 'locate_template', - 'get_parent_theme_file_path' ]; /** diff --git a/WordPressVIPMinimum/Sniffs/Functions/RestrictedFunctionsSniff.php b/WordPressVIPMinimum/Sniffs/Functions/RestrictedFunctionsSniff.php index eb34c058..3edb5672 100644 --- a/WordPressVIPMinimum/Sniffs/Functions/RestrictedFunctionsSniff.php +++ b/WordPressVIPMinimum/Sniffs/Functions/RestrictedFunctionsSniff.php @@ -268,6 +268,13 @@ public function getGroups() { 'delete_site_option', ], ], + 'stats_get_csv' => [ + 'type' => 'error', + 'message' => 'Using `%s` outside of Jetpack context pollutes the stats_cache entry in the wp_options table. We recommend building a custom function instead.', + 'functions' => [ + 'stats_get_csv', + ] + ], 'wp_mail' => [ 'type' => 'warning', 'message' => '`%s` should be used sparingly. For any bulk emailing should be handled by a 3rd party service, in order to prevent domain or IP addresses being flagged as spam.', diff --git a/WordPressVIPMinimum/Tests/Functions/RestrictedFunctionsUnitTest.inc b/WordPressVIPMinimum/Tests/Functions/RestrictedFunctionsUnitTest.inc index d26ac8b4..9b778b40 100644 --- a/WordPressVIPMinimum/Tests/Functions/RestrictedFunctionsUnitTest.inc +++ b/WordPressVIPMinimum/Tests/Functions/RestrictedFunctionsUnitTest.inc @@ -224,3 +224,6 @@ delete_option( $bar ); // Ok. wpcom_vip_get_page_by_path(); // Ok - VIP recommended version of get_page_by_path(). get_page_by_path( $page_path ); // Warning. + +$popular = stats_get_csv( 'postviews', [ 'days' => 2, 'limit' => 20 ] ); // Error. +$popular = custom_stats_get_csv( 'postviews', [ 'days' => 2, 'limit' => 20 ] ); // Ok. \ No newline at end of file diff --git a/WordPressVIPMinimum/Tests/Functions/RestrictedFunctionsUnitTest.php b/WordPressVIPMinimum/Tests/Functions/RestrictedFunctionsUnitTest.php index 598ff307..147c7cfa 100644 --- a/WordPressVIPMinimum/Tests/Functions/RestrictedFunctionsUnitTest.php +++ b/WordPressVIPMinimum/Tests/Functions/RestrictedFunctionsUnitTest.php @@ -109,6 +109,7 @@ public function getErrorList() { 218 => 1, 220 => 1, 222 => 1, + 228 => 1, ]; }