Skip to content

Commit f44a9eb

Browse files
committed
Upgrade/Install: Introduce wp_disallow_file_mods() helper function.
This is a wrapper around the checks for the `DISALLOW_FILE_MODS` constant to determine whether file modifications are disallowed. Props MaximeCulea. Fixes #38673. git-svn-id: https://develop.svn.wordpress.org/trunk@40394 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 49c68e7 commit f44a9eb

5 files changed

Lines changed: 26 additions & 6 deletions

File tree

src/wp-admin/includes/class-wp-automatic-updater.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class WP_Automatic_Updater {
3131
*/
3232
public function is_disabled() {
3333
// Background updates are disabled if you don't want file changes.
34-
if ( defined( 'DISALLOW_FILE_MODS' ) && DISALLOW_FILE_MODS )
34+
if ( wp_disallow_file_mods( 'automatic_updater' ) )
3535
return true;
3636

3737
if ( wp_installing() )

src/wp-admin/includes/dashboard.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1152,7 +1152,7 @@ function wp_dashboard_primary() {
11521152
)
11531153
);
11541154

1155-
if ( ( ! defined( 'DISALLOW_FILE_MODS' ) || ! DISALLOW_FILE_MODS ) && ( ! is_multisite() && is_blog_admin() && current_user_can( 'install_plugins' ) ) || ( is_network_admin() && current_user_can( 'manage_network_plugins' ) && current_user_can( 'install_plugins' ) ) ) {
1155+
if ( ( ! wp_disallow_file_mods( 'dashboard_widget' ) ) && ( ! is_multisite() && is_blog_admin() && current_user_can( 'install_plugins' ) ) || ( is_network_admin() && current_user_can( 'manage_network_plugins' ) && current_user_can( 'install_plugins' ) ) ) {
11561156
$feeds['plugins'] = array(
11571157
'link' => '',
11581158
'url' => array(

src/wp-admin/includes/translation-install.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ function wp_download_language_pack( $download ) {
202202
return $download;
203203
}
204204

205-
if ( defined( 'DISALLOW_FILE_MODS' ) && DISALLOW_FILE_MODS ) {
205+
if ( wp_disallow_file_mods( 'download_language_pack' ) ) {
206206
return false;
207207
}
208208

@@ -245,7 +245,7 @@ function wp_download_language_pack( $download ) {
245245
* @return bool Returns true on success, false on failure.
246246
*/
247247
function wp_can_install_language_pack() {
248-
if ( defined( 'DISALLOW_FILE_MODS' ) && DISALLOW_FILE_MODS ) {
248+
if ( wp_disallow_file_mods( 'can_install_language_pack' ) ) {
249249
return false;
250250
}
251251

src/wp-includes/capabilities.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ function map_meta_cap( $cap, $user_id ) {
362362
// Disallow the file editors.
363363
if ( defined( 'DISALLOW_FILE_EDIT' ) && DISALLOW_FILE_EDIT )
364364
$caps[] = 'do_not_allow';
365-
elseif ( defined( 'DISALLOW_FILE_MODS' ) && DISALLOW_FILE_MODS )
365+
elseif ( wp_disallow_file_mods( 'capability_edit_themes' ) )
366366
$caps[] = 'do_not_allow';
367367
elseif ( is_multisite() && ! is_super_admin( $user_id ) )
368368
$caps[] = 'do_not_allow';
@@ -380,7 +380,7 @@ function map_meta_cap( $cap, $user_id ) {
380380
case 'update_core':
381381
// Disallow anything that creates, deletes, or updates core, plugin, or theme files.
382382
// Files in uploads are excepted.
383-
if ( defined( 'DISALLOW_FILE_MODS' ) && DISALLOW_FILE_MODS ) {
383+
if ( wp_disallow_file_mods( 'capability_update_core' ) ) {
384384
$caps[] = 'do_not_allow';
385385
} elseif ( is_multisite() && ! is_super_admin( $user_id ) ) {
386386
$caps[] = 'do_not_allow';

src/wp-includes/load.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,3 +1072,23 @@ function wp_doing_ajax() {
10721072
function is_wp_error( $thing ) {
10731073
return ( $thing instanceof WP_Error );
10741074
}
1075+
1076+
/**
1077+
* Determines whether file modifications are disallowed.
1078+
*
1079+
* @since 4.8.0
1080+
*
1081+
* @param string $context The usage context.
1082+
* @return bool True if file modification is disallowed, false otherwise.
1083+
*/
1084+
function wp_disallow_file_mods( $context ) {
1085+
/**
1086+
* Filters whether file modifications are disallowed.
1087+
*
1088+
* @since 4.8.0
1089+
*
1090+
* @param bool $disllow_file_mods Whether file modifications are disallowed.
1091+
* @param string $context The usage context.
1092+
*/
1093+
return apply_filters( 'disallow_file_mods' , defined( 'DISALLOW_FILE_MODS' ) && DISALLOW_FILE_MODS, $context );
1094+
}

0 commit comments

Comments
 (0)