Passed
Push — master ( b44fdc...0d29c4 )
by Benjamin
02:28
created

API::check_permissions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 2
ccs 0
cts 0
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Custom routes and endpoints for the plugin.
4
 *
5
 * @package WPSiteMonitor
6
 * @link https://github.com/BWibrew/WP-Site-Monitor/
7
 * @author Benjamin Wibrew <[email protected]>
8
 * @since 1.0.0
9
 */
10
11
namespace WPSiteMonitor;
12
13
use WP_REST_Controller;
14
use WP_REST_Server;
15
16
/**
17
 * Class API
18
 *
19
 * @package WPSiteMonitor
20
 */
21
class API extends WP_REST_Controller {
22
23
	/**
24
	 * Register the routes for the objects of the controller.
25
	 *
26 1
	 * @since 1.0.0
27 1
	 */
28 1
	public function register_routes() {
29 1
		$version   = '1';
30
		$namespace = 'wp-site-monitor/v' . $version;
31 1
		$endpoint  = 'wp-version';
32 1
33
		register_rest_route(
34 1
			$namespace, '/' . $endpoint, array(
35 1
				array(
36 1
					'methods'             => WP_REST_Server::READABLE,
37 1
					'callback'            => array( $this, 'get_wp_version' ),
38 1
					'permission_callback' => array( $this, 'check_permissions' ),
39
				),
40 1
			)
41 1
		);
42
	}
43
44
	/**
45
	 * Get the current WordPress version number.
46
	 *
47
	 * @return string
48
	 * @since 1.0.0
49
	 */
50
	public function get_wp_version() {
51
		global $wp_version;
52
53
		return $wp_version;
54
	}
55
56
	/**
57
	 * Check if the authenticated user has permission to use an endpoint.
58
	 *
59
	 * @return boolean
60
	 * @since 1.0.0
61
	 */
62
	public function check_permissions() {
63
		return current_user_can( 'manage_options' );
64
	}
65
}
66