class-wp-customize-nav-menu-locations-control.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. * Customize API: WP_Customize_Nav_Menu_Locations_Control class
  4. *
  5. * @package WordPress
  6. * @subpackage Customize
  7. * @since 4.9.0
  8. */
  9. /**
  10. * Customize Nav Menu Locations Control Class.
  11. *
  12. * @since 4.9.0
  13. *
  14. * @see WP_Customize_Control
  15. */
  16. class WP_Customize_Nav_Menu_Locations_Control extends WP_Customize_Control {
  17. /**
  18. * Control type.
  19. *
  20. * @since 4.9.0
  21. * @var string
  22. */
  23. public $type = 'nav_menu_locations';
  24. /**
  25. * Don't render the control's content - it uses a JS template instead.
  26. *
  27. * @since 4.9.0
  28. */
  29. public function render_content() {}
  30. /**
  31. * JS/Underscore template for the control UI.
  32. *
  33. * @since 4.9.0
  34. */
  35. public function content_template() {
  36. if ( current_theme_supports( 'menus' ) ) :
  37. ?>
  38. <# var elementId; #>
  39. <ul class="menu-location-settings">
  40. <li class="customize-control assigned-menu-locations-title">
  41. <span class="customize-control-title">{{ wp.customize.Menus.data.l10n.locationsTitle }}</span>
  42. <# if ( data.isCreating ) { #>
  43. <p>
  44. <?php echo _x( 'Where do you want this menu to appear?', 'menu locations' ); ?>
  45. <?php
  46. printf(
  47. /* translators: 1: Documentation URL, 2: Additional link attributes, 3: Accessibility text. */
  48. _x( '(If you plan to use a menu <a href="%1$s" %2$s>widget%3$s</a>, skip this step.)', 'menu locations' ),
  49. __( 'https://wordpress.org/support/article/wordpress-widgets/' ),
  50. ' class="external-link" target="_blank"',
  51. sprintf(
  52. '<span class="screen-reader-text"> %s</span>',
  53. /* translators: Accessibility text. */
  54. __( '(opens in a new tab)' )
  55. )
  56. );
  57. ?>
  58. </p>
  59. <# } else { #>
  60. <p><?php echo _x( 'Here&#8217;s where this menu appears. If you would like to change that, pick another location.', 'menu locations' ); ?></p>
  61. <# } #>
  62. </li>
  63. <?php foreach ( get_registered_nav_menus() as $location => $description ) : ?>
  64. <# elementId = _.uniqueId( 'customize-nav-menu-control-location-' ); #>
  65. <li class="customize-control customize-control-checkbox assigned-menu-location">
  66. <span class="customize-inside-control-row">
  67. <input id="{{ elementId }}" type="checkbox" data-menu-id="{{ data.menu_id }}" data-location-id="<?php echo esc_attr( $location ); ?>" class="menu-location" />
  68. <label for="{{ elementId }}">
  69. <?php echo $description; ?>
  70. <span class="theme-location-set">
  71. <?php
  72. printf(
  73. /* translators: %s: Menu name. */
  74. _x( '(Current: %s)', 'menu location' ),
  75. '<span class="current-menu-location-name-' . esc_attr( $location ) . '"></span>'
  76. );
  77. ?>
  78. </span>
  79. </label>
  80. </span>
  81. </li>
  82. <?php endforeach; ?>
  83. </ul>
  84. <?php
  85. endif;
  86. }
  87. }