PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-beta
Jetpack – WP Security, Backup, Speed, & Growth v16.3-beta
16.3 16.3-beta 16.3-a.5 16.3-a.7 16.3-a.3 16.3-a.1 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 All 508 releases
jetpack / jetpack_vendor / automattic / jetpack-classic-theme-helper / src / social-menu.php

social-menu.php in Jetpack – WP Security, Backup, Speed, & Growth 16.3-beta, at jetpack_vendor/automattic/jetpack-classic-theme-helper/src/social-menu.php

132 lines 3.4 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-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 }
132