| @@ 22-77 (lines=56) @@ | ||
| 19 | add_action( 'wp_footer', 'jetpack_social_menu_include_svg_icons', 9999 ); |
|
| 20 | endif; |
|
| 21 | ||
| 22 | if ( ! function_exists( 'jetpack_social_menu_get_svg' ) ) : |
|
| 23 | /** |
|
| 24 | * Return SVG markup. |
|
| 25 | * |
|
| 26 | * @param array $args { |
|
| 27 | * Parameters needed to display an SVG. |
|
| 28 | * |
|
| 29 | * @type string $icon Required SVG icon filename. |
|
| 30 | * } |
|
| 31 | * @return string SVG markup. |
|
| 32 | */ |
|
| 33 | function jetpack_social_menu_get_svg( $args = array() ) { |
|
| 34 | // Make sure $args are an array. |
|
| 35 | if ( empty( $args ) ) { |
|
| 36 | return esc_html__( 'Please define default parameters in the form of an array.', 'jetpack' ); |
|
| 37 | } |
|
| 38 | ||
| 39 | // Define an icon. |
|
| 40 | if ( false === array_key_exists( 'icon', $args ) ) { |
|
| 41 | return esc_html__( 'Please define an SVG icon filename.', 'jetpack' ); |
|
| 42 | } |
|
| 43 | ||
| 44 | // Set defaults. |
|
| 45 | $defaults = array( |
|
| 46 | 'icon' => '', |
|
| 47 | 'fallback' => false, |
|
| 48 | ); |
|
| 49 | ||
| 50 | // Parse args. |
|
| 51 | $args = wp_parse_args( $args, $defaults ); |
|
| 52 | ||
| 53 | // Set aria hidden. |
|
| 54 | $aria_hidden = ' aria-hidden="true"'; |
|
| 55 | ||
| 56 | // Begin SVG markup. |
|
| 57 | $svg = '<svg class="icon icon-' . esc_attr( $args['icon'] ) . '"' . $aria_hidden . ' role="img">'; |
|
| 58 | ||
| 59 | /* |
|
| 60 | * Display the icon. |
|
| 61 | * |
|
| 62 | * The whitespace around `<use>` is intentional - it is a work around to a keyboard navigation bug in Safari 10. |
|
| 63 | * |
|
| 64 | * See https://core.trac.wordpress.org/ticket/38387. |
|
| 65 | */ |
|
| 66 | $svg .= ' <use href="#icon-' . esc_html( $args['icon'] ) . '" xlink:href="#icon-' . esc_html( $args['icon'] ) . '"></use> '; |
|
| 67 | ||
| 68 | // Add some markup to use as a fallback for browsers that do not support SVGs. |
|
| 69 | if ( $args['fallback'] ) { |
|
| 70 | $svg .= '<span class="svg-fallback icon-' . esc_attr( $args['icon'] ) . '"></span>'; |
|
| 71 | } |
|
| 72 | ||
| 73 | $svg .= '</svg>'; |
|
| 74 | ||
| 75 | return $svg; |
|
| 76 | } |
|
| 77 | endif; |
|
| 78 | ||
| 79 | if ( ! function_exists( 'jetpack_social_menu_nav_menu_social_icons' ) ) : |
|
| 80 | /** |
|
| @@ 309-364 (lines=56) @@ | ||
| 306 | } |
|
| 307 | add_action( 'widgets_init', 'jetpack_widget_social_icons_load' ); |
|
| 308 | ||
| 309 | if ( ! function_exists( 'jetpack_social_menu_get_svg' ) ) : |
|
| 310 | /** |
|
| 311 | * Return SVG markup. |
|
| 312 | * |
|
| 313 | * @param array $args { |
|
| 314 | * Parameters needed to display an SVG. |
|
| 315 | * |
|
| 316 | * @type string $icon Required SVG icon filename. |
|
| 317 | * } |
|
| 318 | * @return string SVG markup. |
|
| 319 | */ |
|
| 320 | function jetpack_social_menu_get_svg( $args = array() ) { |
|
| 321 | // Make sure $args are an array. |
|
| 322 | if ( empty( $args ) ) { |
|
| 323 | return esc_html__( 'Please define default parameters in the form of an array.', 'jetpack' ); |
|
| 324 | } |
|
| 325 | ||
| 326 | // Set defaults. |
|
| 327 | $defaults = array( |
|
| 328 | 'icon' => '', |
|
| 329 | 'fallback' => false, |
|
| 330 | ); |
|
| 331 | ||
| 332 | // Parse args. |
|
| 333 | $args = wp_parse_args( $args, $defaults ); |
|
| 334 | ||
| 335 | // Define an icon. |
|
| 336 | if ( false === array_key_exists( 'icon', $args ) ) { |
|
| 337 | return esc_html__( 'Please define an SVG icon filename.', 'jetpack' ); |
|
| 338 | } |
|
| 339 | ||
| 340 | // Set aria hidden. |
|
| 341 | $aria_hidden = ' aria-hidden="true"'; |
|
| 342 | ||
| 343 | // Begin SVG markup. |
|
| 344 | $svg = '<svg class="icon icon-' . esc_attr( $args['icon'] ) . '"' . $aria_hidden . ' role="img">'; |
|
| 345 | ||
| 346 | /* |
|
| 347 | * Display the icon. |
|
| 348 | * |
|
| 349 | * The whitespace around `<use>` is intentional - it is a work around to a keyboard navigation bug in Safari 10. |
|
| 350 | * |
|
| 351 | * See https://core.trac.wordpress.org/ticket/38387. |
|
| 352 | */ |
|
| 353 | $svg .= ' <use href="#icon-' . esc_html( $args['icon'] ) . '" xlink:href="#icon-' . esc_html( $args['icon'] ) . '"></use> '; |
|
| 354 | ||
| 355 | // Add some markup to use as a fallback for browsers that do not support SVGs. |
|
| 356 | if ( $args['fallback'] ) { |
|
| 357 | $svg .= '<span class="svg-fallback icon-' . esc_attr( $args['icon'] ) . '"></span>'; |
|
| 358 | } |
|
| 359 | ||
| 360 | $svg .= '</svg>'; |
|
| 361 | ||
| 362 | return $svg; |
|
| 363 | } |
|
| 364 | endif; |
|
| 365 | ||
| 366 | if ( ! function_exists( 'jetpack_social_menu_social_links_icons' ) ) : |
|
| 367 | /** |
|