[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-admin/includes/ -> ms.php (source)

   1  <?php
   2  /**
   3   * Multisite administration functions.
   4   *
   5   * @package WordPress
   6   * @subpackage Multisite
   7   * @since 3.0.0
   8   */
   9  
  10  /**
  11   * Determine if uploaded file exceeds space quota.
  12   *
  13   * @since 3.0.0
  14   *
  15   * @param array $file An element from the `$_FILES` array for a given file.
  16   * @return array The `$_FILES` array element with 'error' key set if file exceeds quota. 'error' is empty otherwise.
  17   */
  18  function check_upload_size( $file ) {
  19      if ( get_site_option( 'upload_space_check_disabled' ) ) {
  20          return $file;
  21      }
  22  
  23      if ( $file['error'] > 0 ) { // There's already an error.
  24          return $file;
  25      }
  26  
  27      if ( defined( 'WP_IMPORTING' ) ) {
  28          return $file;
  29      }
  30  
  31      $space_left = get_upload_space_available();
  32  
  33      $file_size = filesize( $file['tmp_name'] );
  34      if ( $space_left < $file_size ) {
  35          /* translators: %s: Required disk space in kilobytes. */
  36          $file['error'] = sprintf( __( 'Not enough space to upload. %s KB needed.' ), number_format( ( $file_size - $space_left ) / KB_IN_BYTES ) );
  37      }
  38  
  39      if ( $file_size > ( KB_IN_BYTES * get_site_option( 'fileupload_maxk', 1500 ) ) ) {
  40          /* translators: %s: Maximum allowed file size in kilobytes. */
  41          $file['error'] = sprintf( __( 'This file is too big. Files must be less than %s KB in size.' ), get_site_option( 'fileupload_maxk', 1500 ) );
  42      }
  43  
  44      if ( upload_is_user_over_quota( false ) ) {
  45          $file['error'] = __( 'You have used your space quota. Please delete files before uploading.' );
  46      }
  47  
  48      if ( $file['error'] > 0 && ! isset( $_POST['html-upload'] ) && ! wp_doing_ajax() ) {
  49          wp_die( $file['error'] . ' <a href="javascript:history.go(-1)">' . __( 'Back' ) . '</a>' );
  50      }
  51  
  52      return $file;
  53  }
  54  
  55  /**
  56   * Delete a site.
  57   *
  58   * @since 3.0.0
  59   * @since 5.1.0 Use wp_delete_site() internally to delete the site row from the database.
  60   *
  61   * @global wpdb $wpdb WordPress database abstraction object.
  62   *
  63   * @param int  $blog_id Site ID.
  64   * @param bool $drop    True if site's database tables should be dropped. Default false.
  65   */
  66  function wpmu_delete_blog( $blog_id, $drop = false ) {
  67      global $wpdb;
  68  
  69      $blog_id = (int) $blog_id;
  70  
  71      $switch = false;
  72      if ( get_current_blog_id() !== $blog_id ) {
  73          $switch = true;
  74          switch_to_blog( $blog_id );
  75      }
  76  
  77      $blog = get_site( $blog_id );
  78  
  79      $current_network = get_network();
  80  
  81      // If a full blog object is not available, do not destroy anything.
  82      if ( $drop && ! $blog ) {
  83          $drop = false;
  84      }
  85  
  86      // Don't destroy the initial, main, or root blog.
  87      if ( $drop
  88          && ( 1 === $blog_id || is_main_site( $blog_id )
  89              || ( $blog->path === $current_network->path && $blog->domain === $current_network->domain ) )
  90      ) {
  91          $drop = false;
  92      }
  93  
  94      $upload_path = trim( get_option( 'upload_path' ) );
  95  
  96      // If ms_files_rewriting is enabled and upload_path is empty, wp_upload_dir is not reliable.
  97      if ( $drop && get_site_option( 'ms_files_rewriting' ) && empty( $upload_path ) ) {
  98          $drop = false;
  99      }
 100  
 101      if ( $drop ) {
 102          wp_delete_site( $blog_id );
 103      } else {
 104          /** This action is documented in wp-includes/ms-blogs.php */
 105          do_action_deprecated( 'delete_blog', array( $blog_id, false ), '5.1.0' );
 106  
 107          $users = get_users(
 108              array(
 109                  'blog_id' => $blog_id,
 110                  'fields'  => 'ids',
 111              )
 112          );
 113  
 114          // Remove users from this blog.
 115          if ( ! empty( $users ) ) {
 116              foreach ( $users as $user_id ) {
 117                  remove_user_from_blog( $user_id, $blog_id );
 118              }
 119          }
 120  
 121          update_blog_status( $blog_id, 'deleted', 1 );
 122  
 123          /** This action is documented in wp-includes/ms-blogs.php */
 124          do_action_deprecated( 'deleted_blog', array( $blog_id, false ), '5.1.0' );
 125      }
 126  
 127      if ( $switch ) {
 128          restore_current_blog();
 129      }
 130  }
 131  
 132  /**
 133   * Delete a user from the network and remove from all sites.
 134   *
 135   * @since 3.0.0
 136   *
 137   * @todo Merge with wp_delete_user()?
 138   *
 139   * @global wpdb $wpdb WordPress database abstraction object.
 140   *
 141   * @param int $id The user ID.
 142   * @return bool True if the user was deleted, otherwise false.
 143   */
 144  function wpmu_delete_user( $id ) {
 145      global $wpdb;
 146  
 147      if ( ! is_numeric( $id ) ) {
 148          return false;
 149      }
 150  
 151      $id   = (int) $id;
 152      $user = new WP_User( $id );
 153  
 154      if ( ! $user->exists() ) {
 155          return false;
 156      }
 157  
 158      // Global super-administrators are protected, and cannot be deleted.
 159      $_super_admins = get_super_admins();
 160      if ( in_array( $user->user_login, $_super_admins, true ) ) {
 161          return false;
 162      }
 163  
 164      /**
 165       * Fires before a user is deleted from the network.
 166       *
 167       * @since MU (3.0.0)
 168       * @since 5.5.0 Added the `$user` parameter.
 169       *
 170       * @param int     $id   ID of the user about to be deleted from the network.
 171       * @param WP_User $user WP_User object of the user about to be deleted from the network.
 172       */
 173      do_action( 'wpmu_delete_user', $id, $user );
 174  
 175      $blogs = get_blogs_of_user( $id );
 176  
 177      if ( ! empty( $blogs ) ) {
 178          foreach ( $blogs as $blog ) {
 179              switch_to_blog( $blog->userblog_id );
 180              remove_user_from_blog( $id, $blog->userblog_id );
 181  
 182              $post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_author = %d", $id ) );
 183              foreach ( (array) $post_ids as $post_id ) {
 184                  wp_delete_post( $post_id );
 185              }
 186  
 187              // Clean links.
 188              $link_ids = $wpdb->get_col( $wpdb->prepare( "SELECT link_id FROM $wpdb->links WHERE link_owner = %d", $id ) );
 189  
 190              if ( $link_ids ) {
 191                  foreach ( $link_ids as $link_id ) {
 192                      wp_delete_link( $link_id );
 193                  }
 194              }
 195  
 196              restore_current_blog();
 197          }
 198      }
 199  
 200      $meta = $wpdb->get_col( $wpdb->prepare( "SELECT umeta_id FROM $wpdb->usermeta WHERE user_id = %d", $id ) );
 201      foreach ( $meta as $mid ) {
 202          delete_metadata_by_mid( 'user', $mid );
 203      }
 204  
 205      $wpdb->delete( $wpdb->users, array( 'ID' => $id ) );
 206  
 207      clean_user_cache( $user );
 208  
 209      /** This action is documented in wp-admin/includes/user.php */
 210      do_action( 'deleted_user', $id, null, $user );
 211  
 212      return true;
 213  }
 214  
 215  /**
 216   * Check whether a site has used its allotted upload space.
 217   *
 218   * @since MU (3.0.0)
 219   *
 220   * @param bool $display_message Optional. If set to true and the quota is exceeded,
 221   *                              a warning message is displayed. Default true.
 222   * @return bool True if user is over upload space quota, otherwise false.
 223   */
 224  function upload_is_user_over_quota( $display_message = true ) {
 225      if ( get_site_option( 'upload_space_check_disabled' ) ) {
 226          return false;
 227      }
 228  
 229      $space_allowed = get_space_allowed();
 230      if ( ! is_numeric( $space_allowed ) ) {
 231          $space_allowed = 10; // Default space allowed is 10 MB.
 232      }
 233      $space_used = get_space_used();
 234  
 235      if ( ( $space_allowed - $space_used ) < 0 ) {
 236          if ( $display_message ) {
 237              printf(
 238                  /* translators: %s: Allowed space allocation. */
 239                  __( 'Sorry, you have used your space allocation of %s. Please delete some files to upload more files.' ),
 240                  size_format( $space_allowed * MB_IN_BYTES )
 241              );
 242          }
 243          return true;
 244      } else {
 245          return false;
 246      }
 247  }
 248  
 249  /**
 250   * Displays the amount of disk space used by the current site. Not used in core.
 251   *
 252   * @since MU (3.0.0)
 253   */
 254  function display_space_usage() {
 255      $space_allowed = get_space_allowed();
 256      $space_used    = get_space_used();
 257  
 258      $percent_used = ( $space_used / $space_allowed ) * 100;
 259  
 260      $space = size_format( $space_allowed * MB_IN_BYTES );
 261      ?>
 262      <strong>
 263      <?php
 264          /* translators: Storage space that's been used. 1: Percentage of used space, 2: Total space allowed in megabytes or gigabytes. */
 265          printf( __( 'Used: %1$s%% of %2$s' ), number_format( $percent_used ), $space );
 266      ?>
 267      </strong>
 268      <?php
 269  }
 270  
 271  /**
 272   * Get the remaining upload space for this site.
 273   *
 274   * @since MU (3.0.0)
 275   *
 276   * @param int $size Current max size in bytes
 277   * @return int Max size in bytes
 278   */
 279  function fix_import_form_size( $size ) {
 280      if ( upload_is_user_over_quota( false ) ) {
 281          return 0;
 282      }
 283      $available = get_upload_space_available();
 284      return min( $size, $available );
 285  }
 286  
 287  /**
 288   * Displays the site upload space quota setting form on the Edit Site Settings screen.
 289   *
 290   * @since 3.0.0
 291   *
 292   * @param int $id The ID of the site to display the setting for.
 293   */
 294  function upload_space_setting( $id ) {
 295      switch_to_blog( $id );
 296      $quota = get_option( 'blog_upload_space' );
 297      restore_current_blog();
 298  
 299      if ( ! $quota ) {
 300          $quota = '';
 301      }
 302  
 303      ?>
 304      <tr>
 305          <th><label for="blog-upload-space-number"><?php _e( 'Site Upload Space Quota' ); ?></label></th>
 306          <td>
 307              <input type="number" step="1" min="0" style="width: 100px" name="option[blog_upload_space]" id="blog-upload-space-number" aria-describedby="blog-upload-space-desc" value="<?php echo $quota; ?>" />
 308              <span id="blog-upload-space-desc"><span class="screen-reader-text"><?php _e( 'Size in megabytes' ); ?></span> <?php _e( 'MB (Leave blank for network default)' ); ?></span>
 309          </td>
 310      </tr>
 311      <?php
 312  }
 313  
 314  /**
 315   * Cleans the user cache for a specific user.
 316   *
 317   * @since 3.0.0
 318   *
 319   * @param int $id The user ID.
 320   * @return int|false The ID of the refreshed user or false if the user does not exist.
 321   */
 322  function refresh_user_details( $id ) {
 323      $id = (int) $id;
 324  
 325      $user = get_userdata( $id );
 326      if ( ! $user ) {
 327          return false;
 328      }
 329  
 330      clean_user_cache( $user );
 331  
 332      return $id;
 333  }
 334  
 335  /**
 336   * Returns the language for a language code.
 337   *
 338   * @since 3.0.0
 339   *
 340   * @param string $code Optional. The two-letter language code. Default empty.
 341   * @return string The language corresponding to $code if it exists. If it does not exist,
 342   *                then the first two letters of $code is returned.
 343   */
 344  function format_code_lang( $code = '' ) {
 345      $code       = strtolower( substr( $code, 0, 2 ) );
 346      $lang_codes = array(
 347          'aa' => 'Afar',
 348          'ab' => 'Abkhazian',
 349          'af' => 'Afrikaans',
 350          'ak' => 'Akan',
 351          'sq' => 'Albanian',
 352          'am' => 'Amharic',
 353          'ar' => 'Arabic',
 354          'an' => 'Aragonese',
 355          'hy' => 'Armenian',
 356          'as' => 'Assamese',
 357          'av' => 'Avaric',
 358          'ae' => 'Avestan',
 359          'ay' => 'Aymara',
 360          'az' => 'Azerbaijani',
 361          'ba' => 'Bashkir',
 362          'bm' => 'Bambara',
 363          'eu' => 'Basque',
 364          'be' => 'Belarusian',
 365          'bn' => 'Bengali',
 366          'bh' => 'Bihari',
 367          'bi' => 'Bislama',
 368          'bs' => 'Bosnian',
 369          'br' => 'Breton',
 370          'bg' => 'Bulgarian',
 371          'my' => 'Burmese',
 372          'ca' => 'Catalan; Valencian',
 373          'ch' => 'Chamorro',
 374          'ce' => 'Chechen',
 375          'zh' => 'Chinese',
 376          'cu' => 'Church Slavic; Old Slavonic; Church Slavonic; Old Bulgarian; Old Church Slavonic',
 377          'cv' => 'Chuvash',
 378          'kw' => 'Cornish',
 379          'co' => 'Corsican',
 380          'cr' => 'Cree',
 381          'cs' => 'Czech',
 382          'da' => 'Danish',
 383          'dv' => 'Divehi; Dhivehi; Maldivian',
 384          'nl' => 'Dutch; Flemish',
 385          'dz' => 'Dzongkha',
 386          'en' => 'English',
 387          'eo' => 'Esperanto',
 388          'et' => 'Estonian',
 389          'ee' => 'Ewe',
 390          'fo' => 'Faroese',
 391          'fj' => 'Fijjian',
 392          'fi' => 'Finnish',
 393          'fr' => 'French',
 394          'fy' => 'Western Frisian',
 395          'ff' => 'Fulah',
 396          'ka' => 'Georgian',
 397          'de' => 'German',
 398          'gd' => 'Gaelic; Scottish Gaelic',
 399          'ga' => 'Irish',
 400          'gl' => 'Galician',
 401          'gv' => 'Manx',
 402          'el' => 'Greek, Modern',
 403          'gn' => 'Guarani',
 404          'gu' => 'Gujarati',
 405          'ht' => 'Haitian; Haitian Creole',
 406          'ha' => 'Hausa',
 407          'he' => 'Hebrew',
 408          'hz' => 'Herero',
 409          'hi' => 'Hindi',
 410          'ho' => 'Hiri Motu',
 411          'hu' => 'Hungarian',
 412          'ig' => 'Igbo',
 413          'is' => 'Icelandic',
 414          'io' => 'Ido',
 415          'ii' => 'Sichuan Yi',
 416          'iu' => 'Inuktitut',
 417          'ie' => 'Interlingue',
 418          'ia' => 'Interlingua (International Auxiliary Language Association)',
 419          'id' => 'Indonesian',
 420          'ik' => 'Inupiaq',
 421          'it' => 'Italian',
 422          'jv' => 'Javanese',
 423          'ja' => 'Japanese',
 424          'kl' => 'Kalaallisut; Greenlandic',
 425          'kn' => 'Kannada',
 426          'ks' => 'Kashmiri',
 427          'kr' => 'Kanuri',
 428          'kk' => 'Kazakh',
 429          'km' => 'Central Khmer',
 430          'ki' => 'Kikuyu; Gikuyu',
 431          'rw' => 'Kinyarwanda',
 432          'ky' => 'Kirghiz; Kyrgyz',
 433          'kv' => 'Komi',
 434          'kg' => 'Kongo',
 435          'ko' => 'Korean',
 436          'kj' => 'Kuanyama; Kwanyama',
 437          'ku' => 'Kurdish',
 438          'lo' => 'Lao',
 439          'la' => 'Latin',
 440          'lv' => 'Latvian',
 441          'li' => 'Limburgan; Limburger; Limburgish',
 442          'ln' => 'Lingala',
 443          'lt' => 'Lithuanian',
 444          'lb' => 'Luxembourgish; Letzeburgesch',
 445          'lu' => 'Luba-Katanga',
 446          'lg' => 'Ganda',
 447          'mk' => 'Macedonian',
 448          'mh' => 'Marshallese',
 449          'ml' => 'Malayalam',
 450          'mi' => 'Maori',
 451          'mr' => 'Marathi',
 452          'ms' => 'Malay',
 453          'mg' => 'Malagasy',
 454          'mt' => 'Maltese',
 455          'mo' => 'Moldavian',
 456          'mn' => 'Mongolian',
 457          'na' => 'Nauru',
 458          'nv' => 'Navajo; Navaho',
 459          'nr' => 'Ndebele, South; South Ndebele',
 460          'nd' => 'Ndebele, North; North Ndebele',
 461          'ng' => 'Ndonga',
 462          'ne' => 'Nepali',
 463          'nn' => 'Norwegian Nynorsk; Nynorsk, Norwegian',
 464          'nb' => 'Bokmål, Norwegian, Norwegian Bokmål',
 465          'no' => 'Norwegian',
 466          'ny' => 'Chichewa; Chewa; Nyanja',
 467          'oc' => 'Occitan, Provençal',
 468          'oj' => 'Ojibwa',
 469          'or' => 'Oriya',
 470          'om' => 'Oromo',
 471          'os' => 'Ossetian; Ossetic',
 472          'pa' => 'Panjabi; Punjabi',
 473          'fa' => 'Persian',
 474          'pi' => 'Pali',
 475          'pl' => 'Polish',
 476          'pt' => 'Portuguese',
 477          'ps' => 'Pushto',
 478          'qu' => 'Quechua',
 479          'rm' => 'Romansh',
 480          'ro' => 'Romanian',
 481          'rn' => 'Rundi',
 482          'ru' => 'Russian',
 483          'sg' => 'Sango',
 484          'sa' => 'Sanskrit',
 485          'sr' => 'Serbian',
 486          'hr' => 'Croatian',
 487          'si' => 'Sinhala; Sinhalese',
 488          'sk' => 'Slovak',
 489          'sl' => 'Slovenian',
 490          'se' => 'Northern Sami',
 491          'sm' => 'Samoan',
 492          'sn' => 'Shona',
 493          'sd' => 'Sindhi',
 494          'so' => 'Somali',
 495          'st' => 'Sotho, Southern',
 496          'es' => 'Spanish; Castilian',
 497          'sc' => 'Sardinian',
 498          'ss' => 'Swati',
 499          'su' => 'Sundanese',
 500          'sw' => 'Swahili',
 501          'sv' => 'Swedish',
 502          'ty' => 'Tahitian',
 503          'ta' => 'Tamil',
 504          'tt' => 'Tatar',
 505          'te' => 'Telugu',
 506          'tg' => 'Tajik',
 507          'tl' => 'Tagalog',
 508          'th' => 'Thai',
 509          'bo' => 'Tibetan',
 510          'ti' => 'Tigrinya',
 511          'to' => 'Tonga (Tonga Islands)',
 512          'tn' => 'Tswana',
 513          'ts' => 'Tsonga',
 514          'tk' => 'Turkmen',
 515          'tr' => 'Turkish',
 516          'tw' => 'Twi',
 517          'ug' => 'Uighur; Uyghur',
 518          'uk' => 'Ukrainian',
 519          'ur' => 'Urdu',
 520          'uz' => 'Uzbek',
 521          've' => 'Venda',
 522          'vi' => 'Vietnamese',
 523          'vo' => 'Volapük',
 524          'cy' => 'Welsh',
 525          'wa' => 'Walloon',
 526          'wo' => 'Wolof',
 527          'xh' => 'Xhosa',
 528          'yi' => 'Yiddish',
 529          'yo' => 'Yoruba',
 530          'za' => 'Zhuang; Chuang',
 531          'zu' => 'Zulu',
 532      );
 533  
 534      /**
 535       * Filters the language codes.
 536       *
 537       * @since MU (3.0.0)
 538       *
 539       * @param string[] $lang_codes Array of key/value pairs of language codes where key is the short version.
 540       * @param string   $code       A two-letter designation of the language.
 541       */
 542      $lang_codes = apply_filters( 'lang_codes', $lang_codes, $code );
 543      return strtr( $code, $lang_codes );
 544  }
 545  
 546  /**
 547   * Displays an access denied message when a user tries to view a site's dashboard they
 548   * do not have access to.
 549   *
 550   * @since 3.2.0
 551   * @access private
 552   */
 553  function _access_denied_splash() {
 554      if ( ! is_user_logged_in() || is_network_admin() ) {
 555          return;
 556      }
 557  
 558      $blogs = get_blogs_of_user( get_current_user_id() );
 559  
 560      if ( wp_list_filter( $blogs, array( 'userblog_id' => get_current_blog_id() ) ) ) {
 561          return;
 562      }
 563  
 564      $blog_name = get_bloginfo( 'name' );
 565  
 566      if ( empty( $blogs ) ) {
 567          wp_die(
 568              sprintf(
 569                  /* translators: 1: Site title. */
 570                  __( 'You attempted to access the "%1$s" dashboard, but you do not currently have privileges on this site. If you believe you should be able to access the "%1$s" dashboard, please contact your network administrator.' ),
 571                  $blog_name
 572              ),
 573              403
 574          );
 575      }
 576  
 577      $output = '<p>' . sprintf(
 578          /* translators: 1: Site title. */
 579          __( 'You attempted to access the "%1$s" dashboard, but you do not currently have privileges on this site. If you believe you should be able to access the "%1$s" dashboard, please contact your network administrator.' ),
 580          $blog_name
 581      ) . '</p>';
 582      $output .= '<p>' . __( 'If you reached this screen by accident and meant to visit one of your own sites, here are some shortcuts to help you find your way.' ) . '</p>';
 583  
 584      $output .= '<h3>' . __( 'Your Sites' ) . '</h3>';
 585      $output .= '<table>';
 586  
 587      foreach ( $blogs as $blog ) {
 588          $output .= '<tr>';
 589          $output .= "<td>{$blog->blogname}</td>";
 590          $output .= '<td><a href="' . esc_url( get_admin_url( $blog->userblog_id ) ) . '">' . __( 'Visit Dashboard' ) . '</a> | ' .
 591              '<a href="' . esc_url( get_home_url( $blog->userblog_id ) ) . '">' . __( 'View Site' ) . '</a></td>';
 592          $output .= '</tr>';
 593      }
 594  
 595      $output .= '</table>';
 596  
 597      wp_die( $output, 403 );
 598  }
 599  
 600  /**
 601   * Checks if the current user has permissions to import new users.
 602   *
 603   * @since 3.0.0
 604   *
 605   * @param string $permission A permission to be checked. Currently not used.
 606   * @return bool True if the user has proper permissions, false if they do not.
 607   */
 608  function check_import_new_users( $permission ) {
 609      if ( ! current_user_can( 'manage_network_users' ) ) {
 610          return false;
 611      }
 612  
 613      return true;
 614  }
 615  // See "import_allow_fetch_attachments" and "import_attachment_size_limit" filters too.
 616  
 617  /**
 618   * Generates and displays a drop-down of available languages.
 619   *
 620   * @since 3.0.0
 621   *
 622   * @param string[] $lang_files Optional. An array of the language files. Default empty array.
 623   * @param string   $current    Optional. The current language code. Default empty.
 624   */
 625  function mu_dropdown_languages( $lang_files = array(), $current = '' ) {
 626      $flag   = false;
 627      $output = array();
 628  
 629      foreach ( (array) $lang_files as $val ) {
 630          $code_lang = basename( $val, '.mo' );
 631  
 632          if ( 'en_US' === $code_lang ) { // American English.
 633              $flag          = true;
 634              $ae            = __( 'American English' );
 635              $output[ $ae ] = '<option value="' . esc_attr( $code_lang ) . '"' . selected( $current, $code_lang, false ) . '> ' . $ae . '</option>';
 636          } elseif ( 'en_GB' === $code_lang ) { // British English.
 637              $flag          = true;
 638              $be            = __( 'British English' );
 639              $output[ $be ] = '<option value="' . esc_attr( $code_lang ) . '"' . selected( $current, $code_lang, false ) . '> ' . $be . '</option>';
 640          } else {
 641              $translated            = format_code_lang( $code_lang );
 642              $output[ $translated ] = '<option value="' . esc_attr( $code_lang ) . '"' . selected( $current, $code_lang, false ) . '> ' . esc_html( $translated ) . '</option>';
 643          }
 644      }
 645  
 646      if ( false === $flag ) { // WordPress English.
 647          $output[] = '<option value=""' . selected( $current, '', false ) . '>' . __( 'English' ) . '</option>';
 648      }
 649  
 650      // Order by name.
 651      uksort( $output, 'strnatcasecmp' );
 652  
 653      /**
 654       * Filters the languages available in the dropdown.
 655       *
 656       * @since MU (3.0.0)
 657       *
 658       * @param string[] $output     Array of HTML output for the dropdown.
 659       * @param string[] $lang_files Array of available language files.
 660       * @param string   $current    The current language code.
 661       */
 662      $output = apply_filters( 'mu_dropdown_languages', $output, $lang_files, $current );
 663  
 664      echo implode( "\n\t", $output );
 665  }
 666  
 667  /**
 668   * Displays an admin notice to upgrade all sites after a core upgrade.
 669   *
 670   * @since 3.0.0
 671   *
 672   * @global int    $wp_db_version WordPress database version.
 673   * @global string $pagenow       The filename of the current screen.
 674   *
 675   * @return void|false Void on success. False if the current user is not a super admin.
 676   */
 677  function site_admin_notice() {
 678      global $wp_db_version, $pagenow;
 679  
 680      if ( ! current_user_can( 'upgrade_network' ) ) {
 681          return false;
 682      }
 683  
 684      if ( 'upgrade.php' === $pagenow ) {
 685          return;
 686      }
 687  
 688      if ( (int) get_site_option( 'wpmu_upgrade_site' ) !== $wp_db_version ) {
 689          echo "<div class='update-nag notice notice-warning inline'>" . sprintf(
 690              /* translators: %s: URL to Upgrade Network screen. */
 691              __( 'Thank you for Updating! Please visit the <a href="%s">Upgrade Network</a> page to update all your sites.' ),
 692              esc_url( network_admin_url( 'upgrade.php' ) )
 693          ) . '</div>';
 694      }
 695  }
 696  
 697  /**
 698   * Avoids a collision between a site slug and a permalink slug.
 699   *
 700   * In a subdirectory installation this will make sure that a site and a post do not use the
 701   * same subdirectory by checking for a site with the same name as a new post.
 702   *
 703   * @since 3.0.0
 704   *
 705   * @param array $data    An array of post data.
 706   * @param array $postarr An array of posts. Not currently used.
 707   * @return array The new array of post data after checking for collisions.
 708   */
 709  function avoid_blog_page_permalink_collision( $data, $postarr ) {
 710      if ( is_subdomain_install() ) {
 711          return $data;
 712      }
 713      if ( 'page' !== $data['post_type'] ) {
 714          return $data;
 715      }
 716      if ( ! isset( $data['post_name'] ) || '' === $data['post_name'] ) {
 717          return $data;
 718      }
 719      if ( ! is_main_site() ) {
 720          return $data;
 721      }
 722      if ( isset( $data['post_parent'] ) && $data['post_parent'] ) {
 723          return $data;
 724      }
 725  
 726      $post_name = $data['post_name'];
 727      $c         = 0;
 728  
 729      while ( $c < 10 && get_id_from_blogname( $post_name ) ) {
 730          $post_name .= mt_rand( 1, 10 );
 731          $c++;
 732      }
 733  
 734      if ( $post_name !== $data['post_name'] ) {
 735          $data['post_name'] = $post_name;
 736      }
 737  
 738      return $data;
 739  }
 740  
 741  /**
 742   * Handles the display of choosing a user's primary site.
 743   *
 744   * This displays the user's primary site and allows the user to choose
 745   * which site is primary.
 746   *
 747   * @since 3.0.0
 748   */
 749  function choose_primary_blog() {
 750      ?>
 751      <table class="form-table" role="presentation">
 752      <tr>
 753      <?php /* translators: My Sites label. */ ?>
 754          <th scope="row"><label for="primary_blog"><?php _e( 'Primary Site' ); ?></label></th>
 755          <td>
 756          <?php
 757          $all_blogs    = get_blogs_of_user( get_current_user_id() );
 758          $primary_blog = (int) get_user_meta( get_current_user_id(), 'primary_blog', true );
 759          if ( count( $all_blogs ) > 1 ) {
 760              $found = false;
 761              ?>
 762              <select name="primary_blog" id="primary_blog">
 763                  <?php
 764                  foreach ( (array) $all_blogs as $blog ) {
 765                      if ( $blog->userblog_id === $primary_blog ) {
 766                          $found = true;
 767                      }
 768                      ?>
 769                      <option value="<?php echo $blog->userblog_id; ?>"<?php selected( $primary_blog, $blog->userblog_id ); ?>><?php echo esc_url( get_home_url( $blog->userblog_id ) ); ?></option>
 770                      <?php
 771                  }
 772                  ?>
 773              </select>
 774              <?php
 775              if ( ! $found ) {
 776                  $blog = reset( $all_blogs );
 777                  update_user_meta( get_current_user_id(), 'primary_blog', $blog->userblog_id );
 778              }
 779          } elseif ( 1 === count( $all_blogs ) ) {
 780              $blog = reset( $all_blogs );
 781              echo esc_url( get_home_url( $blog->userblog_id ) );
 782              if ( $blog->userblog_id !== $primary_blog ) { // Set the primary blog again if it's out of sync with blog list.
 783                  update_user_meta( get_current_user_id(), 'primary_blog', $blog->userblog_id );
 784              }
 785          } else {
 786              echo 'N/A';
 787          }
 788          ?>
 789          </td>
 790      </tr>
 791      </table>
 792      <?php
 793  }
 794  
 795  /**
 796   * Whether or not we can edit this network from this page.
 797   *
 798   * By default editing of network is restricted to the Network Admin for that `$network_id`.
 799   * This function allows for this to be overridden.
 800   *
 801   * @since 3.1.0
 802   *
 803   * @param int $network_id The network ID to check.
 804   * @return bool True if network can be edited, otherwise false.
 805   */
 806  function can_edit_network( $network_id ) {
 807      if ( get_current_network_id() === (int) $network_id ) {
 808          $result = true;
 809      } else {
 810          $result = false;
 811      }
 812  
 813      /**
 814       * Filters whether this network can be edited from this page.
 815       *
 816       * @since 3.1.0
 817       *
 818       * @param bool $result     Whether the network can be edited from this page.
 819       * @param int  $network_id The network ID to check.
 820       */
 821      return apply_filters( 'can_edit_network', $result, $network_id );
 822  }
 823  
 824  /**
 825   * Thickbox image paths for Network Admin.
 826   *
 827   * @since 3.1.0
 828   *
 829   * @access private
 830   */
 831  function _thickbox_path_admin_subfolder() {
 832      ?>
 833  <script type="text/javascript">
 834  var tb_pathToImage = "<?php echo esc_js( includes_url( 'js/thickbox/loadingAnimation.gif', 'relative' ) ); ?>";
 835  </script>
 836      <?php
 837  }
 838  
 839  /**
 840   * @param array $users
 841   */
 842  function confirm_delete_users( $users ) {
 843      $current_user = wp_get_current_user();
 844      if ( ! is_array( $users ) || empty( $users ) ) {
 845          return false;
 846      }
 847      ?>
 848      <h1><?php esc_html_e( 'Users' ); ?></h1>
 849  
 850      <?php if ( 1 === count( $users ) ) : ?>
 851          <p><?php _e( 'You have chosen to delete the user from all networks and sites.' ); ?></p>
 852      <?php else : ?>
 853          <p><?php _e( 'You have chosen to delete the following users from all networks and sites.' ); ?></p>
 854      <?php endif; ?>
 855  
 856      <form action="users.php?action=dodelete" method="post">
 857      <input type="hidden" name="dodelete" />
 858      <?php
 859      wp_nonce_field( 'ms-users-delete' );
 860      $site_admins = get_super_admins();
 861      $admin_out   = '<option value="' . esc_attr( $current_user->ID ) . '">' . $current_user->user_login . '</option>';
 862      ?>
 863      <table class="form-table" role="presentation">
 864      <?php
 865      $allusers = (array) $_POST['allusers'];
 866      foreach ( $allusers as $user_id ) {
 867          if ( '' !== $user_id && '0' !== $user_id ) {
 868              $delete_user = get_userdata( $user_id );
 869  
 870              if ( ! current_user_can( 'delete_user', $delete_user->ID ) ) {
 871                  wp_die(
 872                      sprintf(
 873                          /* translators: %s: User login. */
 874                          __( 'Warning! User %s cannot be deleted.' ),
 875                          $delete_user->user_login
 876                      )
 877                  );
 878              }
 879  
 880              if ( in_array( $delete_user->user_login, $site_admins, true ) ) {
 881                  wp_die(
 882                      sprintf(
 883                          /* translators: %s: User login. */
 884                          __( 'Warning! User cannot be deleted. The user %s is a network administrator.' ),
 885                          '<em>' . $delete_user->user_login . '</em>'
 886                      )
 887                  );
 888              }
 889              ?>
 890              <tr>
 891                  <th scope="row"><?php echo $delete_user->user_login; ?>
 892                      <?php echo '<input type="hidden" name="user[]" value="' . esc_attr( $user_id ) . '" />' . "\n"; ?>
 893                  </th>
 894              <?php
 895              $blogs = get_blogs_of_user( $user_id, true );
 896  
 897              if ( ! empty( $blogs ) ) {
 898                  ?>
 899                  <td><fieldset><p><legend>
 900                  <?php
 901                  printf(
 902                      /* translators: %s: User login. */
 903                      __( 'What should be done with content owned by %s?' ),
 904                      '<em>' . $delete_user->user_login . '</em>'
 905                  );
 906                  ?>
 907                  </legend></p>
 908                  <?php
 909                  foreach ( (array) $blogs as $key => $details ) {
 910                      $blog_users = get_users(
 911                          array(
 912                              'blog_id' => $details->userblog_id,
 913                              'fields'  => array( 'ID', 'user_login' ),
 914                          )
 915                      );
 916  
 917                      if ( is_array( $blog_users ) && ! empty( $blog_users ) ) {
 918                          $user_site      = "<a href='" . esc_url( get_home_url( $details->userblog_id ) ) . "'>{$details->blogname}</a>";
 919                          $user_dropdown  = '<label for="reassign_user" class="screen-reader-text">' . __( 'Select a user' ) . '</label>';
 920                          $user_dropdown .= "<select name='blog[$user_id][$key]' id='reassign_user'>";
 921                          $user_list      = '';
 922  
 923                          foreach ( $blog_users as $user ) {
 924                              if ( ! in_array( (int) $user->ID, $allusers, true ) ) {
 925                                  $user_list .= "<option value='{$user->ID}'>{$user->user_login}</option>";
 926                              }
 927                          }
 928  
 929                          if ( '' === $user_list ) {
 930                              $user_list = $admin_out;
 931                          }
 932  
 933                          $user_dropdown .= $user_list;
 934                          $user_dropdown .= "</select>\n";
 935                          ?>
 936                          <ul style="list-style:none;">
 937                              <li>
 938                                  <?php
 939                                  /* translators: %s: Link to user's site. */
 940                                  printf( __( 'Site: %s' ), $user_site );
 941                                  ?>
 942                              </li>
 943                              <li><label><input type="radio" id="delete_option0" name="delete[<?php echo $details->userblog_id . '][' . $delete_user->ID; ?>]" value="delete" checked="checked" />
 944                              <?php _e( 'Delete all content.' ); ?></label></li>
 945                              <li><label><input type="radio" id="delete_option1" name="delete[<?php echo $details->userblog_id . '][' . $delete_user->ID; ?>]" value="reassign" />
 946                              <?php _e( 'Attribute all content to:' ); ?></label>
 947                              <?php echo $user_dropdown; ?></li>
 948                          </ul>
 949                          <?php
 950                      }
 951                  }
 952                  echo '</fieldset></td></tr>';
 953              } else {
 954                  ?>
 955                  <td><p><?php _e( 'User has no sites or content and will be deleted.' ); ?></p></td>
 956              <?php } ?>
 957              </tr>
 958              <?php
 959          }
 960      }
 961  
 962      ?>
 963      </table>
 964      <?php
 965      /** This action is documented in wp-admin/users.php */
 966      do_action( 'delete_user_form', $current_user, $allusers );
 967  
 968      if ( 1 === count( $users ) ) :
 969          ?>
 970          <p><?php _e( 'Once you hit &#8220;Confirm Deletion&#8221;, the user will be permanently removed.' ); ?></p>
 971      <?php else : ?>
 972          <p><?php _e( 'Once you hit &#8220;Confirm Deletion&#8221;, these users will be permanently removed.' ); ?></p>
 973          <?php
 974      endif;
 975  
 976      submit_button( __( 'Confirm Deletion' ), 'primary' );
 977      ?>
 978      </form>
 979      <?php
 980      return true;
 981  }
 982  
 983  /**
 984   * Print JavaScript in the header on the Network Settings screen.
 985   *
 986   * @since 4.1.0
 987   */
 988  function network_settings_add_js() {
 989      ?>
 990  <script type="text/javascript">
 991  jQuery( function($) {
 992      var languageSelect = $( '#WPLANG' );
 993      $( 'form' ).on( 'submit', function() {
 994          // Don't show a spinner for English and installed languages,
 995          // as there is nothing to download.
 996          if ( ! languageSelect.find( 'option:selected' ).data( 'installed' ) ) {
 997              $( '#submit', this ).after( '<span class="spinner language-install-spinner is-active" />' );
 998          }
 999      });
1000  } );
1001  </script>
1002      <?php
1003  }
1004  
1005  /**
1006   * Outputs the HTML for a network's "Edit Site" tabular interface.
1007   *
1008   * @since 4.6.0
1009   *
1010   * @global string $pagenow The filename of the current screen.
1011   *
1012   * @param array $args {
1013   *     Optional. Array or string of Query parameters. Default empty array.
1014   *
1015   *     @type int    $blog_id  The site ID. Default is the current site.
1016   *     @type array  $links    The tabs to include with (label|url|cap) keys.
1017   *     @type string $selected The ID of the selected link.
1018   * }
1019   */
1020  function network_edit_site_nav( $args = array() ) {
1021  
1022      /**
1023       * Filters the links that appear on site-editing network pages.
1024       *
1025       * Default links: 'site-info', 'site-users', 'site-themes', and 'site-settings'.
1026       *
1027       * @since 4.6.0
1028       *
1029       * @param array $links {
1030       *     An array of link data representing individual network admin pages.
1031       *
1032       *     @type array $link_slug {
1033       *         An array of information about the individual link to a page.
1034       *
1035       *         $type string $label Label to use for the link.
1036       *         $type string $url   URL, relative to `network_admin_url()` to use for the link.
1037       *         $type string $cap   Capability required to see the link.
1038       *     }
1039       * }
1040       */
1041      $links = apply_filters(
1042          'network_edit_site_nav_links',
1043          array(
1044              'site-info'     => array(
1045                  'label' => __( 'Info' ),
1046                  'url'   => 'site-info.php',
1047                  'cap'   => 'manage_sites',
1048              ),
1049              'site-users'    => array(
1050                  'label' => __( 'Users' ),
1051                  'url'   => 'site-users.php',
1052                  'cap'   => 'manage_sites',
1053              ),
1054              'site-themes'   => array(
1055                  'label' => __( 'Themes' ),
1056                  'url'   => 'site-themes.php',
1057                  'cap'   => 'manage_sites',
1058              ),
1059              'site-settings' => array(
1060                  'label' => __( 'Settings' ),
1061                  'url'   => 'site-settings.php',
1062                  'cap'   => 'manage_sites',
1063              ),
1064          )
1065      );
1066  
1067      // Parse arguments.
1068      $parsed_args = wp_parse_args(
1069          $args,
1070          array(
1071              'blog_id'  => isset( $_GET['blog_id'] ) ? (int) $_GET['blog_id'] : 0,
1072              'links'    => $links,
1073              'selected' => 'site-info',
1074          )
1075      );
1076  
1077      // Setup the links array.
1078      $screen_links = array();
1079  
1080      // Loop through tabs.
1081      foreach ( $parsed_args['links'] as $link_id => $link ) {
1082  
1083          // Skip link if user can't access.
1084          if ( ! current_user_can( $link['cap'], $parsed_args['blog_id'] ) ) {
1085              continue;
1086          }
1087  
1088          // Link classes.
1089          $classes = array( 'nav-tab' );
1090  
1091          // Aria-current attribute.
1092          $aria_current = '';
1093  
1094          // Selected is set by the parent OR assumed by the $pagenow global.
1095          if ( $parsed_args['selected'] === $link_id || $link['url'] === $GLOBALS['pagenow'] ) {
1096              $classes[]    = 'nav-tab-active';
1097              $aria_current = ' aria-current="page"';
1098          }
1099  
1100          // Escape each class.
1101          $esc_classes = implode( ' ', $classes );
1102  
1103          // Get the URL for this link.
1104          $url = add_query_arg( array( 'id' => $parsed_args['blog_id'] ), network_admin_url( $link['url'] ) );
1105  
1106          // Add link to nav links.
1107          $screen_links[ $link_id ] = '<a href="' . esc_url( $url ) . '" id="' . esc_attr( $link_id ) . '" class="' . $esc_classes . '"' . $aria_current . '>' . esc_html( $link['label'] ) . '</a>';
1108      }
1109  
1110      // All done!
1111      echo '<nav class="nav-tab-wrapper wp-clearfix" aria-label="' . esc_attr__( 'Secondary menu' ) . '">';
1112      echo implode( '', $screen_links );
1113      echo '</nav>';
1114  }
1115  
1116  /**
1117   * Returns the arguments for the help tab on the Edit Site screens.
1118   *
1119   * @since 4.9.0
1120   *
1121   * @return array Help tab arguments.
1122   */
1123  function get_site_screen_help_tab_args() {
1124      return array(
1125          'id'      => 'overview',
1126          'title'   => __( 'Overview' ),
1127          'content' =>
1128              '<p>' . __( 'The menu is for editing information specific to individual sites, particularly if the admin area of a site is unavailable.' ) . '</p>' .
1129              '<p>' . __( '<strong>Info</strong> &mdash; The site URL is rarely edited as this can cause the site to not work properly. The Registered date and Last Updated date are displayed. Network admins can mark a site as archived, spam, deleted and mature, to remove from public listings or disable.' ) . '</p>' .
1130              '<p>' . __( '<strong>Users</strong> &mdash; This displays the users associated with this site. You can also change their role, reset their password, or remove them from the site. Removing the user from the site does not remove the user from the network.' ) . '</p>' .
1131              '<p>' . sprintf(
1132                  /* translators: %s: URL to Network Themes screen. */
1133                  __( '<strong>Themes</strong> &mdash; This area shows themes that are not already enabled across the network. Enabling a theme in this menu makes it accessible to this site. It does not activate the theme, but allows it to show in the site&#8217;s Appearance menu. To enable a theme for the entire network, see the <a href="%s">Network Themes</a> screen.' ),
1134                  network_admin_url( 'themes.php' )
1135              ) . '</p>' .
1136              '<p>' . __( '<strong>Settings</strong> &mdash; This page shows a list of all settings associated with this site. Some are created by WordPress and others are created by plugins you activate. Note that some fields are grayed out and say Serialized Data. You cannot modify these values due to the way the setting is stored in the database.' ) . '</p>',
1137      );
1138  }
1139  
1140  /**
1141   * Returns the content for the help sidebar on the Edit Site screens.
1142   *
1143   * @since 4.9.0
1144   *
1145   * @return string Help sidebar content.
1146   */
1147  function get_site_screen_help_sidebar_content() {
1148      return '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
1149          '<p>' . __( '<a href="https://wordpress.org/support/article/network-admin-sites-screen/">Documentation on Site Management</a>' ) . '</p>' .
1150          '<p>' . __( '<a href="https://wordpress.org/support/forum/multisite/">Support Forums</a>' ) . '</p>';
1151  }


Generated : Fri Sep 30 08:20:01 2022 Cross-referenced by PHPXref