Added dependency plugins
This commit is contained in:
11
wordpress/wp-content/plugins/wp-rest-api-v2-menus/README.md
Normal file
11
wordpress/wp-content/plugins/wp-rest-api-v2-menus/README.md
Normal file
@@ -0,0 +1,11 @@
|
||||
# WP REST API V2 Menus
|
||||
Adding menus endpoints on WP REST API v2
|
||||
|
||||
## Routes
|
||||
Get all menus:
|
||||
|
||||
GET /menus/v1/menus
|
||||
|
||||
Get menus data from slug:
|
||||
|
||||
GET /menus/v1/menus/{slug}
|
||||
47
wordpress/wp-content/plugins/wp-rest-api-v2-menus/readme.txt
Normal file
47
wordpress/wp-content/plugins/wp-rest-api-v2-menus/readme.txt
Normal file
@@ -0,0 +1,47 @@
|
||||
=== Plugin Name ===
|
||||
Contributors: ClaudioLaBarbera
|
||||
Tags: api, json, json-rest-api, menu-routes, menus, REST, wp-api, wp-rest-api, v2
|
||||
Requires at least: 4.4
|
||||
Tested up to: 4.8.1
|
||||
Stable tag: 0.3
|
||||
License: GPLv2 or later
|
||||
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
|
||||
Adding menus endpoints on WP REST API v2
|
||||
|
||||
== Description ==
|
||||
|
||||
This plugin extends the [WordPress REST API (Version 2)](https://wordpress.org/plugins/rest-api/) with new routes for WordPress registered menus.
|
||||
|
||||
The new routes available will be:
|
||||
|
||||
* `/menus/v1/menus` list of every registered menu.
|
||||
* `/menus/v1/menus/<slug>` data for a specific menu.
|
||||
|
||||
== Installation ==
|
||||
|
||||
1. Upload the plugin files to the `/wp-content/plugins/wp-rest-api-v2-menus` directory, or install the plugin through the WordPress plugins screen directly.
|
||||
2. Activate the plugin through the 'Plugins' screen in WordPress
|
||||
|
||||
|
||||
== Frequently Asked Questions ==
|
||||
|
||||
= Is this an official extension of WP API? =
|
||||
|
||||
There's no such thing.
|
||||
|
||||
= Can I contribute to the project? =
|
||||
|
||||
Of course! This is the GitHub Repository https://github.com/thebatclaudio/wp-rest-api-v2-menus
|
||||
|
||||
== Screenshots ==
|
||||
|
||||
Nothing to show. This plugin has no settings or frontend, it just extends WP API with new routes.
|
||||
|
||||
== Changelog ==
|
||||
|
||||
0.3 - Bug fix
|
||||
|
||||
0.2 - Updated compatibility
|
||||
|
||||
0.1.1 - Bug fix
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/*
|
||||
Plugin Name: WP-REST-API V2 Menus
|
||||
Version: 0.3
|
||||
Description: Adding menus endpoints on WP REST API v2
|
||||
Author: Claudio La Barbera
|
||||
Author URI: http://www.claudiolabarbera.com
|
||||
*/
|
||||
|
||||
/**
|
||||
* Get all registered menus
|
||||
* @return array List of menus with slug and description
|
||||
*/
|
||||
function wp_api_v2_menus_get_all_menus () {
|
||||
$menus = [];
|
||||
foreach (get_registered_nav_menus() as $slug => $description) {
|
||||
$obj = new stdClass;
|
||||
$obj->slug = $slug;
|
||||
$obj->description = $description;
|
||||
$menus[] = $obj;
|
||||
}
|
||||
|
||||
return $menus;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get menu's data from his id
|
||||
* @param array $data WP REST API data variable
|
||||
* @return object Menu's data with his items
|
||||
*/
|
||||
function wp_api_v2_menus_get_menu_data ( $data ) {
|
||||
$menu = new stdClass;
|
||||
$menu->items = [];
|
||||
if ( ( $locations = get_nav_menu_locations() ) && isset( $locations[ $data['id'] ] ) ) {
|
||||
$menu = get_term( $locations[ $data['id'] ] );
|
||||
$menu->items = wp_get_nav_menu_items($menu->term_id);
|
||||
}
|
||||
return $menu;
|
||||
}
|
||||
|
||||
add_action( 'rest_api_init', function () {
|
||||
register_rest_route( 'menus/v1', '/menus', array(
|
||||
'methods' => 'GET',
|
||||
'callback' => 'wp_api_v2_menus_get_all_menus',
|
||||
) );
|
||||
|
||||
register_rest_route( 'menus/v1', '/menus/(?P<id>[a-zA-Z(-]+)', array(
|
||||
'methods' => 'GET',
|
||||
'callback' => 'wp_api_v2_menus_get_menu_data',
|
||||
) );
|
||||
} );
|
||||
Reference in New Issue
Block a user