-
Notifications
You must be signed in to change notification settings - Fork 0
/
smntcs-disable-rest-api-endpoints.php
54 lines (47 loc) · 1.4 KB
/
smntcs-disable-rest-api-endpoints.php
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
<?php
/**
* Plugin Name: SMNTCS Disable REST API User Endpoints
* Plugin URI: https://github.com/nielslange/smntcs-disable-rest-api-user-endpoints
* Description: Disable the REST API user endpoints due to security reasons.
* Author: Niels Lange
* Author URI: https://nielslange.de
* Text Domain: smntcs-disable-rest-api-user-endpoints
* Version: 2.3
* Requires PHP: 5.6
* Requires at least: 5.5
* License: GPL v2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
*
* @package SMNTCS_Disable_REST_API_User_Endpoints
*/
defined( 'ABSPATH' ) || exit;
/**
* Disable REST API user endpoints.
*
* @since 1.0.0
*/
class SMNTCS_Disable_REST_API_User_Endpoints {
/**
* Constructor function.
*/
public function __construct() {
add_filter( 'rest_endpoints', array( $this, 'smntcs_rest_endpoints' ) );
}
/**
* Disable REST API user endpoints.
*
* @param array $endpoints The original endpoints.
* @return array The updated endpoints.
* @since 1.0.0
*/
public function smntcs_rest_endpoints( $endpoints ) {
if ( isset( $endpoints['/wp/v2/users'] ) ) {
unset( $endpoints['/wp/v2/users'] );
}
if ( isset( $endpoints['/wp/v2/users/(?P<id>[\d]+)'] ) ) {
unset( $endpoints['/wp/v2/users/(?P<id>[\d]+)'] );
}
return $endpoints;
}
}
new SMNTCS_Disable_REST_API_User_Endpoints();