Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: other

Social Menu Theme Tool: allow specifying a regex instead of a sisimmple host name for services that have logos.
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,24 @@ function jetpack_social_menu_nav_menu_social_icons( $item_output, $item, $depth,
// 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 ) {
if ( false !== strpos( $item_output, $attr ) ) {
$item_output = str_replace( $args->link_after, '</span>' . jetpack_social_menu_get_svg( array( 'icon' => esc_attr( $value ) ) ), $item_output );
/*
* attr can be a URL host, or a regex, starting with #.
* Let's check for both scenarios.
*/
if (
// First Regex.
(
'#' === substr( $attr, 0, 1 ) && '#' === substr( $attr, -1 )
&& preg_match( $attr, $item_output )
)
// Then, regular host name.
|| false !== strpos( $item_output, $attr )
) {
$item_output = str_replace(
$args->link_after,
'</span>' . jetpack_social_menu_get_svg( array( 'icon' => esc_attr( $value ) ) ),
$item_output
);
}
}
}
Expand All @@ -111,24 +127,16 @@ function jetpack_social_menu_nav_menu_social_icons( $item_output, $item, $depth,

if ( ! function_exists( 'jetpack_social_menu_social_links_icons' ) ) :
/**
* Returns an array of supported social links (URL and icon name).
* 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() {
// Supported social links icons.
$social_links_icons = array(
'#https?:\/\/(www\.)?amazon\.(com|cn|in|fr|de|it|nl|es|co|ca)\/#' => 'amazon',
'500px.com' => '500px',
'amazon.cn' => 'amazon',
'amazon.in' => 'amazon',
'amazon.fr' => 'amazon',
'amazon.de' => 'amazon',
'amazon.it' => 'amazon',
'amazon.nl' => 'amazon',
'amazon.es' => 'amazon',
'amazon.co' => 'amazon',
'amazon.ca' => 'amazon',
'amazon.com' => 'amazon',
'apple.com' => 'apple',
'itunes.com' => 'apple',
'bandcamp.com' => 'bandcamp',
Expand Down