forked from Automattic/vip-go-mu-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmisc.php
146 lines (127 loc) · 4.71 KB
/
misc.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
<?php
/*
Plugin Name: VIP Hosting Miscellaneous
Description: Handles CSS and JS concatenation, Nginx compatibility, SSL verification
Author: Automattic
Version: 1.1
License: GPL version 2 or later - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*/
add_filter( 'upload_mimes', function( $mimes ) {
unset( $mimes['flv'] );
return $mimes;
}, 99999 );
// Ensure we do not send the cache headers through to Varnish,
// so responses obey the cache settings we have configured.
function wpcom_vip_check_for_404_and_remove_cache_headers( $headers ) {
if ( is_404() ) {
unset( $headers['Expires'] );
unset( $headers['Cache-Control'] );
unset( $headers['Pragma'] );
}
return $headers;
}
add_filter( 'nocache_headers', 'wpcom_vip_check_for_404_and_remove_cache_headers' );
// Disable admin notice for jetpack_force_2fa
add_filter( 'jetpack_force_2fa_dependency_notice', '__return_false' );
// Cleaner permalink options
add_filter( 'got_url_rewrite', '__return_true' );
// Disable custom fields meta box dropdown (very slow)
add_filter( 'postmeta_form_keys', '__return_false' );
/**
* This function uses the VIP_VERIFY_STRING and VIP_VERIFY_PATH
* constants to respond with a verification string at a particular
* path. So if you have a VIP_VERIFY_STRING of `Hello` and a
* VIP_VERIFY_PATH of `whatever.html`, then the URL
* yourdomain.com/whatever.html will return `Hello`.
*
* We suggest adding these constants in your `vip-config.php`
*
* @return void
*/
function action_wpcom_vip_verify_string() {
if ( ! defined( 'VIP_VERIFY_PATH' ) || ! defined( 'VIP_VERIFY_STRING' ) ) {
return;
}
$verification_path = '/' . VIP_VERIFY_PATH;
if ( $verification_path === $_SERVER['REQUEST_URI'] ) {
status_header( 200 );
nocache_headers();
echo VIP_VERIFY_STRING;
exit;
}
}
add_action( 'parse_request', 'action_wpcom_vip_verify_string', 0 );
/**
* Disable New Relic browser monitoring on AMP pages, as the JS isn't AMP-compatible
*/
add_action( 'pre_amp_render_post', 'wpcom_vip_disable_new_relic_js' );
/**
* Fix a race condition in alloptions caching
*
* See https://core.trac.wordpress.org/ticket/31245
*/
function _wpcom_vip_maybe_clear_alloptions_cache( $option ) {
if ( ! wp_installing() ) {
$alloptions = wp_load_alloptions(); //alloptions should be cached at this point
if ( isset( $alloptions[ $option ] ) ) { //only if option is among alloptions
wp_cache_delete( 'alloptions', 'options' );
}
}
}
add_action( 'added_option', '_wpcom_vip_maybe_clear_alloptions_cache' );
add_action( 'updated_option', '_wpcom_vip_maybe_clear_alloptions_cache' );
add_action( 'deleted_option', '_wpcom_vip_maybe_clear_alloptions_cache' );
/**
* On Go, all API usage must be over HTTPS for security
*
* Filter `rest_url` to always return the https:// version
*
* This is disabled for local development, but be aware
* that HTTPS is enforced at the web server level in production,
* meaning non-HTTPS API calls will result in a 406 error.
*/
if ( defined( 'WPCOM_IS_VIP_ENV' ) && true === WPCOM_IS_VIP_ENV ) {
add_filter( 'rest_url', '_vip_filter_rest_url_for_ssl' );
}
function _vip_filter_rest_url_for_ssl( $url ) {
$url = set_url_scheme( $url, 'https' );
return $url;
}
function wpcom_vip_query_log() {
if ( '/cache-healthcheck?' === $_SERVER['REQUEST_URI'] ) {
return;
}
$num_queries = count( $GLOBALS['wpdb']->queries );
error_log( 'WPCOM VIP Query Log for ' . $_SERVER['REQUEST_URI'] . ' (action: ' . $_REQUEST['action'] . ') ' . $num_queries . 'q: ' . PHP_EOL . print_r( $GLOBALS['wpdb']->queries, true ) );
}
/**
* Think carefully before enabling this on a production site. Then
* if you still want to do it, think again, and talk it over with
* someone else.
*/
if ( defined( 'WPCOM_VIP_QUERY_LOG' ) && WPCOM_VIP_QUERY_LOG ) {
if ( ! defined( 'SAVEQUERIES' ) || ! SAVEQUERIES ) {
define( 'SAVEQUERIES', true );
}
// For hyperdb, which doesn't use SAVEQUERIES
$GLOBALS['wpdb']->save_queries = SAVEQUERIES;
add_action( 'shutdown', 'wpcom_vip_query_log' );
}
/**
* Improve perfomance of the `_WP_Editors::wp_link_query` method
*
* The WordPress core is currently not setting `no_found_rows` inside the `_WP_Editors::wp_link_query`
* See https://core.trac.wordpress.org/ticket/38784
*
* Since the `_WP_Editors::wp_link_query` method is not using the `found_posts` nor `max_num_pages`
* properties of `WP_Query` class, the `SQL_CALC_FOUND_ROWS` in produced SQL query is extra and
* useless.
*
*/
function wpcom_vip_wp_link_query_args( $query ) {
//Since the WP_Query is not checking the $found_posts nor $max_num_pages properties
//we don't need to know the total number of matching posts in the database
$query['no_found_rows'] = true;
return $query;
}
add_filter( 'wp_link_query_args', 'wpcom_vip_wp_link_query_args', 10, 1 );