PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 18.1
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v18.1
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
wordpress-seo / admin / endpoints / class-endpoint-statistics.php

class-endpoint-statistics.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 18.1, at admin/endpoints/class-endpoint-statistics.php

72 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 */
11 class WPSEO_Endpoint_Statistics implements WPSEO_Endpoint {
12
13 /**
14 * The namespace of the REST route.
15 *
16 * @var string
17 */
18 const REST_NAMESPACE = 'yoast/v1';
19
20 /**
21 * The route of the statistics endpoint.
22 *
23 * @var string
24 */
25 const ENDPOINT_RETRIEVE = 'statistics';
26
27 /**
28 * The name of the capability needed to retrieve data using the endpoints.
29 *
30 * @var string
31 */
32 const CAPABILITY_RETRIEVE = 'read';
33
34 /**
35 * Service to use.
36 *
37 * @var WPSEO_Statistics_Service
38 */
39 protected $service;
40
41 /**
42 * Constructs the WPSEO_Endpoint_Statistics class and sets the service to use.
43 *
44 * @param WPSEO_Statistics_Service $service Service to use.
45 */
46 public function __construct( WPSEO_Statistics_Service $service ) {
47 $this->service = $service;
48 }
49
50 /**
51 * Registers the REST routes that are available on the endpoint.
52 */
53 public function register() {
54 // Register fetch config.
55 $route_args = [
56 'methods' => 'GET',
57 'callback' => [ $this->service, 'get_statistics' ],
58 'permission_callback' => [ $this, 'can_retrieve_data' ],
59 ];
60 register_rest_route( self::REST_NAMESPACE, self::ENDPOINT_RETRIEVE, $route_args );
61 }
62
63 /**
64 * Determines whether or not data can be retrieved for the registered endpoints.
65 *
66 * @return bool Whether or not data can be retrieved.
67 */
68 public function can_retrieve_data() {
69 return current_user_can( self::CAPABILITY_RETRIEVE );
70 }
71 }
72