* SVG icons related functions and filters
* @package automattic/jetpack
if ( ! defined( 'ABSPATH' ) ) {
if ( ! function_exists( 'jetpack_social_menu_include_svg_icons' ) ) {
* Add SVG definitions to the footer.
function jetpack_social_menu_include_svg_icons() {
_deprecated_function( __FUNCTION__, 'jetpack-13.7' );
// Return early if Social Menu doesn't exist.
if ( ! has_nav_menu( 'jetpack-social-menu' ) ) {
// Define SVG sprite file.
$svg_icons = __DIR__ . '/social-menu.svg';
// If it exists and we use the SVG menu type, include it.
if ( file_exists( $svg_icons ) && 'svg' === jetpack_social_menu_get_type() ) {
$svg_contents = file_get_contents( $svg_icons ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- Only reading a local file.
if ( ! empty( $svg_contents ) ) {
echo wp_kses( $svg_contents, $allowed_tags );
add_action( 'wp_footer', 'jetpack_social_menu_include_svg_icons', 9999 );
if ( ! function_exists( 'jetpack_social_menu_get_svg' ) ) {
* Parameters needed to display an SVG.
* @type string $icon Required SVG icon filename.
* @return string SVG markup.
function jetpack_social_menu_get_svg( $args = array() ) {
_deprecated_function( __FUNCTION__, 'jetpack-13.7' );
// Make sure $args are an array.
return esc_html__( 'Please define default parameters in the form of an array.', 'jetpack' );
if ( false === array_key_exists( 'icon', $args ) ) {
return esc_html__( 'Please define an SVG icon filename.', 'jetpack' );
$args = wp_parse_args( $args, $defaults );
$aria_hidden = ' aria-hidden="true"';
$svg = '<svg class="icon icon-' . esc_attr( $args['icon'] ) . '"' . $aria_hidden . ' role="img">';
* The whitespace around `<use>` is intentional - it is a work around to a keyboard navigation bug in Safari 10.
* See https://core.trac.wordpress.org/ticket/38387.
$svg .= ' <use href="#icon-' . esc_html( $args['icon'] ) . '" xlink:href="#icon-' . esc_html( $args['icon'] ) . '"></use> ';
// Add some markup to use as a fallback for browsers that do not support SVGs.
if ( $args['fallback'] ) {
$svg .= '<span class="svg-fallback icon-' . esc_attr( $args['icon'] ) . '"></span>';
if ( ! function_exists( 'jetpack_social_menu_nav_menu_social_icons' ) ) {
* Display SVG icons in social links menu.
* @param string $item_output The menu item output.
* @param WP_Post $item Menu item object.
* @param int $depth Depth of the menu.
* @param array $args wp_nav_menu() arguments.
* @return string $item_output The menu item output with social icon.
function jetpack_social_menu_nav_menu_social_icons( $item_output, $item, $depth, $args ) {
_deprecated_function( __FUNCTION__, 'jetpack-13.7' );
// Get supported social icons.
$social_icons = jetpack_social_menu_social_links_icons();
// Change SVG icon inside social links menu if there is supported URL.
if ( 'jetpack-social-menu' === $args->theme_location ) {
foreach ( $social_icons as $attr => $value ) {
* attr can be a URL host, or a regex, starting with #.
* Let's check for both scenarios.
str_starts_with( $attr, '#' ) && str_ends_with( $attr, '#' )
&& preg_match( $attr, $item_output )
// Then, regular host name.
|| str_contains( $item_output, $attr )
$item_output = str_replace(
'</span>' . jetpack_social_menu_get_svg( array( 'icon' => esc_attr( $value ) ) ),
add_filter( 'walker_nav_menu_start_el', 'jetpack_social_menu_nav_menu_social_icons', 10, 4 );
if ( ! function_exists( 'jetpack_social_menu_social_links_icons' ) ) {
* Returns an array of supported social links (URL / regex and icon name).
* For regex, use the # delimiter.
* @return array $social_links_icons
function jetpack_social_menu_social_links_icons() {
_deprecated_function( __FUNCTION__, 'jetpack-13.7' );
// Supported social links icons.
$social_links_icons = array(
'#https?:\/\/(www\.)?amazon\.(com|cn|in|fr|de|it|nl|es|co|ca)\/#' => 'amazon',
'bandcamp.com' => 'bandcamp',
'behance.net' => 'behance',
'blogger.com' => 'blogger',
'blogspot.com' => 'blogger',
'codepen.io' => 'codepen',
'deviantart.com' => 'deviantart',
'discord.gg' => 'discord',
'discordapp.com' => 'discord',
'dribbble.com' => 'dribbble',
'dropbox.com' => 'dropbox',
'eventbrite.com' => 'eventbrite',
'facebook.com' => 'facebook',
'flickr.com' => 'flickr',
'foursquare.com' => 'foursquare',
'goodreads.com' => 'goodreads',
'google.com' => 'google',
'github.com' => 'github',
'instagram.com' => 'instagram',
'linkedin.com' => 'linkedin',
'meetup.com' => 'meetup',
'medium.com' => 'medium',
'nextdoor.com' => 'nextdoor',
'patreon.com' => 'patreon',
'pinterest.' => 'pinterest',
'ravelry.com' => 'ravelry',
'reddit.com' => 'reddit',
'slideshare.net' => 'slideshare',
'snapchat.com' => 'snapchat',
'soundcloud.com' => 'soundcloud',
'spotify.com' => 'spotify',
'stackoverflow.com' => 'stackoverflow',
'strava.com' => 'strava',
'stumbleupon.com' => 'stumbleupon',
'telegram.me' => 'telegram',
'threads.net' => 'threads',
'tiktok.com' => 'tiktok',
'tumblr.com' => 'tumblr',
'twitter.com' => 'twitter',
'whatsapp.com' => 'whatsapp',
'woocommerce.com' => 'woocommerce',
'wordpress.org' => 'wordpress',
'wordpress.com' => 'wordpress',
'youtube.com' => 'youtube',
* Add Mastodon instances to this array.
$mastodon_instance_list = jetpack_mastodon_get_instance_list();
foreach ( $mastodon_instance_list as $instance ) {
$social_links_icons[ $instance ] = 'mastodon';
return $social_links_icons;