<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[41268] trunk: Role/Capability: Introduce capabilities dedicated to installing and updating language files.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/41268">41268</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/41268","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>flixos90</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2017-08-18 18:30:28 +0000 (Fri, 18 Aug 2017)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>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 <a href="https://core.trac.wordpress.org/ticket/39677">#39677</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpadminmenuphp">trunk/src/wp-admin/menu.php</a></li>
<li><a href="#trunksrcwpadminnetworksettingsphp">trunk/src/wp-admin/network/settings.php</a></li>
<li><a href="#trunksrcwpadminnetworksitenewphp">trunk/src/wp-admin/network/site-new.php</a></li>
<li><a href="#trunksrcwpadminoptionsgeneralphp">trunk/src/wp-admin/options-general.php</a></li>
<li><a href="#trunksrcwpadminoptionsphp">trunk/src/wp-admin/options.php</a></li>
<li><a href="#trunksrcwpadminupdatecorephp">trunk/src/wp-admin/update-core.php</a></li>
<li><a href="#trunksrcwpincludescapabilitiesphp">trunk/src/wp-includes/capabilities.php</a></li>
<li><a href="#trunksrcwpincludesdefaultfiltersphp">trunk/src/wp-includes/default-filters.php</a></li>
<li><a href="#trunktestsphpunittestsusercapabilitiesphp">trunk/tests/phpunit/tests/user/capabilities.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpadminmenuphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/menu.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/menu.php 2017-08-18 18:18:51 UTC (rev 41267)
+++ trunk/src/wp-admin/menu.php 2017-08-18 18:30:28 UTC (rev 41268)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -33,12 +33,15 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( ! is_multisite() ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( current_user_can( 'update_core' ) )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( current_user_can( 'update_core' ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $cap = 'update_core';
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- elseif ( current_user_can( 'update_plugins' ) )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ } elseif ( current_user_can( 'update_plugins' ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $cap = 'update_plugins';
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- else
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ } elseif ( current_user_can( 'update_themes' ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $cap = 'update_themes';
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ } else {
+ $cap = 'update_languages';
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> $submenu[ 'index.php' ][10] = array( sprintf( __('Updates %s'), "<span class='update-plugins count-{$update_data['counts']['total']}'><span class='update-count'>" . number_format_i18n($update_data['counts']['total']) . "</span></span>" ), $cap, 'update-core.php');
</span><span class="cx" style="display: block; padding: 0 10px"> unset( $cap );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="trunksrcwpadminnetworksettingsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/network/settings.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/network/settings.php 2017-08-18 18:18:51 UTC (rev 41267)
+++ trunk/src/wp-admin/network/settings.php 2017-08-18 18:30:28 UTC (rev 41268)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -63,7 +63,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Handle translation install.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ! empty( $_POST['WPLANG'] ) && wp_can_install_language_pack() ) { // @todo: Skip if already installed
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! empty( $_POST['WPLANG'] ) && current_user_can( 'install_languages' ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $language = wp_download_language_pack( $_POST['WPLANG'] );
</span><span class="cx" style="display: block; padding: 0 10px"> if ( $language ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $_POST['WPLANG'] = $language;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -342,7 +342,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'selected' => $lang,
</span><span class="cx" style="display: block; padding: 0 10px"> 'languages' => $languages,
</span><span class="cx" style="display: block; padding: 0 10px"> 'translations' => $translations,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'show_available_translations' => wp_can_install_language_pack(),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'show_available_translations' => current_user_can( 'install_languages' ),
</ins><span class="cx" style="display: block; padding: 0 10px"> ) );
</span><span class="cx" style="display: block; padding: 0 10px"> ?>
</span><span class="cx" style="display: block; padding: 0 10px"> </td>
</span></span></pre></div>
<a id="trunksrcwpadminnetworksitenewphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/network/site-new.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/network/site-new.php 2017-08-18 18:18:51 UTC (rev 41267)
+++ trunk/src/wp-admin/network/site-new.php 2017-08-18 18:30:28 UTC (rev 41268)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -66,7 +66,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> if ( isset( $_POST['WPLANG'] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> if ( '' === $_POST['WPLANG'] ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $meta['WPLANG'] = ''; // en_US
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- } elseif ( wp_can_install_language_pack() ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ } elseif ( in_array( $_POST['WPLANG'], get_available_languages() ) ) {
+ $meta['WPLANG'] = $_POST['WPLANG'];
+ } elseif ( current_user_can( 'install_languages' ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $language = wp_download_language_pack( wp_unslash( $_POST['WPLANG'] ) );
</span><span class="cx" style="display: block; padding: 0 10px"> if ( $language ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $meta['WPLANG'] = $language;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -234,7 +236,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'selected' => $lang,
</span><span class="cx" style="display: block; padding: 0 10px"> 'languages' => $languages,
</span><span class="cx" style="display: block; padding: 0 10px"> 'translations' => $translations,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'show_available_translations' => wp_can_install_language_pack(),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'show_available_translations' => current_user_can( 'install_languages' ),
</ins><span class="cx" style="display: block; padding: 0 10px"> ) );
</span><span class="cx" style="display: block; padding: 0 10px"> ?>
</span><span class="cx" style="display: block; padding: 0 10px"> </td>
</span></span></pre></div>
<a id="trunksrcwpadminoptionsgeneralphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/options-general.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/options-general.php 2017-08-18 18:18:51 UTC (rev 41267)
+++ trunk/src/wp-admin/options-general.php 2017-08-18 18:30:28 UTC (rev 41268)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -151,7 +151,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'selected' => $locale,
</span><span class="cx" style="display: block; padding: 0 10px"> 'languages' => $languages,
</span><span class="cx" style="display: block; padding: 0 10px"> 'translations' => $translations,
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'show_available_translations' => ( ! is_multisite() || is_super_admin() ) && wp_can_install_language_pack(),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'show_available_translations' => current_user_can( 'install_languages' ),
</ins><span class="cx" style="display: block; padding: 0 10px"> ) );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Add note about deprecated WPLANG constant.
</span></span></pre></div>
<a id="trunksrcwpadminoptionsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/options.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/options.php 2017-08-18 18:18:51 UTC (rev 41267)
+++ trunk/src/wp-admin/options.php 2017-08-18 18:30:28 UTC (rev 41268)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -177,14 +177,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // Handle translation install.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ! empty( $_POST['WPLANG'] ) && ( ! is_multisite() || is_super_admin() ) ) { // @todo: Skip if already installed
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! empty( $_POST['WPLANG'] ) && current_user_can( 'install_languages' ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> require_once( ABSPATH . 'wp-admin/includes/translation-install.php' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( wp_can_install_language_pack() ) {
- $language = wp_download_language_pack( $_POST['WPLANG'] );
- if ( $language ) {
- $_POST['WPLANG'] = $language;
- }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $language = wp_download_language_pack( $_POST['WPLANG'] );
+ if ( $language ) {
+ $_POST['WPLANG'] = $language;
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="trunksrcwpadminupdatecorephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/update-core.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/update-core.php 2017-08-18 18:18:51 UTC (rev 41267)
+++ trunk/src/wp-admin/update-core.php 2017-08-18 18:30:28 UTC (rev 41268)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -19,7 +19,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> exit();
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-if ( ! current_user_can( 'update_core' ) && ! current_user_can( 'update_themes' ) && ! current_user_can( 'update_plugins' ) )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+if ( ! current_user_can( 'update_core' ) && ! current_user_can( 'update_themes' ) && ! current_user_can( 'update_plugins' ) && ! current_user_can( 'update_languages' ) )
</ins><span class="cx" style="display: block; padding: 0 10px"> wp_die( __( 'Sorry, you are not allowed to update this site.' ) );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -608,15 +608,19 @@
</span><span class="cx" style="display: block; padding: 0 10px"> echo ' <a class="button" href="' . esc_url( self_admin_url('update-core.php?force-check=1') ) . '">' . __( 'Check Again' ) . '</a>';
</span><span class="cx" style="display: block; padding: 0 10px"> echo '</p>';
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( $core = current_user_can( 'update_core' ) )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( current_user_can( 'update_core' ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> core_upgrade_preamble();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( $plugins = current_user_can( 'update_plugins' ) )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ }
+ if ( current_user_can( 'update_plugins' ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> list_plugin_updates();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( $themes = current_user_can( 'update_themes' ) )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ }
+ if ( current_user_can( 'update_themes' ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> list_theme_updates();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( $core || $plugins || $themes )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ }
+ if ( current_user_can( 'update_languages' ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> list_translation_updates();
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- unset( $core, $plugins, $themes );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="cx" style="display: block; padding: 0 10px"> * Fires after the core, plugin, and theme update tables.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -729,7 +733,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> } elseif ( 'do-translation-upgrade' == $action ) {
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( ! current_user_can( 'update_core' ) && ! current_user_can( 'update_plugins' ) && ! current_user_can( 'update_themes' ) )
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! current_user_can( 'update_languages' ) )
</ins><span class="cx" style="display: block; padding: 0 10px"> wp_die( __( 'Sorry, you are not allowed to update this site.' ) );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> check_admin_referer( 'upgrade-translations' );
</span></span></pre></div>
<a id="trunksrcwpincludescapabilitiesphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/capabilities.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/capabilities.php 2017-08-18 18:18:51 UTC (rev 41267)
+++ trunk/src/wp-includes/capabilities.php 2017-08-18 18:30:28 UTC (rev 41268)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -392,6 +392,20 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $caps[] = $cap;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> break;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ case 'install_languages':
+ case 'update_languages':
+ if ( ! function_exists( 'wp_can_install_language_pack' ) ) {
+ require_once( ABSPATH . 'wp-admin/includes/translation-install.php' );
+ }
+
+ if ( ! wp_can_install_language_pack() ) {
+ $caps[] = 'do_not_allow';
+ } elseif ( is_multisite() && ! is_super_admin( $user_id ) ) {
+ $caps[] = 'do_not_allow';
+ } else {
+ $caps[] = 'install_languages';
+ }
+ break;
</ins><span class="cx" style="display: block; padding: 0 10px"> case 'activate_plugins':
</span><span class="cx" style="display: block; padding: 0 10px"> $caps[] = $cap;
</span><span class="cx" style="display: block; padding: 0 10px"> if ( is_multisite() ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -826,3 +840,22 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px"> return false;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+/**
+ * Filters the user capabilities to grant the 'install_languages' capability as necessary.
+ *
+ * A user must have at least one out of the 'update_core', 'install_plugins', and
+ * 'install_themes' capabilities to qualify for 'install_languages'.
+ *
+ * @since 4.9.0
+ *
+ * @param array $allcaps An array of all the user's capabilities.
+ * @return array Filtered array of the user's capabilities.
+ */
+function wp_maybe_grant_install_languages_cap( $allcaps ) {
+ if ( ! empty( $allcaps['update_core'] ) || ! empty( $allcaps['install_plugins'] ) || ! empty( $allcaps['install_themes'] ) ) {
+ $allcaps['install_languages'] = true;
+ }
+
+ return $allcaps;
+}
</ins></span></pre></div>
<a id="trunksrcwpincludesdefaultfiltersphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/default-filters.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/default-filters.php 2017-08-18 18:18:51 UTC (rev 41267)
+++ trunk/src/wp-includes/default-filters.php 2017-08-18 18:30:28 UTC (rev 41268)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -512,4 +512,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> add_filter( 'oembed_response_data', 'get_oembed_response_data_rich', 10, 4 );
</span><span class="cx" style="display: block; padding: 0 10px"> add_filter( 'pre_oembed_result', 'wp_filter_pre_oembed_result', 10, 3 );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+// Capabilities
+add_filter( 'user_has_cap', 'wp_maybe_grant_install_languages_cap', 1 );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> unset( $filter, $action );
</span></span></pre></div>
<a id="trunktestsphpunittestsusercapabilitiesphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/user/capabilities.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/user/capabilities.php 2017-08-18 18:18:51 UTC (rev 41267)
+++ trunk/tests/phpunit/tests/user/capabilities.php 2017-08-18 18:30:28 UTC (rev 41268)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -233,6 +233,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'upload_themes' => array( 'administrator' ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'customize' => array( 'administrator' ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'add_users' => array( 'administrator' ),
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'install_languages' => array( 'administrator' ),
+ 'update_languages' => array( 'administrator' ),
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> 'edit_categories' => array( 'administrator', 'editor' ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'delete_categories' => array( 'administrator', 'editor' ),
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -261,6 +263,8 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'upload_themes' => array(),
</span><span class="cx" style="display: block; padding: 0 10px"> 'edit_css' => array(),
</span><span class="cx" style="display: block; padding: 0 10px"> 'upgrade_network' => array(),
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'install_languages' => array(),
+ 'update_languages' => array(),
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> 'customize' => array( 'administrator' ),
</span><span class="cx" style="display: block; padding: 0 10px"> 'delete_site' => array( 'administrator' ),
</span></span></pre>
</div>
</div>
</body>
</html>