表題の件です。
$_SERVERへアクセスしようとしたらコード規約で怒られてしまいました。
15 | WARNING | Detected access of super global var $_SERVER, probably
| | needs manual inspection.
| | (WordPress.VIP.SuperGlobalInputUsage.AccessDetected)
恐らくこのあたりの記事だと思うのですがうまく対処がわかりません。

Create new page · WordPress/WordPress-Coding-Standards Wiki
PHP_CodeSniffer rules (sniffs) to enforce WordPress coding conventions - Create new page · WordPress/WordPress-Coding-St...

Fixing errors for input data
PHP_CodeSniffer rules (sniffs) to enforce WordPress coding conventions - WordPress/WordPress-Coding-Standards
Stackoverflowに対処の例が載っていました。
https://wordpress.stackexchange.com/questions/110540/is-it-safe-to-use-serverrequest-uri
$_SERVER[‘REQUEST_URI’] will not be empty in WordPress, because it is filled in wp_fix_server_vars() (file wp-includes/load.php).
This function is called in wp-settings.php before any plugin is loaded. So you can use it.
But always escape the value. It is global and can be changed by any other code, so you cannot trust its value.
A different case is accessing the value per
というわけでfilter_input()を使ったところうまく怒られなくなりました。
ちなみに中身はこんな感じです。






コメント