PageRenderTime 60ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-admin/ms-edit.php

https://gitlab.com/endomorphosis/reservationtelco
PHP | 632 lines | 522 code | 88 blank | 22 comment | 168 complexity | 133d9883da706769e1e61457b9104039 MD5 | raw file
  1. <?php
  2. /**
  3. * Action handler for Multisite administration panels.
  4. *
  5. * @package WordPress
  6. * @subpackage Multisite
  7. * @since 3.0.0
  8. */
  9. require_once( './admin.php' );
  10. if ( ! is_multisite() )
  11. wp_die( __( 'Multisite support is not enabled.' ) );
  12. if ( empty( $_GET['action'] ) )
  13. wp_redirect( admin_url( 'ms-admin.php' ) );
  14. do_action( 'wpmuadminedit' , '');
  15. if ( isset( $_GET['id' ]) )
  16. $id = intval( $_GET['id'] );
  17. elseif ( isset( $_POST['id'] ) )
  18. $id = intval( $_POST['id'] );
  19. switch ( $_GET['action'] ) {
  20. case 'siteoptions':
  21. check_admin_referer( 'siteoptions' );
  22. if ( ! current_user_can( 'manage_network_options' ) )
  23. wp_die( __( 'You do not have permission to access this page.' ) );
  24. if ( empty( $_POST ) )
  25. wp_die( sprintf( __( 'You probably need to go back to the <a href="%s">options page</a>.', esc_url( admin_url( 'ms-options.php' ) ) ) ) );
  26. if ( isset($_POST['WPLANG']) && ( '' === $_POST['WPLANG'] || in_array( $_POST['WPLANG'], get_available_languages() ) ) )
  27. update_site_option( 'WPLANG', $_POST['WPLANG'] );
  28. if ( is_email( $_POST['admin_email'] ) )
  29. update_site_option( 'admin_email', $_POST['admin_email'] );
  30. $illegal_names = split( ' ', $_POST['illegal_names'] );
  31. foreach ( (array) $illegal_names as $name ) {
  32. $name = trim( $name );
  33. if ( $name != '' )
  34. $names[] = trim( $name );
  35. }
  36. update_site_option( 'illegal_names', $names );
  37. if ( $_POST['limited_email_domains'] != '' ) {
  38. $limited_email_domains = str_replace( ' ', "\n", $_POST['limited_email_domains'] );
  39. $limited_email_domains = split( "\n", stripslashes( $limited_email_domains ) );
  40. $limited_email = array();
  41. foreach ( (array) $limited_email_domains as $domain ) {
  42. $domain = trim( $domain );
  43. if ( ! preg_match( '/(--|\.\.)/', $domain ) && preg_match( '|^([a-zA-Z0-9-\.])+$|', $domain ) )
  44. $limited_email[] = trim( $domain );
  45. }
  46. update_site_option( 'limited_email_domains', $limited_email );
  47. } else {
  48. update_site_option( 'limited_email_domains', '' );
  49. }
  50. if ( $_POST['banned_email_domains'] != '' ) {
  51. $banned_email_domains = split( "\n", stripslashes( $_POST['banned_email_domains'] ) );
  52. $banned = array();
  53. foreach ( (array) $banned_email_domains as $domain ) {
  54. $domain = trim( $domain );
  55. if ( ! preg_match( '/(--|\.\.)/', $domain ) && preg_match( '|^([a-zA-Z0-9-\.])+$|', $domain ) )
  56. $banned[] = trim( $domain );
  57. }
  58. update_site_option( 'banned_email_domains', $banned );
  59. } else {
  60. update_site_option( 'banned_email_domains', '' );
  61. }
  62. update_site_option( 'default_user_role', $_POST['default_user_role'] );
  63. if ( trim( $_POST['dashboard_blog_orig'] ) == '' )
  64. $_POST['dashboard_blog_orig'] = $current_site->blog_id;
  65. if ( trim( $_POST['dashboard_blog'] ) == '' ) {
  66. $_POST['dashboard_blog'] = $current_site->blog_id;
  67. $dashboard_blog_id = $current_site->blog_id;
  68. } elseif ( ! preg_match( '/(--|\.)/', $_POST['dashboard_blog'] ) && preg_match( '|^([a-zA-Z0-9-\.])+$|', $_POST['dashboard_blog'] ) ) {
  69. $dashboard_blog = $_POST['dashboard_blog'];
  70. $blog_details = get_blog_details( $dashboard_blog );
  71. if ( false === $blog_details ) {
  72. if ( is_numeric( $dashboard_blog ) )
  73. wp_die( __( 'A dashboard site referenced by ID must already exist' ) );
  74. if ( is_subdomain_install() ) {
  75. $domain = $dashboard_blog . '.' . $current_site->domain;
  76. $path = $current_site->path;
  77. } else {
  78. $domain = $current_site->domain;
  79. $path = trailingslashit( $current_site->path . $dashboard_blog );
  80. }
  81. $wpdb->hide_errors();
  82. $dashboard_blog_id = wpmu_create_blog( $domain, $path, __( 'My Dashboard' ), $current_user->id , array( 'public' => 0 ), $current_site->id );
  83. $wpdb->show_errors();
  84. } else {
  85. $dashboard_blog_id = $blog_details->blog_id;
  86. }
  87. }
  88. if ( is_wp_error( $dashboard_blog_id ) )
  89. wp_die( __( 'Problem creating dashboard site: ' ) . $dashboard_blog_id->get_error_message() );
  90. if ( $_POST['dashboard_blog_orig'] != $_POST['dashboard_blog'] ) {
  91. $users = get_users_of_blog( get_site_option( 'dashboard_blog' ) );
  92. $move_users = array();
  93. foreach ( (array)$users as $user ) {
  94. $user_meta_value = unserialize( $user->meta_value );
  95. if ( is_array( $user_meta_value ) && array_pop( array_keys( $user_meta_value ) ) == 'subscriber' )
  96. $move_users[] = $user->user_id;
  97. }
  98. if ( false == empty( $move_users ) ) {
  99. foreach ( (array)$move_users as $user_id ) {
  100. remove_user_from_blog($user_id, get_site_option( 'dashboard_blog' ) );
  101. add_user_to_blog( $dashboard_blog_id, $user_id, get_site_option( 'default_user_role', 'subscriber' ) );
  102. update_user_meta( $user_id, 'primary_blog', $dashboard_blog_id );
  103. }
  104. }
  105. }
  106. update_site_option( 'dashboard_blog', $dashboard_blog_id );
  107. $options = array( 'registrationnotification', 'registration', 'add_new_users', 'menu_items', 'mu_media_buttons', 'upload_space_check_disabled', 'blog_upload_space', 'upload_filetypes', 'site_name', 'first_post', 'first_page', 'first_comment', 'first_comment_url', 'first_comment_author', 'welcome_email', 'welcome_user_email', 'fileupload_maxk', 'admin_notice_feed', 'global_terms_enabled' );
  108. $checked_options = array( 'mu_media_buttons' => array(), 'menu_items' => array(), 'registrationnotification' => 'no', 'upload_space_check_disabled' => 1 );
  109. foreach ( $checked_options as $option_name => $option_unchecked_value ) {
  110. if ( ! isset( $_POST[$option_name] ) )
  111. $_POST[$option_name] = $option_unchecked_value;
  112. }
  113. foreach ( $options as $option_name ) {
  114. if ( ! isset($_POST[$option_name]) )
  115. continue;
  116. $value = stripslashes_deep( $_POST[$option_name] );
  117. update_site_option( $option_name, $value );
  118. }
  119. // Update more options here
  120. do_action( 'update_wpmu_options' );
  121. wp_redirect( add_query_arg( 'updated', 'true', admin_url( 'ms-options.php' ) ) );
  122. exit();
  123. break;
  124. case 'addblog':
  125. check_admin_referer( 'add-blog', '_wpnonce_add-blog' );
  126. if ( ! current_user_can( 'manage_sites' ) )
  127. wp_die( __( 'You do not have permission to access this page.' ) );
  128. if ( is_array( $_POST['blog'] ) == false )
  129. wp_die( __( 'Can&#8217;t create an empty site.' ) );
  130. $blog = $_POST['blog'];
  131. $domain = '';
  132. if ( ! preg_match( '/(--)/', $blog['domain'] ) && preg_match( '|^([a-zA-Z0-9-])+$|', $blog['domain'] ) )
  133. $domain = strtolower( $blog['domain'] );
  134. // If not a subdomain install, make sure the domain isn't a reserved word
  135. if ( ! is_subdomain_install() ) {
  136. $subdirectory_reserved_names = apply_filters( 'subdirectory_reserved_names', array( 'page', 'comments', 'blog', 'files', 'feed' ) );
  137. if ( in_array( $domain, $subdirectory_reserved_names ) )
  138. wp_die( sprintf( __('The following words are reserved for use by WordPress functions and cannot be used as blog names: <code>%s</code>' ), implode( '</code>, <code>', $subdirectory_reserved_names ) ) );
  139. }
  140. $email = sanitize_email( $blog['email'] );
  141. $title = $blog['title'];
  142. if ( empty( $domain ) )
  143. wp_die( __( 'Missing or invalid site address.' ) );
  144. if ( empty( $email ) )
  145. wp_die( __( 'Missing email address.' ) );
  146. if ( !is_email( $email ) )
  147. wp_die( __( 'Invalid email address.' ) );
  148. if ( is_subdomain_install() ) {
  149. $newdomain = $domain . '.' . preg_replace( '|^www\.|', '', $current_site->domain );
  150. $path = $base;
  151. } else {
  152. $newdomain = $current_site->domain;
  153. $path = $base . $domain . '/';
  154. }
  155. $password = 'N/A';
  156. $user_id = email_exists($email);
  157. if ( !$user_id ) { // Create a new user with a random password
  158. $password = wp_generate_password();
  159. $user_id = wpmu_create_user( $domain, $password, $email );
  160. if ( false == $user_id )
  161. wp_die( __( 'There was an error creating the user.' ) );
  162. else
  163. wp_new_user_notification( $user_id, $password );
  164. }
  165. $wpdb->hide_errors();
  166. $id = wpmu_create_blog( $newdomain, $path, $title, $user_id , array( 'public' => 1 ), $current_site->id );
  167. $wpdb->show_errors();
  168. if ( !is_wp_error( $id ) ) {
  169. $dashboard_blog = get_dashboard_blog();
  170. if ( !is_super_admin( $user_id ) && get_user_option( 'primary_blog', $user_id ) == $dashboard_blog->blog_id )
  171. update_user_option( $user_id, 'primary_blog', $id, true );
  172. $content_mail = sprintf( __( "New site created by %1s\n\nAddress: http://%2s\nName: %3s"), $current_user->user_login , $newdomain . $path, stripslashes( $title ) );
  173. wp_mail( get_site_option('admin_email'), sprintf( __( '[%s] New Site Created' ), $current_site->site_name ), $content_mail, 'From: "Site Admin" <' . get_site_option( 'admin_email' ) . '>' );
  174. wpmu_welcome_notification( $id, $user_id, $password, $title, array( 'public' => 1 ) );
  175. wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'add-blog' ), wp_get_referer() ) );
  176. exit();
  177. } else {
  178. wp_die( $id->get_error_message() );
  179. }
  180. break;
  181. case 'updateblog':
  182. check_admin_referer( 'editblog' );
  183. if ( ! current_user_can( 'manage_sites' ) )
  184. wp_die( __( 'You do not have permission to access this page.' ) );
  185. if ( empty( $_POST ) )
  186. wp_die( sprintf( __( 'You probably need to go back to the <a href="%s">sites page</a>', esc_url( admin_url( 'ms-sites.php' ) ) ) ) );
  187. switch_to_blog( $id );
  188. // themes
  189. $allowedthemes = array();
  190. if ( isset($_POST['theme']) && is_array( $_POST['theme'] ) ) {
  191. foreach ( $_POST['theme'] as $theme => $val ) {
  192. if ( 'on' == $val )
  193. $allowedthemes[$theme] = true;
  194. }
  195. }
  196. update_option( 'allowedthemes', $allowedthemes );
  197. // options
  198. if ( is_array( $_POST['option'] ) ) {
  199. $c = 1;
  200. $count = count( $_POST['option'] );
  201. foreach ( (array) $_POST['option'] as $key => $val ) {
  202. if ( $key === 0 || is_array( $val ) )
  203. continue; // Avoids "0 is a protected WP option and may not be modified" error when edit blog options
  204. if ( $c == $count )
  205. update_option( $key, stripslashes( $val ) );
  206. else
  207. update_option( $key, stripslashes( $val ), false ); // no need to refresh blog details yet
  208. $c++;
  209. }
  210. }
  211. // home and siteurl
  212. if ( isset( $_POST['update_home_url'] ) && $_POST['update_home_url'] == 'update' ) {
  213. $blog_address = get_blogaddress_by_domain( $_POST['blog']['domain'], $_POST['blog']['path'] );
  214. if ( get_option( 'siteurl' ) != $blog_address )
  215. update_option( 'siteurl', $blog_address );
  216. if ( get_option( 'home' ) != $blog_address )
  217. update_option( 'home', $blog_address );
  218. }
  219. // rewrite rules can't be flushed during switch to blog
  220. delete_option( 'rewrite_rules' );
  221. // update blogs table
  222. $blog_data = stripslashes_deep( $_POST['blog'] );
  223. update_blog_details( $id, $blog_data );
  224. // get blog prefix
  225. $blog_prefix = $wpdb->get_blog_prefix( $id );
  226. // user roles
  227. if ( isset( $_POST['role'] ) && is_array( $_POST['role'] ) == true ) {
  228. $newroles = $_POST['role'];
  229. reset( $newroles );
  230. foreach ( (array) $newroles as $userid => $role ) {
  231. $user = new WP_User( $userid );
  232. if ( ! $user )
  233. continue;
  234. $user->for_blog( $id );
  235. $user->set_role( $role );
  236. }
  237. }
  238. // remove user
  239. if ( isset( $_POST['blogusers'] ) && is_array( $_POST['blogusers'] ) ) {
  240. reset( $_POST['blogusers'] );
  241. foreach ( (array) $_POST['blogusers'] as $key => $val )
  242. remove_user_from_blog( $key, $id );
  243. }
  244. // change password
  245. if ( isset( $_POST['user_password'] ) && is_array( $_POST['user_password'] ) ) {
  246. reset( $_POST['user_password'] );
  247. $newroles = $_POST['role'];
  248. foreach ( (array) $_POST['user_password'] as $userid => $pass ) {
  249. unset( $_POST['role'] );
  250. $_POST['role'] = $newroles[ $userid ];
  251. if ( $pass != '' ) {
  252. $cap = $wpdb->get_var( "SELECT meta_value FROM {$wpdb->usermeta} WHERE user_id = '{$userid}' AND meta_key = '{$blog_prefix}capabilities' AND meta_value = 'a:0:{}'" );
  253. $userdata = get_userdata($userid);
  254. $_POST['pass1'] = $_POST['pass2'] = $pass;
  255. $_POST['email'] = $userdata->user_email;
  256. $_POST['rich_editing'] = $userdata->rich_editing;
  257. edit_user( $userid );
  258. if ( $cap == null )
  259. $wpdb->query( "DELETE FROM {$wpdb->usermeta} WHERE user_id = '{$userid}' AND meta_key = '{$blog_prefix}capabilities' AND meta_value = 'a:0:{}'" );
  260. }
  261. }
  262. unset( $_POST['role'] );
  263. $_POST['role'] = $newroles;
  264. }
  265. // add user
  266. if ( !empty( $_POST['newuser'] ) ) {
  267. $newuser = $_POST['newuser'];
  268. $userid = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . $wpdb->users . " WHERE user_login = %s", $newuser ) );
  269. if ( $userid ) {
  270. $user = $wpdb->get_var( "SELECT user_id FROM " . $wpdb->usermeta . " WHERE user_id='$userid' AND meta_key='{$blog_prefix}capabilities'" );
  271. if ( $user == false )
  272. add_user_to_blog( $id, $userid, $_POST['new_role'] );
  273. }
  274. }
  275. do_action( 'wpmu_update_blog_options' );
  276. restore_current_blog();
  277. wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'editblog', 'id' => $id ), wp_get_referer() ) );
  278. break;
  279. case 'deleteblog':
  280. check_admin_referer('deleteblog');
  281. if ( ! current_user_can( 'manage_sites' ) )
  282. wp_die( __( 'You do not have permission to access this page.' ) );
  283. if ( $id != '0' && $id != $current_site->blog_id )
  284. wpmu_delete_blog( $id, true );
  285. wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'delete' ), wp_get_referer() ) );
  286. exit();
  287. break;
  288. case 'allblogs':
  289. if ( isset( $_POST['doaction']) || isset($_POST['doaction2'] ) ) {
  290. check_admin_referer( 'bulk-ms-sites', '_wpnonce_bulk-ms-sites' );
  291. if ( ! current_user_can( 'manage_sites' ) )
  292. wp_die( __( 'You do not have permission to access this page.' ) );
  293. if ( $_GET['action'] != -1 || $_POST['action2'] != -1 )
  294. $doaction = $_POST['action'] != -1 ? $_POST['action'] : $_POST['action2'];
  295. foreach ( (array) $_POST['allblogs'] as $key => $val ) {
  296. if ( $val != '0' && $val != $current_site->blog_id ) {
  297. switch ( $doaction ) {
  298. case 'delete':
  299. $blogfunction = 'all_delete';
  300. wpmu_delete_blog( $val, true );
  301. break;
  302. case 'spam':
  303. $blogfunction = 'all_spam';
  304. update_blog_status( $val, 'spam', '1', 0 );
  305. set_time_limit( 60 );
  306. break;
  307. case 'notspam':
  308. $blogfunction = 'all_notspam';
  309. update_blog_status( $val, 'spam', '0', 0 );
  310. set_time_limit( 60 );
  311. break;
  312. }
  313. } else {
  314. wp_die( __( 'You are not allowed to change the current site.' ) );
  315. }
  316. }
  317. wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => $blogfunction ), wp_get_referer() ) );
  318. exit();
  319. } else {
  320. wp_redirect( admin_url( 'ms-sites.php' ) );
  321. }
  322. break;
  323. case 'archiveblog':
  324. check_admin_referer( 'archiveblog' );
  325. if ( ! current_user_can( 'manage_sites' ) )
  326. wp_die( __( 'You do not have permission to access this page.' ) );
  327. update_blog_status( $id, 'archived', '1' );
  328. do_action( 'archive_blog', $id );
  329. wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'archive' ), wp_get_referer() ) );
  330. exit();
  331. break;
  332. case 'unarchiveblog':
  333. check_admin_referer( 'unarchiveblog' );
  334. if ( ! current_user_can( 'manage_sites' ) )
  335. wp_die( __( 'You do not have permission to access this page.' ) );
  336. do_action( 'unarchive_blog', $id );
  337. update_blog_status( $id, 'archived', '0' );
  338. wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'unarchive' ), wp_get_referer() ) );
  339. exit();
  340. break;
  341. case 'activateblog':
  342. check_admin_referer( 'activateblog' );
  343. if ( ! current_user_can( 'manage_sites' ) )
  344. wp_die( __( 'You do not have permission to access this page.' ) );
  345. update_blog_status( $id, 'deleted', '0' );
  346. do_action( 'activate_blog', $id );
  347. wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'activate' ), wp_get_referer() ) );
  348. exit();
  349. break;
  350. case 'deactivateblog':
  351. check_admin_referer( 'deactivateblog' );
  352. if ( ! current_user_can( 'manage_sites' ) )
  353. wp_die( __( 'You do not have permission to access this page.' ) );
  354. do_action( 'deactivate_blog', $id );
  355. update_blog_status( $id, 'deleted', '1' );
  356. wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'deactivate' ), wp_get_referer() ) );
  357. exit();
  358. break;
  359. case 'unspamblog':
  360. check_admin_referer( 'unspamblog' );
  361. if ( ! current_user_can( 'manage_sites' ) )
  362. wp_die( __( 'You do not have permission to access this page.' ) );
  363. update_blog_status( $id, 'spam', '0' );
  364. wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'unspam' ), wp_get_referer() ) );
  365. exit();
  366. break;
  367. case 'spamblog':
  368. check_admin_referer( 'spamblog' );
  369. if ( ! current_user_can( 'manage_sites' ) )
  370. wp_die( __( 'You do not have permission to access this page.' ) );
  371. update_blog_status( $id, 'spam', '1' );
  372. wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'spam' ), wp_get_referer() ) );
  373. exit();
  374. break;
  375. // Themes
  376. case 'updatethemes':
  377. if ( ! current_user_can( 'manage_network_themes' ) )
  378. wp_die( __( 'You do not have permission to access this page.' ) );
  379. if ( is_array( $_POST['theme'] ) ) {
  380. $themes = get_themes();
  381. reset( $themes );
  382. foreach ( (array) $themes as $key => $theme ) {
  383. if ( $_POST['theme'][ esc_html( $theme['Stylesheet'] ) ] == 'enabled' )
  384. $allowed_themes[ esc_html( $theme['Stylesheet'] ) ] = true;
  385. }
  386. update_site_option( 'allowedthemes', $allowed_themes );
  387. }
  388. wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'themes' ), wp_get_referer() ) );
  389. exit();
  390. break;
  391. // Common
  392. case 'confirm':
  393. if ( !headers_sent() ) {
  394. nocache_headers();
  395. header( 'Content-Type: text/html; charset=utf-8' );
  396. }
  397. if ( $current_site->blog_id == $id )
  398. wp_die( __( 'You are not allowed to change the current site.' ) );
  399. ?>
  400. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  401. <html xmlns="http://www.w3.org/1999/xhtml" <?php if ( function_exists( 'language_attributes' ) ) language_attributes(); ?>>
  402. <head>
  403. <title><?php _e( 'WordPress &rsaquo; Confirm your action' ); ?></title>
  404. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  405. <?php wp_admin_css( 'install', true ); ?>
  406. </head>
  407. <body id="error-page">
  408. <h1 id="logo"><img alt="WordPress" src="<?php echo esc_attr( admin_url( 'images/wordpress-logo.png' ) ); ?>" /></h1>
  409. <form action="ms-edit.php?action=<?php echo esc_attr( $_GET['action2'] ) ?>" method="post">
  410. <input type="hidden" name="action" value="<?php echo esc_attr( $_GET['action2'] ) ?>" />
  411. <input type="hidden" name="id" value="<?php echo esc_attr( $id ); ?>" />
  412. <input type="hidden" name="_wp_http_referer" value="<?php echo esc_attr( wp_get_referer() ); ?>" />
  413. <?php wp_nonce_field( $_GET['action2'], '_wpnonce', false ); ?>
  414. <p><?php echo esc_html( stripslashes( $_GET['msg'] ) ); ?></p>
  415. <p class="submit"><input class="button" type="submit" value="<?php _e( 'Confirm' ); ?>" /></p>
  416. </form>
  417. </body>
  418. </html>
  419. <?php
  420. break;
  421. // Users
  422. case 'deleteuser':
  423. if ( ! current_user_can( 'manage_network_users' ) )
  424. wp_die( __( 'You do not have permission to access this page.' ) );
  425. check_admin_referer( 'deleteuser' );
  426. if ( $id != '0' && $id != '1' ) {
  427. $_POST['allusers'] = array( $id ); // confirm_delete_users() can only handle with arrays
  428. $title = __( 'Users' );
  429. $parent_file = 'ms-admin.php';
  430. require_once( 'admin-header.php' );
  431. echo '<div class="wrap">';
  432. confirm_delete_users( $_POST['allusers'] );
  433. echo '</div>';
  434. require_once( 'admin-footer.php' );
  435. exit();
  436. } else {
  437. wp_redirect( admin_url( 'ms-users.php' ) );
  438. }
  439. break;
  440. case 'allusers':
  441. if ( ! current_user_can( 'manage_network_users' ) )
  442. wp_die( __( 'You do not have permission to access this page.' ) );
  443. if ( isset( $_POST['doaction']) || isset($_POST['doaction2'] ) ) {
  444. check_admin_referer( 'bulk-ms-users', '_wpnonce_bulk-ms-users' );
  445. if ( $_GET['action'] != -1 || $_POST['action2'] != -1 )
  446. $doaction = $_POST['action'] != -1 ? $_POST['action'] : $_POST['action2'];
  447. foreach ( (array) $_POST['allusers'] as $key => $val ) {
  448. if ( !empty( $val ) ) {
  449. switch ( $doaction ) {
  450. case 'delete':
  451. $title = __( 'Users' );
  452. $parent_file = 'ms-admin.php';
  453. require_once( 'admin-header.php' );
  454. echo '<div class="wrap">';
  455. confirm_delete_users( $_POST['allusers'] );
  456. echo '</div>';
  457. require_once( 'admin-footer.php' );
  458. exit();
  459. break;
  460. case 'spam':
  461. $user = new WP_User( $val );
  462. if ( in_array( $user->user_login, get_super_admins() ) )
  463. wp_die( sprintf( __( 'Warning! User cannot be modified. The user %s is a network admnistrator.' ), esc_html( $user->user_login ) ) );
  464. $userfunction = 'all_spam';
  465. $blogs = get_blogs_of_user( $val, true );
  466. foreach ( (array) $blogs as $key => $details ) {
  467. if ( $details->userblog_id != $current_site->blog_id ) // main blog not a spam !
  468. update_blog_status( $details->userblog_id, 'spam', '1' );
  469. }
  470. update_user_status( $val, 'spam', '1', 1 );
  471. break;
  472. case 'notspam':
  473. $userfunction = 'all_notspam';
  474. $blogs = get_blogs_of_user( $val, true );
  475. foreach ( (array) $blogs as $key => $details )
  476. update_blog_status( $details->userblog_id, 'spam', '0' );
  477. update_user_status( $val, 'spam', '0', 1 );
  478. break;
  479. }
  480. }
  481. }
  482. wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => $userfunction ), wp_get_referer() ) );
  483. exit();
  484. } else {
  485. wp_redirect( admin_url( 'ms-users.php' ) );
  486. }
  487. break;
  488. case 'dodelete':
  489. check_admin_referer( 'ms-users-delete' );
  490. if ( ! current_user_can( 'manage_network_users' ) )
  491. wp_die( __( 'You do not have permission to access this page.' ) );
  492. if ( is_array( $_POST['blog'] ) && ! empty( $_POST['blog'] ) ) {
  493. foreach ( $_POST['blog'] as $id => $users ) {
  494. foreach ( $users as $blogid => $user_id ) {
  495. if ( ! empty( $_POST['delete'] ) && 'reassign' == $_POST['delete'][$blogid][$id] )
  496. remove_user_from_blog( $id, $blogid, $user_id );
  497. else
  498. remove_user_from_blog( $id, $blogid );
  499. }
  500. }
  501. }
  502. $i = 0;
  503. if ( is_array( $_POST['user'] ) && ! empty( $_POST['user'] ) )
  504. foreach( $_POST['user'] as $id ) {
  505. wpmu_delete_user( $id );
  506. $i++;
  507. }
  508. if ( $i == 1 )
  509. $deletefunction = 'delete';
  510. else
  511. $deletefunction = 'all_delete';
  512. wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => $deletefunction ), admin_url( 'ms-users.php' ) ) );
  513. break;
  514. case 'adduser':
  515. check_admin_referer( 'add-user', '_wpnonce_add-user' );
  516. if ( ! current_user_can( 'manage_network_users' ) )
  517. wp_die( __( 'You do not have permission to access this page.' ) );
  518. if ( is_array( $_POST['user'] ) == false )
  519. wp_die( __( 'Cannot create an empty user.' ) );
  520. $user = $_POST['user'];
  521. if ( empty($user['username']) && empty($user['email']) )
  522. wp_die( __( 'Missing username and email.' ) );
  523. elseif ( empty($user['username']) )
  524. wp_die( __( 'Missing username.' ) );
  525. elseif ( empty($user['email']) )
  526. wp_die( __( 'Missing email.' ) );
  527. $password = wp_generate_password();
  528. $user_id = wpmu_create_user( esc_html( strtolower( $user['username'] ) ), $password, esc_html( $user['email'] ) );
  529. if ( false == $user_id )
  530. wp_die( __( 'Duplicated username or email address.' ) );
  531. else
  532. wp_new_user_notification( $user_id, $password );
  533. if ( get_site_option( 'dashboard_blog' ) == false )
  534. add_user_to_blog( $current_site->blog_id, $user_id, get_site_option( 'default_user_role', 'subscriber' ) );
  535. else
  536. add_user_to_blog( get_site_option( 'dashboard_blog' ), $user_id, get_site_option( 'default_user_role', 'subscriber' ) );
  537. wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'add' ), wp_get_referer() ) );
  538. exit();
  539. break;
  540. default:
  541. wp_redirect( admin_url( 'ms-admin.php' ) );
  542. break;
  543. }
  544. ?>