Skip to content

Instantly share code, notes, and snippets.

@ockham
Created December 10, 2014 21:22
Show Gist options
  • Save ockham/bffdf72507facf56c328 to your computer and use it in GitHub Desktop.
Save ockham/bffdf72507facf56c328 to your computer and use it in GitHub Desktop.
ForbiddenPHPFunctionsCheck.php
<?php
/**
* Checks for the usage of forbidden PHP functions.
*/
class ForbiddenPHPFunctionsCheck extends CodeCheck {
protected static $forbidden_php_functions = array(
'popen',
'proc_open',
'exec',
'shell_exec',
'system',
'passthru',
'base64_decode',
'base64_encode',
'uudecode',
'str_rot13',
'ini_set',
'create_function',
'extract',
);
function __construct() {
$checks = array(
'eval' => array(
'slug' => 'forbidden-php',
'level' => 'blocker',
'note' => sprintf( 'The PHP function %s was found. Themes cannot use this function.', '<code>eval()</code>' ),
'fn' => function( $node ) {
return ( $node instanceof PhpParser\Node\Expr\Eval_ );
}
)
);
foreach( self::$forbidden_php_functions as $function ) {
$checks[ $function ] = array(
'slug' => 'forbidden-php',
'level' => 'blocker',
'note' => sprintf( 'The PHP function %s was found. Themes cannot use this function.', '<code>' . $function. '()</code>' ),
'fn' => function( $node ) use( $function ) {
if ( $node instanceof PhpParser\Node\Expr\FuncCall ) {
return $node->name->toString() === $function;
}
return false;
}
);
}
$visitor = new FlexibleCheckVisitor( $checks );
parent::__construct( $visitor );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment