Skip to content

Commit

Permalink
Add ability to whitelist specific functions to the `AbstractFunctionR…
Browse files Browse the repository at this point in the history
…estrictions` class.

This is only useful when used in combination with blocking a function group using a wildcard in the function name.

However, it does make it more forward compatible. This allows to still block a complete (PHP) extension , even for new functions being added to the extension, while whitelisting - for instance - a WP native function which was named a bit unfortunately.
  • Loading branch information
jrfnl authored and grappler committed Sep 25, 2016
1 parent d56dd27 commit 87a3919
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions WordPress/AbstractFunctionRestrictionsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) {
continue;
}

if ( isset( $group['whitelist'][ $token['content'] ] ) ) {
continue;
}

if ( preg_match( $group['regex'], $token['content'] ) < 1 ) {
continue;
}
Expand Down
3 changes: 3 additions & 0 deletions WordPress/Sniffs/DB/RestrictedFunctionsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ public function getGroups() {
'mysqlnd_memcache_*',
'maxdb_*',
),
'whitelist' => array(
'mysql_to_rfc3339' => true,
),
),

);
Expand Down
14 changes: 14 additions & 0 deletions WordPress/Tests/DB/RestrictedFunctionsUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,17 @@ maxdb_num_fields();
maxdb_prepare();
maxdb_real_query
maxdb_stat();


/**
* And these shouldn't give an error.
*/

// WP Native function which was named a bit unfortunately.
mysql_to_rfc3339(); // Ok.

// Other WP Native functions which shouldn't give a problem anyway.
mysql2date(); // Ok.
wp_check_mysql_version(); // Ok.
wp_check_php_mysql_version(); // Ok.
WP_Date_Query::build_mysql_datetime(); // Ok.

0 comments on commit 87a3919

Please sign in to comment.