-
Notifications
You must be signed in to change notification settings - Fork 101
/
plugin-fixes.php
67 lines (60 loc) · 2.3 KB
/
plugin-fixes.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
<?php
/*
Plugin Name: VIP Go Plugin Compat
Description: A collection of compatibility fixes to make sure various plugins run smoothly on VIP Go.
Author: Automattic
Version: 1.0
License: GPL version 2 or later - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*/
/**
* Contact Form 7 (https://en-ca.wordpress.org/plugins/contact-form-7/)
*
* The plugin attempts to write to a `wp-content` path which will fail.
* These files are transient and only meant to be included as attachment,
* so let's just tell CF7 to put them in `/tmp/`.
*/
if ( ! defined( 'WPCF7_UPLOADS_TMP_DIR' ) ) {
define( 'WPCF7_UPLOADS_TMP_DIR', get_temp_dir() );
}
/**
* Woocommerce log location
*
* @constant WC_LOG_DIR Write Woocommerce logs to the /tmp directory to prevent
* them from being copied to the Files Service.
*/
if ( ! defined( 'WC_LOG_DIR' ) ) {
define( 'WC_LOG_DIR', '/tmp' );
}
/**
* AMP for WordPress (https://github.com/ampproject/amp-wp)
* Make sure the `amp` query var has an explicit value.
* Avoids issues when filtering the deprecated `query_string` hook.
*
* Copy of upstream fix: https://github.com/Automattic/amp-wp/pull/910
*/
function vip_go_amp_force_query_var_value( $query_vars ) {
// Don't bother if AMP is not active
if ( ! defined( 'AMP_QUERY_VAR' ) ) {
return $query_vars;
}
if ( isset( $query_vars[ AMP_QUERY_VAR ] ) ) {
if ( '' === $query_vars[ AMP_QUERY_VAR ] ) {
$query_vars[ AMP_QUERY_VAR ] = 1;
} else if ( '1' !== $query_vars[ AMP_QUERY_VAR ] && 1 !== $query_vars[ AMP_QUERY_VAR ] ) { // Allow for some fuzziness on string/integer type matching.
global $wp_rewrite;
// If there is something after /amp/, pretend we didn't hit that rewrite rule.
if ( $wp_rewrite->use_trailing_slashes && '' !== $query_vars[ AMP_QUERY_VAR ] ) {
// Check for extra-long slugs, which will truncate and remove the /amp/* part.
if ( strlen( $query_vars['name'] ) > 190 ) {
// Give WP_Query an improbable string to get a 404.
$query_vars['name'] = substr( $query_vars['name'], 0, - 20 ) . substr( md5( $query_vars['name'] ), 0, 20 );
} else {
$query_vars['name'] = $query_vars['name'] . "/amp/" . $query_vars[ AMP_QUERY_VAR ];
}
unset( $query_vars[ AMP_QUERY_VAR ] );
}
}
}
return $query_vars;
}
add_filter( 'request', 'vip_go_amp_force_query_var_value', 9, 1 );