Make WordPress Core


Ignore:
Timestamp:
08/18/2017 06:30:28 PM (7 years ago)
Author:
flixos90
Message:

Role/Capability: Introduce capabilities dedicated to installing and updating language files.

The new meta capabilities are called install_languages and update_languages. Prior to this change, there were no proper capability checks applied. Instead only the filesystem and related constants were checked, and for actual permissions a rather vague fallback was used where a user needed to have at least one of the other updating capabilities. In addition to being generally more verbose, the new capabilities make it possible for example to allow a user to update languages, but nothing else. By default they fall back to the original way of how they were handled.

Props johnbillion, flixos90.
Fixes #39677.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/capabilities.php

    r40999 r41268  
    393393        }
    394394        break;
     395    case 'install_languages':
     396    case 'update_languages':
     397        if ( ! function_exists( 'wp_can_install_language_pack' ) ) {
     398            require_once( ABSPATH . 'wp-admin/includes/translation-install.php' );
     399        }
     400
     401        if ( ! wp_can_install_language_pack() ) {
     402            $caps[] = 'do_not_allow';
     403        } elseif ( is_multisite() && ! is_super_admin( $user_id ) ) {
     404            $caps[] = 'do_not_allow';
     405        } else {
     406            $caps[] = 'install_languages';
     407        }
     408        break;
    395409    case 'activate_plugins':
    396410        $caps[] = $cap;
     
    827841    return false;
    828842}
     843
     844/**
     845 * Filters the user capabilities to grant the 'install_languages' capability as necessary.
     846 *
     847 * A user must have at least one out of the 'update_core', 'install_plugins', and
     848 * 'install_themes' capabilities to qualify for 'install_languages'.
     849 *
     850 * @since 4.9.0
     851 *
     852 * @param array $allcaps An array of all the user's capabilities.
     853 * @return array Filtered array of the user's capabilities.
     854 */
     855function wp_maybe_grant_install_languages_cap( $allcaps ) {
     856    if ( ! empty( $allcaps['update_core'] ) || ! empty( $allcaps['install_plugins'] ) || ! empty( $allcaps['install_themes'] ) ) {
     857        $allcaps['install_languages'] = true;
     858    }
     859
     860    return $allcaps;
     861}
Note: See TracChangeset for help on using the changeset viewer.