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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. $value_hidden_class = '';
  55. $no_value_hidden_class = '';
  56. if ( $this->value() ) {
  57. $value_hidden_class = ' hidden';
  58. } else {
  59. $no_value_hidden_class = ' hidden';
  60. }
  61. ?>
  62. <label>
  63. <?php if ( ! empty( $this->label ) ) : ?>
  64. <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
  65. <?php endif; ?>
  66. <?php if ( ! empty( $this->description ) ) : ?>
  67. <span class="description customize-control-description"><?php echo $this->description; ?></span>
  68. <?php endif; ?>
  69. <select <?php $this->link(); ?>>
  70. <?php
  71. foreach ( $this->choices as $value => $label ) :
  72. echo '<option value="' . esc_attr( $value ) . '"' . selected( $this->value(), $value, false ) . '>' . $label . '</option>';
  73. endforeach;
  74. ?>
  75. </select>
  76. </label>
  77. <button type="button" class="button-link create-menu<?php echo $value_hidden_class; ?>" 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>
  78. <button type="button" class="button-link edit-menu<?php echo $no_value_hidden_class; ?>" aria-label="<?php esc_attr_e( 'Edit selected menu' ); ?>"><?php _e( 'Edit Menu' ); ?></button>
  79. <?php
  80. }
  81. }