for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* Custom routes and endpoints for the plugin.
*
* @package WPSiteMonitor
* @link https://github.com/BWibrew/WP-Site-Monitor/
* @author Benjamin Wibrew <[email protected]>
* @since 1.0.0
*/
namespace WPSiteMonitor;
use WP_REST_Controller;
use WP_REST_Server;
* Class API
class API extends WP_REST_Controller {
* Register the routes for the objects of the controller.
public function register_routes() {
$version = '1';
$namespace = 'wp-site-monitor/v' . $version;
$endpoint = 'wp-version';
register_rest_route(
$namespace, '/' . $endpoint, array(
array(
'methods' => WP_REST_Server::READABLE,
'callback' => array( $this, 'get_wp_version' ),
'permission_callback' => array( $this, 'check_permissions' ),
),
)
);
}
* Get the current WordPress version number.
* @return string
public function get_wp_version() {
global $wp_version;
return $wp_version;
* Check if the authenticated user has permission to use an endpoint.
* @return boolean
public function check_permissions() {
return current_user_can( 'manage_options' );