-
Notifications
You must be signed in to change notification settings - Fork 100
/
001-core.php
166 lines (139 loc) · 5 KB
/
001-core.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
<?php
/**
* Plugin Name: VIP Go Core Modifications
* Description: Changes to make WordPress core work better on VIP Go.
* Author: Automattic
* License: GPL version 2 or later - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*/
require_once __DIR__ . '/001-core/privacy.php';
if ( file_exists( __DIR__ . '/001-core/options-api.php' ) ) {
require_once __DIR__ . '/001-core/options-api.php';
}
/**
* Disable current theme validation
*
* By default, WordPress falls back to a default theme if it can't find
* the active theme. This is undesirable because it requires manually
* re-activating the correct theme and can lead to data loss in the form
* of deactivated widgets and menu location assignments.
*/
add_filter( 'validate_current_theme', '__return_false' );
if ( false !== WPCOM_IS_VIP_ENV ) {
add_action( 'muplugins_loaded', 'wpcom_vip_init_core_restrictions' );
}
function wpcom_vip_init_core_restrictions() {
add_action( 'admin_init', 'wpcom_vip_disable_core_update_nag' );
add_filter( 'map_meta_cap', 'wpcom_vip_disable_core_update_cap', 100, 2 );
wpcom_vip_disable_temp_backups_cleanup();
}
function wpcom_vip_disable_core_update_nag() {
remove_action( 'admin_notices', 'update_nag', 3 );
remove_action( 'network_admin_notices', 'update_nag', 3 );
}
/**
* Disables action introduced in WordPress 6.3 which, when triggered, will lead
* to another action being set up which will attempt to clean up a temporary
* backup directory used during plugin/theme updates. The clean up logic will
* fail on the WordPress VIP platform and is not necessary.
*/
function wpcom_vip_disable_temp_backups_cleanup() {
remove_action( 'wp_delete_temp_updater_backups', 'wp_delete_all_temp_backups' );
}
function wpcom_vip_disable_core_update_cap( $caps, $cap ) {
if ( 'update_core' === $cap ) {
$caps = [ 'do_not_allow' ];
}
return $caps;
}
/**
* Disable tests in the Site Health (AKA site status) tool page
*
* By default, WordPress runs a series of tests on the Site Health tool
* page in wp-admin. This disables all irrelevant or unnecessary tests.
*/
function vip_disable_unnecessary_site_health_tests( $tests ) {
// Disable "Background Updates" test.
// WordPress updates are managed by the VIP team.
unset( $tests['async']['background_updates'] );
// Disable "WP-Content Writable" test.
// Code updates are managed in GitHub.
unset( $tests['direct']['update_temp_backup_writable'] );
// Disable "Available disk space" test.
// We manage the disk space, test gives bogus results.
unset( $tests['direct']['available_updates_disk_space'] );
return $tests;
}
add_filter( 'site_status_tests', 'vip_disable_unnecessary_site_health_tests' );
/**
* Filter PHP modules in the Site Health (AKA site status) tool page
*
* By default, WordPress runs php_extension tests on the Site Health tool
* page in wp-admin. This filters out all irrelevant or unnecessary PHP modules
* within the test.
*/
function vip_filter_unnecessary_php_modules_for_site_health_tests( $modules ) {
// Remove 'exif' PHP module.
if ( isset( $modules['exif'] ) ) {
unset( $modules['exif'] );
}
// Remove 'imagick' PHP module.
if ( isset( $modules['imagick'] ) ) {
unset( $modules['imagick'] );
}
return $modules;
}
add_filter( 'site_status_test_php_modules', 'vip_filter_unnecessary_php_modules_for_site_health_tests' );
/*
* WordPress Core has a bug in the use_block_editor_for_post filter.
* Here we temporarily patch this bug, the patch can be removed once
* the bug has been fixed in Core.
*
* This bug can lead to Gutenberg Editor being loaded for posts of
* types that do not support the editor, resulting in a JavaScript error
* and a white screen. This will happen when using the filter in the
* following way:
*
* add_filter( 'use_block_editor_for_post', '__return_true' );
*
* Here we add a check to the filter so that this is averted.
*
* Note that use_block_editor_for_post_type filter does not have this problem
* and that the function that calls the filter does a similar check.
*
* WordPress Core Trac ticket with ways to replicate and a proposed patch
* can be found here: https://core.trac.wordpress.org/ticket/52363
*/
add_filter(
'use_block_editor_for_post',
function ( $can_edit, $post ) {
if ( ! isset( $post->post_type ) ) {
return $can_edit;
}
if ( ! post_type_supports( $post->post_type, 'editor' ) ) {
return false;
}
return $can_edit;
},
20,
2
);
/**
* Prevent invalid query args from causing php errors & a limitless query.
*
* This patch can be removed when the following core ticket is resolved:
* @see https://core.trac.wordpress.org/ticket/17737
*/
function vip_prevent_invalid_core_query_args() {
if ( is_admin() ) {
return;
}
// phpcs:disable WordPress.Security.NonceVerification.Recommended
if ( isset( $_GET['name'] ) && ! is_string( $_GET['name'] ) ) {
unset( $_GET['name'] );
}
if ( isset( $_GET['pagename'] ) && ! is_string( $_GET['pagename'] ) ) {
unset( $_GET['pagename'] );
}
// phpcs:enable
}
add_action( 'wp_loaded', 'vip_prevent_invalid_core_query_args', 1 );