| @@ -16,9 +16,9 @@ | ||
| 16 | 16 | /** |
| 17 | 17 | * Constructor. |
| 18 | 18 | */ |
| 19 | 19 | public function __construct() { |
| 20 | - $this->namespace = 'wp/v2'; | |
| 20 | + $this->namespace = '__experimental'; | |
| 21 | 21 | $this->rest_base = 'menu-locations'; |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | /** |
| @@ -151,24 +151,14 @@ | ||
| 151 | 151 | */ |
| 152 | 152 | public function prepare_item_for_response( $location, $request ) { |
| 153 | 153 | $locations = get_nav_menu_locations(); |
| 154 | 154 | $menu = ( isset( $locations[ $location->name ] ) ) ? $locations[ $location->name ] : 0; |
| 155 | + $data = array( | |
| 156 | + 'name' => $location->name, | |
| 157 | + 'description' => $location->description, | |
| 158 | + 'menu' => $menu, | |
| 159 | + ); | |
| 155 | 160 | |
| 156 | - $fields = $this->get_fields_for_response( $request ); | |
| 157 | - $data = array(); | |
| 158 | - | |
| 159 | - if ( rest_is_field_included( 'name', $fields ) ) { | |
| 160 | - $data['name'] = $location->name; | |
| 161 | - } | |
| 162 | - | |
| 163 | - if ( rest_is_field_included( 'description', $fields ) ) { | |
| 164 | - $data['description'] = $location->description; | |
| 165 | - } | |
| 166 | - | |
| 167 | - if ( rest_is_field_included( 'menu', $fields ) ) { | |
| 168 | - $data['menu'] = (int) $menu; | |
| 169 | - } | |
| 170 | - | |
| 171 | 161 | $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
| 172 | 162 | $data = $this->add_additional_fields_to_object( $data, $request ); |
| 173 | 163 | $data = $this->filter_response_by_context( $data, $context ); |
| 174 | 164 | |
| @@ -259,12 +249,10 @@ | ||
| 259 | 249 | $menu = ( isset( $locations[ $location->name ] ) ) ? $locations[ $location->name ] : 0; |
| 260 | 250 | if ( $menu ) { |
| 261 | 251 | $taxonomy_object = get_taxonomy( 'nav_menu' ); |
| 262 | 252 | if ( $taxonomy_object->show_in_rest ) { |
| 263 | - $rest_base = ! empty( $taxonomy_object->rest_base ) ? $taxonomy_object->rest_base : $taxonomy_object->name; | |
| 264 | - $namespace = ! empty( $taxonomy_object->rest_namespace ) ? $taxonomy_object->rest_namespace : '__experimental'; | |
| 265 | - $url = rest_url( sprintf( '%s/%s/%d', $namespace, $rest_base, $menu ) ); | |
| 266 | - | |
| 253 | + $rest_base = ! empty( $taxonomy_object->rest_base ) ? $taxonomy_object->rest_base : $taxonomy_object->name; | |
| 254 | + $url = rest_url( sprintf( '__experimental/%s/%d', $rest_base, $menu ) ); | |
| 267 | 255 | $links['https://api.w.org/menu'][] = array( |
| 268 | 256 | 'href' => $url, |
| 269 | 257 | 'embeddable' => true, |
| 270 | 258 | ); |