wppaste
WordPress

TwentyTwenty_SVG_Icons

Since
Twenty Twenty 1.0
Source
wp-content/themes/twentytwenty/classes/class-twentytwenty-svg-icons.php:17
SVG ICONS CLASS Retrieves the SVG code for the specified icon. Based on a solution in Twenty Nineteen.

Compatibility

WordPress
since Twenty Twenty 1.0
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0).

Hooks and filters fired · 4

Every hook that fires from inside TwentyTwenty_SVG_Icons, in the order it appears in the class, grouped by the method that fires it.

Properties · 3

$ui_iconsarraypublic static
ICON STORAGE Stores the code for all SVGs in an array.
$social_icons_maparraypublic static
Social Icons – domain mappings.
$social_iconsarraypublic static
Social Icons – svg sources.

Methods · 2

  • get_svg()GET SVG CODE Gets the SVG code for the specified icon.
  • get_social_link_svg()GET SOCIAL LINK SVG Detects the social network from a URL and returns the SVG code for its icon.

Source code

	class TwentyTwenty_SVG_Icons {		/**		 * GET SVG CODE		 * Gets the SVG code for the specified icon.		 *		 * @since Twenty Twenty 1.0		 *		 * @param string $icon  Icon name.		 * @param string $group Icon group.		 * @param string $color Color.		 */		public static function get_svg( $icon, $group = 'ui', $color = '#1A1A1B' ) {			if ( 'ui' === $group ) {				$arr = self::$ui_icons;			} elseif ( 'social' === $group ) {				$arr = self::$social_icons;			} else {				$arr = array();			} 			/**			 * Filters Twenty Twenty's array of icons.			 *			 * The dynamic portion of the hook name, `$group`, refers to			 * the name of the group of icons, either "ui" or "social".			 *			 * @since Twenty Twenty 1.5			 *			 * @param array $arr Array of icons.			 */			$arr = apply_filters( "twentytwenty_svg_icons_{$group}", $arr ); 			/**			 * Filters an SVG icon's color.			 *			 * @since Twenty Twenty 1.5			 *			 * @param string $color The icon color.			 * @param string $icon  The icon name.			 * @param string $group The icon group.			 */			$color = apply_filters( 'twentytwenty_svg_icon_color', $color, $icon, $group ); 			if ( array_key_exists( $icon, $arr ) ) {				$repl = '<svg class="svg-icon" aria-hidden="true" role="img" focusable="false" ';				$svg  = preg_replace( '/^<svg /', $repl, trim( $arr[ $icon ] ) ); // Add extra attributes to SVG code.				$svg  = str_replace( '#1A1A1B', $color, $svg );   // Replace the color.				$svg  = str_replace( '#', '%23', $svg );          // Urlencode hashes.				$svg  = preg_replace( "/([\n\t]+)/", ' ', $svg ); // Remove newlines & tabs.				$svg  = preg_replace( '/>\s*</', '><', $svg );    // Remove whitespace between SVG tags.				return $svg;			}			return null;		} 		/**		 * GET SOCIAL LINK SVG		 * Detects the social network from a URL and returns the SVG code for its icon.		 *		 * @since Twenty Twenty 1.0		 *		 * @param string $uri The URL to retrieve SVG for.		 */		public static function get_social_link_svg( $uri ) {			static $regex_map; // Only compute regex map once, for performance.			if ( ! isset( $regex_map ) ) {				$regex_map = array(); 				/**				 * Filters Twenty Twenty's array of domain mappings for social icons.				 *				 * By default, each Icon ID is matched against a .com TLD. To override this behavior,				 * specify all the domains it covers (including the .com TLD too, if applicable).				 *				 * @since Twenty Twenty 1.5				 *				 * @param array $social_icons_map Array of default social icons.				 */				$map = apply_filters( 'twentytwenty_social_icons_map', self::$social_icons_map );

Changelog

Introduced in Twenty Twenty 1.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-content/themes/twentytwenty/classes/class-twentytwenty-svg-icons.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.