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