/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. * Represents an implementation of the WPSEO_Endpoint interface to register one or multiple endpoints.
  9. */
  10. class WPSEO_Endpoint_Statistics implements WPSEO_Endpoint {
  11. const REST_NAMESPACE = 'yoast/v1';
  12. const ENDPOINT_RETRIEVE = 'statistics';
  13. const CAPABILITY_RETRIEVE = 'read';
  14. /** @var WPSEO_Statistics_Service Service to use */
  15. protected $service;
  16. /**
  17. * Constructs the WPSEO_Endpoint_Statistics class and sets the service to use.
  18. *
  19. * @param WPSEO_Statistics_Service $service Service to use.
  20. */
  21. public function __construct( WPSEO_Statistics_Service $service ) {
  22. $this->service = $service;
  23. }
  24. /**
  25. * Registers the REST routes that are available on the endpoint.
  26. */
  27. public function register() {
  28. // Register fetch config.
  29. register_rest_route( self::REST_NAMESPACE, self::ENDPOINT_RETRIEVE, array(
  30. 'methods' => 'GET',
  31. 'callback' => array(
  32. $this->service,
  33. 'get_statistics',
  34. ),
  35. 'permission_callback' => array(
  36. $this,
  37. 'can_retrieve_data',
  38. ),
  39. ) );
  40. }
  41. /**
  42. * Determines whether or not data can be retrieved for the registered endpoints.
  43. *
  44. * @return bool Whether or not data can be retrieved.
  45. */
  46. public function can_retrieve_data() {
  47. return current_user_can( self::CAPABILITY_RETRIEVE );
  48. }
  49. }