From b2f5778a959fa9ec1edfc6e4fcba1abdaedaee80 Mon Sep 17 00:00:00 2001 From: Leo Germani Date: Fri, 1 Dec 2023 17:24:48 -0300 Subject: [PATCH] feat: add filter to social icons map --- .../classes/class-newspack-svg-icons.php | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/newspack-theme/classes/class-newspack-svg-icons.php b/newspack-theme/classes/class-newspack-svg-icons.php index 24cf69015..a97ca17c9 100755 --- a/newspack-theme/classes/class-newspack-svg-icons.php +++ b/newspack-theme/classes/class-newspack-svg-icons.php @@ -50,7 +50,7 @@ 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(); - $map = &self::$social_icons_map; // Use reference instead of copy, to save memory. + $map = self::get_social_icons_map(); foreach ( array_keys( self::$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. @@ -66,6 +66,22 @@ public static function get_social_link_svg( $uri, $size ) { return null; } + /** + * Gets the mapping of social icons to URLs. + * + * @return array Social icons map. + */ + public static function get_social_icons_map() { + /** + * Filters the mapping of social icons to URLs. + * + * Allows plugins or child themes to insert alternative mappings for recognition in the social links menu. + * + * @param array $servers Social icons map. + */ + return apply_filters( 'newspack_social_icons_map', self::$social_icons_map ); + } + /** * User Interface icons – svg sources. * @@ -201,6 +217,8 @@ public static function get_social_link_svg( $uri, $size ) { * 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). * + * Do not access this property directly, use self::get_social_icons_map() instead to get the filtered version. + * * @var array */ static $social_icons_map = array(