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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. class WP_Customize_Nav_Menu_Locations_Control extends WP_Customize_Control {
  15. /**
  16. * Control type.
  17. *
  18. * @since 4.9.0
  19. * @var string
  20. */
  21. public $type = 'nav_menu_locations';
  22. /**
  23. * Don't render the control's content - it uses a JS template instead.
  24. *
  25. * @since 4.9.0
  26. */
  27. public function render_content() {}
  28. /**
  29. * JS/Underscore template for the control UI.
  30. *
  31. * @since 4.9.0
  32. */
  33. public function content_template() {
  34. if ( current_theme_supports( 'menus' ) ) :
  35. ?>
  36. <# var elementId; #>
  37. <ul class="menu-location-settings">
  38. <li class="customize-control assigned-menu-locations-title">
  39. <span class="customize-control-title">{{ wp.customize.Menus.data.l10n.locationsTitle }}</span>
  40. <# if ( data.isCreating ) { #>
  41. <p>
  42. <?php echo _x( 'Where do you want this menu to appear?', 'menu locations' ); ?>
  43. <em class="new-menu-locations-widget-note">
  44. <?php
  45. printf(
  46. /* translators: 1: Codex URL, 2: additional link attributes, 3: accessibility text */
  47. _x( '(If you plan to use a menu <a href="%1$s" %2$s>widget%3$s</a>, skip this step.)', 'menu locations' ),
  48. __( 'https://codex.wordpress.org/WordPress_Widgets' ),
  49. ' class="external-link" target="_blank"',
  50. sprintf( '<span class="screen-reader-text"> %s</span>',
  51. /* translators: accessibility text */
  52. __( '(opens in a new window)' )
  53. )
  54. );
  55. ?>
  56. </em>
  57. </p>
  58. <# } else { #>
  59. <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>
  60. <# } #>
  61. </li>
  62. <?php foreach ( get_registered_nav_menus() as $location => $description ) : ?>
  63. <# elementId = _.uniqueId( 'customize-nav-menu-control-location-' ); #>
  64. <li class="customize-control customize-control-checkbox assigned-menu-location">
  65. <span class="customize-inside-control-row">
  66. <input id="{{ elementId }}" type="checkbox" data-menu-id="{{ data.menu_id }}" data-location-id="<?php echo esc_attr( $location ); ?>" class="menu-location" />
  67. <label for="{{ elementId }}">
  68. <?php echo $description; ?>
  69. <span class="theme-location-set">
  70. <?php
  71. /* translators: %s: menu name */
  72. printf( _x( '(Current: %s)', 'menu location' ),
  73. '<span class="current-menu-location-name-' . esc_attr( $location ) . '"></span>'
  74. );
  75. ?>
  76. </span>
  77. </label>
  78. </span>
  79. </li>
  80. <?php endforeach; ?>
  81. </ul>
  82. <?php
  83. endif;
  84. }
  85. }