-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwp-harden.php
68 lines (56 loc) · 1.78 KB
/
wp-harden.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
/*
Plugin Name: WP Harden
Plugin URI: https://sysadmin.lol
Description: Combines Several Plugins and disables unnecessary functions.
Tags: xml-rpc,rest, rest-api, api, json, disable, head, header, link, http
Author: Various Authors
Author URI: https://sysadmin.lol
Requires at least: 4.8
Tested up to: 5.5
Stable tag: 1.0
Version: 1.0
Requires PHP: 5.6.20
License: GPL v2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
*/
if (!defined('ABSPATH')) die();
/*
Disable REST API link in HTTP headers
Link: <https://example.com/wp-json/>; rel="https://api.w.org/"
*/
remove_action('template_redirect', 'rest_output_link_header', 11);
/*
Disable REST API links in HTML <head>
<link rel='https://api.w.org/' href='https://example.com/wp-json/' />
*/
remove_action('wp_head', 'rest_output_link_wp_head', 10);
remove_action('xmlrpc_rsd_apis', 'rest_output_rsd');
/*
Disable REST API
*/
add_filter('rest_authentication_errors', 'disable_wp_rest_api');
function disable_wp_rest_api($access) {
if (!is_user_logged_in()) {
$message = apply_filters('disable_wp_rest_api_error', __('REST API restricted to authenticated users.', 'disable-wp-rest-api'));
return new WP_Error('rest_login_required', $message, array('status' => rest_authorization_required_code()));
}
return $access;
}
/*
Disable XML-RPC
*/
add_filter( 'xmlrpc_enabled', '__return_false' );
/*
Remove WordPress Version From Head
*/
remove_action( 'wp_head', 'wp_generator' );
remove_action( 'wp_head', 'wlwmanifest_link' );
remove_action( 'wp_head', 'rsd_link' );
remove_action( 'wp_head', 'wp_shortlink_wp_head' );
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'wp_print_styles', 'print_emoji_styles' );
/*
Remove X-Pingback Header
*/
header_remove( 'X-Pingback' );