[ 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              $post_type_object->capabilities ??= array();
 835              $post_type_capabilities           = get_post_type_capabilities( $post_type_object );
 836              $caps                             = map_meta_cap( $post_type_capabilities->edit_post, $user_id, $object_id );
 837              break;
 838          default:
 839              // Handle meta capabilities for custom post types.
 840              global $post_type_meta_caps;
 841              if ( isset( $post_type_meta_caps[ $cap ] ) ) {
 842                  return map_meta_cap( $post_type_meta_caps[ $cap ], $user_id, ...$args );
 843              }
 844  
 845              // Block capabilities map to their post equivalent.
 846              $block_caps = array(
 847                  'edit_blocks',
 848                  'edit_others_blocks',
 849                  'publish_blocks',
 850                  'read_private_blocks',
 851                  'delete_blocks',
 852                  'delete_private_blocks',
 853                  'delete_published_blocks',
 854                  'delete_others_blocks',
 855                  'edit_private_blocks',
 856                  'edit_published_blocks',
 857              );
 858              if ( in_array( $cap, $block_caps, true ) ) {
 859                  $cap = str_replace( '_blocks', '_posts', $cap );
 860              }
 861  
 862              // If no meta caps match, return the original cap.
 863              $caps[] = $cap;
 864      }
 865  
 866      /**
 867       * Filters the primitive capabilities required of the given user to satisfy the
 868       * capability being checked.
 869       *
 870       * @since 2.8.0
 871       *
 872       * @param string[] $caps    Primitive capabilities required of the user.
 873       * @param string   $cap     Capability being checked.
 874       * @param int      $user_id The user ID.
 875       * @param array    $args    Adds context to the capability check, typically
 876       *                          starting with an object ID.
 877       */
 878      return apply_filters( 'map_meta_cap', $caps, $cap, $user_id, $args );
 879  }
 880  
 881  /**
 882   * Returns whether the current user has the specified capability.
 883   *
 884   * This function also accepts an ID of an object to check against if the capability is a meta capability. Meta
 885   * capabilities such as `edit_post` and `edit_user` are capabilities used by the `map_meta_cap()` function to
 886   * map to primitive capabilities that a user or role has, such as `edit_posts` and `edit_others_posts`.
 887   *
 888   * Example usage:
 889   *
 890   *     current_user_can( 'edit_posts' );
 891   *     current_user_can( 'edit_post', $post->ID );
 892   *     current_user_can( 'edit_post_meta', $post->ID, $meta_key );
 893   *
 894   * While checking against particular roles in place of a capability is supported
 895   * in part, this practice is discouraged as it may produce unreliable results.
 896   *
 897   * Note: Will always return true if the current user is a super admin, unless specifically denied.
 898   *
 899   * @since 2.0.0
 900   * @since 5.3.0 Formalized the existing and already documented `...$args` parameter
 901   *              by adding it to the function signature.
 902   * @since 5.8.0 Converted to wrapper for the user_can() function.
 903   *
 904   * @see WP_User::has_cap()
 905   * @see map_meta_cap()
 906   *
 907   * @param string $capability Capability name.
 908   * @param mixed  ...$args    Optional further parameters, typically starting with an object ID.
 909   * @return bool Whether the current user has the given capability. If `$capability` is a meta cap and `$object_id` is
 910   *              passed, whether the current user has the given meta capability for the given object.
 911   *
 912   * @phpstan-impure
 913   */
 914  function current_user_can( $capability, ...$args ) {
 915      return user_can( wp_get_current_user(), $capability, ...$args );
 916  }
 917  
 918  /**
 919   * Returns whether the current user has the specified capability for a given site.
 920   *
 921   * This function also accepts an ID of an object to check against if the capability is a meta capability. Meta
 922   * capabilities such as `edit_post` and `edit_user` are capabilities used by the `map_meta_cap()` function to
 923   * map to primitive capabilities that a user or role has, such as `edit_posts` and `edit_others_posts`.
 924   *
 925   * This function replaces the current_user_can_for_blog() function.
 926   *
 927   * Example usage:
 928   *
 929   *     current_user_can_for_site( $site_id, 'edit_posts' );
 930   *     current_user_can_for_site( $site_id, 'edit_post', $post->ID );
 931   *     current_user_can_for_site( $site_id, 'edit_post_meta', $post->ID, $meta_key );
 932   *
 933   * @since 6.7.0
 934   *
 935   * @param int    $site_id    Site ID.
 936   * @param string $capability Capability name.
 937   * @param mixed  ...$args    Optional further parameters, typically starting with an object ID.
 938   * @return bool Whether the user has the given capability.
 939   */
 940  function current_user_can_for_site( $site_id, $capability, ...$args ) {
 941      $switched = is_multisite() ? switch_to_blog( $site_id ) : false;
 942  
 943      $can = current_user_can( $capability, ...$args );
 944  
 945      if ( $switched ) {
 946          restore_current_blog();
 947      }
 948  
 949      return $can;
 950  }
 951  
 952  /**
 953   * Returns whether the author of the supplied post has the specified capability.
 954   *
 955   * This function also accepts an ID of an object to check against if the capability is a meta capability. Meta
 956   * capabilities such as `edit_post` and `edit_user` are capabilities used by the `map_meta_cap()` function to
 957   * map to primitive capabilities that a user or role has, such as `edit_posts` and `edit_others_posts`.
 958   *
 959   * Example usage:
 960   *
 961   *     author_can( $post, 'edit_posts' );
 962   *     author_can( $post, 'edit_post', $post->ID );
 963   *     author_can( $post, 'edit_post_meta', $post->ID, $meta_key );
 964   *
 965   * @since 2.9.0
 966   * @since 5.3.0 Formalized the existing and already documented `...$args` parameter
 967   *              by adding it to the function signature.
 968   *
 969   * @param int|WP_Post $post       Post ID or post object.
 970   * @param string      $capability Capability name.
 971   * @param mixed       ...$args    Optional further parameters, typically starting with an object ID.
 972   * @return bool Whether the post author has the given capability.
 973   */
 974  function author_can( $post, $capability, ...$args ) {
 975      $post = get_post( $post );
 976      if ( ! $post ) {
 977          return false;
 978      }
 979  
 980      $author = get_userdata( $post->post_author );
 981  
 982      if ( ! $author ) {
 983          return false;
 984      }
 985  
 986      return $author->has_cap( $capability, ...$args );
 987  }
 988  
 989  /**
 990   * Returns whether a particular user has the specified capability.
 991   *
 992   * This function also accepts an ID of an object to check against if the capability is a meta capability. Meta
 993   * capabilities such as `edit_post` and `edit_user` are capabilities used by the `map_meta_cap()` function to
 994   * map to primitive capabilities that a user or role has, such as `edit_posts` and `edit_others_posts`.
 995   *
 996   * Example usage:
 997   *
 998   *     user_can( $user->ID, 'edit_posts' );
 999   *     user_can( $user->ID, 'edit_post', $post->ID );
1000   *     user_can( $user->ID, 'edit_post_meta', $post->ID, $meta_key );
1001   *
1002   * @since 3.1.0
1003   * @since 5.3.0 Formalized the existing and already documented `...$args` parameter
1004   *              by adding it to the function signature.
1005   *
1006   * @param int|WP_User $user       User ID or object.
1007   * @param string      $capability Capability name.
1008   * @param mixed       ...$args    Optional further parameters, typically starting with an object ID.
1009   * @return bool Whether the user has the given capability.
1010   */
1011  function user_can( $user, $capability, ...$args ) {
1012      if ( ! is_object( $user ) ) {
1013          $user = get_userdata( $user );
1014      }
1015  
1016      if ( empty( $user ) ) {
1017          // User is logged out, create anonymous user object.
1018          $user = new WP_User( 0 );
1019          $user->init( new stdClass() );
1020      }
1021  
1022      return $user->has_cap( $capability, ...$args );
1023  }
1024  
1025  /**
1026   * Returns whether a particular user has the specified capability for a given site.
1027   *
1028   * This function also accepts an ID of an object to check against if the capability is a meta capability. Meta
1029   * capabilities such as `edit_post` and `edit_user` are capabilities used by the `map_meta_cap()` function to
1030   * map to primitive capabilities that a user or role has, such as `edit_posts` and `edit_others_posts`.
1031   *
1032   * Example usage:
1033   *
1034   *     user_can_for_site( $user->ID, $site_id, 'edit_posts' );
1035   *     user_can_for_site( $user->ID, $site_id, 'edit_post', $post->ID );
1036   *     user_can_for_site( $user->ID, $site_id, 'edit_post_meta', $post->ID, $meta_key );
1037   *
1038   * @since 6.7.0
1039   *
1040   * @param int|WP_User $user       User ID or object.
1041   * @param int         $site_id    Site ID.
1042   * @param string      $capability Capability name.
1043   * @param mixed       ...$args    Optional further parameters, typically starting with an object ID.
1044   * @return bool Whether the user has the given capability.
1045   */
1046  function user_can_for_site( $user, $site_id, $capability, ...$args ) {
1047      if ( ! is_object( $user ) ) {
1048          $user = get_userdata( $user );
1049      }
1050  
1051      if ( empty( $user ) ) {
1052          // User is logged out, create anonymous user object.
1053          $user = new WP_User( 0 );
1054          $user->init( new stdClass() );
1055      }
1056  
1057      // Check if the blog ID is valid.
1058      if ( ! is_numeric( $site_id ) || $site_id <= 0 ) {
1059          return false;
1060      }
1061  
1062      $switched = is_multisite() ? switch_to_blog( $site_id ) : false;
1063  
1064      $can = user_can( $user->ID, $capability, ...$args );
1065  
1066      if ( $switched ) {
1067          restore_current_blog();
1068      }
1069  
1070      return $can;
1071  }
1072  
1073  /**
1074   * Retrieves the global WP_Roles instance and instantiates it if necessary.
1075   *
1076   * @since 4.3.0
1077   *
1078   * @global WP_Roles $wp_roles WordPress role management object.
1079   *
1080   * @return WP_Roles WP_Roles global instance if not already instantiated.
1081   */
1082  function wp_roles(): WP_Roles {
1083      global $wp_roles;
1084  
1085      if ( ! ( $wp_roles instanceof WP_Roles ) ) {
1086          $wp_roles = new WP_Roles();
1087      }
1088      return $wp_roles;
1089  }
1090  
1091  /**
1092   * Retrieves role object.
1093   *
1094   * @since 2.0.0
1095   *
1096   * @param string $role Role name.
1097   * @return WP_Role|null WP_Role object if found, null if the role does not exist.
1098   */
1099  function get_role( $role ) {
1100      return wp_roles()->get_role( $role );
1101  }
1102  
1103  /**
1104   * Adds a role, if it does not exist.
1105   *
1106   * The list of capabilities can be passed either as a numerically indexed array of capability names, or an
1107   * associative array of boolean values keyed by the capability name. To explicitly deny the role a capability, set
1108   * the value for that capability to false.
1109   *
1110   * Examples:
1111   *
1112   *     // Add a role that can edit posts.
1113   *     add_role( 'custom_role', 'Custom Role', array(
1114   *         'read',
1115   *         'edit_posts',
1116   *     ) );
1117   *
1118   * Or, using an associative array:
1119   *
1120   *     // Add a role that can edit posts but explicitly cannot not delete them.
1121   *     add_role( 'custom_role', 'Custom Role', array(
1122   *         'read' => true,
1123   *         'edit_posts' => true,
1124   *         'delete_posts' => false,
1125   *     ) );
1126   *
1127   * @since 2.0.0
1128   * @since 6.9.0 Support was added for a numerically indexed array of strings for the capabilities array.
1129   *
1130   * @param string                               $role         Role name.
1131   * @param string                               $display_name Display name for role.
1132   * @param array<string,bool>|array<int,string> $capabilities Capabilities to be added to the role.
1133   *                                                           Default empty array.
1134   * @return WP_Role|null WP_Role object, if the role is added.
1135   */
1136  function add_role( $role, $display_name, $capabilities = array() ) {
1137      if ( empty( $role ) ) {
1138          return null;
1139      }
1140  
1141      return wp_roles()->add_role( $role, $display_name, $capabilities );
1142  }
1143  
1144  /**
1145   * Removes a role, if it exists.
1146   *
1147   * @since 2.0.0
1148   *
1149   * @param string $role Role name.
1150   */
1151  function remove_role( $role ) {
1152      wp_roles()->remove_role( $role );
1153  }
1154  
1155  /**
1156   * Retrieves a list of super admins.
1157   *
1158   * @since 3.0.0
1159   *
1160   * @global array $super_admins
1161   *
1162   * @return string[] List of super admin logins.
1163   */
1164  function get_super_admins() {
1165      global $super_admins;
1166  
1167      return $super_admins ?? get_site_option( 'site_admins', array( 'admin' ) );
1168  }
1169  
1170  /**
1171   * Determines whether user is a site admin.
1172   *
1173   * @since 3.0.0
1174   *
1175   * @param int|false $user_id Optional. The ID of a user. Defaults to false, to check the current user.
1176   * @return bool Whether the user is a site admin.
1177   */
1178  function is_super_admin( $user_id = false ) {
1179      if ( ! $user_id ) {
1180          $user = wp_get_current_user();
1181      } else {
1182          $user = get_userdata( $user_id );
1183      }
1184  
1185      if ( ! $user || ! $user->exists() ) {
1186          return false;
1187      }
1188  
1189      if ( is_multisite() ) {
1190          $super_admins = get_super_admins();
1191          if ( is_array( $super_admins ) && in_array( $user->user_login, $super_admins, true ) ) {
1192              return true;
1193          }
1194      } elseif ( $user->has_cap( 'delete_users' ) ) {
1195          return true;
1196      }
1197  
1198      return false;
1199  }
1200  
1201  /**
1202   * Grants Super Admin privileges.
1203   *
1204   * @since 3.0.0
1205   *
1206   * @global array $super_admins
1207   *
1208   * @param int $user_id ID of the user to be granted Super Admin privileges.
1209   * @return bool True on success, false on failure. This can fail when the user is
1210   *              already a super admin or when the `$super_admins` global is defined.
1211   */
1212  function grant_super_admin( $user_id ) {
1213      // If global super_admins override is defined, there is nothing to do here.
1214      if ( isset( $GLOBALS['super_admins'] ) || ! is_multisite() ) {
1215          return false;
1216      }
1217  
1218      /**
1219       * Fires before the user is granted Super Admin privileges.
1220       *
1221       * @since 3.0.0
1222       *
1223       * @param int $user_id ID of the user that is about to be granted Super Admin privileges.
1224       */
1225      do_action( 'grant_super_admin', $user_id );
1226  
1227      // Directly fetch site_admins instead of using get_super_admins().
1228      $super_admins = get_site_option( 'site_admins', array( 'admin' ) );
1229  
1230      $user = get_userdata( $user_id );
1231      if ( $user && ! in_array( $user->user_login, $super_admins, true ) ) {
1232          $super_admins[] = $user->user_login;
1233          update_site_option( 'site_admins', $super_admins );
1234  
1235          /**
1236           * Fires after the user is granted Super Admin privileges.
1237           *
1238           * @since 3.0.0
1239           *
1240           * @param int $user_id ID of the user that was granted Super Admin privileges.
1241           */
1242          do_action( 'granted_super_admin', $user_id );
1243          return true;
1244      }
1245      return false;
1246  }
1247  
1248  /**
1249   * Revokes Super Admin privileges.
1250   *
1251   * @since 3.0.0
1252   * @since 6.9.0 Super admin privileges can be revoked regardless of email address.
1253   *
1254   * @global array $super_admins
1255   *
1256   * @param int $user_id ID of the user Super Admin privileges to be revoked from.
1257   * @return bool True on success, false on failure. This can fail when the user's email
1258   *              is the network admin email or when the `$super_admins` global is defined.
1259   */
1260  function revoke_super_admin( $user_id ) {
1261      // If global super_admins override is defined, there is nothing to do here.
1262      if ( isset( $GLOBALS['super_admins'] ) || ! is_multisite() ) {
1263          return false;
1264      }
1265  
1266      /**
1267       * Fires before the user's Super Admin privileges are revoked.
1268       *
1269       * @since 3.0.0
1270       *
1271       * @param int $user_id ID of the user Super Admin privileges are being revoked from.
1272       */
1273      do_action( 'revoke_super_admin', $user_id );
1274  
1275      // Directly fetch site_admins instead of using get_super_admins().
1276      $super_admins = get_site_option( 'site_admins', array( 'admin' ) );
1277  
1278      $user = get_userdata( $user_id );
1279      if ( $user ) {
1280          $key = array_search( $user->user_login, $super_admins, true );
1281          if ( false !== $key ) {
1282              unset( $super_admins[ $key ] );
1283              update_site_option( 'site_admins', $super_admins );
1284  
1285              /**
1286               * Fires after the user's Super Admin privileges are revoked.
1287               *
1288               * @since 3.0.0
1289               *
1290               * @param int $user_id ID of the user Super Admin privileges were revoked from.
1291               */
1292              do_action( 'revoked_super_admin', $user_id );
1293              return true;
1294          }
1295      }
1296      return false;
1297  }
1298  
1299  /**
1300   * Filters the user capabilities to grant the 'install_languages' capability as necessary.
1301   *
1302   * A user must have at least one out of the 'update_core', 'install_plugins', and
1303   * 'install_themes' capabilities to qualify for 'install_languages'.
1304   *
1305   * @since 4.9.0
1306   *
1307   * @param bool[] $allcaps An array of all the user's capabilities.
1308   * @return bool[] Filtered array of the user's capabilities.
1309   */
1310  function wp_maybe_grant_install_languages_cap( $allcaps ) {
1311      if ( ! empty( $allcaps['update_core'] ) || ! empty( $allcaps['install_plugins'] ) || ! empty( $allcaps['install_themes'] ) ) {
1312          $allcaps['install_languages'] = true;
1313      }
1314  
1315      return $allcaps;
1316  }
1317  
1318  /**
1319   * Filters the user capabilities to grant the 'resume_plugins' and 'resume_themes' capabilities as necessary.
1320   *
1321   * @since 5.2.0
1322   *
1323   * @param bool[] $allcaps An array of all the user's capabilities.
1324   * @return bool[] Filtered array of the user's capabilities.
1325   */
1326  function wp_maybe_grant_resume_extensions_caps( $allcaps ) {
1327      // Even in a multisite, regular administrators should be able to resume plugins.
1328      if ( ! empty( $allcaps['activate_plugins'] ) ) {
1329          $allcaps['resume_plugins'] = true;
1330      }
1331  
1332      // Even in a multisite, regular administrators should be able to resume themes.
1333      if ( ! empty( $allcaps['switch_themes'] ) ) {
1334          $allcaps['resume_themes'] = true;
1335      }
1336  
1337      return $allcaps;
1338  }
1339  
1340  /**
1341   * Filters the user capabilities to grant the 'view_site_health_checks' capabilities as necessary.
1342   *
1343   * @since 5.2.2
1344   *
1345   * @param bool[]   $allcaps An array of all the user's capabilities.
1346   * @param string[] $caps    Required primitive capabilities for the requested capability.
1347   * @param array    $args {
1348   *     Arguments that accompany the requested capability check.
1349   *
1350   *     @type string    $0 Requested capability.
1351   *     @type int       $1 Concerned user ID.
1352   *     @type mixed  ...$2 Optional second and further parameters, typically object ID.
1353   * }
1354   * @param WP_User  $user    The user object.
1355   * @return bool[] Filtered array of the user's capabilities.
1356   */
1357  function wp_maybe_grant_site_health_caps( $allcaps, $caps, $args, $user ) {
1358      if ( ! empty( $allcaps['install_plugins'] ) && ( ! is_multisite() || is_super_admin( $user->ID ) ) ) {
1359          $allcaps['view_site_health_checks'] = true;
1360      }
1361  
1362      return $allcaps;
1363  }
1364  
1365  return;
1366  
1367  // Dummy gettext calls to get strings in the catalog.
1368  /* translators: User role for administrators. */
1369  _x( 'Administrator', 'User role' );
1370  /* translators: User role for editors. */
1371  _x( 'Editor', 'User role' );
1372  /* translators: User role for authors. */
1373  _x( 'Author', 'User role' );
1374  /* translators: User role for contributors. */
1375  _x( 'Contributor', 'User role' );
1376  /* translators: User role for subscribers. */
1377  _x( 'Subscriber', 'User role' );


Generated : Sat Nov 14 08:20:01 2026 Cross-referenced by PHPXref