Skip to content

Commit 0911aec

Browse files
Privacy: Un-map privacy capabilities to make them available to be assigned for custom roles:
* `erase_others_personal_data` * `export_others_personal_data` * `manage_privacy_options` Previously mapped to `manage_options` or `manage_network` (on Multisite), these are now added to the Administrator role separately. Additionally, `manage_privacy_options` is added to the Editor role. Props garrett-eclipse, xkon, pbiron, desrosj, johnbillion, flixos90, juliobox, lakenh, Ov3rfly, ianatkins. Fixes #44176. git-svn-id: https://develop.svn.wordpress.org/trunk@47269 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 49b145c commit 0911aec

6 files changed

Lines changed: 267 additions & 224 deletions

File tree

src/wp-admin/includes/schema.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,7 @@ function populate_roles() {
695695
populate_roles_270();
696696
populate_roles_280();
697697
populate_roles_300();
698+
populate_roles_540();
698699
}
699700

700701
/**
@@ -923,6 +924,27 @@ function populate_roles_300() {
923924
}
924925
}
925926

927+
/**
928+
* Create and modify WordPress roles for WordPress 5.4.0.
929+
*
930+
* @since 5.4.0
931+
*/
932+
function populate_roles_540() {
933+
// Add the privacy caps to the Administrators.
934+
$role = get_role( 'administrator' );
935+
936+
if ( ! empty( $role ) ) {
937+
$role->add_cap( 'export_others_personal_data' );
938+
$role->add_cap( 'erase_others_personal_data' );
939+
$role->add_cap( 'manage_privacy_options' );
940+
}
941+
942+
$role = get_role( 'editor' );
943+
if ( ! empty( $role ) ) {
944+
$role->add_cap( 'manage_privacy_options' );
945+
}
946+
}
947+
926948
if ( ! function_exists( 'install_network' ) ) :
927949
/**
928950
* Install Network.

src/wp-admin/includes/upgrade.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -834,6 +834,10 @@ function upgrade_all() {
834834
upgrade_530();
835835
}
836836

837+
if ( $wp_current_db_version < 47269 ) {
838+
upgrade_540();
839+
}
840+
837841
maybe_disable_link_manager();
838842

839843
maybe_disable_automattic_widgets();
@@ -2154,6 +2158,22 @@ function upgrade_530() {
21542158
}
21552159
}
21562160

2161+
/**
2162+
* Executes changes made in WordPress 5.4.0.
2163+
*
2164+
* @ignore
2165+
* @since 5.4.0
2166+
*
2167+
* @global int $wp_current_db_version The old (current) database version.
2168+
*/
2169+
function upgrade_540() {
2170+
global $wp_current_db_version;
2171+
2172+
if ( $wp_current_db_version < 47269 ) {
2173+
populate_roles_540();
2174+
}
2175+
}
2176+
21572177
/**
21582178
* Executes network-level upgrade routines.
21592179
*

src/wp-admin/menu.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,11 @@ function _add_themes_utility_last() {
288288
$submenu['tools.php'][50] = array( __( 'Network Setup' ), 'setup_network', 'network.php' );
289289
}
290290

291-
$menu[80] = array( __( 'Settings' ), 'manage_options', 'options-general.php', '', 'menu-top menu-icon-settings', 'menu-settings', 'dashicons-admin-settings' );
291+
$menu[80] = array( __( 'Settings' ), 'manage_options', 'options-general.php', '', 'menu-top menu-icon-settings', 'menu-settings', 'dashicons-admin-settings' );
292+
if ( current_user_can( 'manage_privacy_options' ) && ! current_user_can( 'manage_options' ) ) {
293+
$menu[80] = array( __( 'Settings' ), 'manage_privacy_options', 'options-privacy.php', '', 'menu-top menu-icon-settings', 'menu-settings', 'dashicons-admin-settings' );
294+
}
295+
292296
$submenu['options-general.php'][10] = array( _x( 'General', 'settings screen' ), 'manage_options', 'options-general.php' );
293297
$submenu['options-general.php'][15] = array( __( 'Writing' ), 'manage_options', 'options-writing.php' );
294298
$submenu['options-general.php'][20] = array( __( 'Reading' ), 'manage_options', 'options-reading.php' );

src/wp-includes/capabilities.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ function map_meta_cap( $cap, $user_id, ...$args ) {
132132
* so deleting it should require that too.
133133
*/
134134
if ( (int) get_option( 'wp_page_for_privacy_policy' ) === $post->ID ) {
135-
$caps = array_merge( $caps, map_meta_cap( 'manage_privacy_options', $user_id ) );
135+
$caps[] = 'manage_privacy_options';
136136
}
137137

138138
break;
@@ -203,7 +203,7 @@ function map_meta_cap( $cap, $user_id, ...$args ) {
203203
* so editing it should require that too.
204204
*/
205205
if ( (int) get_option( 'wp_page_for_privacy_policy' ) === $post->ID ) {
206-
$caps = array_merge( $caps, map_meta_cap( 'manage_privacy_options', $user_id ) );
206+
$caps[] = 'manage_privacy_options';
207207
}
208208

209209
break;
@@ -580,11 +580,6 @@ function map_meta_cap( $cap, $user_id, ...$args ) {
580580
$caps[] = 'update_core';
581581
}
582582
break;
583-
case 'export_others_personal_data':
584-
case 'erase_others_personal_data':
585-
case 'manage_privacy_options':
586-
$caps[] = is_multisite() ? 'manage_network' : 'manage_options';
587-
break;
588583
default:
589584
// Handle meta capabilities for custom post types.
590585
global $post_type_meta_caps;

src/wp-includes/version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*
2121
* @global int $wp_db_version
2222
*/
23-
$wp_db_version = 47018;
23+
$wp_db_version = 47269;
2424

2525
/**
2626
* Holds the TinyMCE version.

0 commit comments

Comments
 (0)