parse(); $blocks = $cssDocument->getAllDeclarationBlocks(); foreach($blocks as $block) { /** @var Sabberworm\CSS\RuleSet\DeclarationBlock $block */ //We want the ".dashicons-*:before" selectors. $selectors = $block->getSelectors(); foreach($selectors as $selector) { /** @var Sabberworm\CSS\Property\Selector $selector */ if ( preg_match('/\.dashicons-(?P[\w\-]+):before/', $selector->getSelector(), $matches) ) { $name = $matches['name']; $char = null; //The arrow icons aren't really suitable as menu icons. if ( preg_match('/^(arrow)-/', $name) ) { break; } //Some icons are duplicates of the "admin-" icons or just wouldn't look very good in a menu. if ( array_key_exists($name, $ignoreIcons) ) { break; } $rules = $block->getRules('content'); //Expect something like "content: '\f123'". foreach($rules as $rule) { /** @var Sabberworm\CSS\Rule\Rule $rule */ $value = $rule->getValue(); if ($value instanceof Sabberworm\CSS\Value\CSSString) { //The parser defaults to UTF-8. Convert the char to a hexadecimal escape code //so we don't have to worry about our CSS charset. $char = ltrim(bin2hex(iconv('UTF-8', 'UCS-4', $value->getString())), '0'); $icons[$name] = '\\' . $char; } } if (isset($char) && ($name !== 'before')) { $allDashiconDefinitions .= sprintf( '%s { content: "\%s" !important; }', implode(', ', $selectors), $char ) . "\n"; } break; } } } $dashiconComment = sprintf( "/*\nThis file was automatically generated from /wp-includes/css/dashicons.css.\nLast update: %s\n*/", date('c') ); file_put_contents( dirname(__FILE__) . '/../css/_dashicons.scss', $dashiconComment . "\n" . $allDashiconDefinitions ); ?>

Dashicons to Menu Icons

$character) { //Output each icon for visual verification. printf( '
%1$s
', $name ); //Wrap the array definition at about 80 characters for legibility. $item = "'" . $name . "', "; if ( strlen($currentLine . $item) > 80 ) { $arrayDefinition .= $currentLine . "\n"; $currentLine = "\t"; } $currentLine .= $item; } if (strlen($currentLine) > 1) { $arrayDefinition .= $currentLine . "\n"; } $arrayDefinition .= ')'; echo '

'; echo ''; echo '
';