Completed
Push — master ( 0e4fe9...f5c78e )
by Fulvio
02:21
created

wp-api-menus.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 49 and the first side effect is on line 60.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

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