forked from Automattic/vip-go-mu-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path000-vip-init.php
152 lines (124 loc) · 5.55 KB
/
000-vip-init.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
<?php
/**
* Plugin Name: VIP Init
* Description: Initializes critical elements of the VIP environment.
* Author: Automattic
* License: GPL version 2 or later - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*
* Remember vip-init.php? This is like that, but better!
*/
/**
* By virtue of the filename, this file is included first of
* all the files in the VIP Go MU plugins directory. All
* VIP code should be initialised here, unless there's a
* good reason not to.
*/
// Execute the healthcheck as quickly as possible
if ( '/cache-healthcheck?' === $_SERVER['REQUEST_URI'] ) {
if ( function_exists( 'newrelic_end_transaction' ) ) {
// Discard the transaction (the `true` param)
// See: https://docs.newrelic.com/docs/agents/php-agent/configuration/php-agent-api#api-end-txn
newrelic_end_transaction( true );
}
http_response_code( 200 );
die( 'ok' );
}
// Sites can be blocked for various reasons - usually maintenance, so exit
// early if the constant has been set (defined by VIP Go in config/wp-config.php)
if ( defined( 'WPCOM_VIP_SITE_MAINTENANCE_MODE' ) && WPCOM_VIP_SITE_MAINTENANCE_MODE ) {
// WP CLI is allowed, but disable cron
if ( defined( 'WP_CLI' ) && WP_CLI ) {
add_filter( 'pre_option_a8c_cron_control_disable_run', function() {
return 1;
}, 9999 );
} else {
http_response_code( 503 );
header( 'X-VIP-Go-Maintenance: true' );
echo file_get_contents( __DIR__ . '/errors/site-maintenance.html' );
exit;
}
}
if ( file_exists( __DIR__ . '/.secrets/vip-secrets.php' ) ) {
require __DIR__ . '/.secrets/vip-secrets.php';
}
if ( ! defined( 'A8C_PROXIED_REQUEST' ) ) {
/**
* @var constant A8C_PROXIED_REQUEST Set to true if the current request is made via the Automattic proxy, which is only available to Automatticians.
*/
define( 'A8C_PROXIED_REQUEST', false );
}
if ( ! defined( 'VIP_GO_ENV' ) ) {
/**
* @constant VIP_GO_ENV The name of the current VIP Go environment. Falls back to `false`.
*/
define( 'VIP_GO_ENV', false );
}
// On VIP Go environments this will already be set to true in wp-config.php
// Default to false for other environments, e.g. local development
if ( ! defined( 'WPCOM_IS_VIP_ENV' ) ) {
define( 'WPCOM_IS_VIP_ENV', false );
}
define( 'WPCOM_SANDBOXED', false !== strpos( gethostname(), '_web_dev_' ) );
define( 'VIP_GO_IS_CLI_CONTAINER', false !== strpos( gethostname(), '_wpcli_' ) );
// Used to verify emails sent via our SMTP servers
if ( ! defined( 'WPCOM_VIP_MAIL_TRACKING_KEY' ) ) {
define( 'WPCOM_VIP_MAIL_TRACKING_KEY', false );
}
// Define constants for custom VIP Go paths
define( 'WPCOM_VIP_CLIENT_MU_PLUGIN_DIR', WP_CONTENT_DIR . '/client-mu-plugins' );
define( 'WPCOM_VIP_PRIVATE_DIR', WPCOM_SANDBOXED || VIP_GO_IS_CLI_CONTAINER ? '/chroot/private' : '/private' );
// Define these values just in case
defined( 'WPCOM_VIP_MACHINE_USER_LOGIN' ) or define( 'WPCOM_VIP_MACHINE_USER_LOGIN', 'vip' );
defined( 'WPCOM_VIP_MACHINE_USER_NAME' ) or define( 'WPCOM_VIP_MACHINE_USER_NAME', 'VIP' );
defined( 'WPCOM_VIP_MACHINE_USER_EMAIL' ) or define( 'WPCOM_VIP_MACHINE_USER_EMAIL', '[email protected]' );
defined( 'WPCOM_VIP_MACHINE_USER_ROLE' ) or define( 'WPCOM_VIP_MACHINE_USER_ROLE', 'administrator' );
// Support a limited number of additional "Internal Events" in Cron Control.
// These events run regardless of the number of pending events, and they cannot be deleted.
define( 'CRON_CONTROL_ADDITIONAL_INTERNAL_EVENTS', array(
array(
'schedule' => 'hourly',
'action' => 'wpcom_vip_support_remove_user_via_cron', // Automattic\VIP\Support_User\User::CRON_ACTION
'callback' => array( 'Automattic\VIP\Support_User\User', 'do_cron_cleanup' ),
),
) );
// Interaction with the filesystem will always be direct.
// Avoids issues with `get_filesystem_method` which attempts to write to `WP_CONTENT_DIR` and fails.
define( 'FS_METHOD', 'direct' );
if ( WPCOM_SANDBOXED ) {
require __DIR__ . '/vip-helpers/sandbox.php';
}
// Debugging Tools
require_once( __DIR__ . '/000-debug/0-load.php' );
// Load our development and environment helpers
require_once( __DIR__ . '/vip-helpers/vip-utils.php' );
require_once( __DIR__ . '/vip-helpers/vip-newrelic.php' );
require_once( __DIR__ . '/vip-helpers/vip-caching.php' );
require_once( __DIR__ . '/vip-helpers/vip-roles.php' );
require_once( __DIR__ . '/vip-helpers/vip-permastructs.php' );
require_once( __DIR__ . '/vip-helpers/vip-mods.php' );
require_once( __DIR__ . '/vip-helpers/vip-media.php' );
require_once( __DIR__ . '/vip-helpers/vip-elasticsearch.php' );
require_once( __DIR__ . '/vip-helpers/vip-stats.php' );
require_once( __DIR__ . '/vip-helpers/vip-deprecated.php' );
require_once( __DIR__ . '/vip-helpers/vip-syndication-cache.php' );
require_once( __DIR__ . '/vip-helpers/vip-migrations.php' );
//enabled on selected sites for now
if ( true === defined( 'WPCOM_VIP_CLEAN_TERM_CACHE' ) && true === constant( 'WPCOM_VIP_CLEAN_TERM_CACHE' ) ) {
require_once dirname( __FILE__ ) . '/vip-helpers/vip-clean-term-cache.php';
}
// Load WP_CLI helpers
if ( defined( 'WP_CLI' ) && WP_CLI ) {
require_once( __DIR__ . '/vip-helpers/vip-wp-cli.php' );
}
// Add custom header for VIP
add_filter( 'wp_headers', function( $headers ) {
$headers['X-hacker'] = 'If you\'re reading this, you should visit automattic.com/jobs and apply to join the fun, mention this header.';
$headers['X-Powered-By'] = 'WordPress.com VIP <https://vip.wordpress.com>';
// All non-production domains should not be indexed.
// This should not apply only to *.vip-go.co
if ( 'production' !== VIP_GO_ENV ) {
$headers['X-Robots-Tag'] = 'noindex, nofollow';
}
return $headers;
} );
do_action( 'vip_loaded' );