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