Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add filter to social icons map #2212

Merged
merged 1 commit into from
Dec 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion newspack-theme/classes/class-newspack-svg-icons.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
*
Expand Down Expand Up @@ -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(
Expand Down