• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
WordPress a2z

WordPress a2z

WordPress Dynamic API Reference

  • Home
  • Plugins
  • Themes
  • Shortcodes
  • APIs
  • Classes
  • Files
  • Hooks
  • Sitemap
  • Blog
Home / APIs / Twenty_Twenty_One_SVG_Icons::get_social_link_svg() – Detects the social network from a URL and returns the SVG code for its icon.

You appear to be a bot. Output may be restricted

Description

Detects the social network from a URL and returns the SVG code for its icon.

Usage

$string|null = Twenty_Twenty_One_SVG_Icons::get_social_link_svg( $uri, $size );

Parameters

$uri
( string ) required – Social link.
$size
( int ) required – The icon-size in pixels.

Returns

string|null

Source

File name: twentytwentyone/classes/class-twenty-twenty-one-svg-icons.php
Lines:

1 to 42 of 42
  public static function get_social_link_svg( $uri, $size ) {
    static $regex_map; // Only compute regex map once, for performance.

    if ( ! isset( $regex_map ) ) {
      $regex_map = array();

      
/**
 * Filters Twenty Twenty-Ones'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-One 1.0
 *
 * @param array $social_icons_map Array of default social icons.
 */
      $map = apply_filters( 'twenty_twenty_one_social_icons_map', self::$social_icons_map );

      
/**
 * Filters Twenty Twenty-One's array of social icons.
 *
 * @since Twenty Twenty-One 1.0
 *
 * @param array $social_icons Array of default social icons.
 */
      $social_icons = apply_filters( 'twenty_twenty_one_svg_icons_social', self::$social_icons );

      foreach ( array_keys( $social_icons ) as $icon ) {
        $domains            = array_key_exists( $icon, $map ) ? $map[ $icon ] : array( sprintf( '%s.com', $icon ) );
        $domains            = array_map( 'trim', $domains ); // Remove leading/trailing spaces, to prevent regex from failing to match.
        $domains            = array_map( 'preg_quote', $domains );
        $regex_map[ $icon ] = sprintf( '/(%s)/i', implode( '|', $domains ) );
      }
    }
    foreach ( $regex_map as $icon => $regex ) {
      if ( preg_match( $regex, $uri ) ) {

        return self::get_svg( 'social', $icon, $size ) . '<span class="screen-reader-text">';
      }
    }
    return null;
  }
 

 View on GitHub View on Trac

Published: 9th December 2020 | Last updated: 23rd February 2021

Primary Sidebar

Information

Function name: Twenty_Twenty_One_SVG_Icons::get_social_link_svg
Class ref: Twenty_Twenty_One_SVG_Icons
Plugin ref: Twenty Twenty-One
Version: 1.7
Sourcefile: classes/class-twenty-twenty-one-svg-icons.php
File ref: classes/class-twenty-twenty-one-svg-icons.php
Deprecated?: No
API Letters: I,O,S,T

Footer

WordPress a2z
WordPress a2z
WordPress Dynamic API Reference
WordPress 6.1.1. PHP: 8.0.28
WordPress a2z
WordPress core a2z
Genesis Theme Framework a2z
Jetpack a2z
WordPress develop tests
Easy Digital Downloads a2z
WooCommerce a2z
Yoast SEO a2z
WordPress Blocks

Site:  wp-a2z.org
© Copyright WordPress a2z 2014-2023. All rights reserved.


Website designed and developed by Herb Miller
Proudly powered by WordPress and oik plugins

  • Home
  • Blog
  • Sitemap
  • Sites