[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/ -> capabilities.php (source)

   1  <?php
   2  /**
   3   * Core User Role & Capabilities API
   4   *
   5   * @package WordPress
   6   * @subpackage Users
   7   */
   8  
   9  /**
  10   * Maps a capability to the primitive capabilities required of the given user to
  11   * satisfy the capability being checked.
  12   *
  13   * This function also accepts an ID of an object to map against if the capability is a meta capability. Meta
  14   * capabilities such as `edit_post` and `edit_user` are capabilities used by this function to map to primitive
  15   * capabilities that a user or role requires, such as `edit_posts` and `edit_others_posts`.
  16   *
  17   * Example usage:
  18   *
  19   *     map_meta_cap( 'edit_posts', $user->ID );
  20   *     map_meta_cap( 'edit_post', $user->ID, $post->ID );
  21   *     map_meta_cap( 'edit_post_meta', $user->ID, $post->ID, $meta_key );
  22   *
  23   * This function does not check whether the user has the required capabilities,
  24   * it just returns what the required capabilities are.
  25   *
  26   * @since 2.0.0
  27   * @since 4.9.6 Added the `export_others_personal_data`, `erase_others_personal_data`,
  28   *              and `manage_privacy_options` capabilities.
  29   * @since 5.1.0 Added the `update_php` capability.
  30   * @since 5.2.0 Added the `resume_plugin` and `resume_theme` capabilities.
  31   * @since 5.3.0 Formalized the existing and already documented `...$args` parameter
  32   *              by adding it to the function signature.
  33   * @since 5.7.0 Added the `create_app_password`, `list_app_passwords`, `read_app_password`,
  34   *              `edit_app_password`, `delete_app_passwords`, `delete_app_password`,
  35   *              and `update_https` capabilities.
  36   * @since 6.7.0 Added the `edit_block_binding` capability.
  37   *
  38   * @global array $post_type_meta_caps Used to get post type meta capabilities.
  39   *
  40   * @param string $cap     Capability being checked.
  41   * @param int    $user_id User ID.
  42   * @param mixed  ...$args Optional further parameters, typically starting with an object ID.
  43   * @return string[] Primitive capabilities required of the user.
  44   */
  45  function map_meta_cap( $cap, $user_id, ...$args ) {
  46      $caps = array();
  47  
  48      switch ( $cap ) {
  49          case 'remove_user':
  50              // In multisite the user must be a super admin to remove themselves.
  51              if ( isset( $args[0] ) && $user_id === (int) $args[0] && ! is_super_admin( $user_id ) ) {
  52                  $caps[] = 'do_not_allow';
  53              } else {
  54                  $caps[] = 'remove_users';
  55              }
  56              break;
  57          case 'promote_user':
  58          case 'add_users':
  59              $caps[] = 'promote_users';
  60              break;
  61          case 'edit_user':
  62          case 'edit_users':
  63              // Non-existent users can't edit users, not even themselves.
  64              if ( $user_id < 1 ) {
  65                  $caps[] = 'do_not_allow';
  66                  break;
  67              }
  68  
  69              // Allow user to edit themselves.
  70              if ( 'edit_user' === $cap && isset( $args[0] ) && $user_id === (int) $args[0] ) {
  71                  break;
  72              }
  73  
  74              // In multisite the user must have manage_network_users caps. If editing a super admin, the user must be a super admin.
  75              if ( is_multisite() && ( ( ! is_super_admin( $user_id ) && 'edit_user' === $cap && is_super_admin( $args[0] ) ) || ! user_can( $user_id, 'manage_network_users' ) ) ) {
  76                  $caps[] = 'do_not_allow';
  77              } else {
  78                  $caps[] = 'edit_users'; // edit_user maps to edit_users.
  79              }
  80              break;
  81          case 'delete_post':
  82          case 'delete_page':
  83              if ( ! isset( $args[0] ) ) {
  84                  if ( 'delete_post' === $cap ) {
  85                      /* translators: %s: Capability name. */
  86                      $message = __( 'When checking for the %s capability, you must always check it against a specific post.' );
  87                  } else {
  88                      /* translators: %s: Capability name. */
  89                      $message = __( 'When checking for the %s capability, you must always check it against a specific page.' );
  90                  }
  91  
  92                  _doing_it_wrong(
  93                      __FUNCTION__,
  94                      sprintf( $message, '<code>' . $cap . '</code>' ),
  95                      '6.1.0'
  96                  );
  97  
  98                  $caps[] = 'do_not_allow';
  99                  break;
 100              }
 101  
 102              $post = get_post( $args[0] );
 103              if ( ! $post ) {
 104                  $caps[] = 'do_not_allow';
 105                  break;
 106              }
 107  
 108              if ( 'revision' === $post->post_type ) {
 109                  $caps[] = 'do_not_allow';
 110                  break;
 111              }
 112  
 113              if ( (int) get_option( 'page_for_posts' ) === $post->ID
 114                  || (int) get_option( 'page_on_front' ) === $post->ID
 115              ) {
 116                  $caps[] = 'manage_options';
 117                  break;
 118              }
 119  
 120              $post_type = get_post_type_object( $post->post_type );
 121              if ( ! $post_type ) {
 122                  /* translators: 1: Post type, 2: Capability name. */
 123                  $message = __( 'The post type %1$s is not registered, so it may not be reliable to check the capability %2$s against a post of that type.' );
 124  
 125                  _doing_it_wrong(
 126                      __FUNCTION__,
 127                      sprintf(
 128                          $message,
 129                          '<code>' . $post->post_type . '</code>',
 130                          '<code>' . $cap . '</code>'
 131                      ),
 132                      '4.4.0'
 133                  );
 134  
 135                  $caps[] = 'edit_others_posts';
 136                  break;
 137              }
 138  
 139              if ( ! $post_type->map_meta_cap ) {
 140                  $caps[] = $post_type->cap->$cap;
 141                  // Prior to 3.1 we would re-call map_meta_cap here.
 142                  if ( 'delete_post' === $cap ) {
 143                      $cap = $post_type->cap->$cap;
 144                  }
 145                  break;
 146              }
 147  
 148              // If the post author is set and the user is the author...
 149              if ( $post->post_author && $user_id === (int) $post->post_author ) {
 150                  // If the post is published or scheduled...
 151                  if ( in_array( $post->post_status, array( 'publish', 'future' ), true ) ) {
 152                      $caps[] = $post_type->cap->delete_published_posts;
 153                  } elseif ( 'trash' === $post->post_status ) {
 154                      $status = get_post_meta( $post->ID, '_wp_trash_meta_status', true );
 155                      if ( in_array( $status, array( 'publish', 'future' ), true ) ) {
 156                          $caps[] = $post_type->cap->delete_published_posts;
 157                      } else {
 158                          $caps[] = $post_type->cap->delete_posts;
 159                      }
 160                  } else {
 161                      // If the post is draft...
 162                      $caps[] = $post_type->cap->delete_posts;
 163                  }
 164              } else {
 165                  // The user is trying to edit someone else's post.
 166                  $caps[] = $post_type->cap->delete_others_posts;
 167                  // The post is published or scheduled, extra cap required.
 168                  if ( in_array( $post->post_status, array( 'publish', 'future' ), true ) ) {
 169                      $caps[] = $post_type->cap->delete_published_posts;
 170                  } elseif ( 'private' === $post->post_status ) {
 171                      $caps[] = $post_type->cap->delete_private_posts;
 172                  }
 173              }
 174  
 175              /*
 176               * Setting the privacy policy page requires `manage_privacy_options`,
 177               * so deleting it should require that too.
 178               */
 179              if ( (int) get_option( 'wp_page_for_privacy_policy' ) === $post->ID ) {
 180                  $caps = array_merge( $caps, map_meta_cap( 'manage_privacy_options', $user_id ) );
 181              }
 182  
 183              break;
 184          /*
 185           * edit_post breaks down to edit_posts, edit_published_posts, or
 186           * edit_others_posts.
 187           */
 188          case 'edit_post':
 189          case 'edit_page':
 190              if ( ! isset( $args[0] ) ) {
 191                  if ( 'edit_post' === $cap ) {
 192                      /* translators: %s: Capability name. */
 193                      $message = __( 'When checking for the %s capability, you must always check it against a specific post.' );
 194                  } else {
 195                      /* translators: %s: Capability name. */
 196                      $message = __( 'When checking for the %s capability, you must always check it against a specific page.' );
 197                  }
 198  
 199                  _doing_it_wrong(
 200                      __FUNCTION__,
 201                      sprintf( $message, '<code>' . $cap . '</code>' ),
 202                      '6.1.0'
 203                  );
 204  
 205                  $caps[] = 'do_not_allow';
 206                  break;
 207              }
 208  
 209              $post = get_post( $args[0] );
 210              if ( ! $post ) {
 211                  $caps[] = 'do_not_allow';
 212                  break;
 213              }
 214  
 215              if ( 'revision' === $post->post_type ) {
 216                  $post = get_post( $post->post_parent );
 217                  if ( ! $post ) {
 218                      $caps[] = 'do_not_allow';
 219                      break;
 220                  }
 221              }
 222  
 223              $post_type = get_post_type_object( $post->post_type );
 224              if ( ! $post_type ) {
 225                  /* translators: 1: Post type, 2: Capability name. */
 226                  $message = __( 'The post type %1$s is not registered, so it may not be reliable to check the capability %2$s against a post of that type.' );
 227  
 228                  _doing_it_wrong(
 229                      __FUNCTION__,
 230                      sprintf(
 231                          $message,
 232                          '<code>' . $post->post_type . '</code>',
 233                          '<code>' . $cap . '</code>'
 234                      ),
 235                      '4.4.0'
 236                  );
 237  
 238                  $caps[] = 'edit_others_posts';
 239                  break;
 240              }
 241  
 242              if ( ! $post_type->map_meta_cap ) {
 243                  $caps[] = $post_type->cap->$cap;
 244                  // Prior to 3.1 we would re-call map_meta_cap here.
 245                  if ( 'edit_post' === $cap ) {
 246                      $cap = $post_type->cap->$cap;
 247                  }
 248                  break;
 249              }
 250  
 251              // If the post author is set and the user is the author...
 252              if ( $post->post_author && $user_id === (int) $post->post_author ) {
 253                  // If the post is published or scheduled...
 254                  if ( in_array( $post->post_status, array( 'publish', 'future' ), true ) ) {
 255                      $caps[] = $post_type->cap->edit_published_posts;
 256                  } elseif ( 'trash' === $post->post_status ) {
 257                      $status = get_post_meta( $post->ID, '_wp_trash_meta_status', true );
 258                      if ( in_array( $status, array( 'publish', 'future' ), true ) ) {
 259                          $caps[] = $post_type->cap->edit_published_posts;
 260                      } else {
 261                          $caps[] = $post_type->cap->edit_posts;
 262                      }
 263                  } else {
 264                      // If the post is draft...
 265                      $caps[] = $post_type->cap->edit_posts;
 266                  }
 267              } else {
 268                  // The user is trying to edit someone else's post.
 269                  $caps[] = $post_type->cap->edit_others_posts;
 270                  // The post is published or scheduled, extra cap required.
 271                  if ( in_array( $post->post_status, array( 'publish', 'future' ), true ) ) {
 272                      $caps[] = $post_type->cap->edit_published_posts;
 273                  } elseif ( 'private' === $post->post_status ) {
 274                      $caps[] = $post_type->cap->edit_private_posts;
 275                  }
 276              }
 277  
 278              /*
 279               * Setting the privacy policy page requires `manage_privacy_options`,
 280               * so editing it should require that too.
 281               */
 282              if ( (int) get_option( 'wp_page_for_privacy_policy' ) === $post->ID ) {
 283                  $caps = array_merge( $caps, map_meta_cap( 'manage_privacy_options', $user_id ) );
 284              }
 285  
 286              break;
 287          case 'read_post':
 288          case 'read_page':
 289              if ( ! isset( $args[0] ) ) {
 290                  if ( 'read_post' === $cap ) {
 291                      /* translators: %s: Capability name. */
 292                      $message = __( 'When checking for the %s capability, you must always check it against a specific post.' );
 293                  } else {
 294                      /* translators: %s: Capability name. */
 295                      $message = __( 'When checking for the %s capability, you must always check it against a specific page.' );
 296                  }
 297  
 298                  _doing_it_wrong(
 299                      __FUNCTION__,
 300                      sprintf( $message, '<code>' . $cap . '</code>' ),
 301                      '6.1.0'
 302                  );
 303  
 304                  $caps[] = 'do_not_allow';
 305                  break;
 306              }
 307  
 308              $post = get_post( $args[0] );
 309              if ( ! $post ) {
 310                  $caps[] = 'do_not_allow';
 311                  break;
 312              }
 313  
 314              if ( 'revision' === $post->post_type ) {
 315                  $post = get_post( $post->post_parent );
 316                  if ( ! $post ) {
 317                      $caps[] = 'do_not_allow';
 318                      break;
 319                  }
 320              }
 321  
 322              $post_type = get_post_type_object( $post->post_type );
 323              if ( ! $post_type ) {
 324                  /* translators: 1: Post type, 2: Capability name. */
 325                  $message = __( 'The post type %1$s is not registered, so it may not be reliable to check the capability %2$s against a post of that type.' );
 326  
 327                  _doing_it_wrong(
 328                      __FUNCTION__,
 329                      sprintf(
 330                          $message,
 331                          '<code>' . $post->post_type . '</code>',
 332                          '<code>' . $cap . '</code>'
 333                      ),
 334                      '4.4.0'
 335                  );
 336  
 337                  $caps[] = 'edit_others_posts';
 338                  break;
 339              }
 340  
 341              if ( ! $post_type->map_meta_cap ) {
 342                  $caps[] = $post_type->cap->$cap;
 343                  // Prior to 3.1 we would re-call map_meta_cap here.
 344                  if ( 'read_post' === $cap ) {
 345                      $cap = $post_type->cap->$cap;
 346                  }
 347                  break;
 348              }
 349  
 350              $status_obj = get_post_status_object( get_post_status( $post ) );
 351              if ( ! $status_obj ) {
 352                  /* translators: 1: Post status, 2: Capability name. */
 353                  $message = __( 'The post status %1$s is not registered, so it may not be reliable to check the capability %2$s against a post with that status.' );
 354  
 355                  _doing_it_wrong(
 356                      __FUNCTION__,
 357                      sprintf(
 358                          $message,
 359                          '<code>' . get_post_status( $post ) . '</code>',
 360                          '<code>' . $cap . '</code>'
 361                      ),
 362                      '5.4.0'
 363                  );
 364  
 365                  $caps[] = 'edit_others_posts';
 366                  break;
 367              }
 368  
 369              if ( $status_obj->public ) {
 370                  $caps[] = $post_type->cap->read;
 371                  break;
 372              }
 373  
 374              if ( $post->post_author && $user_id === (int) $post->post_author ) {
 375                  $caps[] = $post_type->cap->read;
 376              } elseif ( $status_obj->private ) {
 377                  $caps[] = $post_type->cap->read_private_posts;
 378              } else {
 379                  $caps = map_meta_cap( 'edit_post', $user_id, $post->ID );
 380              }
 381              break;
 382          case 'publish_post':
 383              if ( ! isset( $args[0] ) ) {
 384                  /* translators: %s: Capability name. */
 385                  $message = __( 'When checking for the %s capability, you must always check it against a specific post.' );
 386  
 387                  _doing_it_wrong(
 388                      __FUNCTION__,
 389                      sprintf( $message, '<code>' . $cap . '</code>' ),
 390                      '6.1.0'
 391                  );
 392  
 393                  $caps[] = 'do_not_allow';
 394                  break;
 395              }
 396  
 397              $post = get_post( $args[0] );
 398              if ( ! $post ) {
 399                  $caps[] = 'do_not_allow';
 400                  break;
 401              }
 402  
 403              $post_type = get_post_type_object( $post->post_type );
 404              if ( ! $post_type ) {
 405                  /* translators: 1: Post type, 2: Capability name. */
 406                  $message = __( 'The post type %1$s is not registered, so it may not be reliable to check the capability %2$s against a post of that type.' );
 407  
 408                  _doing_it_wrong(
 409                      __FUNCTION__,
 410                      sprintf(
 411                          $message,
 412                          '<code>' . $post->post_type . '</code>',
 413                          '<code>' . $cap . '</code>'
 414                      ),
 415                      '4.4.0'
 416                  );
 417  
 418                  $caps[] = 'edit_others_posts';
 419                  break;
 420              }
 421  
 422              $caps[] = $post_type->cap->publish_posts;
 423              break;
 424          case 'edit_post_meta':
 425          case 'delete_post_meta':
 426          case 'add_post_meta':
 427          case 'edit_comment_meta':
 428          case 'delete_comment_meta':
 429          case 'add_comment_meta':
 430          case 'edit_term_meta':
 431          case 'delete_term_meta':
 432          case 'add_term_meta':
 433          case 'edit_user_meta':
 434          case 'delete_user_meta':
 435          case 'add_user_meta':
 436              $object_type = explode( '_', $cap )[1];
 437  
 438              if ( ! isset( $args[0] ) ) {
 439                  if ( 'post' === $object_type ) {
 440                      /* translators: %s: Capability name. */
 441                      $message = __( 'When checking for the %s capability, you must always check it against a specific post.' );
 442                  } elseif ( 'comment' === $object_type ) {
 443                      /* translators: %s: Capability name. */
 444                      $message = __( 'When checking for the %s capability, you must always check it against a specific comment.' );
 445                  } elseif ( 'term' === $object_type ) {
 446                      /* translators: %s: Capability name. */
 447                      $message = __( 'When checking for the %s capability, you must always check it against a specific term.' );
 448                  } else {
 449                      /* translators: %s: Capability name. */
 450                      $message = __( 'When checking for the %s capability, you must always check it against a specific user.' );
 451                  }
 452  
 453                  _doing_it_wrong(
 454                      __FUNCTION__,
 455                      sprintf( $message, '<code>' . $cap . '</code>' ),
 456                      '6.1.0'
 457                  );
 458  
 459                  $caps[] = 'do_not_allow';
 460                  break;
 461              }
 462  
 463              $object_id = (int) $args[0];
 464  
 465              $object_subtype = get_object_subtype( $object_type, $object_id );
 466  
 467              if ( empty( $object_subtype ) ) {
 468                  $caps[] = 'do_not_allow';
 469                  break;
 470              }
 471  
 472              $caps = map_meta_cap( "edit_{$object_type}", $user_id, $object_id );
 473  
 474              $meta_key = $args[1] ?? false;
 475  
 476              if ( $meta_key ) {
 477                  $allowed = ! is_protected_meta( $meta_key, $object_type );
 478  
 479                  if ( has_filter( "auth_{$object_type}_meta_{$meta_key}_for_{$object_subtype}" ) ) {
 480  
 481                      /**
 482                       * Filters whether the user is allowed to edit a specific meta key of a specific object type and subtype.
 483                       *
 484                       * The dynamic portions of the hook name, `$object_type`, `$meta_key`,
 485                       * and `$object_subtype`, refer to the metadata object type (comment, post, term or user),
 486                       * the meta key value, and the object subtype respectively.
 487                       *
 488                       * @since 4.9.8
 489                       *
 490                       * @param bool     $allowed   Whether the user can add the object meta. Default false.
 491                       * @param string   $meta_key  The meta key.
 492                       * @param int      $object_id Object ID.
 493                       * @param int      $user_id   User ID.
 494                       * @param string   $cap       Capability name.
 495                       * @param string[] $caps      Array of the user's capabilities.
 496                       */
 497                      $allowed = apply_filters( "auth_{$object_type}_meta_{$meta_key}_for_{$object_subtype}", $allowed, $meta_key, $object_id, $user_id, $cap, $caps );
 498                  } else {
 499  
 500                      /**
 501                       * Filters whether the user is allowed to edit a specific meta key of a specific object type.
 502                       *
 503                       * Return true to have the mapped meta caps from `edit_{$object_type}` apply.
 504                       *
 505                       * The dynamic portion of the hook name, `$object_type` refers to the object type being filtered.
 506                       * The dynamic portion of the hook name, `$meta_key`, refers to the meta key passed to map_meta_cap().
 507                       *
 508                       * @since 3.3.0 As `auth_post_meta_{$meta_key}`.
 509                       * @since 4.6.0
 510                       *
 511                       * @param bool     $allowed   Whether the user can add the object meta. Default false.
 512                       * @param string   $meta_key  The meta key.
 513                       * @param int      $object_id Object ID.
 514                       * @param int      $user_id   User ID.
 515                       * @param string   $cap       Capability name.
 516                       * @param string[] $caps      Array of the user's capabilities.
 517                       */
 518                      $allowed = apply_filters( "auth_{$object_type}_meta_{$meta_key}", $allowed, $meta_key, $object_id, $user_id, $cap, $caps );
 519                  }
 520  
 521                  /**
 522                   * Filters whether the user is allowed to edit meta for specific object types/subtypes.
 523                   *
 524                   * Return true to have the mapped meta caps from `edit_{$object_type}` apply.
 525                   *
 526                   * The dynamic portion of the hook name, `$object_type` refers to the object type being filtered.
 527                   * The dynamic portion of the hook name, `$object_subtype` refers to the object subtype being filtered.
 528                   * The dynamic portion of the hook name, `$meta_key`, refers to the meta key passed to map_meta_cap().
 529                   *
 530                   * @since 4.6.0 As `auth_post_{$post_type}_meta_{$meta_key}`.
 531                   * @since 4.7.0 Renamed from `auth_post_{$post_type}_meta_{$meta_key}` to
 532                   *              `auth_{$object_type}_{$object_subtype}_meta_{$meta_key}`.
 533                   * @deprecated 4.9.8 Use {@see 'auth_{$object_type}_meta_{$meta_key}_for_{$object_subtype}'} instead.
 534                   *
 535                   * @param bool     $allowed   Whether the user can add the object meta. Default false.
 536                   * @param string   $meta_key  The meta key.
 537                   * @param int      $object_id Object ID.
 538                   * @param int      $user_id   User ID.
 539                   * @param string   $cap       Capability name.
 540                   * @param string[] $caps      Array of the user's capabilities.
 541                   */
 542                  $allowed = apply_filters_deprecated(
 543                      "auth_{$object_type}_{$object_subtype}_meta_{$meta_key}",
 544                      array( $allowed, $meta_key, $object_id, $user_id, $cap, $caps ),
 545                      '4.9.8',
 546                      "auth_{$object_type}_meta_{$meta_key}_for_{$object_subtype}"
 547                  );
 548  
 549                  if ( ! $allowed ) {
 550                      $caps[] = $cap;
 551                  }
 552              }
 553              break;
 554          case 'edit_comment':
 555              if ( ! isset( $args[0] ) ) {
 556                  /* translators: %s: Capability name. */
 557                  $message = __( 'When checking for the %s capability, you must always check it against a specific comment.' );
 558  
 559                  _doing_it_wrong(
 560                      __FUNCTION__,
 561                      sprintf( $message, '<code>' . $cap . '</code>' ),
 562                      '6.1.0'
 563                  );
 564  
 565                  $caps[] = 'do_not_allow';
 566                  break;
 567              }
 568  
 569              $comment = get_comment( $args[0] );
 570              if ( ! $comment ) {
 571                  $caps[] = 'do_not_allow';
 572                  break;
 573              }
 574  
 575              $post = get_post( $comment->comment_post_ID );
 576  
 577              /*
 578               * If the post doesn't exist, we have an orphaned comment.
 579               * Fall back to the edit_posts capability, instead.
 580               */
 581              if ( $post ) {
 582                  $caps = map_meta_cap( 'edit_post', $user_id, $post->ID );
 583              } else {
 584                  $caps = map_meta_cap( 'edit_posts', $user_id );
 585              }
 586              break;
 587          case 'unfiltered_upload':
 588              if ( defined( 'ALLOW_UNFILTERED_UPLOADS' ) && ALLOW_UNFILTERED_UPLOADS && ( ! is_multisite() || is_super_admin( $user_id ) ) ) {
 589                  $caps[] = $cap;
 590              } else {
 591                  $caps[] = 'do_not_allow';
 592              }
 593              break;
 594          case 'edit_css':
 595          case 'unfiltered_html':
 596              // Disallow unfiltered_html for all users, even admins and super admins.
 597              if ( defined( 'DISALLOW_UNFILTERED_HTML' ) && DISALLOW_UNFILTERED_HTML ) {
 598                  $caps[] = 'do_not_allow';
 599              } elseif ( is_multisite() && ! is_super_admin( $user_id ) ) {
 600                  $caps[] = 'do_not_allow';
 601              } else {
 602                  $caps[] = 'unfiltered_html';
 603              }
 604              break;
 605          case 'edit_files':
 606          case 'edit_plugins':
 607          case 'edit_themes':
 608              // Disallow the file editors.
 609              if ( defined( 'DISALLOW_FILE_EDIT' ) && DISALLOW_FILE_EDIT ) {
 610                  $caps[] = 'do_not_allow';
 611              } elseif ( ! wp_is_file_mod_allowed( 'capability_edit_themes' ) ) {
 612                  $caps[] = 'do_not_allow';
 613              } elseif ( is_multisite() && ! is_super_admin( $user_id ) ) {
 614                  $caps[] = 'do_not_allow';
 615              } else {
 616                  $caps[] = $cap;
 617              }
 618              break;
 619          case 'update_plugins':
 620          case 'delete_plugins':
 621          case 'install_plugins':
 622          case 'upload_plugins':
 623          case 'update_themes':
 624          case 'delete_themes':
 625          case 'install_themes':
 626          case 'upload_themes':
 627          case 'update_core':
 628              /*
 629               * Disallow anything that creates, deletes, or updates core, plugin, or theme files.
 630               * Files in uploads are excepted.
 631               */
 632              if ( ! wp_is_file_mod_allowed( 'capability_update_core' ) ) {
 633                  $caps[] = 'do_not_allow';
 634              } elseif ( is_multisite() && ! is_super_admin( $user_id ) ) {
 635                  $caps[] = 'do_not_allow';
 636              } elseif ( 'upload_themes' === $cap ) {
 637                  $caps[] = 'install_themes';
 638              } elseif ( 'upload_plugins' === $cap ) {
 639                  $caps[] = 'install_plugins';
 640              } else {
 641                  $caps[] = $cap;
 642              }
 643              break;
 644          case 'install_languages':
 645          case 'update_languages':
 646              if ( ! wp_is_file_mod_allowed( 'can_install_language_pack' ) ) {
 647                  $caps[] = 'do_not_allow';
 648              } elseif ( is_multisite() && ! is_super_admin( $user_id ) ) {
 649                  $caps[] = 'do_not_allow';
 650              } else {
 651                  $caps[] = 'install_languages';
 652              }
 653              break;
 654          case 'activate_plugins':
 655          case 'deactivate_plugins':
 656          case 'activate_plugin':
 657          case 'deactivate_plugin':
 658              $caps[] = 'activate_plugins';
 659              if ( is_multisite() ) {
 660                  // update_, install_, and delete_ are handled above with is_super_admin().
 661                  $menu_perms = get_site_option( 'menu_items', array() );
 662                  if ( empty( $menu_perms['plugins'] ) ) {
 663                      $caps[] = 'manage_network_plugins';
 664                  }
 665              }
 666              break;
 667          case 'resume_plugin':
 668              $caps[] = 'resume_plugins';
 669              break;
 670          case 'resume_theme':
 671              $caps[] = 'resume_themes';
 672              break;
 673          case 'delete_user':
 674          case 'delete_users':
 675              // If multisite only super admins can delete users.
 676              if ( is_multisite() && ! is_super_admin( $user_id ) ) {
 677                  $caps[] = 'do_not_allow';
 678              } else {
 679                  $caps[] = 'delete_users'; // delete_user maps to delete_users.
 680              }
 681              break;
 682          case 'create_users':
 683              if ( ! is_multisite() ) {
 684                  $caps[] = $cap;
 685              } elseif ( is_super_admin( $user_id ) || get_site_option( 'add_new_users' ) ) {
 686                  $caps[] = $cap;
 687              } else {
 688                  $caps[] = 'do_not_allow';
 689              }
 690              break;
 691          case 'manage_links':
 692              if ( get_option( 'link_manager_enabled' ) ) {
 693                  $caps[] = $cap;
 694              } else {
 695                  $caps[] = 'do_not_allow';
 696              }
 697              break;
 698          case 'customize':
 699              $caps[] = 'edit_theme_options';
 700              break;
 701          case 'delete_site':
 702              if ( is_multisite() ) {
 703                  $caps[] = 'manage_options';
 704              } else {
 705                  $caps[] = 'do_not_allow';
 706              }
 707              break;
 708          case 'edit_term':
 709          case 'delete_term':
 710          case 'assign_term':
 711              if ( ! isset( $args[0] ) ) {
 712                  /* translators: %s: Capability name. */
 713                  $message = __( 'When checking for the %s capability, you must always check it against a specific term.' );
 714  
 715                  _doing_it_wrong(
 716                      __FUNCTION__,
 717                      sprintf( $message, '<code>' . $cap . '</code>' ),
 718                      '6.1.0'
 719                  );
 720  
 721                  $caps[] = 'do_not_allow';
 722                  break;
 723              }
 724  
 725              $term_id = (int) $args[0];
 726              $term    = get_term( $term_id );
 727              if ( ! $term || is_wp_error( $term ) ) {
 728                  $caps[] = 'do_not_allow';
 729                  break;
 730              }
 731  
 732              $tax = get_taxonomy( $term->taxonomy );
 733              if ( ! $tax ) {
 734                  $caps[] = 'do_not_allow';
 735                  break;
 736              }
 737  
 738              if ( 'delete_term' === $cap
 739                  && ( (int) get_option( 'default_' . $term->taxonomy ) === $term->term_id
 740                      || (int) get_option( 'default_term_' . $term->taxonomy ) === $term->term_id )
 741              ) {
 742                  $caps[] = 'do_not_allow';
 743                  break;
 744              }
 745  
 746              $taxo_cap = $cap . 's';
 747  
 748              $caps = map_meta_cap( $tax->cap->$taxo_cap, $user_id, $term_id );
 749  
 750              break;
 751          case 'manage_post_tags':
 752          case 'edit_categories':
 753          case 'edit_post_tags':
 754          case 'delete_categories':
 755          case 'delete_post_tags':
 756              $caps[] = 'manage_categories';
 757              break;
 758          case 'assign_categories':
 759          case 'assign_post_tags':
 760              $caps[] = 'edit_posts';
 761              break;
 762          case 'create_sites':
 763          case 'delete_sites':
 764          case 'manage_network':
 765          case 'manage_sites':
 766          case 'manage_network_users':
 767          case 'manage_network_plugins':
 768          case 'manage_network_themes':
 769          case 'manage_network_options':
 770          case 'manage_network_secrets':
 771          case 'upgrade_network':
 772              $caps[] = $cap;
 773              break;
 774          case 'setup_network':
 775              if ( is_multisite() ) {
 776                  $caps[] = 'manage_network_options';
 777              } else {
 778                  $caps[] = 'manage_options';
 779              }
 780              break;
 781          case 'update_php':
 782              if ( is_multisite() && ! is_super_admin( $user_id ) ) {
 783                  $caps[] = 'do_not_allow';
 784              } else {
 785                  $caps[] = 'update_core';
 786              }
 787              break;
 788          case 'update_https':
 789              if ( is_multisite() && ! is_super_admin( $user_id ) ) {
 790                  $caps[] = 'do_not_allow';
 791              } else {
 792                  $caps[] = 'manage_options';
 793                  $caps[] = 'update_core';
 794              }
 795              break;
 796          case 'export_others_personal_data':
 797          case 'erase_others_personal_data':
 798          case 'manage_privacy_options':
 799              $caps[] = is_multisite() ? 'manage_network' : 'manage_options';
 800              break;
 801          case 'create_app_password':
 802          case 'list_app_passwords':
 803          case 'read_app_password':
 804          case 'edit_app_password':
 805          case 'delete_app_passwords':
 806          case 'delete_app_password':
 807              $caps = map_meta_cap( 'edit_user', $user_id, $args[0] );
 808              break;
 809          case 'edit_block_binding':
 810              $block_editor_context = $args[0];
 811              if ( isset( $block_editor_context->post ) ) {
 812                  $object_id = $block_editor_context->post->ID;
 813              }
 814              /*
 815               * If the post ID is null, check if the context is the site editor.
 816               * Fall back to the edit_theme_options in that case.
 817               */
 818              if ( ! isset( $object_id ) ) {
 819                  if ( ! isset( $block_editor_context->name ) || 'core/edit-site' !== $block_editor_context->name ) {
 820                      $caps[] = 'do_not_allow';
 821                      break;
 822                  }
 823                  $caps = map_meta_cap( 'edit_theme_options', $user_id );
 824                  break;
 825              }
 826  
 827              $object_subtype = get_object_subtype( 'post', (int) $object_id );
 828              if ( empty( $object_subtype ) ) {
 829                  $caps[] = 'do_not_allow';
 830                  break;
 831              }
 832              $post_type_object = get_post_type_object( $object_subtype );
 833              // Initialize empty array if it doesn't exist.
 834              if ( ! isset( $post_type_object->capabilities ) ) {
 835                  $post_type_object->capabilities = array();
 836              }
 837              $post_type_capabilities = get_post_type_capabilities( $post_type_object );
 838              $caps                   = map_meta_cap( $post_type_capabilities->edit_post, $user_id, $object_id );
 839              break;
 840          default:
 841              // Handle meta capabilities for custom post types.
 842              global $post_type_meta_caps;
 843              if ( isset( $post_type_meta_caps[ $cap ] ) ) {
 844                  return map_meta_cap( $post_type_meta_caps[ $cap ], $user_id, ...$args );
 845              }
 846  
 847              // Block capabilities map to their post equivalent.
 848              $block_caps = array(
 849                  'edit_blocks',
 850                  'edit_others_blocks',
 851                  'publish_blocks',
 852                  'read_private_blocks',
 853                  'delete_blocks',
 854                  'delete_private_blocks',
 855                  'delete_published_blocks',
 856                  'delete_others_blocks',
 857                  'edit_private_blocks',
 858                  'edit_published_blocks',
 859              );
 860              if ( in_array( $cap, $block_caps, true ) ) {
 861                  $cap = str_replace( '_blocks', '_posts', $cap );
 862              }
 863  
 864              // If no meta caps match, return the original cap.
 865              $caps[] = $cap;
 866      }
 867  
 868      /**
 869       * Filters the primitive capabilities required of the given user to satisfy the
 870       * capability being checked.
 871       *
 872       * @since 2.8.0
 873       *
 874       * @param string[] $caps    Primitive capabilities required of the user.
 875       * @param string   $cap     Capability being checked.
 876       * @param int      $user_id The user ID.
 877       * @param array    $args    Adds context to the capability check, typically
 878       *                          starting with an object ID.
 879       */
 880      return apply_filters( 'map_meta_cap', $caps, $cap, $user_id, $args );
 881  }
 882  
 883  /**
 884   * Returns whether the current user has the specified capability.
 885   *
 886   * This function also accepts an ID of an object to check against if the capability is a meta capability. Meta
 887   * capabilities such as `edit_post` and `edit_user` are capabilities used by the `map_meta_cap()` function to
 888   * map to primitive capabilities that a user or role has, such as `edit_posts` and `edit_others_posts`.
 889   *
 890   * Example usage:
 891   *
 892   *     current_user_can( 'edit_posts' );
 893   *     current_user_can( 'edit_post', $post->ID );
 894   *     current_user_can( 'edit_post_meta', $post->ID, $meta_key );
 895   *
 896   * While checking against particular roles in place of a capability is supported
 897   * in part, this practice is discouraged as it may produce unreliable results.
 898   *
 899   * Note: Will always return true if the current user is a super admin, unless specifically denied.
 900   *
 901   * @since 2.0.0
 902   * @since 5.3.0 Formalized the existing and already documented `...$args` parameter
 903   *              by adding it to the function signature.
 904   * @since 5.8.0 Converted to wrapper for the user_can() function.
 905   *
 906   * @see WP_User::has_cap()
 907   * @see map_meta_cap()
 908   *
 909   * @param string $capability Capability name.
 910   * @param mixed  ...$args    Optional further parameters, typically starting with an object ID.
 911   * @return bool Whether the current user has the given capability. If `$capability` is a meta cap and `$object_id` is
 912   *              passed, whether the current user has the given meta capability for the given object.
 913   *
 914   * @phpstan-impure
 915   */
 916  function current_user_can( $capability, ...$args ) {
 917      return user_can( wp_get_current_user(), $capability, ...$args );
 918  }
 919  
 920  /**
 921   * Returns whether the current user has the specified capability for a given site.
 922   *
 923   * This function also accepts an ID of an object to check against if the capability is a meta capability. Meta
 924   * capabilities such as `edit_post` and `edit_user` are capabilities used by the `map_meta_cap()` function to
 925   * map to primitive capabilities that a user or role has, such as `edit_posts` and `edit_others_posts`.
 926   *
 927   * This function replaces the current_user_can_for_blog() function.
 928   *
 929   * Example usage:
 930   *
 931   *     current_user_can_for_site( $site_id, 'edit_posts' );
 932   *     current_user_can_for_site( $site_id, 'edit_post', $post->ID );
 933   *     current_user_can_for_site( $site_id, 'edit_post_meta', $post->ID, $meta_key );
 934   *
 935   * @since 6.7.0
 936   *
 937   * @param int    $site_id    Site ID.
 938   * @param string $capability Capability name.
 939   * @param mixed  ...$args    Optional further parameters, typically starting with an object ID.
 940   * @return bool Whether the user has the given capability.
 941   */
 942  function current_user_can_for_site( $site_id, $capability, ...$args ) {
 943      $switched = is_multisite() ? switch_to_blog( $site_id ) : false;
 944  
 945      $can = current_user_can( $capability, ...$args );
 946  
 947      if ( $switched ) {
 948          restore_current_blog();
 949      }
 950  
 951      return $can;
 952  }
 953  
 954  /**
 955   * Returns whether the author of the supplied post has the specified capability.
 956   *
 957   * This function also accepts an ID of an object to check against if the capability is a meta capability. Meta
 958   * capabilities such as `edit_post` and `edit_user` are capabilities used by the `map_meta_cap()` function to
 959   * map to primitive capabilities that a user or role has, such as `edit_posts` and `edit_others_posts`.
 960   *
 961   * Example usage:
 962   *
 963   *     author_can( $post, 'edit_posts' );
 964   *     author_can( $post, 'edit_post', $post->ID );
 965   *     author_can( $post, 'edit_post_meta', $post->ID, $meta_key );
 966   *
 967   * @since 2.9.0
 968   * @since 5.3.0 Formalized the existing and already documented `...$args` parameter
 969   *              by adding it to the function signature.
 970   *
 971   * @param int|WP_Post $post       Post ID or post object.
 972   * @param string      $capability Capability name.
 973   * @param mixed       ...$args    Optional further parameters, typically starting with an object ID.
 974   * @return bool Whether the post author has the given capability.
 975   */
 976  function author_can( $post, $capability, ...$args ) {
 977      $post = get_post( $post );
 978      if ( ! $post ) {
 979          return false;
 980      }
 981  
 982      $author = get_userdata( $post->post_author );
 983  
 984      if ( ! $author ) {
 985          return false;
 986      }
 987  
 988      return $author->has_cap( $capability, ...$args );
 989  }
 990  
 991  /**
 992   * Returns whether a particular user has the specified capability.
 993   *
 994   * This function also accepts an ID of an object to check against if the capability is a meta capability. Meta
 995   * capabilities such as `edit_post` and `edit_user` are capabilities used by the `map_meta_cap()` function to
 996   * map to primitive capabilities that a user or role has, such as `edit_posts` and `edit_others_posts`.
 997   *
 998   * Example usage:
 999   *
1000   *     user_can( $user->ID, 'edit_posts' );
1001   *     user_can( $user->ID, 'edit_post', $post->ID );
1002   *     user_can( $user->ID, 'edit_post_meta', $post->ID, $meta_key );
1003   *
1004   * @since 3.1.0
1005   * @since 5.3.0 Formalized the existing and already documented `...$args` parameter
1006   *              by adding it to the function signature.
1007   *
1008   * @param int|WP_User $user       User ID or object.
1009   * @param string      $capability Capability name.
1010   * @param mixed       ...$args    Optional further parameters, typically starting with an object ID.
1011   * @return bool Whether the user has the given capability.
1012   */
1013  function user_can( $user, $capability, ...$args ) {
1014      if ( ! is_object( $user ) ) {
1015          $user = get_userdata( $user );
1016      }
1017  
1018      if ( empty( $user ) ) {
1019          // User is logged out, create anonymous user object.
1020          $user = new WP_User( 0 );
1021          $user->init( new stdClass() );
1022      }
1023  
1024      return $user->has_cap( $capability, ...$args );
1025  }
1026  
1027  /**
1028   * Returns whether a particular user has the specified capability for a given site.
1029   *
1030   * This function also accepts an ID of an object to check against if the capability is a meta capability. Meta
1031   * capabilities such as `edit_post` and `edit_user` are capabilities used by the `map_meta_cap()` function to
1032   * map to primitive capabilities that a user or role has, such as `edit_posts` and `edit_others_posts`.
1033   *
1034   * Example usage:
1035   *
1036   *     user_can_for_site( $user->ID, $site_id, 'edit_posts' );
1037   *     user_can_for_site( $user->ID, $site_id, 'edit_post', $post->ID );
1038   *     user_can_for_site( $user->ID, $site_id, 'edit_post_meta', $post->ID, $meta_key );
1039   *
1040   * @since 6.7.0
1041   *
1042   * @param int|WP_User $user       User ID or object.
1043   * @param int         $site_id    Site ID.
1044   * @param string      $capability Capability name.
1045   * @param mixed       ...$args    Optional further parameters, typically starting with an object ID.
1046   * @return bool Whether the user has the given capability.
1047   */
1048  function user_can_for_site( $user, $site_id, $capability, ...$args ) {
1049      if ( ! is_object( $user ) ) {
1050          $user = get_userdata( $user );
1051      }
1052  
1053      if ( empty( $user ) ) {
1054          // User is logged out, create anonymous user object.
1055          $user = new WP_User( 0 );
1056          $user->init( new stdClass() );
1057      }
1058  
1059      // Check if the blog ID is valid.
1060      if ( ! is_numeric( $site_id ) || $site_id <= 0 ) {
1061          return false;
1062      }
1063  
1064      $switched = is_multisite() ? switch_to_blog( $site_id ) : false;
1065  
1066      $can = user_can( $user->ID, $capability, ...$args );
1067  
1068      if ( $switched ) {
1069          restore_current_blog();
1070      }
1071  
1072      return $can;
1073  }
1074  
1075  /**
1076   * Retrieves the global WP_Roles instance and instantiates it if necessary.
1077   *
1078   * @since 4.3.0
1079   *
1080   * @global WP_Roles $wp_roles WordPress role management object.
1081   *
1082   * @return WP_Roles WP_Roles global instance if not already instantiated.
1083   */
1084  function wp_roles(): WP_Roles {
1085      global $wp_roles;
1086  
1087      if ( ! ( $wp_roles instanceof WP_Roles ) ) {
1088          $wp_roles = new WP_Roles();
1089      }
1090      return $wp_roles;
1091  }
1092  
1093  /**
1094   * Retrieves role object.
1095   *
1096   * @since 2.0.0
1097   *
1098   * @param string $role Role name.
1099   * @return WP_Role|null WP_Role object if found, null if the role does not exist.
1100   */
1101  function get_role( $role ) {
1102      return wp_roles()->get_role( $role );
1103  }
1104  
1105  /**
1106   * Adds a role, if it does not exist.
1107   *
1108   * The list of capabilities can be passed either as a numerically indexed array of capability names, or an
1109   * associative array of boolean values keyed by the capability name. To explicitly deny the role a capability, set
1110   * the value for that capability to false.
1111   *
1112   * Examples:
1113   *
1114   *     // Add a role that can edit posts.
1115   *     add_role( 'custom_role', 'Custom Role', array(
1116   *         'read',
1117   *         'edit_posts',
1118   *     ) );
1119   *
1120   * Or, using an associative array:
1121   *
1122   *     // Add a role that can edit posts but explicitly cannot not delete them.
1123   *     add_role( 'custom_role', 'Custom Role', array(
1124   *         'read' => true,
1125   *         'edit_posts' => true,
1126   *         'delete_posts' => false,
1127   *     ) );
1128   *
1129   * @since 2.0.0
1130   * @since 6.9.0 Support was added for a numerically indexed array of strings for the capabilities array.
1131   *
1132   * @param string                               $role         Role name.
1133   * @param string                               $display_name Display name for role.
1134   * @param array<string,bool>|array<int,string> $capabilities Capabilities to be added to the role.
1135   *                                                           Default empty array.
1136   * @return WP_Role|null WP_Role object, if the role is added.
1137   */
1138  function add_role( $role, $display_name, $capabilities = array() ) {
1139      if ( empty( $role ) ) {
1140          return null;
1141      }
1142  
1143      return wp_roles()->add_role( $role, $display_name, $capabilities );
1144  }
1145  
1146  /**
1147   * Removes a role, if it exists.
1148   *
1149   * @since 2.0.0
1150   *
1151   * @param string $role Role name.
1152   */
1153  function remove_role( $role ) {
1154      wp_roles()->remove_role( $role );
1155  }
1156  
1157  /**
1158   * Retrieves a list of super admins.
1159   *
1160   * @since 3.0.0
1161   *
1162   * @global array $super_admins
1163   *
1164   * @return string[] List of super admin logins.
1165   */
1166  function get_super_admins() {
1167      global $super_admins;
1168  
1169      return $super_admins ?? get_site_option( 'site_admins', array( 'admin' ) );
1170  }
1171  
1172  /**
1173   * Determines whether user is a site admin.
1174   *
1175   * @since 3.0.0
1176   *
1177   * @param int|false $user_id Optional. The ID of a user. Defaults to false, to check the current user.
1178   * @return bool Whether the user is a site admin.
1179   */
1180  function is_super_admin( $user_id = false ) {
1181      if ( ! $user_id ) {
1182          $user = wp_get_current_user();
1183      } else {
1184          $user = get_userdata( $user_id );
1185      }
1186  
1187      if ( ! $user || ! $user->exists() ) {
1188          return false;
1189      }
1190  
1191      if ( is_multisite() ) {
1192          $super_admins = get_super_admins();
1193          if ( is_array( $super_admins ) && in_array( $user->user_login, $super_admins, true ) ) {
1194              return true;
1195          }
1196      } elseif ( $user->has_cap( 'delete_users' ) ) {
1197          return true;
1198      }
1199  
1200      return false;
1201  }
1202  
1203  /**
1204   * Grants Super Admin privileges.
1205   *
1206   * @since 3.0.0
1207   *
1208   * @global array $super_admins
1209   *
1210   * @param int $user_id ID of the user to be granted Super Admin privileges.
1211   * @return bool True on success, false on failure. This can fail when the user is
1212   *              already a super admin or when the `$super_admins` global is defined.
1213   */
1214  function grant_super_admin( $user_id ) {
1215      // If global super_admins override is defined, there is nothing to do here.
1216      if ( isset( $GLOBALS['super_admins'] ) || ! is_multisite() ) {
1217          return false;
1218      }
1219  
1220      /**
1221       * Fires before the user is granted Super Admin privileges.
1222       *
1223       * @since 3.0.0
1224       *
1225       * @param int $user_id ID of the user that is about to be granted Super Admin privileges.
1226       */
1227      do_action( 'grant_super_admin', $user_id );
1228  
1229      // Directly fetch site_admins instead of using get_super_admins().
1230      $super_admins = get_site_option( 'site_admins', array( 'admin' ) );
1231  
1232      $user = get_userdata( $user_id );
1233      if ( $user && ! in_array( $user->user_login, $super_admins, true ) ) {
1234          $super_admins[] = $user->user_login;
1235          update_site_option( 'site_admins', $super_admins );
1236  
1237          /**
1238           * Fires after the user is granted Super Admin privileges.
1239           *
1240           * @since 3.0.0
1241           *
1242           * @param int $user_id ID of the user that was granted Super Admin privileges.
1243           */
1244          do_action( 'granted_super_admin', $user_id );
1245          return true;
1246      }
1247      return false;
1248  }
1249  
1250  /**
1251   * Revokes Super Admin privileges.
1252   *
1253   * @since 3.0.0
1254   * @since 6.9.0 Super admin privileges can be revoked regardless of email address.
1255   *
1256   * @global array $super_admins
1257   *
1258   * @param int $user_id ID of the user Super Admin privileges to be revoked from.
1259   * @return bool True on success, false on failure. This can fail when the user's email
1260   *              is the network admin email or when the `$super_admins` global is defined.
1261   */
1262  function revoke_super_admin( $user_id ) {
1263      // If global super_admins override is defined, there is nothing to do here.
1264      if ( isset( $GLOBALS['super_admins'] ) || ! is_multisite() ) {
1265          return false;
1266      }
1267  
1268      /**
1269       * Fires before the user's Super Admin privileges are revoked.
1270       *
1271       * @since 3.0.0
1272       *
1273       * @param int $user_id ID of the user Super Admin privileges are being revoked from.
1274       */
1275      do_action( 'revoke_super_admin', $user_id );
1276  
1277      // Directly fetch site_admins instead of using get_super_admins().
1278      $super_admins = get_site_option( 'site_admins', array( 'admin' ) );
1279  
1280      $user = get_userdata( $user_id );
1281      if ( $user ) {
1282          $key = array_search( $user->user_login, $super_admins, true );
1283          if ( false !== $key ) {
1284              unset( $super_admins[ $key ] );
1285              update_site_option( 'site_admins', $super_admins );
1286  
1287              /**
1288               * Fires after the user's Super Admin privileges are revoked.
1289               *
1290               * @since 3.0.0
1291               *
1292               * @param int $user_id ID of the user Super Admin privileges were revoked from.
1293               */
1294              do_action( 'revoked_super_admin', $user_id );
1295              return true;
1296          }
1297      }
1298      return false;
1299  }
1300  
1301  /**
1302   * Filters the user capabilities to grant the 'install_languages' capability as necessary.
1303   *
1304   * A user must have at least one out of the 'update_core', 'install_plugins', and
1305   * 'install_themes' capabilities to qualify for 'install_languages'.
1306   *
1307   * @since 4.9.0
1308   *
1309   * @param bool[] $allcaps An array of all the user's capabilities.
1310   * @return bool[] Filtered array of the user's capabilities.
1311   */
1312  function wp_maybe_grant_install_languages_cap( $allcaps ) {
1313      if ( ! empty( $allcaps['update_core'] ) || ! empty( $allcaps['install_plugins'] ) || ! empty( $allcaps['install_themes'] ) ) {
1314          $allcaps['install_languages'] = true;
1315      }
1316  
1317      return $allcaps;
1318  }
1319  
1320  /**
1321   * Filters the user capabilities to grant the 'resume_plugins' and 'resume_themes' capabilities as necessary.
1322   *
1323   * @since 5.2.0
1324   *
1325   * @param bool[] $allcaps An array of all the user's capabilities.
1326   * @return bool[] Filtered array of the user's capabilities.
1327   */
1328  function wp_maybe_grant_resume_extensions_caps( $allcaps ) {
1329      // Even in a multisite, regular administrators should be able to resume plugins.
1330      if ( ! empty( $allcaps['activate_plugins'] ) ) {
1331          $allcaps['resume_plugins'] = true;
1332      }
1333  
1334      // Even in a multisite, regular administrators should be able to resume themes.
1335      if ( ! empty( $allcaps['switch_themes'] ) ) {
1336          $allcaps['resume_themes'] = true;
1337      }
1338  
1339      return $allcaps;
1340  }
1341  
1342  /**
1343   * Filters the user capabilities to grant the 'view_site_health_checks' capabilities as necessary.
1344   *
1345   * @since 5.2.2
1346   *
1347   * @param bool[]   $allcaps An array of all the user's capabilities.
1348   * @param string[] $caps    Required primitive capabilities for the requested capability.
1349   * @param array    $args {
1350   *     Arguments that accompany the requested capability check.
1351   *
1352   *     @type string    $0 Requested capability.
1353   *     @type int       $1 Concerned user ID.
1354   *     @type mixed  ...$2 Optional second and further parameters, typically object ID.
1355   * }
1356   * @param WP_User  $user    The user object.
1357   * @return bool[] Filtered array of the user's capabilities.
1358   */
1359  function wp_maybe_grant_site_health_caps( $allcaps, $caps, $args, $user ) {
1360      if ( ! empty( $allcaps['install_plugins'] ) && ( ! is_multisite() || is_super_admin( $user->ID ) ) ) {
1361          $allcaps['view_site_health_checks'] = true;
1362      }
1363  
1364      return $allcaps;
1365  }
1366  
1367  return;
1368  
1369  // Dummy gettext calls to get strings in the catalog.
1370  /* translators: User role for administrators. */
1371  _x( 'Administrator', 'User role' );
1372  /* translators: User role for editors. */
1373  _x( 'Editor', 'User role' );
1374  /* translators: User role for authors. */
1375  _x( 'Author', 'User role' );
1376  /* translators: User role for contributors. */
1377  _x( 'Contributor', 'User role' );
1378  /* translators: User role for subscribers. */
1379  _x( 'Subscriber', 'User role' );


Generated : Sun Oct 25 08:20:35 2026 Cross-referenced by PHPXref