Make WordPress Core


Ignore:
Timestamp:
06/10/2019 07:49:27 AM (3 years 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.
Merges [45507] to the 5.2 branch.
Fixes #46957 for 5.2.2.

Location:
branches/5.2
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/5.2

  • branches/5.2/src/wp-includes/capabilities.php

    r44976 r45508  
    980980}
    981981
     982/**
     983 * Filters the user capabilities to grant the 'view_site_health_checks' capabilities as necessary.
     984 *
     985 * @since 5.2.2
     986 *
     987 * @param bool[]   $allcaps An array of all the user's capabilities.
     988 * @param string[] $caps    Required primitive capabilities for the requested capability.
     989 * @param array    $args {
     990 *     Arguments that accompany the requested capability check.
     991 *
     992 *     @type string    $0 Requested capability.
     993 *     @type int       $1 Concerned user ID.
     994 *     @type mixed  ...$2 Optional second and further parameters, typically object ID.
     995 * }
     996 * @param WP_User  $user    The user object.
     997 * @return bool[] Filtered array of the user's capabilities.
     998 */
     999function wp_maybe_grant_site_health_caps( $allcaps, $caps, $args, $user ) {
     1000    if ( ! empty( $allcaps['install_plugins'] ) && ( ! is_multisite() || is_super_admin( $user->ID ) ) ) {
     1001        $allcaps['view_site_health_checks'] = true;
     1002    }
     1003
     1004    return $allcaps;
     1005}
     1006
    9821007return;
    9831008
Note: See TracChangeset for help on using the changeset viewer.