Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 48 |
|
0.00% |
0 / 4 |
CRAP | n/a |
0 / 0 |
|
| jetpack_social_menu_init | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
12 | |||
| jetpack_social_menu_get_type | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
30 | |||
| jetpack_social_menu_style | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
20 | |||
| jetpack_social_menu | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Social Menu. |
| 4 | * |
| 5 | * This feature will only be activated for themes that declare their support. |
| 6 | * This can be done by adding code similar to the following during the |
| 7 | * 'after_setup_theme' action: |
| 8 | * |
| 9 | * add_theme_support( 'jetpack-social-menu' ); |
| 10 | * |
| 11 | * @package automattic/jetpack-classic-theme-helper |
| 12 | */ |
| 13 | |
| 14 | if ( ! defined( 'ABSPATH' ) ) { |
| 15 | exit( 0 ); |
| 16 | } |
| 17 | |
| 18 | if ( ! function_exists( 'jetpack_social_menu_init' ) ) { |
| 19 | /** |
| 20 | * Activate the Social Menu plugin. |
| 21 | * |
| 22 | * @uses current_theme_supports() |
| 23 | */ |
| 24 | function jetpack_social_menu_init() { |
| 25 | // Only load our code if our theme declares support |
| 26 | if ( ! current_theme_supports( 'jetpack-social-menu' ) ) { |
| 27 | return; |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * Social Menu description. |
| 32 | * |
| 33 | * Rename the social menu description. |
| 34 | * |
| 35 | * @module theme-tools |
| 36 | * |
| 37 | * @since 3.9.0 |
| 38 | * |
| 39 | * @param string $social_menu_description Social Menu description |
| 40 | */ |
| 41 | $social_menu_description = apply_filters( 'jetpack_social_menu_description', __( 'Social Menu', 'jetpack-classic-theme-helper' ) ); |
| 42 | |
| 43 | // Register a new menu location |
| 44 | register_nav_menus( |
| 45 | array( |
| 46 | 'jetpack-social-menu' => esc_html( $social_menu_description ), |
| 47 | ) |
| 48 | ); |
| 49 | |
| 50 | // Enqueue CSS |
| 51 | add_action( 'wp_enqueue_scripts', 'jetpack_social_menu_style' ); |
| 52 | |
| 53 | // Load SVG icons related functions and filters |
| 54 | if ( 'svg' === jetpack_social_menu_get_type() ) { |
| 55 | require __DIR__ . '/social-menu/icon-functions.php'; |
| 56 | } |
| 57 | } |
| 58 | add_action( 'after_setup_theme', 'jetpack_social_menu_init', 99 ); |
| 59 | add_action( 'restapi_theme_init', 'jetpack_social_menu_init' ); |
| 60 | } |
| 61 | |
| 62 | if ( ! function_exists( 'jetpack_social_menu_get_type' ) ) { |
| 63 | /** |
| 64 | * Return the type of menu the theme is using. |
| 65 | * |
| 66 | * @uses get_theme_support() |
| 67 | * @return null|string $menu_type |
| 68 | */ |
| 69 | function jetpack_social_menu_get_type() { |
| 70 | $options = get_theme_support( 'jetpack-social-menu' ); |
| 71 | |
| 72 | if ( ! $options ) { |
| 73 | $menu_type = null; |
| 74 | } else { |
| 75 | $menu_type = 'genericons'; |
| 76 | if ( is_array( $options ) && isset( $options[0] ) ) { |
| 77 | $menu_type = ( in_array( $options[0], array( 'genericons', 'svg' ), true ) ) ? $options[0] : 'genericons'; |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | return $menu_type; |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | if ( ! function_exists( 'jetpack_social_menu_style' ) ) { |
| 86 | /** |
| 87 | * Function to enqueue the CSS. |
| 88 | */ |
| 89 | function jetpack_social_menu_style() { |
| 90 | $menu_type = jetpack_social_menu_get_type(); |
| 91 | |
| 92 | if ( ! $menu_type ) { |
| 93 | return; |
| 94 | } |
| 95 | |
| 96 | $deps = ( 'genericons' === $menu_type ) ? array( 'genericons' ) : null; |
| 97 | |
| 98 | if ( has_nav_menu( 'jetpack-social-menu' ) ) { |
| 99 | wp_enqueue_style( 'jetpack-social-menu', plugins_url( 'social-menu/social-menu.css', __FILE__ ), $deps, '1.0' ); |
| 100 | } |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | if ( ! function_exists( 'jetpack_social_menu' ) ) { |
| 105 | /** |
| 106 | * Create the function for the menu. |
| 107 | */ |
| 108 | function jetpack_social_menu() { |
| 109 | if ( has_nav_menu( 'jetpack-social-menu' ) ) : |
| 110 | $menu_type = (string) jetpack_social_menu_get_type(); |
| 111 | $link_after = '</span>'; |
| 112 | |
| 113 | if ( 'svg' === $menu_type ) { |
| 114 | $link_after .= jetpack_social_menu_get_svg( array( 'icon' => 'chain' ) ); |
| 115 | } ?> |
| 116 | <nav class="jetpack-social-navigation jetpack-social-navigation-<?php echo esc_attr( $menu_type ); ?>" aria-label="<?php esc_html_e( 'Social Links Menu', 'jetpack-classic-theme-helper' ); ?>"> |
| 117 | <?php |
| 118 | wp_nav_menu( |
| 119 | array( |
| 120 | 'theme_location' => 'jetpack-social-menu', |
| 121 | 'link_before' => '<span class="screen-reader-text">', |
| 122 | 'link_after' => $link_after, |
| 123 | 'depth' => 1, |
| 124 | ) |
| 125 | ); |
| 126 | ?> |
| 127 | </nav><!-- .jetpack-social-navigation --> |
| 128 | <?php |
| 129 | endif; |
| 130 | } |
| 131 | } |