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.

Built from https://develop.svn.wordpress.org/trunk@40394


git-svn-id: http://core.svn.wordpress.org/trunk@40301 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Pascal Birchler 2017-04-07 14:36:50 +00:00
parent 0c2338fab2
commit 8473f9ef66
6 changed files with 27 additions and 7 deletions

View File

@ -31,7 +31,7 @@ class WP_Automatic_Updater {
*/
public function is_disabled() {
// Background updates are disabled if you don't want file changes.
if ( defined( 'DISALLOW_FILE_MODS' ) && DISALLOW_FILE_MODS )
if ( wp_disallow_file_mods( 'automatic_updater' ) )
return true;
if ( wp_installing() )

View File

@ -1152,7 +1152,7 @@ function wp_dashboard_primary() {
)
);
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' ) ) ) {
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' ) ) ) {
$feeds['plugins'] = array(
'link' => '',
'url' => array(

View File

@ -202,7 +202,7 @@ function wp_download_language_pack( $download ) {
return $download;
}
if ( defined( 'DISALLOW_FILE_MODS' ) && DISALLOW_FILE_MODS ) {
if ( wp_disallow_file_mods( 'download_language_pack' ) ) {
return false;
}
@ -245,7 +245,7 @@ function wp_download_language_pack( $download ) {
* @return bool Returns true on success, false on failure.
*/
function wp_can_install_language_pack() {
if ( defined( 'DISALLOW_FILE_MODS' ) && DISALLOW_FILE_MODS ) {
if ( wp_disallow_file_mods( 'can_install_language_pack' ) ) {
return false;
}

View File

@ -362,7 +362,7 @@ function map_meta_cap( $cap, $user_id ) {
// Disallow the file editors.
if ( defined( 'DISALLOW_FILE_EDIT' ) && DISALLOW_FILE_EDIT )
$caps[] = 'do_not_allow';
elseif ( defined( 'DISALLOW_FILE_MODS' ) && DISALLOW_FILE_MODS )
elseif ( wp_disallow_file_mods( 'capability_edit_themes' ) )
$caps[] = 'do_not_allow';
elseif ( is_multisite() && ! is_super_admin( $user_id ) )
$caps[] = 'do_not_allow';
@ -380,7 +380,7 @@ function map_meta_cap( $cap, $user_id ) {
case 'update_core':
// Disallow anything that creates, deletes, or updates core, plugin, or theme files.
// Files in uploads are excepted.
if ( defined( 'DISALLOW_FILE_MODS' ) && DISALLOW_FILE_MODS ) {
if ( wp_disallow_file_mods( 'capability_update_core' ) ) {
$caps[] = 'do_not_allow';
} elseif ( is_multisite() && ! is_super_admin( $user_id ) ) {
$caps[] = 'do_not_allow';

View File

@ -1072,3 +1072,23 @@ function wp_doing_ajax() {
function is_wp_error( $thing ) {
return ( $thing instanceof WP_Error );
}
/**
* Determines whether file modifications are disallowed.
*
* @since 4.8.0
*
* @param string $context The usage context.
* @return bool True if file modification is disallowed, false otherwise.
*/
function wp_disallow_file_mods( $context ) {
/**
* Filters whether file modifications are disallowed.
*
* @since 4.8.0
*
* @param bool $disllow_file_mods Whether file modifications are disallowed.
* @param string $context The usage context.
*/
return apply_filters( 'disallow_file_mods' , defined( 'DISALLOW_FILE_MODS' ) && DISALLOW_FILE_MODS, $context );
}

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.8-alpha-40393';
$wp_version = '4.8-alpha-40394';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.