forked from unfulvio/wp-api-menus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wp-api-menus.php
63 lines (55 loc) · 1.8 KB
/
wp-api-menus.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
/**
* Plugin Name: WP REST API Menus
* Plugin URI: https://github.com/nekojira/wp-api-menus
* Description: Extends WP API with WordPress menu routes.
*
* Version: 1.2.1
*
* Author: Fulvio Notarstefano
* Author URI: https://github.com/nekojira
*
* Text Domain: wp-api-menus
*
* @package WP_API_Menus
*/
/**
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2 or, at
* your discretion, any later version, as published by the Free
* Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
// WP API v1.
include_once 'includes/wp-api-menus-v1.php';
// WP API v2.
include_once 'includes/wp-api-menus-v2.php';
if ( ! function_exists ( 'wp_rest_menus_init' ) ) :
/**
* Init JSON REST API Menu routes.
*
* @since 1.0.0
*/
function wp_rest_menus_init() {
if ( ! defined( 'JSON_API_VERSION' ) &&
! in_array( 'json-rest-api/plugin.php', get_option( 'active_plugins' ) ) ) {
$class = new WP_REST_Menus();
add_filter( 'rest_api_init', array( $class, 'register_routes' ) );
} else {
$class = new WP_JSON_Menus();
add_filter( 'json_endpoints', array( $class, 'register_routes' ) );
}
}
add_action( 'init', 'wp_rest_menus_init' );
endif;