WordPress.org

Make WordPress Core


Ignore:
Timestamp:
06/10/2019 07:41:12 AM (20 months ago)
Author:
peterwilsoncc
Message:

Site health: Introduce view_site_health_checks capability.

Introduces the faux primitive capability view_site_health_checks available to single site admins and multisite super-admin to view the site health page within the admin.

The capability is mapped to the install_plugins capability without being dependent on the file system being writable. This fixes a bug where the feature couldn't be used by sites unable to write to the file system or managed through version control.

The capability is granted on the user_has_cap filter.

Props birgire, Clorith, palmiak, peterwilsoncc, spacedmonkey.
Fixes #46957.

File:
1 edited

Legend:

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

    r45419 r45507  
    10261026}
    10271027
     1028/**
     1029 * Filters the user capabilities to grant the 'view_site_health_checks' capabilities as necessary.
     1030 *
     1031 * @since 5.2.2
     1032 *
     1033 * @param bool[]   $allcaps An array of all the user's capabilities.
     1034 * @param string[] $caps    Required primitive capabilities for the requested capability.
     1035 * @param array    $args {
     1036 *     Arguments that accompany the requested capability check.
     1037 *
     1038 *     @type string    $0 Requested capability.
     1039 *     @type int       $1 Concerned user ID.
     1040 *     @type mixed  ...$2 Optional second and further parameters, typically object ID.
     1041 * }
     1042 * @param WP_User  $user    The user object.
     1043 * @return bool[] Filtered array of the user's capabilities.
     1044 */
     1045function wp_maybe_grant_site_health_caps( $allcaps, $caps, $args, $user ) {
     1046    if ( ! empty( $allcaps['install_plugins'] ) && ( ! is_multisite() || is_super_admin( $user->ID ) ) ) {
     1047        $allcaps['view_site_health_checks'] = true;
     1048    }
     1049
     1050    return $allcaps;
     1051}
     1052
    10281053return;
    10291054
Note: See TracChangeset for help on using the changeset viewer.