PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 12.3
Jetpack – WP Security, Backup, Speed, & Growth v12.3
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 14.3.1 All 501 releases
jetpack / modules / theme-tools / social-menu.php

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

120 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 * @package automattic/jetpack
12 */
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 }
24
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' ) );
37
38 // Register a new menu location
39 register_nav_menus(
40 array(
41 'jetpack-social-menu' => esc_html( $social_menu_description ),
42 )
43 );
44
45 // Enqueue CSS
46 add_action( 'wp_enqueue_scripts', 'jetpack_social_menu_style' );
47
48 // Load SVG icons related functions and filters
49 if ( 'svg' === jetpack_social_menu_get_type() ) {
50 require __DIR__ . '/social-menu/icon-functions.php';
51 }
52 }
53 add_action( 'after_setup_theme', 'jetpack_social_menu_init', 99 );
54 add_action( 'restapi_theme_init', 'jetpack_social_menu_init' );
55
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
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';
71 }
72 }
73
74 return $menu_type;
75 }
76
77 /**
78 * Function to enqueue the CSS.
79 */
80 function jetpack_social_menu_style() {
81 $menu_type = jetpack_social_menu_get_type();
82
83 if ( ! $menu_type ) {
84 return;
85 }
86
87 $deps = ( 'genericons' === $menu_type ) ? array( 'genericons' ) : null;
88
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' );
91 }
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 }
120