Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
76.92% covered (warning)
76.92%
10 / 13
50.00% covered (danger)
50.00%
2 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
VideoPress_Rest_Api_V1_Site
76.92% covered (warning)
76.92%
10 / 13
50.00% covered (danger)
50.00%
2 / 4
4.20
0.00% covered (danger)
0.00%
0 / 1
 init
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 register_rest_endpoints
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
1
 permissions_callback
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 get_site_info
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2/**
3 * VideoPress Site Info Endpoint
4 *
5 * @package automattic/jetpack-videopress
6 */
7
8namespace Automattic\Jetpack\VideoPress;
9
10use WP_REST_Response;
11
12/**
13 * VideoPress rest api class for fetching site information
14 */
15class VideoPress_Rest_Api_V1_Site {
16    /**
17     * Initializes the endpoints
18     *
19     * @return void
20     */
21    public static function init() {
22        add_action( 'rest_api_init', array( static::class, 'register_rest_endpoints' ) );
23    }
24
25    /**
26     * Register the REST API routes.
27     *
28     * @return void
29     */
30    public static function register_rest_endpoints() {
31        register_rest_route(
32            'videopress/v1',
33            'site',
34            array(
35                'methods'             => \WP_REST_Server::READABLE,
36                'callback'            => static::class . '::get_site_info',
37                'permission_callback' => static::class . '::permissions_callback',
38            )
39        );
40    }
41
42    /**
43     * Checks wether the user have permissions to see the site info
44     *
45     * @return boolean
46     */
47    public static function permissions_callback() {
48        return current_user_can( 'read' ); // TODO: confirm this
49    }
50
51    /**
52     * Returns all the site information usually provided by Jetpack, without relying on Jetpack
53     *
54     * @return WP_Rest_Response The response object.
55     */
56    public static function get_site_info() {
57        $data = Site::get_site_info();
58        return rest_ensure_response( $data );
59    }
60}