[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

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


Generated: Mon Jun 17 08:20:02 2019 Cross-referenced by PHPXref 0.7