← All changes
|
modules/theme-tools/social-menu/icon-functions.php
+44
-15
12.5.2
→
16.3-a.1
View file →
| @@ -4,13 +4,18 @@ | ||
| 4 | 4 | * |
| 5 | 5 | * @package automattic/jetpack |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | -if ( ! function_exists( 'jetpack_social_menu_include_svg_icons' ) ) : | |
| 8 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 9 | + exit( 0 ); | |
| 10 | +} | |
| 11 | + | |
| 12 | +if ( ! function_exists( 'jetpack_social_menu_include_svg_icons' ) ) { | |
| 9 | 13 | /** |
| 10 | 14 | * Add SVG definitions to the footer. |
| 11 | 15 | */ |
| 12 | 16 | function jetpack_social_menu_include_svg_icons() { |
| 17 | + _deprecated_function( __FUNCTION__, 'jetpack-13.7' ); | |
| 13 | 18 | // Return early if Social Menu doesn't exist. |
| 14 | 19 | if ( ! has_nav_menu( 'jetpack-social-menu' ) ) { |
| 15 | 20 | return; |
| 16 | 21 | } |
| @@ -17,15 +22,36 @@ | ||
| 17 | 22 | // Define SVG sprite file. |
| 18 | 23 | $svg_icons = __DIR__ . '/social-menu.svg'; |
| 19 | 24 | // If it exists and we use the SVG menu type, include it. |
| 20 | 25 | if ( file_exists( $svg_icons ) && 'svg' === jetpack_social_menu_get_type() ) { |
| 21 | - require_once $svg_icons; | |
| 26 | + $svg_contents = file_get_contents( $svg_icons ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- Only reading a local file. | |
| 22 | 27 | } |
| 28 | + | |
| 29 | + if ( ! empty( $svg_contents ) ) { | |
| 30 | + $allowed_tags = array( | |
| 31 | + 'svg' => array( | |
| 32 | + 'style' => true, | |
| 33 | + 'version' => true, | |
| 34 | + 'xmlns' => true, | |
| 35 | + 'xmlns:xlink' => true, | |
| 36 | + ), | |
| 37 | + 'defs' => array(), | |
| 38 | + 'symbol' => array( | |
| 39 | + 'id' => true, | |
| 40 | + 'viewbox' => true, | |
| 41 | + ), | |
| 42 | + 'path' => array( | |
| 43 | + 'd' => true, | |
| 44 | + 'style' => true, | |
| 45 | + ), | |
| 46 | + ); | |
| 47 | + echo wp_kses( $svg_contents, $allowed_tags ); | |
| 48 | + } | |
| 23 | 49 | } |
| 24 | 50 | add_action( 'wp_footer', 'jetpack_social_menu_include_svg_icons', 9999 ); |
| 25 | -endif; | |
| 51 | +} | |
| 26 | 52 | |
| 27 | -if ( ! function_exists( 'jetpack_social_menu_get_svg' ) ) : | |
| 53 | +if ( ! function_exists( 'jetpack_social_menu_get_svg' ) ) { | |
| 28 | 54 | /** |
| 29 | 55 | * Return SVG markup. |
| 30 | 56 | * |
| 31 | 57 | * @param array $args { |
| @@ -35,8 +61,9 @@ | ||
| 35 | 61 | * } |
| 36 | 62 | * @return string SVG markup. |
| 37 | 63 | */ |
| 38 | 64 | function jetpack_social_menu_get_svg( $args = array() ) { |
| 65 | + _deprecated_function( __FUNCTION__, 'jetpack-13.7' ); | |
| 39 | 66 | // Make sure $args are an array. |
| 40 | 67 | if ( empty( $args ) ) { |
| 41 | 68 | return esc_html__( 'Please define default parameters in the form of an array.', 'jetpack' ); |
| 42 | 69 | } |
| @@ -41,9 +68,9 @@ | ||
| 41 | 68 | return esc_html__( 'Please define default parameters in the form of an array.', 'jetpack' ); |
| 42 | 69 | } |
| 43 | 70 | |
| 44 | 71 | // Define an icon. |
| 45 | - if ( false === array_key_exists( 'icon', $args ) ) { | |
| 72 | + if ( ! array_key_exists( 'icon', $args ) ) { | |
| 46 | 73 | return esc_html__( 'Please define an SVG icon filename.', 'jetpack' ); |
| 47 | 74 | } |
| 48 | 75 | |
| 49 | 76 | // Set defaults. |
| @@ -78,11 +105,11 @@ | ||
| 78 | 105 | $svg .= '</svg>'; |
| 79 | 106 | |
| 80 | 107 | return $svg; |
| 81 | 108 | } |
| 82 | -endif; | |
| 109 | +} | |
| 83 | 110 | |
| 84 | -if ( ! function_exists( 'jetpack_social_menu_nav_menu_social_icons' ) ) : | |
| 111 | +if ( ! function_exists( 'jetpack_social_menu_nav_menu_social_icons' ) ) { | |
| 85 | 112 | /** |
| 86 | 113 | * Display SVG icons in social links menu. |
| 87 | 114 | * |
| 88 | 115 | * @param string $item_output The menu item output. |
| @@ -91,8 +118,9 @@ | ||
| 91 | 118 | * @param array $args wp_nav_menu() arguments. |
| 92 | 119 | * @return string $item_output The menu item output with social icon. |
| 93 | 120 | */ |
| 94 | 121 | function jetpack_social_menu_nav_menu_social_icons( $item_output, $item, $depth, $args ) { |
| 122 | + _deprecated_function( __FUNCTION__, 'jetpack-13.7' ); | |
| 95 | 123 | // Get supported social icons. |
| 96 | 124 | $social_icons = jetpack_social_menu_social_links_icons(); |
| 97 | 125 | |
| 98 | 126 | // Change SVG icon inside social links menu if there is supported URL. |
| @@ -104,13 +132,13 @@ | ||
| 104 | 132 | */ |
| 105 | 133 | if ( |
| 106 | 134 | // First Regex. |
| 107 | 135 | ( |
| 108 | - '#' === substr( $attr, 0, 1 ) && '#' === substr( $attr, -1 ) | |
| 136 | + str_starts_with( $attr, '#' ) && str_ends_with( $attr, '#' ) | |
| 109 | 137 | && preg_match( $attr, $item_output ) |
| 110 | 138 | ) |
| 111 | 139 | // Then, regular host name. |
| 112 | - || false !== strpos( $item_output, $attr ) | |
| 140 | + || str_contains( $item_output, $attr ) | |
| 113 | 141 | ) { |
| 114 | 142 | $item_output = str_replace( |
| 115 | 143 | $args->link_after, |
| 116 | 144 | '</span>' . jetpack_social_menu_get_svg( array( 'icon' => esc_attr( $value ) ) ), |
| @@ -122,11 +150,11 @@ | ||
| 122 | 150 | |
| 123 | 151 | return $item_output; |
| 124 | 152 | } |
| 125 | 153 | add_filter( 'walker_nav_menu_start_el', 'jetpack_social_menu_nav_menu_social_icons', 10, 4 ); |
| 126 | -endif; | |
| 154 | +} | |
| 127 | 155 | |
| 128 | -if ( ! function_exists( 'jetpack_social_menu_social_links_icons' ) ) : | |
| 156 | +if ( ! function_exists( 'jetpack_social_menu_social_links_icons' ) ) { | |
| 129 | 157 | /** |
| 130 | 158 | * Returns an array of supported social links (URL / regex and icon name). |
| 131 | 159 | * For regex, use the # delimiter. |
| 132 | 160 | * |
| @@ -132,8 +160,9 @@ | ||
| 132 | 160 | * |
| 133 | 161 | * @return array $social_links_icons |
| 134 | 162 | */ |
| 135 | 163 | function jetpack_social_menu_social_links_icons() { |
| 164 | + _deprecated_function( __FUNCTION__, 'jetpack-13.7' ); | |
| 136 | 165 | // Supported social links icons. |
| 137 | 166 | $social_links_icons = array( |
| 138 | 167 | '#https?:\/\/(www\.)?amazon\.(com|cn|in|fr|de|it|nl|es|co|ca)\/#' => 'amazon', |
| 139 | 168 | '500px.com' => '500px', |
| @@ -142,8 +171,9 @@ | ||
| 142 | 171 | 'bandcamp.com' => 'bandcamp', |
| 143 | 172 | 'behance.net' => 'behance', |
| 144 | 173 | 'blogger.com' => 'blogger', |
| 145 | 174 | 'blogspot.com' => 'blogger', |
| 175 | + 'bsky.app' => 'bluesky', | |
| 146 | 176 | 'codepen.io' => 'codepen', |
| 147 | 177 | 'deviantart.com' => 'deviantart', |
| 148 | 178 | 'discord.gg' => 'discord', |
| 149 | 179 | 'discordapp.com' => 'discord', |
| @@ -167,14 +197,12 @@ | ||
| 167 | 197 | 'medium.com' => 'medium', |
| 168 | 198 | 'nextdoor.com' => 'nextdoor', |
| 169 | 199 | 'patreon.com' => 'patreon', |
| 170 | 200 | 'pinterest.' => 'pinterest', |
| 171 | - 'getpocket.com' => 'pocket', | |
| 172 | 201 | 'ravelry.com' => 'ravelry', |
| 173 | 202 | 'reddit.com' => 'reddit', |
| 174 | - 'skype.com' => 'skype', | |
| 175 | - 'skype:' => 'skype', | |
| 176 | 203 | 'slideshare.net' => 'slideshare', |
| 204 | + 'sms:' => 'sms', | |
| 177 | 205 | 'snapchat.com' => 'snapchat', |
| 178 | 206 | 'soundcloud.com' => 'soundcloud', |
| 179 | 207 | 'spotify.com' => 'spotify', |
| 180 | 208 | 'stackoverflow.com' => 'stackoverflow', |
| @@ -192,8 +220,9 @@ | ||
| 192 | 220 | 'woocommerce.com' => 'woocommerce', |
| 193 | 221 | 'wordpress.org' => 'wordpress', |
| 194 | 222 | 'wordpress.com' => 'wordpress', |
| 195 | 223 | 'yelp.com' => 'yelp', |
| 224 | + 'x.com' => 'x', | |
| 196 | 225 | 'xanga.com' => 'xanga', |
| 197 | 226 | 'youtube.com' => 'youtube', |
| 198 | 227 | ); |
| 199 | 228 | |
| @@ -206,5 +235,5 @@ | ||
| 206 | 235 | } |
| 207 | 236 | |
| 208 | 237 | return $social_links_icons; |
| 209 | 238 | } |
| 210 | -endif; | |
| 239 | +} | |