Inner markup of outline icons (viewBox 0 0 24 24). */ private const OUTLINE = array( 'upload-cloud' => '', 'bars' => '', 'chevron-down' => '', 'chevron-right' => '', 'plus' => '', 'plus-circle' => '', 'x' => '', 'file' => '', 'link' => '', 'server' => '', 'cloud' => '', 'box' => '', 'external-link' => '', 'upload' => '', 'download' => '', 'restore' => '', 'trash' => '', 'check-circle' => '', 'info' => '', 'shield' => '', 'hard-drive' => '', 'mail' => '', 'loader' => '', 'send' => '', // Two arrows chasing each other round a circle: transfer / sync / restore. Drawn on the // same 24 grid as the rest, so it stays crisp at the 20 px the admin menu uses. 'sync' => '', 'check' => '', 'copy' => '', 'clock' => '', 'layers' => '', 'plug' => '', 'palette' => '', 'image' => '', 'power' => '', 'alert' => '', 'database' => '', ); /** @var array Filled brand glyphs (viewBox 0 0 24 24). */ private const BRAND = array( 'whatsapp' => '', ); /** * Markup for one icon. Decorative by default (hidden from screen readers); pass a * label for an icon that carries meaning on its own. * * @param string $name Key from the tables above. * @param string $class Extra CSS classes. * @param string $label Accessible name; empty for decorative icons. */ public static function get( string $name, string $class = '', string $label = '' ): string { $brand = isset( self::BRAND[ $name ] ); $inner = $brand ? self::BRAND[ $name ] : ( self::OUTLINE[ $name ] ?? '' ); if ( '' === $inner ) { return ''; } $paint = $brand ? 'fill="currentColor"' : 'fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"'; $a11y = '' === $label ? 'aria-hidden="true" focusable="false"' : 'role="img" aria-label="' . esc_attr( $label ) . '"'; return sprintf( '%s', '' === $class ? '' : ' ' . esc_attr( $class ), $paint, $a11y, $inner ); } /** * Prints an icon. Kept separate from get() so templates read as a plain echo and the * escaping decision lives in one place. */ public static function render( string $name, string $class = '', string $label = '' ): void { echo self::get( $name, $class, $label ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- static markup from this class; the only variables are escaped above. } /** The icon's resting colour in the admin menu: the plugin's brand Royal Blue. */ public const MENU_COLOR = '#2563eb'; /** Its colour on the brand-coloured active or hover background. */ public const MENU_COLOR_ACTIVE = '#ffffff'; /** * A standalone SVG with its colour fixed, as a URL-encoded data URI for use in CSS. * * Deliberately not base64. WordPress repaints every base64 SVG menu icon in the admin * colour scheme's grey (wp-admin/js/svg-painter.js), which is exactly what makes a plugin * icon look dull. An icon supplied as plain URL-encoded text is left alone, so its colour * is the one chosen here. * * @param string $name Outline icon name. * @param string $color Any CSS colour that is safe inside an SVG attribute. * @param string $width Stroke width on the 24 grid. */ public static function dataUri( string $name, string $color, string $width = '2.2' ): string { if ( ! isset( self::OUTLINE[ $name ] ) || 1 !== preg_match( '/^#[0-9a-f]{3,8}$/i', $color ) ) { return ''; } $svg = sprintf( '%s', $color, (float) $width, self::OUTLINE[ $name ] ); return 'data:image/svg+xml,' . rawurlencode( $svg ); } /** * The admin-menu icon at rest: the sync loop in Royal Blue. */ public static function menuIcon(): string { return self::dataUri( 'sync', self::MENU_COLOR ); } /** * The same icon in white, for the active and hover states, where the menu item has a * brand-coloured background and a blue icon would disappear into it. */ public static function menuIconActive(): string { return self::dataUri( 'sync', self::MENU_COLOR_ACTIVE ); } }