-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathwp-api-menus.php
115 lines (106 loc) · 3.1 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
/**
* Plugin Name: WP REST API Menus
* Plugin URI: https://github.com/unfulvio/wp-api-menus
* Description: Extends WP API with WordPress menu routes.
* Version: 1.4.0
* Requires at least: 5.8
* Tested up to: 5.9.1
* Requires PHP: 5.6
* Author: Fulvio Notarstefano
* Author URI: https://github.com/unfulvio
* 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', array() ) )
) {
$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;
if ( ! function_exists( '_wp_rest_menus_doing_it_wrong' ) ) :
/**
* Mark a function as "deprecated" using doing_it_wrong().
*
* @param string $function
* @param string $route
* @param string $replacement
*
* @access private
* @since 1.4.0
* @uses _doing_it_wrong()
*/
function _wp_rest_menus_doing_it_wrong( $function, $route, $replacement ) {
if (
_wp_rest_menus_allow_legacy_menus() ||
is_wp_version_compatible( '5.9' ) && _wp_rest_menus_allow_legacy_menus()
) {
return;
}
_doing_it_wrong(
$function,
sprintf(
/* translators: 1: The REST API route namespace, 2: The plugin version. */
__( 'The REST API Menu route %1$s is "deprecated". Please use WordPres cores menu route replacement found in WP >= 5.9: %2$s' ),
sprintf('<code>%1$s%2$s</code>', WP_REST_Menus::get_plugin_namespace(), $route),
'<code>' . $replacement . '</code>'
),
'1.4.0'
);
}
endif;
if ( ! function_exists( '_wp_rest_menus_allow_legacy_menus' ) ) :
/**
* Allow legacy menus "filter".
*
* @return bool
* @since 1.4.0
* @access private
*/
function _wp_rest_menus_allow_legacy_menus() {
/**
* Allow legacy menus.
*
* @param bool $allow_legacy_menus
*
* @return bool
*/
return apply_filters( 'rest_menus_allow_legacy_menus', false ) === true;
}
endif;