Make WordPress Core

Ticket #44176: 44176.3.diff

File 44176.3.diff, 4.8 KB (added by pbiron, 5 years ago)
  • src/wp-admin/includes/schema.php

    From 3763f746ef48c58caadbb17f68f514e146429296 Mon Sep 17 00:00:00 2001
    From: Paul Biron <paul@sparrowhawkcomputing.com>
    Date: Thu, 26 Dec 2019 12:14:30 -0700
    Subject: [PATCH] Un-map Privacy Capabilities.
    
    ---
     src/wp-admin/includes/schema.php  | 17 +++++++++++++++++
     src/wp-admin/includes/upgrade.php | 20 ++++++++++++++++++++
     src/wp-admin/menu.php             |  7 ++++++-
     src/wp-includes/capabilities.php  |  9 ++-------
     4 files changed, 45 insertions(+), 8 deletions(-)
    
    diff --git a/src/wp-admin/includes/schema.php b/src/wp-admin/includes/schema.php
    index a2e8216457..b0d2a4ec6e 100644
    a b function populate_roles() { 
    695695        populate_roles_270();
    696696        populate_roles_280();
    697697        populate_roles_300();
     698        populate_roles_540();
    698699}
    699700
    700701/**
    function populate_roles_300() { 
    924925        }
    925926}
    926927
     928/**
     929 * Create and modify WordPress roles for WordPress 5.4.
     930 *
     931 * @since 5.4.0
     932 */
     933function populate_roles_540() {
     934        // Add the privacy caps to the Administrators.
     935        $role = get_role( 'administrator' );
     936
     937        if ( ! empty( $role ) ) {
     938                $role->add_cap( 'export_others_personal_data' );
     939                $role->add_cap( 'erase_others_personal_data' );
     940                $role->add_cap( 'manage_privacy_options' );
     941        }
     942}
     943
    927944if ( ! function_exists( 'install_network' ) ) :
    928945        /**
    929946         * Install Network.
  • src/wp-admin/includes/upgrade.php

    diff --git a/src/wp-admin/includes/upgrade.php b/src/wp-admin/includes/upgrade.php
    index df3b8edcc3..e323f7af75 100644
    a b function upgrade_all() { 
    833833                upgrade_530();
    834834        }
    835835
     836        // @todo update the db_version in this check when the proper one is known.
     837        if ( $wp_current_db_version < 45806 ) {
     838                upgrade_540();
     839        }
     840
    836841        maybe_disable_link_manager();
    837842
    838843        maybe_disable_automattic_widgets();
    function upgrade_530() { 
    21482153        }
    21492154}
    21502155
     2156/**
     2157 * Executes changes made in WordPress 5.4.0.
     2158 *
     2159 * @ignore
     2160 * @since 5.4.0
     2161 */
     2162function upgrade_540() {
     2163        global $wp_current_db_version;
     2164
     2165        // @todo update the db_version in this check when the proper one is known.
     2166        if ( $wp_current_db_version < 45806 ) {
     2167                populate_roles_540();
     2168        }
     2169}
     2170
    21512171/**
    21522172 * Executes network-level upgrade routines.
    21532173 *
  • src/wp-admin/menu.php

    diff --git a/src/wp-admin/menu.php b/src/wp-admin/menu.php
    index 7aec19663d..b78d4f5bde 100644
    a b if ( ! is_multisite() && defined( 'WP_ALLOW_MULTISITE' ) && WP_ALLOW_MULTISITE ) 
    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' );
     291if ( current_user_can( 'manage_options' ) ) {
     292        $menu[80] = array( __( 'Settings' ), 'manage_options', 'options-general.php', '', 'menu-top menu-icon-settings', 'menu-settings', 'dashicons-admin-settings' );
     293} elseif ( current_user_can( 'manage_privacy_options' ) && ! current_user_can( 'manage_options' ) ) {
     294        $menu[80] = array( __( 'Settings' ), 'manage_privacy_options', 'options-general.php', '', 'menu-top menu-icon-settings', 'menu-settings', 'dashicons-admin-settings' );
     295}
     296
    292297        $submenu['options-general.php'][10] = array( _x( 'General', 'settings screen' ), 'manage_options', 'options-general.php' );
    293298        $submenu['options-general.php'][15] = array( __( 'Writing' ), 'manage_options', 'options-writing.php' );
    294299        $submenu['options-general.php'][20] = array( __( 'Reading' ), 'manage_options', 'options-reading.php' );
  • src/wp-includes/capabilities.php

    diff --git a/src/wp-includes/capabilities.php b/src/wp-includes/capabilities.php
    index 0c40c7e384..fb3de11a06 100644
    a b 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;
    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;
    function map_meta_cap( $cap, $user_id, ...$args ) { 
    573573                                $caps[] = 'update_core';
    574574                        }
    575575                        break;
    576                 case 'export_others_personal_data':
    577                 case 'erase_others_personal_data':
    578                 case 'manage_privacy_options':
    579                         $caps[] = is_multisite() ? 'manage_network' : 'manage_options';
    580                         break;
    581576                default:
    582577                        // Handle meta capabilities for custom post types.
    583578                        global $post_type_meta_caps;