PageRenderTime 22ms CodeModel.GetById 14ms app.highlight 4ms RepoModel.GetById 2ms app.codeStats 0ms

/wp-content/plugins/wordpress-seo/admin/endpoints/class-endpoint-statistics.php

https://bitbucket.org/carloskikea/helpet
PHP | 56 lines | 26 code | 7 blank | 23 comment | 0 complexity | 54690f765415568ecc2ad6303bd7ee29 MD5 | raw file
 1<?php
 2/**
 3 * WPSEO plugin file.
 4 *
 5 * @package WPSEO\Admin\Statistics
 6 */
 7
 8/**
 9 * Represents an implementation of the WPSEO_Endpoint interface to register one or multiple endpoints.
10 */
11class WPSEO_Endpoint_Statistics implements WPSEO_Endpoint {
12
13	const REST_NAMESPACE = 'yoast/v1';
14	const ENDPOINT_RETRIEVE = 'statistics';
15
16	const CAPABILITY_RETRIEVE = 'read';
17
18	/** @var WPSEO_Statistics_Service Service to use */
19	protected $service;
20
21	/**
22	 * Constructs the WPSEO_Endpoint_Statistics class and sets the service to use.
23	 *
24	 * @param WPSEO_Statistics_Service $service Service to use.
25	 */
26	public function __construct( WPSEO_Statistics_Service $service ) {
27		$this->service = $service;
28	}
29
30	/**
31	 * Registers the REST routes that are available on the endpoint.
32	 */
33	public function register() {
34		// Register fetch config.
35		register_rest_route( self::REST_NAMESPACE, self::ENDPOINT_RETRIEVE, array(
36			'methods'             => 'GET',
37			'callback'            => array(
38				$this->service,
39				'get_statistics',
40			),
41			'permission_callback' => array(
42				$this,
43				'can_retrieve_data',
44			),
45		) );
46	}
47
48	/**
49	 * Determines whether or not data can be retrieved for the registered endpoints.
50	 *
51	 * @return bool Whether or not data can be retrieved.
52	 */
53	public function can_retrieve_data() {
54		return current_user_can( self::CAPABILITY_RETRIEVE );
55	}
56}