class-wp-customize-nav-menu-location-control.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. * Customize API: WP_Customize_Nav_Menu_Location_Control class
  4. *
  5. * @package WordPress
  6. * @subpackage Customize
  7. * @since 4.4.0
  8. */
  9. /**
  10. * Customize Menu Location Control Class.
  11. *
  12. * This custom control is only needed for JS.
  13. *
  14. * @since 4.3.0
  15. *
  16. * @see WP_Customize_Control
  17. */
  18. class WP_Customize_Nav_Menu_Location_Control extends WP_Customize_Control {
  19. /**
  20. * Control type.
  21. *
  22. * @since 4.3.0
  23. * @var string
  24. */
  25. public $type = 'nav_menu_location';
  26. /**
  27. * Location ID.
  28. *
  29. * @since 4.3.0
  30. * @var string
  31. */
  32. public $location_id = '';
  33. /**
  34. * Refresh the parameters passed to JavaScript via JSON.
  35. *
  36. * @since 4.3.0
  37. *
  38. * @see WP_Customize_Control::to_json()
  39. */
  40. public function to_json() {
  41. parent::to_json();
  42. $this->json['locationId'] = $this->location_id;
  43. }
  44. /**
  45. * Render content just like a normal select control.
  46. *
  47. * @since 4.3.0
  48. * @since 4.9.0 Added a button to create menus.
  49. */
  50. public function render_content() {
  51. if ( empty( $this->choices ) ) {
  52. return;
  53. }
  54. ?>
  55. <label>
  56. <?php if ( ! empty( $this->label ) ) : ?>
  57. <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
  58. <?php endif; ?>
  59. <?php if ( ! empty( $this->description ) ) : ?>
  60. <span class="description customize-control-description"><?php echo $this->description; ?></span>
  61. <?php endif; ?>
  62. <select <?php $this->link(); ?>>
  63. <?php
  64. foreach ( $this->choices as $value => $label ) :
  65. echo '<option value="' . esc_attr( $value ) . '"' . selected( $this->value(), $value, false ) . '>' . $label . '</option>';
  66. endforeach;
  67. ?>
  68. </select>
  69. </label>
  70. <button type="button" class="button-link create-menu<?php if ( $this->value() ) { echo ' hidden'; } ?>" data-location-id="<?php echo esc_attr( $this->location_id ); ?>" aria-label="<?php esc_attr_e( 'Create a menu for this location' ); ?>"><?php _e( '+ Create New Menu' ); ?></button>
  71. <button type="button" class="button-link edit-menu<?php if ( ! $this->value() ) { echo ' hidden'; } ?>" aria-label="<?php esc_attr_e( 'Edit selected menu' ); ?>"><?php _e( 'Edit Menu' ); ?></button>
  72. <?php
  73. }
  74. }