No Description

social-menu.php 3.0KB

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