[ 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 bool|int 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 false 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  
 740      $post_name = $data['post_name'];
 741      $c         = 0;
 742      while ( $c < 10 && get_id_from_blogname( $post_name ) ) {
 743          $post_name .= mt_rand( 1, 10 );
 744          $c ++;
 745      }
 746      if ( $post_name != $data['post_name'] ) {
 747          $data['post_name'] = $post_name;
 748      }
 749      return $data;
 750  }
 751  
 752  /**
 753   * Handles the display of choosing a user's primary site.
 754   *
 755   * This displays the user's primary site and allows the user to choose
 756   * which site is primary.
 757   *
 758   * @since 3.0.0
 759   */
 760  function choose_primary_blog() {
 761      ?>
 762      <table class="form-table" role="presentation">
 763      <tr>
 764      <?php /* translators: My Sites label. */ ?>
 765          <th scope="row"><label for="primary_blog"><?php _e( 'Primary Site' ); ?></label></th>
 766          <td>
 767          <?php
 768          $all_blogs    = get_blogs_of_user( get_current_user_id() );
 769          $primary_blog = get_user_meta( get_current_user_id(), 'primary_blog', true );
 770          if ( count( $all_blogs ) > 1 ) {
 771              $found = false;
 772              ?>
 773              <select name="primary_blog" id="primary_blog">
 774                  <?php
 775                  foreach ( (array) $all_blogs as $blog ) {
 776                      if ( $primary_blog == $blog->userblog_id ) {
 777                          $found = true;
 778                      }
 779                      ?>
 780                      <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>
 781                      <?php
 782                  }
 783                  ?>
 784              </select>
 785              <?php
 786              if ( ! $found ) {
 787                  $blog = reset( $all_blogs );
 788                  update_user_meta( get_current_user_id(), 'primary_blog', $blog->userblog_id );
 789              }
 790          } elseif ( count( $all_blogs ) == 1 ) {
 791              $blog = reset( $all_blogs );
 792              echo esc_url( get_home_url( $blog->userblog_id ) );
 793              if ( $primary_blog != $blog->userblog_id ) { // Set the primary blog again if it's out of sync with blog list.
 794                  update_user_meta( get_current_user_id(), 'primary_blog', $blog->userblog_id );
 795              }
 796          } else {
 797              echo 'N/A';
 798          }
 799          ?>
 800          </td>
 801      </tr>
 802      </table>
 803      <?php
 804  }
 805  
 806  /**
 807   * Whether or not we can edit this network from this page.
 808   *
 809   * By default editing of network is restricted to the Network Admin for that `$network_id`.
 810   * This function allows for this to be overridden.
 811   *
 812   * @since 3.1.0
 813   *
 814   * @param int $network_id The network ID to check.
 815   * @return bool True if network can be edited, otherwise false.
 816   */
 817  function can_edit_network( $network_id ) {
 818      if ( get_current_network_id() == $network_id ) {
 819          $result = true;
 820      } else {
 821          $result = false;
 822      }
 823  
 824      /**
 825       * Filters whether this network can be edited from this page.
 826       *
 827       * @since 3.1.0
 828       *
 829       * @param bool $result     Whether the network can be edited from this page.
 830       * @param int  $network_id The network ID to check.
 831       */
 832      return apply_filters( 'can_edit_network', $result, $network_id );
 833  }
 834  
 835  /**
 836   * Thickbox image paths for Network Admin.
 837   *
 838   * @since 3.1.0
 839   *
 840   * @access private
 841   */
 842  function _thickbox_path_admin_subfolder() {
 843      ?>
 844  <script type="text/javascript">
 845  var tb_pathToImage = "<?php echo includes_url( 'js/thickbox/loadingAnimation.gif', 'relative' ); ?>";
 846  </script>
 847      <?php
 848  }
 849  
 850  /**
 851   * @param array $users
 852   */
 853  function confirm_delete_users( $users ) {
 854      $current_user = wp_get_current_user();
 855      if ( ! is_array( $users ) || empty( $users ) ) {
 856          return false;
 857      }
 858      ?>
 859      <h1><?php esc_html_e( 'Users' ); ?></h1>
 860  
 861      <?php if ( 1 === count( $users ) ) : ?>
 862          <p><?php _e( 'You have chosen to delete the user from all networks and sites.' ); ?></p>
 863      <?php else : ?>
 864          <p><?php _e( 'You have chosen to delete the following users from all networks and sites.' ); ?></p>
 865      <?php endif; ?>
 866  
 867      <form action="users.php?action=dodelete" method="post">
 868      <input type="hidden" name="dodelete" />
 869      <?php
 870      wp_nonce_field( 'ms-users-delete' );
 871      $site_admins = get_super_admins();
 872      $admin_out   = '<option value="' . esc_attr( $current_user->ID ) . '">' . $current_user->user_login . '</option>';
 873      ?>
 874      <table class="form-table" role="presentation">
 875      <?php
 876      $allusers = (array) $_POST['allusers'];
 877      foreach ( $allusers as $user_id ) {
 878          if ( '' !== $user_id && '0' != $user_id ) {
 879              $delete_user = get_userdata( $user_id );
 880  
 881              if ( ! current_user_can( 'delete_user', $delete_user->ID ) ) {
 882                  wp_die(
 883                      sprintf(
 884                          /* translators: %s: User login. */
 885                          __( 'Warning! User %s cannot be deleted.' ),
 886                          $delete_user->user_login
 887                      )
 888                  );
 889              }
 890  
 891              if ( in_array( $delete_user->user_login, $site_admins, true ) ) {
 892                  wp_die(
 893                      sprintf(
 894                          /* translators: %s: User login. */
 895                          __( 'Warning! User cannot be deleted. The user %s is a network administrator.' ),
 896                          '<em>' . $delete_user->user_login . '</em>'
 897                      )
 898                  );
 899              }
 900              ?>
 901              <tr>
 902                  <th scope="row"><?php echo $delete_user->user_login; ?>
 903                      <?php echo '<input type="hidden" name="user[]" value="' . esc_attr( $user_id ) . '" />' . "\n"; ?>
 904                  </th>
 905              <?php
 906              $blogs = get_blogs_of_user( $user_id, true );
 907  
 908              if ( ! empty( $blogs ) ) {
 909                  ?>
 910                  <td><fieldset><p><legend>
 911                  <?php
 912                  printf(
 913                      /* translators: %s: User login. */
 914                      __( 'What should be done with content owned by %s?' ),
 915                      '<em>' . $delete_user->user_login . '</em>'
 916                  );
 917                  ?>
 918                  </legend></p>
 919                  <?php
 920                  foreach ( (array) $blogs as $key => $details ) {
 921                      $blog_users = get_users(
 922                          array(
 923                              'blog_id' => $details->userblog_id,
 924                              'fields'  => array( 'ID', 'user_login' ),
 925                          )
 926                      );
 927  
 928                      if ( is_array( $blog_users ) && ! empty( $blog_users ) ) {
 929                          $user_site      = "<a href='" . esc_url( get_home_url( $details->userblog_id ) ) . "'>{$details->blogname}</a>";
 930                          $user_dropdown  = '<label for="reassign_user" class="screen-reader-text">' . __( 'Select a user' ) . '</label>';
 931                          $user_dropdown .= "<select name='blog[$user_id][$key]' id='reassign_user'>";
 932                          $user_list      = '';
 933  
 934                          foreach ( $blog_users as $user ) {
 935                              if ( ! in_array( (int) $user->ID, $allusers, true ) ) {
 936                                  $user_list .= "<option value='{$user->ID}'>{$user->user_login}</option>";
 937                              }
 938                          }
 939  
 940                          if ( '' === $user_list ) {
 941                              $user_list = $admin_out;
 942                          }
 943  
 944                          $user_dropdown .= $user_list;
 945                          $user_dropdown .= "</select>\n";
 946                          ?>
 947                          <ul style="list-style:none;">
 948                              <li>
 949                                  <?php
 950                                  /* translators: %s: Link to user's site. */
 951                                  printf( __( 'Site: %s' ), $user_site );
 952                                  ?>
 953                              </li>
 954                              <li><label><input type="radio" id="delete_option0" name="delete[<?php echo $details->userblog_id . '][' . $delete_user->ID; ?>]" value="delete" checked="checked" />
 955                              <?php _e( 'Delete all content.' ); ?></label></li>
 956                              <li><label><input type="radio" id="delete_option1" name="delete[<?php echo $details->userblog_id . '][' . $delete_user->ID; ?>]" value="reassign" />
 957                              <?php _e( 'Attribute all content to:' ); ?></label>
 958                              <?php echo $user_dropdown; ?></li>
 959                          </ul>
 960                          <?php
 961                      }
 962                  }
 963                  echo '</fieldset></td></tr>';
 964              } else {
 965                  ?>
 966                  <td><p><?php _e( 'User has no sites or content and will be deleted.' ); ?></p></td>
 967              <?php } ?>
 968              </tr>
 969              <?php
 970          }
 971      }
 972  
 973      ?>
 974      </table>
 975      <?php
 976      /** This action is documented in wp-admin/users.php */
 977      do_action( 'delete_user_form', $current_user, $allusers );
 978  
 979      if ( 1 === count( $users ) ) :
 980          ?>
 981          <p><?php _e( 'Once you hit &#8220;Confirm Deletion&#8221;, the user will be permanently removed.' ); ?></p>
 982      <?php else : ?>
 983          <p><?php _e( 'Once you hit &#8220;Confirm Deletion&#8221;, these users will be permanently removed.' ); ?></p>
 984          <?php
 985      endif;
 986  
 987      submit_button( __( 'Confirm Deletion' ), 'primary' );
 988      ?>
 989      </form>
 990      <?php
 991      return true;
 992  }
 993  
 994  /**
 995   * Print JavaScript in the header on the Network Settings screen.
 996   *
 997   * @since 4.1.0
 998   */
 999  function network_settings_add_js() {
1000      ?>
1001  <script type="text/javascript">
1002  jQuery(document).ready( function($) {
1003      var languageSelect = $( '#WPLANG' );
1004      $( 'form' ).submit( function() {
1005          // Don't show a spinner for English and installed languages,
1006          // as there is nothing to download.
1007          if ( ! languageSelect.find( 'option:selected' ).data( 'installed' ) ) {
1008              $( '#submit', this ).after( '<span class="spinner language-install-spinner is-active" />' );
1009          }
1010      });
1011  });
1012  </script>
1013      <?php
1014  }
1015  
1016  /**
1017   * Outputs the HTML for a network's "Edit Site" tabular interface.
1018   *
1019   * @since 4.6.0
1020   *
1021   * @param array $args {
1022   *     Optional. Array or string of Query parameters. Default empty array.
1023   *
1024   *     @type int    $blog_id  The site ID. Default is the current site.
1025   *     @type array  $links    The tabs to include with (label|url|cap) keys.
1026   *     @type string $selected The ID of the selected link.
1027   * }
1028   */
1029  function network_edit_site_nav( $args = array() ) {
1030  
1031      /**
1032       * Filters the links that appear on site-editing network pages.
1033       *
1034       * Default links: 'site-info', 'site-users', 'site-themes', and 'site-settings'.
1035       *
1036       * @since 4.6.0
1037       *
1038       * @param array $links {
1039       *     An array of link data representing individual network admin pages.
1040       *
1041       *     @type array $link_slug {
1042       *         An array of information about the individual link to a page.
1043       *
1044       *         $type string $label Label to use for the link.
1045       *         $type string $url   URL, relative to `network_admin_url()` to use for the link.
1046       *         $type string $cap   Capability required to see the link.
1047       *     }
1048       * }
1049       */
1050      $links = apply_filters(
1051          'network_edit_site_nav_links',
1052          array(
1053              'site-info'     => array(
1054                  'label' => __( 'Info' ),
1055                  'url'   => 'site-info.php',
1056                  'cap'   => 'manage_sites',
1057              ),
1058              'site-users'    => array(
1059                  'label' => __( 'Users' ),
1060                  'url'   => 'site-users.php',
1061                  'cap'   => 'manage_sites',
1062              ),
1063              'site-themes'   => array(
1064                  'label' => __( 'Themes' ),
1065                  'url'   => 'site-themes.php',
1066                  'cap'   => 'manage_sites',
1067              ),
1068              'site-settings' => array(
1069                  'label' => __( 'Settings' ),
1070                  'url'   => 'site-settings.php',
1071                  'cap'   => 'manage_sites',
1072              ),
1073          )
1074      );
1075  
1076      // Parse arguments.
1077      $parsed_args = wp_parse_args(
1078          $args,
1079          array(
1080              'blog_id'  => isset( $_GET['blog_id'] ) ? (int) $_GET['blog_id'] : 0,
1081              'links'    => $links,
1082              'selected' => 'site-info',
1083          )
1084      );
1085  
1086      // Setup the links array.
1087      $screen_links = array();
1088  
1089      // Loop through tabs.
1090      foreach ( $parsed_args['links'] as $link_id => $link ) {
1091  
1092          // Skip link if user can't access.
1093          if ( ! current_user_can( $link['cap'], $parsed_args['blog_id'] ) ) {
1094              continue;
1095          }
1096  
1097          // Link classes.
1098          $classes = array( 'nav-tab' );
1099  
1100          // Aria-current attribute.
1101          $aria_current = '';
1102  
1103          // Selected is set by the parent OR assumed by the $pagenow global.
1104          if ( $parsed_args['selected'] === $link_id || $link['url'] === $GLOBALS['pagenow'] ) {
1105              $classes[]    = 'nav-tab-active';
1106              $aria_current = ' aria-current="page"';
1107          }
1108  
1109          // Escape each class.
1110          $esc_classes = implode( ' ', $classes );
1111  
1112          // Get the URL for this link.
1113          $url = add_query_arg( array( 'id' => $parsed_args['blog_id'] ), network_admin_url( $link['url'] ) );
1114  
1115          // Add link to nav links.
1116          $screen_links[ $link_id ] = '<a href="' . esc_url( $url ) . '" id="' . esc_attr( $link_id ) . '" class="' . $esc_classes . '"' . $aria_current . '>' . esc_html( $link['label'] ) . '</a>';
1117      }
1118  
1119      // All done!
1120      echo '<nav class="nav-tab-wrapper wp-clearfix" aria-label="' . esc_attr__( 'Secondary menu' ) . '">';
1121      echo implode( '', $screen_links );
1122      echo '</nav>';
1123  }
1124  
1125  /**
1126   * Returns the arguments for the help tab on the Edit Site screens.
1127   *
1128   * @since 4.9.0
1129   *
1130   * @return array Help tab arguments.
1131   */
1132  function get_site_screen_help_tab_args() {
1133      return array(
1134          'id'      => 'overview',
1135          'title'   => __( 'Overview' ),
1136          'content' =>
1137              '<p>' . __( 'The menu is for editing information specific to individual sites, particularly if the admin area of a site is unavailable.' ) . '</p>' .
1138              '<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>' .
1139              '<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>' .
1140              '<p>' . sprintf(
1141                  /* translators: %s: URL to Network Themes screen. */
1142                  __( '<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.' ),
1143                  network_admin_url( 'themes.php' )
1144              ) . '</p>' .
1145              '<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>',
1146      );
1147  }
1148  
1149  /**
1150   * Returns the content for the help sidebar on the Edit Site screens.
1151   *
1152   * @since 4.9.0
1153   *
1154   * @return string Help sidebar content.
1155   */
1156  function get_site_screen_help_sidebar_content() {
1157      return '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
1158          '<p>' . __( '<a href="https://wordpress.org/support/article/network-admin-sites-screen/">Documentation on Site Management</a>' ) . '</p>' .
1159          '<p>' . __( '<a href="https://wordpress.org/support/forum/multisite/">Support Forums</a>' ) . '</p>';
1160  }


Generated: Mon Sep 28 01:00:02 2020 Cross-referenced by PHPXref 0.7.1