diff --git a/projects/plugins/jetpack/changelog/add-social-menu-add-regex-option b/projects/plugins/jetpack/changelog/add-social-menu-add-regex-option new file mode 100644 index 000000000000..e1743f04fb52 --- /dev/null +++ b/projects/plugins/jetpack/changelog/add-social-menu-add-regex-option @@ -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. diff --git a/projects/plugins/jetpack/modules/theme-tools/social-menu/icon-functions.php b/projects/plugins/jetpack/modules/theme-tools/social-menu/icon-functions.php index 510dee48775d..72f9828a1e03 100644 --- a/projects/plugins/jetpack/modules/theme-tools/social-menu/icon-functions.php +++ b/projects/plugins/jetpack/modules/theme-tools/social-menu/icon-functions.php @@ -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, '' . 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, + '' . jetpack_social_menu_get_svg( array( 'icon' => esc_attr( $value ) ) ), + $item_output + ); } } } @@ -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',