No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 
 

1131 líneas
38 KiB

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