PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 10.2.2
Jetpack – WP Security, Backup, Speed, & Growth v10.2.2
16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 All 502 releases
jetpack / modules / theme-tools / social-menu.php

social-menu.php in Jetpack – WP Security, Backup, Speed, & Growth 10.2.2, at modules/theme-tools/social-menu.php

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