PageRenderTime 50ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-admin/includes/ms.php

https://bitbucket.org/stratworkouts/wordpress
PHP | 747 lines | 525 code | 121 blank | 101 comment | 133 complexity | 95041992fc3cb9d643d8f1b00ae15733 MD5 | raw file
Possible License(s): GPL-2.0, AGPL-1.0, LGPL-2.1
  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_allowed = 1048576 * get_space_allowed();
  25. $space_used = get_dirsize( BLOGUPLOADDIR );
  26. $space_left = $space_allowed - $space_used;
  27. $file_size = filesize( $file['tmp_name'] );
  28. if ( $space_left < $file_size )
  29. $file['error'] = sprintf( __( 'Not enough space to upload. %1$s KB needed.' ), number_format( ($file_size - $space_left) /1024 ) );
  30. if ( $file_size > ( 1024 * get_site_option( 'fileupload_maxk', 1500 ) ) )
  31. $file['error'] = sprintf(__('This file is too big. Files must be less than %1$s KB in size.'), get_site_option( 'fileupload_maxk', 1500 ) );
  32. if ( upload_is_user_over_quota( false ) ) {
  33. $file['error'] = __( 'You have used your space quota. Please delete files before uploading.' );
  34. }
  35. if ( $file['error'] != '0' && !isset($_POST['html-upload']) )
  36. wp_die( $file['error'] . ' <a href="javascript:history.go(-1)">' . __( 'Back' ) . '</a>' );
  37. return $file;
  38. }
  39. add_filter( 'wp_handle_upload_prefilter', 'check_upload_size' );
  40. /**
  41. * Delete a blog
  42. *
  43. * @since 3.0.0
  44. *
  45. * @param int $blog_id Blog ID
  46. * @param bool $drop True if blog's table should be dropped. Default is false.
  47. * @return void
  48. */
  49. function wpmu_delete_blog( $blog_id, $drop = false ) {
  50. global $wpdb, $current_site;
  51. $switch = false;
  52. if ( $blog_id != $wpdb->blogid ) {
  53. $switch = true;
  54. switch_to_blog( $blog_id );
  55. $blog = get_blog_details( $blog_id );
  56. } else {
  57. $blog = $GLOBALS['current_blog'];
  58. }
  59. do_action( 'delete_blog', $blog_id, $drop );
  60. $users = get_users( array( 'blog_id' => $blog_id, 'fields' => 'ids' ) );
  61. // Remove users from this blog.
  62. if ( ! empty( $users ) ) {
  63. foreach ( $users as $user_id ) {
  64. remove_user_from_blog( $user_id, $blog_id );
  65. }
  66. }
  67. update_blog_status( $blog_id, 'deleted', 1 );
  68. // Don't destroy the initial, main, or root blog.
  69. if ( $drop && ( 1 == $blog_id || is_main_site( $blog_id ) || ( $blog->path == $current_site->path && $blog->domain == $current_site->domain ) ) )
  70. $drop = false;
  71. if ( $drop ) {
  72. $drop_tables = apply_filters( 'wpmu_drop_tables', $wpdb->tables( 'blog' ) );
  73. foreach ( (array) $drop_tables as $table ) {
  74. $wpdb->query( "DROP TABLE IF EXISTS `$table`" );
  75. }
  76. $wpdb->delete( $wpdb->blogs, array( 'blog_id' => $blog_id ) );
  77. $dir = apply_filters( 'wpmu_delete_blog_upload_dir', WP_CONTENT_DIR . "/blogs.dir/{$blog_id}/files/", $blog_id );
  78. $dir = rtrim( $dir, DIRECTORY_SEPARATOR );
  79. $top_dir = $dir;
  80. $stack = array($dir);
  81. $index = 0;
  82. while ( $index < count( $stack ) ) {
  83. # Get indexed directory from stack
  84. $dir = $stack[$index];
  85. $dh = @opendir( $dir );
  86. if ( $dh ) {
  87. while ( ( $file = @readdir( $dh ) ) !== false ) {
  88. if ( $file == '.' || $file == '..' )
  89. continue;
  90. if ( @is_dir( $dir . DIRECTORY_SEPARATOR . $file ) )
  91. $stack[] = $dir . DIRECTORY_SEPARATOR . $file;
  92. else if ( @is_file( $dir . DIRECTORY_SEPARATOR . $file ) )
  93. @unlink( $dir . DIRECTORY_SEPARATOR . $file );
  94. }
  95. }
  96. $index++;
  97. }
  98. $stack = array_reverse( $stack ); // Last added dirs are deepest
  99. foreach( (array) $stack as $dir ) {
  100. if ( $dir != $top_dir)
  101. @rmdir( $dir );
  102. }
  103. }
  104. if ( $switch )
  105. restore_current_blog();
  106. }
  107. // @todo Merge with wp_delete_user() ?
  108. function wpmu_delete_user( $id ) {
  109. global $wpdb;
  110. $id = (int) $id;
  111. $user = new WP_User( $id );
  112. do_action( 'wpmu_delete_user', $id );
  113. $blogs = get_blogs_of_user( $id );
  114. if ( ! empty( $blogs ) ) {
  115. foreach ( $blogs as $blog ) {
  116. switch_to_blog( $blog->userblog_id );
  117. remove_user_from_blog( $id, $blog->userblog_id );
  118. $post_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_author = %d", $id ) );
  119. foreach ( (array) $post_ids as $post_id ) {
  120. wp_delete_post( $post_id );
  121. }
  122. // Clean links
  123. $link_ids = $wpdb->get_col( $wpdb->prepare( "SELECT link_id FROM $wpdb->links WHERE link_owner = %d", $id ) );
  124. if ( $link_ids ) {
  125. foreach ( $link_ids as $link_id )
  126. wp_delete_link( $link_id );
  127. }
  128. restore_current_blog();
  129. }
  130. }
  131. $meta = $wpdb->get_col( $wpdb->prepare( "SELECT umeta_id FROM $wpdb->usermeta WHERE user_id = %d", $id ) );
  132. foreach ( $meta as $mid )
  133. delete_metadata_by_mid( 'user', $mid );
  134. $wpdb->delete( $wpdb->users, array( 'ID' => $id ) );
  135. clean_user_cache( $user );
  136. // allow for commit transaction
  137. do_action( 'deleted_user', $id );
  138. return true;
  139. }
  140. function update_option_new_admin_email( $old_value, $value ) {
  141. $email = get_option( 'admin_email' );
  142. if ( $value == get_option( 'admin_email' ) || !is_email( $value ) )
  143. return;
  144. $hash = md5( $value. time() .mt_rand() );
  145. $new_admin_email = array(
  146. 'hash' => $hash,
  147. 'newemail' => $value
  148. );
  149. update_option( 'adminhash', $new_admin_email );
  150. $content = apply_filters( 'new_admin_email_content', __( "Dear user,
  151. You recently requested to have the administration email address on
  152. your site changed.
  153. If this is correct, please click on the following link to change it:
  154. ###ADMIN_URL###
  155. You can safely ignore and delete this email if you do not want to
  156. take this action.
  157. This email has been sent to ###EMAIL###
  158. Regards,
  159. All at ###SITENAME###
  160. ###SITEURL### "), $new_admin_email );
  161. $content = str_replace( '###ADMIN_URL###', esc_url( admin_url( 'options.php?adminhash='.$hash ) ), $content );
  162. $content = str_replace( '###EMAIL###', $value, $content );
  163. $content = str_replace( '###SITENAME###', get_site_option( 'site_name' ), $content );
  164. $content = str_replace( '###SITEURL###', network_home_url(), $content );
  165. wp_mail( $value, sprintf( __( '[%s] New Admin Email Address' ), get_option( 'blogname' ) ), $content );
  166. }
  167. add_action( 'update_option_new_admin_email', 'update_option_new_admin_email', 10, 2 );
  168. add_action( 'add_option_new_admin_email', 'update_option_new_admin_email', 10, 2 );
  169. function send_confirmation_on_profile_email() {
  170. global $errors, $wpdb;
  171. $current_user = wp_get_current_user();
  172. if ( ! is_object($errors) )
  173. $errors = new WP_Error();
  174. if ( $current_user->ID != $_POST['user_id'] )
  175. return false;
  176. if ( $current_user->user_email != $_POST['email'] ) {
  177. if ( !is_email( $_POST['email'] ) ) {
  178. $errors->add( 'user_email', __( "<strong>ERROR</strong>: The e-mail address isn't correct." ), array( 'form-field' => 'email' ) );
  179. return;
  180. }
  181. if ( $wpdb->get_var( $wpdb->prepare( "SELECT user_email FROM {$wpdb->users} WHERE user_email=%s", $_POST['email'] ) ) ) {
  182. $errors->add( 'user_email', __( "<strong>ERROR</strong>: The e-mail address is already used." ), array( 'form-field' => 'email' ) );
  183. delete_option( $current_user->ID . '_new_email' );
  184. return;
  185. }
  186. $hash = md5( $_POST['email'] . time() . mt_rand() );
  187. $new_user_email = array(
  188. 'hash' => $hash,
  189. 'newemail' => $_POST['email']
  190. );
  191. update_option( $current_user->ID . '_new_email', $new_user_email );
  192. $content = apply_filters( 'new_user_email_content', __( "Dear user,
  193. You recently requested to have the email address on your account changed.
  194. If this is correct, please click on the following link to change it:
  195. ###ADMIN_URL###
  196. You can safely ignore and delete this email if you do not want to
  197. take this action.
  198. This email has been sent to ###EMAIL###
  199. Regards,
  200. All at ###SITENAME###
  201. ###SITEURL###" ), $new_user_email );
  202. $content = str_replace( '###ADMIN_URL###', esc_url( admin_url( 'profile.php?newuseremail='.$hash ) ), $content );
  203. $content = str_replace( '###EMAIL###', $_POST['email'], $content);
  204. $content = str_replace( '###SITENAME###', get_site_option( 'site_name' ), $content );
  205. $content = str_replace( '###SITEURL###', network_home_url(), $content );
  206. wp_mail( $_POST['email'], sprintf( __( '[%s] New Email Address' ), get_option( 'blogname' ) ), $content );
  207. $_POST['email'] = $current_user->user_email;
  208. }
  209. }
  210. add_action( 'personal_options_update', 'send_confirmation_on_profile_email' );
  211. function new_user_email_admin_notice() {
  212. if ( strpos( $_SERVER['PHP_SELF'], 'profile.php' ) && isset( $_GET['updated'] ) && $email = get_option( get_current_user_id() . '_new_email' ) )
  213. echo "<div class='update-nag'>" . sprintf( __( "Your email address has not been updated yet. Please check your inbox at %s for a confirmation email." ), $email['newemail'] ) . "</div>";
  214. }
  215. add_action( 'admin_notices', 'new_user_email_admin_notice' );
  216. /**
  217. * Determines if there is any upload space left in the current blog's quota.
  218. *
  219. * @since 3.0.0
  220. * @return bool True if space is available, false otherwise.
  221. */
  222. function is_upload_space_available() {
  223. if ( get_site_option( 'upload_space_check_disabled' ) )
  224. return true;
  225. if ( !( $space_allowed = get_upload_space_available() ) )
  226. return false;
  227. return true;
  228. }
  229. /**
  230. * @since 3.0.0
  231. *
  232. * @return int of upload size limit in bytes
  233. */
  234. function upload_size_limit_filter( $size ) {
  235. $fileupload_maxk = 1024 * get_site_option( 'fileupload_maxk', 1500 );
  236. if ( get_site_option( 'upload_space_check_disabled' ) )
  237. return min( $size, $fileupload_maxk );
  238. return min( $size, $fileupload_maxk, get_upload_space_available() );
  239. }
  240. /**
  241. * Determines if there is any upload space left in the current blog's quota.
  242. *
  243. * @return int of upload space available in bytes
  244. */
  245. function get_upload_space_available() {
  246. $space_allowed = get_space_allowed() * 1024 * 1024;
  247. if ( get_site_option( 'upload_space_check_disabled' ) )
  248. return $space_allowed;
  249. $dir_name = trailingslashit( BLOGUPLOADDIR );
  250. if ( !( is_dir( $dir_name) && is_readable( $dir_name ) ) )
  251. return $space_allowed;
  252. $dir = dir( $dir_name );
  253. $size = 0;
  254. while ( $file = $dir->read() ) {
  255. if ( $file != '.' && $file != '..' ) {
  256. if ( is_dir( $dir_name . $file) ) {
  257. $size += get_dirsize( $dir_name . $file );
  258. } else {
  259. $size += filesize( $dir_name . $file );
  260. }
  261. }
  262. }
  263. $dir->close();
  264. if ( ( $space_allowed - $size ) <= 0 )
  265. return 0;
  266. return $space_allowed - $size;
  267. }
  268. /**
  269. * Returns the upload quota for the current blog.
  270. *
  271. * @return int Quota
  272. */
  273. function get_space_allowed() {
  274. $space_allowed = get_option( 'blog_upload_space' );
  275. if ( ! is_numeric( $space_allowed ) )
  276. $space_allowed = get_site_option( 'blog_upload_space' );
  277. if ( empty( $space_allowed ) || ! is_numeric( $space_allowed ) )
  278. $space_allowed = 50;
  279. return $space_allowed;
  280. }
  281. function display_space_usage() {
  282. $space = get_space_allowed();
  283. $used = get_dirsize( BLOGUPLOADDIR ) / 1024 / 1024;
  284. $percentused = ( $used / $space ) * 100;
  285. if ( $space > 1000 ) {
  286. $space = number_format( $space / 1024 );
  287. /* translators: Gigabytes */
  288. $space .= __( 'GB' );
  289. } else {
  290. /* translators: Megabytes */
  291. $space .= __( 'MB' );
  292. }
  293. ?>
  294. <strong><?php printf( __( 'Used: %1s%% of %2s' ), number_format( $percentused ), $space ); ?></strong>
  295. <?php
  296. }
  297. // Edit blog upload space setting on Edit Blog page
  298. function upload_space_setting( $id ) {
  299. $quota = get_blog_option( $id, 'blog_upload_space' );
  300. if ( !$quota )
  301. $quota = '';
  302. ?>
  303. <tr>
  304. <th><?php _e( 'Site Upload Space Quota '); ?></th>
  305. <td><input type="number" step="1" min="0" style="width: 100px" name="option[blog_upload_space]" value="<?php echo $quota; ?>" /> <?php _e( 'MB (Leave blank for network default)' ); ?></td>
  306. </tr>
  307. <?php
  308. }
  309. add_action( 'wpmueditblogaction', 'upload_space_setting' );
  310. function update_user_status( $id, $pref, $value, $deprecated = null ) {
  311. global $wpdb;
  312. if ( null !== $deprecated )
  313. _deprecated_argument( __FUNCTION__, '3.1' );
  314. $wpdb->update( $wpdb->users, array( $pref => $value ), array( 'ID' => $id ) );
  315. $user = new WP_User( $id );
  316. clean_user_cache( $user );
  317. if ( $pref == 'spam' ) {
  318. if ( $value == 1 )
  319. do_action( 'make_spam_user', $id );
  320. else
  321. do_action( 'make_ham_user', $id );
  322. }
  323. return $value;
  324. }
  325. function refresh_user_details( $id ) {
  326. $id = (int) $id;
  327. if ( !$user = get_userdata( $id ) )
  328. return false;
  329. clean_user_cache( $user );
  330. return $id;
  331. }
  332. function format_code_lang( $code = '' ) {
  333. $code = strtolower( substr( $code, 0, 2 ) );
  334. $lang_codes = array(
  335. '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',
  336. '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',
  337. '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',
  338. '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',
  339. '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',
  340. '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',
  341. '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',
  342. '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',
  343. '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',
  344. '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',
  345. 've' => 'Venda', 'vi' => 'Vietnamese', 'vo' => 'Volapük', 'cy' => 'Welsh','wa' => 'Walloon','wo' => 'Wolof', 'xh' => 'Xhosa', 'yi' => 'Yiddish', 'yo' => 'Yoruba', 'za' => 'Zhuang; Chuang', 'zu' => 'Zulu' );
  346. $lang_codes = apply_filters( 'lang_codes', $lang_codes, $code );
  347. return strtr( $code, $lang_codes );
  348. }
  349. function sync_category_tag_slugs( $term, $taxonomy ) {
  350. if ( global_terms_enabled() && ( $taxonomy == 'category' || $taxonomy == 'post_tag' ) ) {
  351. if ( is_object( $term ) ) {
  352. $term->slug = sanitize_title( $term->name );
  353. } else {
  354. $term['slug'] = sanitize_title( $term['name'] );
  355. }
  356. }
  357. return $term;
  358. }
  359. add_filter( 'get_term', 'sync_category_tag_slugs', 10, 2 );
  360. function _access_denied_splash() {
  361. if ( ! is_user_logged_in() || is_network_admin() )
  362. return;
  363. $blogs = get_blogs_of_user( get_current_user_id() );
  364. if ( wp_list_filter( $blogs, array( 'userblog_id' => get_current_blog_id() ) ) )
  365. return;
  366. $blog_name = get_bloginfo( 'name' );
  367. if ( empty( $blogs ) )
  368. 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 ) );
  369. $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>';
  370. $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>';
  371. $output .= '<h3>' . __('Your Sites') . '</h3>';
  372. $output .= '<table>';
  373. foreach ( $blogs as $blog ) {
  374. $output .= "<tr>";
  375. $output .= "<td valign='top'>";
  376. $output .= "{$blog->blogname}";
  377. $output .= "</td>";
  378. $output .= "<td valign='top'>";
  379. $output .= "<a href='" . esc_url( get_admin_url( $blog->userblog_id ) ) . "'>" . __( 'Visit Dashboard' ) . "</a> | <a href='" . esc_url( get_home_url( $blog->userblog_id ) ). "'>" . __( 'View Site' ) . "</a>" ;
  380. $output .= "</td>";
  381. $output .= "</tr>";
  382. }
  383. $output .= '</table>';
  384. wp_die( $output );
  385. }
  386. add_action( 'admin_page_access_denied', '_access_denied_splash', 99 );
  387. function check_import_new_users( $permission ) {
  388. if ( !is_super_admin() )
  389. return false;
  390. return true;
  391. }
  392. add_filter( 'import_allow_create_users', 'check_import_new_users' );
  393. // See "import_allow_fetch_attachments" and "import_attachment_size_limit" filters too.
  394. function mu_dropdown_languages( $lang_files = array(), $current = '' ) {
  395. $flag = false;
  396. $output = array();
  397. foreach ( (array) $lang_files as $val ) {
  398. $code_lang = basename( $val, '.mo' );
  399. if ( $code_lang == 'en_US' ) { // American English
  400. $flag = true;
  401. $ae = __( 'American English' );
  402. $output[$ae] = '<option value="' . esc_attr( $code_lang ) . '"' . selected( $current, $code_lang, false ) . '> ' . $ae . '</option>';
  403. } elseif ( $code_lang == 'en_GB' ) { // British English
  404. $flag = true;
  405. $be = __( 'British English' );
  406. $output[$be] = '<option value="' . esc_attr( $code_lang ) . '"' . selected( $current, $code_lang, false ) . '> ' . $be . '</option>';
  407. } else {
  408. $translated = format_code_lang( $code_lang );
  409. $output[$translated] = '<option value="' . esc_attr( $code_lang ) . '"' . selected( $current, $code_lang, false ) . '> ' . esc_html ( $translated ) . '</option>';
  410. }
  411. }
  412. if ( $flag === false ) // WordPress english
  413. $output[] = '<option value=""' . selected( $current, '', false ) . '>' . __( 'English' ) . "</option>";
  414. // Order by name
  415. uksort( $output, 'strnatcasecmp' );
  416. $output = apply_filters( 'mu_dropdown_languages', $output, $lang_files, $current );
  417. echo implode( "\n\t", $output );
  418. }
  419. /* Warn the admin if SECRET SALT information is missing from wp-config.php */
  420. function secret_salt_warning() {
  421. if ( !is_super_admin() )
  422. return;
  423. $secret_keys = array( 'AUTH_KEY', 'SECURE_AUTH_KEY', 'LOGGED_IN_KEY', 'NONCE_KEY', 'AUTH_SALT', 'SECURE_AUTH_SALT', 'LOGGED_IN_SALT', 'NONCE_SALT' );
  424. $out = '';
  425. foreach( $secret_keys as $key ) {
  426. if ( ! defined( $key ) )
  427. $out .= "define( '$key', '" . esc_html( wp_generate_password( 64, true, true ) ) . "' );<br />";
  428. }
  429. if ( $out != '' ) {
  430. $msg = __( 'Warning! WordPress encrypts user cookies, but you must add the following lines to <strong>wp-config.php</strong> for it to be more secure.' );
  431. $msg .= '<br/>' . __( "Before the line <code>/* That's all, stop editing! Happy blogging. */</code> please add this code:" );
  432. $msg .= "<br/><br/><code>$out</code>";
  433. echo "<div class='update-nag'>$msg</div>";
  434. }
  435. }
  436. add_action( 'network_admin_notices', 'secret_salt_warning' );
  437. function site_admin_notice() {
  438. global $wp_db_version;
  439. if ( !is_super_admin() )
  440. return false;
  441. if ( get_site_option( 'wpmu_upgrade_site' ) != $wp_db_version )
  442. echo "<div class='update-nag'>" . sprintf( __( 'Thank you for Updating! Please visit the <a href="%s">Update Network</a> page to update all your sites.' ), esc_url( network_admin_url( 'upgrade.php' ) ) ) . "</div>";
  443. }
  444. add_action( 'admin_notices', 'site_admin_notice' );
  445. add_action( 'network_admin_notices', 'site_admin_notice' );
  446. function avoid_blog_page_permalink_collision( $data, $postarr ) {
  447. if ( is_subdomain_install() )
  448. return $data;
  449. if ( $data['post_type'] != 'page' )
  450. return $data;
  451. if ( !isset( $data['post_name'] ) || $data['post_name'] == '' )
  452. return $data;
  453. if ( !is_main_site() )
  454. return $data;
  455. $post_name = $data['post_name'];
  456. $c = 0;
  457. while( $c < 10 && get_id_from_blogname( $post_name ) ) {
  458. $post_name .= mt_rand( 1, 10 );
  459. $c ++;
  460. }
  461. if ( $post_name != $data['post_name'] ) {
  462. $data['post_name'] = $post_name;
  463. }
  464. return $data;
  465. }
  466. add_filter( 'wp_insert_post_data', 'avoid_blog_page_permalink_collision', 10, 2 );
  467. function choose_primary_blog() {
  468. ?>
  469. <table class="form-table">
  470. <tr>
  471. <?php /* translators: My sites label */ ?>
  472. <th scope="row"><?php _e( 'Primary Site' ); ?></th>
  473. <td>
  474. <?php
  475. $all_blogs = get_blogs_of_user( get_current_user_id() );
  476. $primary_blog = get_user_meta( get_current_user_id(), 'primary_blog', true );
  477. if ( count( $all_blogs ) > 1 ) {
  478. $found = false;
  479. ?>
  480. <select name="primary_blog">
  481. <?php foreach( (array) $all_blogs as $blog ) {
  482. if ( $primary_blog == $blog->userblog_id )
  483. $found = true;
  484. ?><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
  485. } ?>
  486. </select>
  487. <?php
  488. if ( !$found ) {
  489. $blog = array_shift( $all_blogs );
  490. update_user_meta( get_current_user_id(), 'primary_blog', $blog->userblog_id );
  491. }
  492. } elseif ( count( $all_blogs ) == 1 ) {
  493. $blog = array_shift( $all_blogs );
  494. echo $blog->domain;
  495. if ( $primary_blog != $blog->userblog_id ) // Set the primary blog again if it's out of sync with blog list.
  496. update_user_meta( get_current_user_id(), 'primary_blog', $blog->userblog_id );
  497. } else {
  498. echo "N/A";
  499. }
  500. ?>
  501. </td>
  502. </tr>
  503. <?php if ( in_array( get_site_option( 'registration' ), array( 'all', 'blog' ) ) ) : ?>
  504. <tr>
  505. <th scope="row" colspan="2" class="th-full">
  506. <a href="<?php echo apply_filters( 'wp_signup_location', network_home_url( 'wp-signup.php' ) ); ?>"><?php _e( 'Create a New Site' ); ?></a>
  507. </th>
  508. </tr>
  509. <?php endif; ?>
  510. </table>
  511. <?php
  512. }
  513. function ms_deprecated_blogs_file() {
  514. if ( ! is_super_admin() )
  515. return;
  516. if ( ! file_exists( WP_CONTENT_DIR . '/blogs.php' ) )
  517. return;
  518. echo '<div class="update-nag">' . sprintf( __( 'The <code>%1$s</code> file is deprecated. Please remove it and update your server rewrite rules to use <code>%2$s</code> instead.' ), 'wp-content/blogs.php', 'wp-includes/ms-files.php' ) . '</div>';
  519. }
  520. add_action( 'network_admin_notices', 'ms_deprecated_blogs_file' );
  521. /**
  522. * Grants super admin privileges.
  523. *
  524. * @since 3.0.0
  525. * @param int $user_id
  526. */
  527. function grant_super_admin( $user_id ) {
  528. global $super_admins;
  529. // If global super_admins override is defined, there is nothing to do here.
  530. if ( isset($super_admins) )
  531. return false;
  532. do_action( 'grant_super_admin', $user_id );
  533. // Directly fetch site_admins instead of using get_super_admins()
  534. $super_admins = get_site_option( 'site_admins', array( 'admin' ) );
  535. $user = new WP_User( $user_id );
  536. if ( ! in_array( $user->user_login, $super_admins ) ) {
  537. $super_admins[] = $user->user_login;
  538. update_site_option( 'site_admins' , $super_admins );
  539. do_action( 'granted_super_admin', $user_id );
  540. return true;
  541. }
  542. return false;
  543. }
  544. /**
  545. * Revokes super admin privileges.
  546. *
  547. * @since 3.0.0
  548. * @param int $user_id
  549. */
  550. function revoke_super_admin( $user_id ) {
  551. global $super_admins;
  552. // If global super_admins override is defined, there is nothing to do here.
  553. if ( isset($super_admins) )
  554. return false;
  555. do_action( 'revoke_super_admin', $user_id );
  556. // Directly fetch site_admins instead of using get_super_admins()
  557. $super_admins = get_site_option( 'site_admins', array( 'admin' ) );
  558. $user = new WP_User( $user_id );
  559. if ( $user->user_email != get_site_option( 'admin_email' ) ) {
  560. if ( false !== ( $key = array_search( $user->user_login, $super_admins ) ) ) {
  561. unset( $super_admins[$key] );
  562. update_site_option( 'site_admins', $super_admins );
  563. do_action( 'revoked_super_admin', $user_id );
  564. return true;
  565. }
  566. }
  567. return false;
  568. }
  569. /**
  570. * Whether or not we can edit this network from this page
  571. *
  572. * By default editing of network is restricted to the Network Admin for that site_id this allows for this to be overridden
  573. *
  574. * @since 3.1.0
  575. * @param integer $site_id The network/site id to check.
  576. */
  577. function can_edit_network( $site_id ) {
  578. global $wpdb;
  579. if ($site_id == $wpdb->siteid )
  580. $result = true;
  581. else
  582. $result = false;
  583. return apply_filters( 'can_edit_network', $result, $site_id );
  584. }
  585. /**
  586. * Thickbox image paths for Network Admin.
  587. *
  588. * @since 3.1.0
  589. * @access private
  590. */
  591. function _thickbox_path_admin_subfolder() {
  592. ?>
  593. <script type="text/javascript">
  594. //<![CDATA[
  595. var tb_pathToImage = "../../wp-includes/js/thickbox/loadingAnimation.gif";
  596. var tb_closeImage = "../../wp-includes/js/thickbox/tb-close.png";
  597. //]]>
  598. </script>
  599. <?php
  600. }
  601. /**
  602. * Whether or not we have a large network.
  603. *
  604. * The default criteria for a large network is either more than 10,000 users or more than 10,000 sites.
  605. * Plugins can alter this criteria using the 'wp_is_large_network' filter.
  606. *
  607. * @since 3.3.0
  608. * @param string $using 'sites or 'users'. Default is 'sites'.
  609. * @return bool True if the network meets the criteria for large. False otherwise.
  610. */
  611. function wp_is_large_network( $using = 'sites' ) {
  612. if ( 'users' == $using ) {
  613. $count = get_user_count();
  614. return apply_filters( 'wp_is_large_network', $count > 10000, 'users', $count );
  615. }
  616. $count = get_blog_count();
  617. return apply_filters( 'wp_is_large_network', $count > 10000, 'sites', $count );
  618. }