PageRenderTime 52ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-admin/network/edit.php

https://github.com/muskmelon/Greemo
PHP | 482 lines | 396 code | 73 blank | 13 comment | 109 complexity | 9a0fd46b32c7c1ee957a5b8e50dfdf92 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. /** Load WordPress Administration Bootstrap */
  10. require_once( './admin.php' );
  11. if ( ! is_multisite() )
  12. wp_die( __( 'Multisite support is not enabled.' ) );
  13. if ( empty( $_GET['action'] ) ) {
  14. wp_redirect( admin_url( 'index.php' ) );
  15. exit;
  16. }
  17. function confirm_delete_users( $users ) {
  18. $current_user = wp_get_current_user();
  19. if ( !is_array( $users ) )
  20. return false;
  21. screen_icon();
  22. ?>
  23. <h2><?php esc_html_e( 'Users' ); ?></h2>
  24. <p><?php _e( 'Transfer or delete posts and links before deleting users.' ); ?></p>
  25. <form action="edit.php?action=dodelete" method="post">
  26. <input type="hidden" name="dodelete" />
  27. <?php
  28. wp_nonce_field( 'ms-users-delete' );
  29. $site_admins = get_super_admins();
  30. $admin_out = "<option value='$current_user->ID'>$current_user->user_login</option>";
  31. foreach ( ( $allusers = (array) $_POST['allusers'] ) as $key => $val ) {
  32. if ( $val != '' && $val != '0' ) {
  33. $delete_user = new WP_User( $val );
  34. if ( ! current_user_can( 'delete_user', $delete_user->ID ) )
  35. wp_die( sprintf( __( 'Warning! User %s cannot be deleted.' ), $delete_user->user_login ) );
  36. if ( in_array( $delete_user->user_login, $site_admins ) )
  37. wp_die( sprintf( __( 'Warning! User cannot be deleted. The user %s is a network admnistrator.' ), $delete_user->user_login ) );
  38. echo "<input type='hidden' name='user[]' value='{$val}'/>\n";
  39. $blogs = get_blogs_of_user( $val, true );
  40. if ( !empty( $blogs ) ) {
  41. ?>
  42. <br /><fieldset><p><legend><?php printf( __( "What should be done with posts and links owned by <em>%s</em>?" ), $delete_user->user_login ); ?></legend></p>
  43. <?php
  44. foreach ( (array) $blogs as $key => $details ) {
  45. $blog_users = get_users( array( 'blog_id' => $details->userblog_id ) );
  46. if ( is_array( $blog_users ) && !empty( $blog_users ) ) {
  47. $user_site = "<a href='" . esc_url( get_home_url( $details->userblog_id ) ) . "'>{$details->blogname}</a>";
  48. $user_dropdown = "<select name='blog[$val][{$key}]'>";
  49. $user_list = '';
  50. foreach ( $blog_users as $user ) {
  51. if ( ! in_array( $user->ID, $allusers ) )
  52. $user_list .= "<option value='{$user->ID}'>{$user->user_login}</option>";
  53. }
  54. if ( '' == $user_list )
  55. $user_list = $admin_out;
  56. $user_dropdown .= $user_list;
  57. $user_dropdown .= "</select>\n";
  58. ?>
  59. <ul style="list-style:none;">
  60. <li><?php printf( __( 'Site: %s' ), $user_site ); ?></li>
  61. <li><label><input type="radio" id="delete_option0" name="delete[<?php echo $details->userblog_id . '][' . $delete_user->ID ?>]" value="delete" checked="checked" />
  62. <?php _e( 'Delete all posts and links.' ); ?></label></li>
  63. <li><label><input type="radio" id="delete_option1" name="delete[<?php echo $details->userblog_id . '][' . $delete_user->ID ?>]" value="reassign" />
  64. <?php echo __( 'Attribute all posts and links to:' ) . '</label>' . $user_dropdown; ?></li>
  65. </ul>
  66. <?php
  67. }
  68. }
  69. echo "</fieldset>";
  70. }
  71. }
  72. }
  73. submit_button( __('Confirm Deletion'), 'delete' );
  74. ?>
  75. </form>
  76. <?php
  77. return true;
  78. }
  79. do_action( 'wpmuadminedit' , '');
  80. if ( isset( $_GET['id' ]) )
  81. $id = intval( $_GET['id'] );
  82. elseif ( isset( $_POST['id'] ) )
  83. $id = intval( $_POST['id'] );
  84. switch ( $_GET['action'] ) {
  85. case 'siteoptions':
  86. check_admin_referer( 'siteoptions' );
  87. if ( ! current_user_can( 'manage_network_options' ) )
  88. wp_die( __( 'You do not have permission to access this page.' ) );
  89. if ( empty( $_POST ) )
  90. wp_die( sprintf( __( 'You probably need to go back to the <a href="%s">options page</a>.' ), esc_url( admin_url( 'settings.php' ) ) ) );
  91. if ( isset($_POST['WPLANG']) && ( '' === $_POST['WPLANG'] || in_array( $_POST['WPLANG'], get_available_languages() ) ) )
  92. update_site_option( 'WPLANG', $_POST['WPLANG'] );
  93. if ( is_email( $_POST['admin_email'] ) )
  94. update_site_option( 'admin_email', $_POST['admin_email'] );
  95. $illegal_names = split( ' ', $_POST['illegal_names'] );
  96. foreach ( (array) $illegal_names as $name ) {
  97. $name = trim( $name );
  98. if ( $name != '' )
  99. $names[] = trim( $name );
  100. }
  101. update_site_option( 'illegal_names', $names );
  102. if ( $_POST['limited_email_domains'] != '' ) {
  103. $limited_email_domains = str_replace( ' ', "\n", $_POST['limited_email_domains'] );
  104. $limited_email_domains = split( "\n", stripslashes( $limited_email_domains ) );
  105. $limited_email = array();
  106. foreach ( (array) $limited_email_domains as $domain ) {
  107. $domain = trim( $domain );
  108. if ( ! preg_match( '/(--|\.\.)/', $domain ) && preg_match( '|^([a-zA-Z0-9-\.])+$|', $domain ) )
  109. $limited_email[] = trim( $domain );
  110. }
  111. update_site_option( 'limited_email_domains', $limited_email );
  112. } else {
  113. update_site_option( 'limited_email_domains', '' );
  114. }
  115. if ( $_POST['banned_email_domains'] != '' ) {
  116. $banned_email_domains = split( "\n", stripslashes( $_POST['banned_email_domains'] ) );
  117. $banned = array();
  118. foreach ( (array) $banned_email_domains as $domain ) {
  119. $domain = trim( $domain );
  120. if ( ! preg_match( '/(--|\.\.)/', $domain ) && preg_match( '|^([a-zA-Z0-9-\.])+$|', $domain ) )
  121. $banned[] = trim( $domain );
  122. }
  123. update_site_option( 'banned_email_domains', $banned );
  124. } else {
  125. update_site_option( 'banned_email_domains', '' );
  126. }
  127. $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', 'global_terms_enabled' );
  128. $checked_options = array( 'mu_media_buttons' => array(), 'menu_items' => array(), 'registrationnotification' => 'no', 'upload_space_check_disabled' => 1, 'add_new_users' => 0 );
  129. foreach ( $checked_options as $option_name => $option_unchecked_value ) {
  130. if ( ! isset( $_POST[$option_name] ) )
  131. $_POST[$option_name] = $option_unchecked_value;
  132. }
  133. foreach ( $options as $option_name ) {
  134. if ( ! isset($_POST[$option_name]) )
  135. continue;
  136. $value = stripslashes_deep( $_POST[$option_name] );
  137. update_site_option( $option_name, $value );
  138. }
  139. // Update more options here
  140. do_action( 'update_wpmu_options' );
  141. wp_redirect( add_query_arg( 'updated', 'true', network_admin_url( 'settings.php' ) ) );
  142. exit();
  143. break;
  144. case 'updateblog':
  145. // No longer used.
  146. break;
  147. case 'deleteblog':
  148. check_admin_referer('deleteblog');
  149. if ( ! ( current_user_can( 'manage_sites' ) && current_user_can( 'delete_sites' ) ) )
  150. wp_die( __( 'You do not have permission to access this page.' ) );
  151. if ( $id != '0' && $id != $current_site->blog_id && current_user_can( 'delete_site', $id ) ) {
  152. wpmu_delete_blog( $id, true );
  153. wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'delete' ), wp_get_referer() ) );
  154. } else {
  155. wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'not_deleted' ), wp_get_referer() ) );
  156. }
  157. exit();
  158. break;
  159. case 'allblogs':
  160. if ( ( isset( $_POST['action'] ) || isset( $_POST['action2'] ) ) && isset( $_POST['allblogs'] ) ) {
  161. check_admin_referer( 'bulk-sites' );
  162. if ( ! current_user_can( 'manage_sites' ) )
  163. wp_die( __( 'You do not have permission to access this page.' ) );
  164. if ( $_GET['action'] != -1 || $_POST['action2'] != -1 )
  165. $doaction = $_POST['action'] != -1 ? $_POST['action'] : $_POST['action2'];
  166. $blogfunction = '';
  167. foreach ( (array) $_POST['allblogs'] as $key => $val ) {
  168. if ( $val != '0' && $val != $current_site->blog_id ) {
  169. switch ( $doaction ) {
  170. case 'delete':
  171. if ( ! current_user_can( 'delete_site', $val ) )
  172. wp_die( __( 'You are not allowed to delete the site.' ) );
  173. $blogfunction = 'all_delete';
  174. wpmu_delete_blog( $val, true );
  175. break;
  176. case 'spam':
  177. $blogfunction = 'all_spam';
  178. update_blog_status( $val, 'spam', '1' );
  179. set_time_limit( 60 );
  180. break;
  181. case 'notspam':
  182. $blogfunction = 'all_notspam';
  183. update_blog_status( $val, 'spam', '0' );
  184. set_time_limit( 60 );
  185. break;
  186. }
  187. } else {
  188. wp_die( __( 'You are not allowed to change the current site.' ) );
  189. }
  190. }
  191. wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => $blogfunction ), wp_get_referer() ) );
  192. } else {
  193. wp_redirect( network_admin_url( 'sites.php' ) );
  194. }
  195. exit();
  196. break;
  197. case 'archiveblog':
  198. check_admin_referer( 'archiveblog' );
  199. if ( ! current_user_can( 'manage_sites' ) )
  200. wp_die( __( 'You do not have permission to access this page.' ) );
  201. update_blog_status( $id, 'archived', '1' );
  202. wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'archive' ), wp_get_referer() ) );
  203. exit();
  204. break;
  205. case 'unarchiveblog':
  206. check_admin_referer( 'unarchiveblog' );
  207. if ( ! current_user_can( 'manage_sites' ) )
  208. wp_die( __( 'You do not have permission to access this page.' ) );
  209. update_blog_status( $id, 'archived', '0' );
  210. wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'unarchive' ), wp_get_referer() ) );
  211. exit();
  212. break;
  213. case 'activateblog':
  214. check_admin_referer( 'activateblog' );
  215. if ( ! current_user_can( 'manage_sites' ) )
  216. wp_die( __( 'You do not have permission to access this page.' ) );
  217. update_blog_status( $id, 'deleted', '0' );
  218. do_action( 'activate_blog', $id );
  219. wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'activate' ), wp_get_referer() ) );
  220. exit();
  221. break;
  222. case 'deactivateblog':
  223. check_admin_referer( 'deactivateblog' );
  224. if ( ! current_user_can( 'manage_sites' ) )
  225. wp_die( __( 'You do not have permission to access this page.' ) );
  226. do_action( 'deactivate_blog', $id );
  227. update_blog_status( $id, 'deleted', '1' );
  228. wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'deactivate' ), wp_get_referer() ) );
  229. exit();
  230. break;
  231. case 'unspamblog':
  232. check_admin_referer( 'unspamblog' );
  233. if ( ! current_user_can( 'manage_sites' ) )
  234. wp_die( __( 'You do not have permission to access this page.' ) );
  235. update_blog_status( $id, 'spam', '0' );
  236. wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'unspam' ), wp_get_referer() ) );
  237. exit();
  238. break;
  239. case 'spamblog':
  240. check_admin_referer( 'spamblog' );
  241. if ( ! current_user_can( 'manage_sites' ) )
  242. wp_die( __( 'You do not have permission to access this page.' ) );
  243. update_blog_status( $id, 'spam', '1' );
  244. wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'spam' ), wp_get_referer() ) );
  245. exit();
  246. break;
  247. case 'unmatureblog':
  248. check_admin_referer( 'unmatureblog' );
  249. if ( ! current_user_can( 'manage_sites' ) )
  250. wp_die( __( 'You do not have permission to access this page.' ) );
  251. update_blog_status( $id, 'mature', '0' );
  252. wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'unmature' ), wp_get_referer() ) );
  253. exit();
  254. break;
  255. case 'matureblog':
  256. check_admin_referer( 'matureblog' );
  257. if ( ! current_user_can( 'manage_sites' ) )
  258. wp_die( __( 'You do not have permission to access this page.' ) );
  259. update_blog_status( $id, 'mature', '1' );
  260. wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'mature' ), wp_get_referer() ) );
  261. exit();
  262. break;
  263. // Common
  264. case 'confirm':
  265. check_admin_referer( 'confirm' );
  266. if ( !headers_sent() ) {
  267. nocache_headers();
  268. header( 'Content-Type: text/html; charset=utf-8' );
  269. }
  270. if ( $current_site->blog_id == $id )
  271. wp_die( __( 'You are not allowed to change the current site.' ) );
  272. ?>
  273. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  274. <html xmlns="http://www.w3.org/1999/xhtml" <?php if ( function_exists( 'language_attributes' ) ) language_attributes(); ?>>
  275. <head>
  276. <title><?php _e( 'WordPress &rsaquo; Confirm your action' ); ?></title>
  277. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  278. <?php
  279. wp_admin_css( 'install', true );
  280. wp_admin_css( 'ie', true );
  281. ?>
  282. </head>
  283. <body>
  284. <h1 id="logo"><img alt="WordPress" src="<?php echo esc_attr( admin_url( 'images/wordpress-logo.png' ) ); ?>" /></h1>
  285. <form action="edit.php?action=<?php echo esc_attr( $_GET['action2'] ) ?>" method="post">
  286. <input type="hidden" name="action" value="<?php echo esc_attr( $_GET['action2'] ) ?>" />
  287. <input type="hidden" name="id" value="<?php echo esc_attr( $id ); ?>" />
  288. <input type="hidden" name="_wp_http_referer" value="<?php echo esc_attr( wp_get_referer() ); ?>" />
  289. <?php wp_nonce_field( $_GET['action2'], '_wpnonce', false ); ?>
  290. <p><?php echo esc_html( stripslashes( $_GET['msg'] ) ); ?></p>
  291. <?php submit_button( __('Confirm'), 'button' ); ?>
  292. </form>
  293. </body>
  294. </html>
  295. <?php
  296. exit();
  297. break;
  298. // Users
  299. case 'deleteuser':
  300. if ( ! current_user_can( 'manage_network_users' ) )
  301. wp_die( __( 'You do not have permission to access this page.' ) );
  302. check_admin_referer( 'deleteuser' );
  303. if ( $id != '0' && $id != '1' ) {
  304. $_POST['allusers'] = array( $id ); // confirm_delete_users() can only handle with arrays
  305. $title = __( 'Users' );
  306. $parent_file = 'users.php';
  307. require_once( '../admin-header.php' );
  308. echo '<div class="wrap">';
  309. confirm_delete_users( $_POST['allusers'] );
  310. echo '</div>';
  311. require_once( '../admin-footer.php' );
  312. } else {
  313. wp_redirect( network_admin_url( 'users.php' ) );
  314. }
  315. exit();
  316. break;
  317. case 'allusers':
  318. if ( !current_user_can( 'manage_network_users' ) )
  319. wp_die( __( 'You do not have permission to access this page.' ) );
  320. if ( ( isset( $_POST['action']) || isset($_POST['action2'] ) ) && isset( $_POST['allusers'] ) ) {
  321. check_admin_referer( 'bulk-users-network' );
  322. if ( $_GET['action'] != -1 || $_POST['action2'] != -1 )
  323. $doaction = $_POST['action'] != -1 ? $_POST['action'] : $_POST['action2'];
  324. $userfunction = '';
  325. foreach ( (array) $_POST['allusers'] as $key => $val ) {
  326. if ( !empty( $val ) ) {
  327. switch ( $doaction ) {
  328. case 'delete':
  329. if ( ! current_user_can( 'delete_users' ) )
  330. wp_die( __( 'You do not have permission to access this page.' ) );
  331. $title = __( 'Users' );
  332. $parent_file = 'users.php';
  333. require_once( '../admin-header.php' );
  334. echo '<div class="wrap">';
  335. confirm_delete_users( $_POST['allusers'] );
  336. echo '</div>';
  337. require_once( '../admin-footer.php' );
  338. exit();
  339. break;
  340. case 'spam':
  341. $user = new WP_User( $val );
  342. if ( in_array( $user->user_login, get_super_admins() ) )
  343. wp_die( sprintf( __( 'Warning! User cannot be modified. The user %s is a network administrator.' ), esc_html( $user->user_login ) ) );
  344. $userfunction = 'all_spam';
  345. $blogs = get_blogs_of_user( $val, true );
  346. foreach ( (array) $blogs as $key => $details ) {
  347. if ( $details->userblog_id != $current_site->blog_id ) // main blog not a spam !
  348. update_blog_status( $details->userblog_id, 'spam', '1' );
  349. }
  350. update_user_status( $val, 'spam', '1' );
  351. break;
  352. case 'notspam':
  353. $userfunction = 'all_notspam';
  354. $blogs = get_blogs_of_user( $val, true );
  355. foreach ( (array) $blogs as $key => $details )
  356. update_blog_status( $details->userblog_id, 'spam', '0' );
  357. update_user_status( $val, 'spam', '0' );
  358. break;
  359. }
  360. }
  361. }
  362. wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => $userfunction ), wp_get_referer() ) );
  363. } else {
  364. $location = network_admin_url( 'users.php' );
  365. if ( ! empty( $_REQUEST['paged'] ) )
  366. $location = add_query_arg( 'paged', (int) $_REQUEST['paged'], $location );
  367. wp_redirect( $location );
  368. }
  369. exit();
  370. break;
  371. case 'dodelete':
  372. check_admin_referer( 'ms-users-delete' );
  373. if ( ! ( current_user_can( 'manage_network_users' ) && current_user_can( 'delete_users' ) ) )
  374. wp_die( __( 'You do not have permission to access this page.' ) );
  375. if ( ! empty( $_POST['blog'] ) && is_array( $_POST['blog'] ) ) {
  376. foreach ( $_POST['blog'] as $id => $users ) {
  377. foreach ( $users as $blogid => $user_id ) {
  378. if ( ! current_user_can( 'delete_user', $id ) )
  379. continue;
  380. if ( ! empty( $_POST['delete'] ) && 'reassign' == $_POST['delete'][$blogid][$id] )
  381. remove_user_from_blog( $id, $blogid, $user_id );
  382. else
  383. remove_user_from_blog( $id, $blogid );
  384. }
  385. }
  386. }
  387. $i = 0;
  388. if ( is_array( $_POST['user'] ) && ! empty( $_POST['user'] ) )
  389. foreach( $_POST['user'] as $id ) {
  390. if ( ! current_user_can( 'delete_user', $id ) )
  391. continue;
  392. wpmu_delete_user( $id );
  393. $i++;
  394. }
  395. if ( $i == 1 )
  396. $deletefunction = 'delete';
  397. else
  398. $deletefunction = 'all_delete';
  399. wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => $deletefunction ), network_admin_url( 'users.php' ) ) );
  400. exit();
  401. break;
  402. default:
  403. // Let plugins use us as a post handler easily
  404. do_action( 'network_admin_edit_' . $_GET['action'] );
  405. wp_redirect( network_admin_url( 'index.php' ) );
  406. exit();
  407. break;
  408. }
  409. ?>