diff --git a/WordPress/Sniffs/WP/AlternativeFunctionsSniff.php b/WordPress/Sniffs/WP/AlternativeFunctionsSniff.php index e47aa3fbcf..dbca31c0a4 100644 --- a/WordPress/Sniffs/WP/AlternativeFunctionsSniff.php +++ b/WordPress/Sniffs/WP/AlternativeFunctionsSniff.php @@ -126,11 +126,37 @@ public function getGroups() { ), ), - 'file_system_read' => array( + 'unlink' => array( 'type' => 'warning', - 'message' => 'File operations should use WP_Filesystem methods instead of direct PHP filesystem calls. Found: %s()', + 'message' => '%s() is discouraged. Use wp_delete_file() to delete a file.', + 'since' => '4.2.0', + 'functions' => array( + 'unlink', + ), + ), + + 'rename' => array( + 'type' => 'warning', + 'message' => '%s() is discouraged. Use WP_Filesystem::move() to rename a file.', + 'since' => '2.5.0', + 'functions' => array( + 'rename', + ), + ), + + 'file_system_operations' => array( + 'type' => 'warning', + 'message' => 'File operations should use WP_Filesystem methods instead of direct PHP filesystem calls. Found: %s().', 'since' => '2.5.0', 'functions' => array( + 'chgrp', + 'chmod', + 'chown', + 'is_writable', + 'is_writeable', + 'mkdir', + 'rmdir', + 'touch', 'readfile', 'fclose', 'fopen', @@ -139,6 +165,7 @@ public function getGroups() { 'file_put_contents', 'fsockopen', 'pfsockopen', + 'fputs', ), ), diff --git a/WordPress/Tests/WP/AlternativeFunctionsUnitTest.inc b/WordPress/Tests/WP/AlternativeFunctionsUnitTest.inc index 6723050a83..ea9baea449 100644 --- a/WordPress/Tests/WP/AlternativeFunctionsUnitTest.inc +++ b/WordPress/Tests/WP/AlternativeFunctionsUnitTest.inc @@ -78,3 +78,15 @@ function curl_version_ssl() {} // OK. use function curl_version; // OK. use function something as curl_version; // OK. use function curl_init as curl_version; // Bad. + +unlink(); // Warning. +rename(); // Warning. +chgrp(); // Warning. +chmod(); // Warning. +chown(); // Warning. +is_writable(); // Warning. +is_writeable(); // Warning. +mkdir(); // Warning. +rmdir(); // Warning. +touch(); // Warning. +fputs(); // Warning. diff --git a/WordPress/Tests/WP/AlternativeFunctionsUnitTest.php b/WordPress/Tests/WP/AlternativeFunctionsUnitTest.php index ca95672572..44db0131b2 100644 --- a/WordPress/Tests/WP/AlternativeFunctionsUnitTest.php +++ b/WordPress/Tests/WP/AlternativeFunctionsUnitTest.php @@ -65,6 +65,17 @@ public function getWarningList() { 68 => 1, 73 => 1, 80 => 1, + 82 => 1, + 83 => 1, + 84 => 1, + 85 => 1, + 86 => 1, + 87 => 1, + 88 => 1, + 89 => 1, + 90 => 1, + 91 => 1, + 92 => 1, ); }