[ 'icon', 'shortcut icon', 'bookmark icon', 'apple-touch-icon', 'apple-touch-icon-precomposed', ], 'name' => [ 'msapplication-config', 'msapplication-TileImage', 'msapplication-square70x70logo', 'msapplication-square150x150logo', 'msapplication-wide310x150logo', 'msapplication-square310x310logo', ], ]; /** * The regex to catch the blacklisted attributes. * * @var string */ protected $favicon_regex; /** * Returns an array of tokens this test wants to listen for. * * @return array */ public function register() { // Build the regex to be used only once. $regex_parts = []; foreach ( $this->attribute_blacklist as $key => $values ) { $values = array_map( 'preg_quote', $values, array_fill( 0, count( $values ), '`' ) ); $values = implode( '|', $values ); $regex_parts[] = sprintf( self::REGEX_ATTR_TEMPLATE, preg_quote( $key, '`' ), $values ); } $this->favicon_regex = sprintf( self::REGEX_TEMPLATE, implode( '|', $regex_parts ) ); return Tokens::$textStringTokens; } /** * Processes this test, when one of its tokens is encountered. * * @param \PHP_CodeSniffer\Files\File $phpcsFile The PHP_CodeSniffer file where the * token was found. * @param int $stackPtr The position of the current token * in the stack. * * @return void */ public function process( File $phpcsFile, $stackPtr ) { $tokens = $phpcsFile->getTokens(); $token = $tokens[ $stackPtr ]; if ( preg_match( $this->favicon_regex, $token['content'] ) > 0 ) { $phpcsFile->addError( 'Code for favicon found. Favicons are handled by the "Site Icon" setting in the customizer since WP version 4.3.', $stackPtr, 'NoFavicon' ); } } }