function __construct()
 {
     parent::__construct(array('PhpParser\\Node\\Expr\\ConstFetch' => function ($node) {
         $name = $node->name->toString();
         if (array_key_exists($name, self::$deprecated_constants)) {
             $this->add_error('deprecated', sprintf('The constant %1$s is deprecated. Use %2$s instead.', '<code>' . esc_html($name) . '</code>', '<code>' . esc_html(self::$deprecated_constants[$name]) . '</code>'), BaseScanner::LEVEL_BLOCKER);
         }
     }));
 }
Ejemplo n.º 2
0
 function __construct()
 {
     parent::__construct(array('PhpParser\\Node\\Expr\\ConstFetch' => function ($node) {
         $name = $node->name->toString();
         if (in_array($name, self::$forbidden_constants)) {
             $this->add_error('forbidden', sprintf('Themes cannot use the constant %s.', '<code>' . $name . '</code>'), BaseScanner::LEVEL_BLOCKER);
         }
     }));
 }
Ejemplo n.º 3
0
 function __construct()
 {
     parent::__construct(array('PhpParser\\Node\\Expr\\FuncCall' => function ($node) {
         if (!$node->name instanceof PhpParser\Node\Name) {
             return;
         }
         $name = $node->name->toString();
         if (in_array($name, self::$forbidden_functions)) {
             $this->add_error('forbidden-function', sprintf('The function %s was found in the theme. Themes cannot use this function, please remove it.', '<code>' . $name . '</code>'), BaseScanner::LEVEL_BLOCKER);
         }
     }));
 }
 function __construct()
 {
     parent::__construct(array('PhpParser\\Node\\Expr\\New_' => function ($node) {
         if (!$node->class instanceof PhpParser\Node\Name) {
             return;
         }
         $class_name = $node->class->toString();
         if (in_array($class_name, array_keys(self::$forbidden_class_names))) {
             $error = self::$forbidden_class_names[$class_name];
             $this->add_error($class_name, $error['note'], $error['level']);
         }
     }));
 }
 function __construct()
 {
     parent::__construct(array('PhpParser\\Node\\Expr\\Eval_' => function ($node) {
         $this->add_error('forbidden-php', sprintf('The PHP function %s was found. Themes cannot use this function.', '<code>eval()</code>'), 'blocker');
     }, 'PhpParser\\Node\\Expr\\FuncCall' => function ($node) {
         if (!$node->name instanceof PhpParser\Node\Name) {
             return;
         }
         $name = $node->name->toString();
         if (in_array($name, self::$forbidden_php_functions)) {
             $this->add_error('forbidden-php', sprintf('The PHP function %s was found. Themes cannot use this function.', '<code>' . $name . '()</code>'), 'blocker');
         }
     }));
 }
 function __construct()
 {
     parent::__construct(array('PhpParser\\Node\\Expr\\Eval_' => function ($node) {
         $this->add_error('eval', 'Meta programming', 'Blocker');
     }, 'PhpParser\\Node\\Expr\\FuncCall' => function ($node) {
         if (!$node->name instanceof PhpParser\Node\Name) {
             return;
         }
         $name = $node->name->toString();
         if (in_array($name, array_keys(self::$functions))) {
             $error = self::$functions[$name];
             $this->add_error($name, $error['note'], $error['level']);
         }
     }));
 }
Ejemplo n.º 7
0
 function __construct()
 {
     parent::__construct(array('PhpParser\\Node\\Expr\\New_' => function ($node) {
         if (!$node->class instanceof PhpParser\Node\Name) {
             return;
         }
         $class_name = $node->class->toString();
         if ('WP_Customize_Image_Control' === $class_name) {
             $this->add_error('customizer', 'The theme uses the <code>WP_Customize_Image_Control</code> class. Custom logo options should be implemented using the <a href="http://en.support.wordpress.com/site-logo/">Site Logo</a> feature.', BaseScanner::LEVEL_WARNING);
         }
     }, 'PhpParser\\Node\\Stmt\\Class_' => function ($node) {
         if (isset($node->extends) && 'WP_Customize_Control' === $node->extends->toString()) {
             $this->add_error('customizer', 'The theme creates a new Customizer control by extending <code>WP_Customize_Control</code>.', BaseScanner::LEVEL_WARNING);
         }
     }, 'PhpParser\\Node\\Expr\\MethodCall' => function ($node) {
         if ('wp_customize' !== $node->var->name || 'add_setting' !== $node->name || count($node->args) < 2) {
             return;
         }
         // Get the second argument passed to the add_setting method
         $args = $node->args[1]->value;
         $found_sanitize_callback = false;
         if (!$args instanceof PhpParser\Node\Expr\Array_) {
             return;
         }
         foreach ($args->items as $arg) {
             if (!$arg->key instanceof PhpParser\Node\Scalar\String) {
                 continue;
             }
             $key = $arg->key->value;
             // Check if we have sanitize_callback or sanitize_js_callback
             if ('sanitize_callback' !== $key && 'sanitize_js_callback' !== $key) {
                 continue;
             }
             $found_sanitize_callback = true;
             // There's a callback, check that no empty parameter is passed.
             if (!$arg->value instanceof PhpParser\Node\Scalar\String) {
                 continue;
             }
             $value = trim($arg->value->value);
             if (empty($value)) {
                 $this->add_error('customizer', 'Found a Customizer setting that had an empty value passed as sanitization callback. You need to pass a function name as sanitization callback.', BaseScanner::LEVEL_BLOCKER);
             }
         }
         if (!$found_sanitize_callback) {
             $this->add_error('customizer', 'Found a Customizer setting that did not have a sanitization callback function. Every call to the <code>add_setting()</code> method needs to have a sanitization callback function passed.', BaseScanner::LEVEL_BLOCKER);
         }
     }));
 }
 function __construct()
 {
     parent::__construct(array('PhpParser\\Node\\Expr\\FuncCall' => function ($node) {
         if (!$node->name instanceof PhpParser\Node\Name) {
             return;
         }
         $name = $node->name->toString();
         if (array_key_exists($name, self::$deprecated_functions)) {
             $message = sprintf(self::$description_template, '<code>' . $name . '</code>');
             if (!empty(self::$deprecated_functions[$name])) {
                 $message .= sprintf(self::$replacement_template, '<code>' . self::$deprecated_functions[$name] . '</code>');
             }
             $this->add_error('deprecated', $message, BaseScanner::LEVEL_BLOCKER);
         }
     }));
 }
 function __construct()
 {
     parent::__construct(array('PhpParser\\Node\\Expr\\FuncCall' => function ($node) {
         if (!$node->name instanceof PhpParser\Node\Name) {
             return;
         }
         $name = $node->name->toString();
         if (!array_key_exists($name, self::$parameters) || empty($node->args)) {
             return;
         }
         $pars = self::$parameters[$name];
         $value = $node->args[0]->value;
         if ($value instanceof PhpParser\Node\Scalar\String && array_key_exists($value->value, $pars)) {
             $message = 'The deprecated function parameter %1$s was found. Use %2$s instead.';
             $this->add_error('deprecated', sprintf($message, '<code>' . esc_html($name . "( '" . $value->value . "' )") . '</code>', '<code>' . esc_html($pars[$value->value]) . '</code>'), BaseScanner::LEVEL_BLOCKER);
         }
     }));
 }
Ejemplo n.º 10
0
 function __construct()
 {
     parent::__construct(array('PhpParser\\Node\\Expr\\FuncCall' => function ($node) {
         if (!$node->name instanceof PhpParser\Node\Name) {
             return;
         }
         $name = $node->name->toString();
         if (!array_key_exists($name, self::$parameters)) {
             return;
         }
         $pars = self::$parameters[$name];
         foreach ($node->args as $idx => $arg) {
             $value = $arg->value;
             if (!$value instanceof PhpParser\Node\Scalar\String || !array_key_exists($value->value, $pars)) {
                 continue;
             }
             $parameter_data = $pars[$value->value];
             if (isset($parameter_data['position']) && $idx === $parameter_data['position']) {
                 $this->add_error('vip-parameters-' . $value->value, esc_html($parameter_data['note']), $parameter_data['level']);
             }
         }
     }));
 }