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


Generated: Thu Apr 25 01:00:03 2024 Cross-referenced by PHPXref 0.7.1