[ Index ]

PHP Cross Reference of WordPress

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


Generated: Tue Oct 26 01:00:02 2021 Cross-referenced by PHPXref 0.7.1