WPSEO_Configuration_Endpoint

Class WPSEO_Configuration_Endpoint.

Defined (1)

The class is defined in the following location(s).

/admin/config-ui/class-configuration-endpoint.php  
  1. class WPSEO_Configuration_Endpoint { 
  2.  
  3. const REST_NAMESPACE = 'yoast/v1'; 
  4. const ENDPOINT_RETRIEVE = 'configurator'; 
  5. const ENDPOINT_STORE = 'configurator'; 
  6.  
  7. const CAPABILITY_RETRIEVE = 'manage_options'; 
  8. const CAPABILITY_STORE = 'manage_options'; 
  9.  
  10. /** @var WPSEO_Configuration_Service Service to use */ 
  11. protected $service; 
  12.  
  13. /** 
  14. * Sets the service to use. 
  15. * @param WPSEO_Configuration_Service $service Service to use. 
  16. */ 
  17. public function set_service( WPSEO_Configuration_Service $service ) { 
  18. $this->service = $service; 
  19.  
  20. /** 
  21. * Register REST routes. 
  22. */ 
  23. public function register() { 
  24. // Register fetch config. 
  25. register_rest_route( self::REST_NAMESPACE, self::ENDPOINT_RETRIEVE, array( 
  26. 'methods' => 'GET',  
  27. 'callback' => array( 
  28. $this->service,  
  29. 'get_configuration',  
  30. ),  
  31. 'permission_callback' => array( 
  32. $this,  
  33. 'can_retrieve_data',  
  34. ),  
  35. ) ); 
  36.  
  37. // Register save changes. 
  38. register_rest_route( self::REST_NAMESPACE, self::ENDPOINT_STORE, array( 
  39. 'methods' => 'POST',  
  40. 'callback' => array( 
  41. $this->service,  
  42. 'set_configuration',  
  43. ),  
  44. 'permission_callback' => array( 
  45. $this,  
  46. 'can_save_data',  
  47. ),  
  48. ) ); 
  49.  
  50. /** 
  51. * Permission callback implementation 
  52. * @return bool 
  53. */ 
  54. public function can_retrieve_data() { 
  55. return current_user_can( self::CAPABILITY_RETRIEVE ); 
  56.  
  57. /** 
  58. * Permission callback implementation 
  59. * @return bool 
  60. */ 
  61. public function can_save_data() { 
  62. return current_user_can( self::CAPABILITY_STORE );