class-premium-link-suggestions-endpoint.php
1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
/**
* @package WPSEO\Premium
*/
/**
* Registers the endpoint for the prominent words to WordPress.
*/
class WPSEO_Premium_Link_Suggestions_Endpoint implements WPSEO_WordPress_Integration {
const REST_NAMESPACE = 'yoast/v1';
const ENDPOINT_QUERY = 'link_suggestions';
const CAPABILITY_RETRIEVE = 'manage_categories';
/**
* @var WPSEO_Premium_Link_Suggestions_Service
*/
protected $service;
/**
* WPSEO_Premium_Prominent_Words_Endpoint constructor.
*
* @param WPSEO_Premium_Link_Suggestions_Service $service The service to handle the requests to the endpoint.
*/
public function __construct( WPSEO_Premium_Link_Suggestions_Service $service ) {
$this->service = $service;
}
/**
* Registers all hooks to WordPress
*/
public function register_hooks() {
add_action( 'rest_api_init', array( $this, 'register' ) );
}
/**
* Register the REST endpoint to WordPress.
*/
public function register() {
register_rest_route( self::REST_NAMESPACE, self::ENDPOINT_QUERY, array(
'methods' => 'GET',
'args' => array(
'prominent_words' => array(
'required' => true,
'type' => 'array',
'description' => 'IDs of the prominent words we want link suggestions based on',
'items' => array(
'type' => 'int',
),
),
),
'callback' => array(
$this->service,
'query',
),
'permission_callback' => array(
$this,
'can_retrieve_data',
),
) );
}
/**
* Determines if the current user is allowed to use this endpoint.
*
* @return bool
*/
public function can_retrieve_data() {
return current_user_can( self::CAPABILITY_RETRIEVE );
}
}