[wp-trac] [WordPress Trac] #49034: Twenty Twenty: Add filter for social icons regex map to facilitate adding new social icons

WordPress Trac noreply at wordpress.org
Thu Dec 19 04:00:02 UTC 2019


#49034: Twenty Twenty: Add filter for social icons regex map to facilitate adding
new social icons
---------------------------+-----------------------------
 Reporter:  msaari         |      Owner:  (none)
     Type:  enhancement    |     Status:  new
 Priority:  normal         |  Milestone:  Awaiting Review
Component:  Bundled Theme  |    Version:  5.3.1
 Severity:  minor          |   Keywords:  has-patch
  Focuses:                 |
---------------------------+-----------------------------
 Since adding new social icons is a heavy process, how about making it
 easier for developers to add their own social icons? It's already possible
 by overriding the whole `TwentyTwenty_SVG_Icons` class with your own, but
 that's a bit much for adding just an icon or two.

 On the other hand, overriding the `twentytwenty_get_theme_svg()` function
 with your own version that adds couple of more icons is easy. This works
 really well with UI icons, but less so with social icons. The social icons
 use regex mapping to automatically match social media service URLs to the
 correct icons.

 To facilitate adding new social media icons, I propose adding a new filter
 hook in the social link SVG code in the `get_social_link_svg()` function
 in `classes/class-twentytwenty-svg-icons.php`. Applying a filter to the
 `$regex_map` variable would allow developers to add new social link
 regexes to the list and thus add new social link icons easily.

 With the new filter, adding a new social icon is simple once you have your
 own version of `twentytwenty_get_theme_svg()` that provides the icon SVG.
 All you need then is this:

 {{{
 add_filter( 'social_icon_regex_map', 'add_telegram' );
 function add_telegram( $regex_map ) {
         $telegram_domains = array(
                 'telegram.org',
                 'telegram.me',
                 't.me',
         );
         array_map( 'preg_quote', $telegram_domains );
         $regex_map[ 'telegram' ] = sprintf( '/(%s)/i', implode( '|',
 $telegram_domains ) );

         return $regex_map;
 }
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/49034>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list