-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimple-wp-mods.php
322 lines (281 loc) · 8.24 KB
/
simple-wp-mods.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
<?php
/**
* Plugin Name: Simple Wp Mods
* Plugin URI: https://github.com/johnakos/simple-wp-mods
* Description: Simple WordPress plugin to set/remove/add settings/hooks, no UI for developers
* Author: John Kaziridis
* Author URI: https://github.com/johnakos/simple-wp-mods
* Text Domain: swpm
* Version: 1.1.1
*
* GitHub Plugin URI: johnakos/simple-wp-mods
* Primary Branch: main
*
* @package swpm
*/
/**
* Disable XML RPC for security.
*
* @link https://developer.wordpress.org/reference/hooks/xmlrpc_enabled/
* @since 1.0.0
*/
add_filter( 'xmlrpc_enabled', '__return_false' );
/**
* Remove WordPress version from head
*
* @link https://developer.wordpress.org/reference/functions/wp_generator/
* @since 1.0.0
*/
remove_action( 'wp_head', 'wp_generator' );
/**
* Remove shortlink from head
*
* @link https://developer.wordpress.org/reference/functions/wp_shortlink_wp_head/
* @since 1.0.0
*/
remove_action( 'wp_head', 'wp_shortlink_wp_head', 10 );
/**
* Remove shortlink Link: header from HTTP requests
*
* @link https://developer.wordpress.org/reference/functions/wp_shortlink_header/
* @since 1.0.0
*/
remove_action( 'template_redirect', 'wp_shortlink_header', 11 );
/**
* Remove RSD (Really Simple Discovery) link from head
*
* @link https://developer.wordpress.org/reference/functions/rsd_link/
* @since 1.0.0
*/
remove_action( 'wp_head', 'rsd_link' );
/**
* Remove RSS feed links from head
*
* @link https://developer.wordpress.org/reference/functions/feed_links/
* @since 1.0.0
*/
remove_action( 'wp_head', 'feed_links', 2 );
/**
* Remove all extra RSS feed links from head
*
* @link https://developer.wordpress.org/reference/functions/feed_links_extra/
* @since 1.0.0
*/
remove_action( 'wp_head', 'feed_links_extra', 3 );
/**
* Remove comments feed
*
* @link https://developer.wordpress.org/reference/hooks/feed_links_show_comments_feed/
* @since 1.0.0
*/
add_filter( 'feed_links_show_comments_feed', '__return_false' );
/**
* Redirect all feeds to home page.
*
* @since 1.0.0
*/
function swpm_disable_feeds() {
return wp_safe_redirect( site_url() );
exit;
}
/**
* Redirect all feeds to home url
*
* @link https://developer.wordpress.org/reference/hooks/do_feed_feed/
* @since 1.0.0
*/
add_action( 'do_feed', 'swpm_disable_feeds', 1 );
add_action( 'do_feed_rdf', 'swpm_disable_feeds', 1 );
add_action( 'do_feed_rss', 'swpm_disable_feeds', 1 );
add_action( 'do_feed_rss2', 'swpm_disable_feeds', 1 );
add_action( 'do_feed_atom', 'swpm_disable_feeds', 1 );
// Redirect comment feeds.
add_action( 'do_feed_rss2_comments', 'swpm_disable_feeds', 1 );
add_action( 'do_feed_atom_comments', 'swpm_disable_feeds', 1 );
/**
* Remove Windows Live Writer manifest (wlwmanifest.xml) file link from head
*
* @link https://developer.wordpress.org/reference/functions/wlwmanifest_link/
* @since 1.0.0
*/
remove_action( 'wp_head', 'wlwmanifest_link' );
/**
* Remove prefetch for s.w.org from head
*
* @link https://developer.wordpress.org/reference/functions/wp_resource_hints/
* @since 1.0.0
*/
remove_action( 'wp_head', 'wp_resource_hints', 2 );
/**
* Remove relational links for posts.
*
* @link https://developer.wordpress.org/reference/functions/adjacent_posts_rel_link_wp_head/
* @since 1.0.0
*/
remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0 );
/**
* Remove REST API URL output from head.
*
* @link https://developer.wordpress.org/reference/functions/rest_output_link_wp_head/
* @since 1.0.0
*/
remove_action( 'wp_head', 'rest_output_link_wp_head', 10 );
/**
* Remove REST API URL from WP RSD endpoint
*
* @link https://developer.wordpress.org/reference/functions/rest_output_rsd/
* @since 1.0.0
*/
remove_action( 'xmlrpc_rsd_apis', 'rest_output_rsd' );
/**
* Remove REST API URL Link: header from HTTP requests
*
* @link https://developer.wordpress.org/reference/functions/rest_output_link_header/
* @since 1.0.0
*/
remove_action( 'template_redirect', 'rest_output_link_header', 11 );
/**
* Remove script link tag for emoji from head
*
* @link https://developer.wordpress.org/reference/functions/print_emoji_detection_script/
* @since 1.0.0
*/
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
/**
* Remove script link tag for emoji from head in admin area
*
* @link https://developer.wordpress.org/reference/functions/print_emoji_detection_script/
* @since 1.0.0
*/
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
/**
* Remove style link tag for emoji from head
*
* @link https://developer.wordpress.org/reference/functions/print_emoji_styles/
* @since 1.0.0
*/
remove_action( 'wp_print_styles', 'print_emoji_styles' );
/**
* Remove style link tag for emoji from head in admin area
*
* @link https://developer.wordpress.org/reference/functions/print_emoji_styles/
* @since 1.0.0
*/
remove_action( 'admin_print_styles', 'print_emoji_styles' );
/**
* Remove emoji from comments & feed
*
* @link https://developer.wordpress.org/reference/functions/wp_staticize_emoji/
* @since 1.0.0
*/
remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );
/**
* Remove emojis URL
*
* @link https://developer.wordpress.org/reference/hooks/emoji_svg_url/
* @since 1.0.0
*/
add_filter( 'emoji_svg_url', '__return_false' );
/**
* Remove emoji for emails
*
* @link https://developer.wordpress.org/reference/functions/wp_staticize_emoji_for_email/
* @since 1.0.0
*/
// remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
/**
* Remove oEmbeds
*
* @link https://developer.wordpress.org/reference/functions/wp_oembed_add_discovery_links/
* @link https://developer.wordpress.org/reference/functions/wp_oembed_add_host_js/
* @since 1.0.0
*/
remove_action( 'wp_head', 'wp_oembed_add_discovery_links', 10 );
remove_action( 'wp_head', 'wp_oembed_add_host_js' );
/**
* Remove default galllery css
*
* @link https://developer.wordpress.org/reference/hooks/use_default_gallery_style/
* @since 1.0.0
*/
add_filter( 'use_default_gallery_style', '__return_false' );
/**
* Remove Gutenberg's front-end block styles.
*
* @since 1.0.0
*/
function swpm_disable_gutenberg_style_block() {
wp_deregister_style( 'wp-block-library' );
}
add_action( 'wp_enqueue_scripts', 'swpm_disable_gutenberg_style_block' );
/**
* Disable X-Pingback header from HTTP requests
*
* @param array $headers
* @return array
*
* @since 1.0.0
*/
function swpm_disable_x_pingback( $headers ) {
unset( $headers['X-Pingback'] );
return $headers;
}
add_filter( 'wp_headers', 'swpm_disable_x_pingback' );
/**
* Disable default users API endpoints for security.
*
* @param array $endpoints
* @return array
*
* @link https://developer.wordpress.org/reference/hooks/rest_endpoints/
* @link https://www.wp-tweaks.com/hackers-can-find-your-wordpress-username/
* @since 1.0.0
*/
function swpm_disable_users_rest_endpoints( $endpoints ) {
if ( !is_user_logged_in() ) {
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;
}
add_filter( 'rest_endpoints', 'swpm_disable_users_rest_endpoints' );
/**
* Update login page image link
*
* @link https://developer.wordpress.org/reference/hooks/login_headerurl/
* @since 1.0.0
*/
function swpm_login_url() {
return home_url();
}
add_filter( 'login_headerurl', 'swpm_login_url' );
/**
* Remove contributor & subscriber roles.
*
* @link https://developer.wordpress.org/reference/hooks/init/
* @since 1.0.0
*/
function swpm_remove_roles() {
remove_role( 'contributor' );
remove_role( 'subscriber' );
}
add_action( 'init', 'swpm_remove_roles' );
/**
* Set the number of revisions to keep in the database
*
* @param int $num
* @return int
*
* @link https://wordpress.org/support/article/revisions/#revision-options
* @link https://developer.wordpress.org/reference/hooks/wp_revisions_to_keep/
* @since 1.0.0
*/
function swpm_set_revisions_number( $num ) {
return $num = 3;
}
add_filter( 'wp_revisions_to_keep', 'swpm_set_revisions_number', 10 );