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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. <em class="new-menu-locations-widget-note">
  46. <?php
  47. printf(
  48. /* translators: 1: Documentation URL, 2: Additional link attributes, 3: Accessibility text. */
  49. _x( '(If you plan to use a menu <a href="%1$s" %2$s>widget%3$s</a>, skip this step.)', 'menu locations' ),
  50. __( 'https://wordpress.org/support/article/wordpress-widgets/' ),
  51. ' class="external-link" target="_blank"',
  52. sprintf(
  53. '<span class="screen-reader-text"> %s</span>',
  54. /* translators: Accessibility text. */
  55. __( '(opens in a new tab)' )
  56. )
  57. );
  58. ?>
  59. </em>
  60. </p>
  61. <# } else { #>
  62. <p><?php echo _x( 'Here&#8217;s where this menu appears. If you&#8217;d like to change that, pick another location.', 'menu locations' ); ?></p>
  63. <# } #>
  64. </li>
  65. <?php foreach ( get_registered_nav_menus() as $location => $description ) : ?>
  66. <# elementId = _.uniqueId( 'customize-nav-menu-control-location-' ); #>
  67. <li class="customize-control customize-control-checkbox assigned-menu-location">
  68. <span class="customize-inside-control-row">
  69. <input id="{{ elementId }}" type="checkbox" data-menu-id="{{ data.menu_id }}" data-location-id="<?php echo esc_attr( $location ); ?>" class="menu-location" />
  70. <label for="{{ elementId }}">
  71. <?php echo $description; ?>
  72. <span class="theme-location-set">
  73. <?php
  74. printf(
  75. /* translators: %s: Menu name. */
  76. _x( '(Current: %s)', 'menu location' ),
  77. '<span class="current-menu-location-name-' . esc_attr( $location ) . '"></span>'
  78. );
  79. ?>
  80. </span>
  81. </label>
  82. </span>
  83. </li>
  84. <?php endforeach; ?>
  85. </ul>
  86. <?php
  87. endif;
  88. }
  89. }