Automattic /
jetpack
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 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( array( |
||
| 38 | 'jetpack-social-menu' => esc_html( $social_menu_description ), |
||
| 39 | ) ); |
||
| 40 | |||
| 41 | // Enqueue CSS |
||
| 42 | add_action( 'wp_enqueue_scripts', 'jetpack_social_menu_style' ); |
||
| 43 | |||
| 44 | // Load SVG icons related functions and filters |
||
| 45 | if ( 'svg' === jetpack_social_menu_get_type() ) { |
||
| 46 | require( dirname( __FILE__ ) . '/social-menu/icon-functions.php' ); |
||
| 47 | } |
||
| 48 | } |
||
| 49 | add_action( 'after_setup_theme', 'jetpack_social_menu_init', 99 ); |
||
| 50 | |||
| 51 | /** |
||
| 52 | * Return the type of menu the theme is using. |
||
| 53 | * |
||
| 54 | * @uses get_theme_support() |
||
| 55 | * @return null|string $menu_type |
||
| 56 | */ |
||
| 57 | function jetpack_social_menu_get_type() { |
||
| 58 | $options = get_theme_support( 'jetpack-social-menu' ); |
||
| 59 | |||
| 60 | if ( empty( $options ) ) { |
||
| 61 | $menu_type = null; |
||
| 62 | } else { |
||
| 63 | $menu_type = ( in_array( $options[0], array( 'genericons', 'svg' ) ) ) ? $options[0] : 'genericons'; |
||
| 64 | } |
||
| 65 | |||
| 66 | return $menu_type; |
||
| 67 | } |
||
| 68 | |||
| 69 | /** |
||
| 70 | * Function to enqueue the CSS. |
||
| 71 | */ |
||
| 72 | function jetpack_social_menu_style() { |
||
| 73 | $menu_type = jetpack_social_menu_get_type(); |
||
| 74 | |||
| 75 | if ( ! $menu_type ) { |
||
|
0 ignored issues
–
show
|
|||
| 76 | return; |
||
| 77 | } |
||
| 78 | |||
| 79 | $deps = ( 'genericons' === $menu_type ) ? array( 'genericons' ) : null; |
||
| 80 | |||
| 81 | if ( has_nav_menu( 'jetpack-social-menu' ) ) { |
||
| 82 | wp_enqueue_style( 'jetpack-social-menu', plugins_url( 'social-menu/social-menu.css', __FILE__ ), $deps, '1.0' ); |
||
| 83 | } |
||
| 84 | } |
||
| 85 | |||
| 86 | /** |
||
| 87 | * Create the function for the menu. |
||
| 88 | */ |
||
| 89 | function jetpack_social_menu() { |
||
| 90 | if ( has_nav_menu( 'jetpack-social-menu' ) ) : |
||
| 91 | $menu_type = jetpack_social_menu_get_type(); |
||
| 92 | $link_after = '</span>'; |
||
| 93 | |||
| 94 | if ( 'svg' === $menu_type ) { |
||
| 95 | $link_after .= jetpack_social_menu_get_svg( array( 'icon' => 'chain' ) ); |
||
| 96 | } ?> |
||
| 97 | <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' ); ?>"> |
||
| 98 | <?php |
||
| 99 | wp_nav_menu( array( |
||
| 100 | 'theme_location' => 'jetpack-social-menu', |
||
| 101 | 'link_before' => '<span class="screen-reader-text">', |
||
| 102 | 'link_after' => $link_after, |
||
| 103 | 'depth' => 1, |
||
| 104 | ) ); |
||
| 105 | ?> |
||
| 106 | </nav><!-- .jetpack-social-navigation --> |
||
| 107 | <?php endif; |
||
| 108 | } |
||
| 109 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: