|
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 /** |
|
11 * Customize Menu Location Control Class. |
|
12 * |
|
13 * This custom control is only needed for JS. |
|
14 * |
|
15 * @since 4.3.0 |
|
16 * |
|
17 * @see WP_Customize_Control |
|
18 */ |
|
19 class WP_Customize_Nav_Menu_Location_Control extends WP_Customize_Control { |
|
20 |
|
21 /** |
|
22 * Control type. |
|
23 * |
|
24 * @since 4.3.0 |
|
25 * @var string |
|
26 */ |
|
27 public $type = 'nav_menu_location'; |
|
28 |
|
29 /** |
|
30 * Location ID. |
|
31 * |
|
32 * @since 4.3.0 |
|
33 * @var string |
|
34 */ |
|
35 public $location_id = ''; |
|
36 |
|
37 /** |
|
38 * Refresh the parameters passed to JavaScript via JSON. |
|
39 * |
|
40 * @since 4.3.0 |
|
41 * |
|
42 * @see WP_Customize_Control::to_json() |
|
43 */ |
|
44 public function to_json() { |
|
45 parent::to_json(); |
|
46 $this->json['locationId'] = $this->location_id; |
|
47 } |
|
48 |
|
49 /** |
|
50 * Render content just like a normal select control. |
|
51 * |
|
52 * @since 4.3.0 |
|
53 * @since 4.9.0 Added a button to create menus. |
|
54 */ |
|
55 public function render_content() { |
|
56 if ( empty( $this->choices ) ) { |
|
57 return; |
|
58 } |
|
59 ?> |
|
60 <label> |
|
61 <?php if ( ! empty( $this->label ) ) : ?> |
|
62 <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span> |
|
63 <?php endif; ?> |
|
64 |
|
65 <?php if ( ! empty( $this->description ) ) : ?> |
|
66 <span class="description customize-control-description"><?php echo $this->description; ?></span> |
|
67 <?php endif; ?> |
|
68 |
|
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 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> |
|
78 <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> |
|
79 <?php |
|
80 } |
|
81 } |