Make WordPress Core

Changeset 48180


Ignore:
Timestamp:
06/26/2020 02:40:27 PM (6 years ago)
Author:
ianbelanger
Message:

Bundled Themes: Twenty Twenty Social Icons Filter.

Adds a Social Icons Filter to Twenty Twenty that allows for new icons to be added to the theme by filter.

Props JarretC, nielslange, acosmin, desrosj.
Fixes #48713.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-content/themes/twentytwenty/classes/class-twentytwenty-svg-icons.php

    r47796 r48180  
    3030                                $arr = array();
    3131                        }
     32
     33                        /**
     34                         * Filters Twenty Twenty's array of icons.
     35                         *
     36                         * The dynamic portion of the hook name, `$group`, refers to
     37                         * the name of the group of icons, either "ui" or "social".
     38                         *
     39                         * @since 1.5.0
     40                         *
     41                         * @param array $arr Array of icons.
     42                         */
     43                        $arr = apply_filters( "twentytwenty_svg_icons_{$group}", $arr );
     44
     45                        /**
     46                         * Filters an SVG icon's color.
     47                         *
     48                         * @since 1.5.0
     49                         *
     50                         * @param array $color The icon color.
     51                         * @param array $icon  The icon name.
     52                         * @param array $group The icon group.
     53                         */
     54                        $color = apply_filters( 'twentytwenty_svg_icon_color', $color, $icon, $group );
     55
    3256                        if ( array_key_exists( $icon, $arr ) ) {
    3357                                $repl = '<svg class="svg-icon" aria-hidden="true" role="img" focusable="false" ';
     
    5276                        if ( ! isset( $regex_map ) ) {
    5377                                $regex_map = array();
    54                                 $map       = &self::$social_icons_map; // Use reference instead of copy, to save memory.
    55                                 foreach ( array_keys( self::$social_icons ) as $icon ) {
     78
     79                                /**
     80                                 * Filters Twenty Twenty's array of domain mappings for social icons.
     81                                 *
     82                                 * By default, each Icon ID is matched against a .com TLD. To override this behavior,
     83                                 * specify all the domains it covers (including the .com TLD too, if applicable).
     84                                 *
     85                                 * @since 1.5.0
     86                                 *
     87                                 * @param array $social_icons_map Array of default social icons.
     88                                 */
     89                                $map = apply_filters( 'twentytwenty_social_icons_map', self::$social_icons_map );
     90
     91                                /**
     92                                 * Filters Twenty Twenty's array of social icons.
     93                                 *
     94                                 * @since 1.5.0
     95                                 *
     96                                 * @param array $social_icons Array of default social icons.
     97                                 */
     98                                $social_icons = apply_filters( 'twentytwenty_svg_icons_social', self::$social_icons );
     99
     100                                foreach ( array_keys( $social_icons ) as $icon ) {
    56101                                        $domains            = array_key_exists( $icon, $map ) ? $map[ $icon ] : array( sprintf( '%s.com', $icon ) );
    57102                                        $domains            = array_map( 'trim', $domains ); // Remove leading/trailing spaces, to prevent regex from failing to match.
Note: See TracChangeset for help on using the changeset viewer.