2010-10-21 14:35:52 -04:00
< ? php
/**
* Edit Site Users Administration Screen
*
* @ package WordPress
2010-11-10 09:27:15 -05:00
* @ subpackage Multisite
2010-10-21 14:35:52 -04:00
* @ since 3.1 . 0
*/
/** Load WordPress Administration Bootstrap */
2013-09-24 20:18:11 -04:00
require_once ( dirname ( __FILE__ ) . '/admin.php' );
2010-10-21 14:35:52 -04:00
if ( ! is_multisite () )
wp_die ( __ ( 'Multisite support is not enabled.' ) );
if ( ! current_user_can ( 'manage_sites' ) )
wp_die ( __ ( 'You do not have sufficient permissions to edit this site.' ));
2011-01-16 16:47:24 -05:00
$wp_list_table = _get_list_table ( 'WP_Users_List_Table' );
2010-11-24 00:31:25 -05:00
$wp_list_table -> prepare_items ();
2011-11-30 21:22:07 -05:00
get_current_screen () -> add_help_tab ( array (
'id' => 'overview' ,
'title' => __ ( 'Overview' ),
'content' =>
'<p>' . __ ( 'The menu is for editing information specific to individual sites, particularly if the admin area of a site is unavailable.' ) . '</p>' .
2015-09-05 16:53:24 -04:00
'<p>' . __ ( '<strong>Info</strong> — The site URL is rarely edited as this can cause the site to not work properly. The Registered date and Last Updated date are displayed. Network admins can mark a site as archived, spam, deleted and mature, to remove from public listings or disable.' ) . '</p>' .
2015-08-19 00:53:25 -04:00
'<p>' . __ ( '<strong>Users</strong> — This displays the users associated with this site. You can also change their role, reset their password, or remove them from the site. Removing the user from the site does not remove the user from the network.' ) . '</p>' .
'<p>' . sprintf ( __ ( '<strong>Themes</strong> — This area shows themes that are not already enabled across the network. Enabling a theme in this menu makes it accessible to this site. It does not activate the theme, but allows it to show in the site’s Appearance menu. To enable a theme for the entire network, see the <a href="%s">Network Themes</a> screen.' ), network_admin_url ( 'themes.php' ) ) . '</p>' .
'<p>' . __ ( '<strong>Settings</strong> — This page shows a list of all settings associated with this site. Some are created by WordPress and others are created by plugins you activate. Note that some fields are grayed out and say Serialized Data. You cannot modify these values due to the way the setting is stored in the database.' ) . '</p>'
2011-11-30 21:22:07 -05:00
) );
2011-11-02 01:33:53 -04:00
2011-11-02 17:32:16 -04:00
get_current_screen () -> set_help_sidebar (
2010-12-16 01:52:47 -05:00
'<p><strong>' . __ ( 'For more information:' ) . '</strong></p>' .
2015-04-12 17:29:32 -04:00
'<p>' . __ ( '<a href="https://codex.wordpress.org/Network_Admin_Sites_Screen" target="_blank">Documentation on Site Management</a>' ) . '</p>' .
2014-03-07 23:14:15 -05:00
'<p>' . __ ( '<a href="https://wordpress.org/support/forum/multisite/" target="_blank">Support Forums</a>' ) . '</p>'
2010-12-16 01:52:47 -05:00
);
2011-12-08 18:02:33 -05:00
$_SERVER [ 'REQUEST_URI' ] = remove_query_arg ( 'update' , $_SERVER [ 'REQUEST_URI' ] );
2011-11-22 00:55:55 -05:00
$referer = remove_query_arg ( 'update' , wp_get_referer () );
2014-03-25 12:57:15 -04:00
if ( ! empty ( $_REQUEST [ 'paged' ] ) ) {
$referer = add_query_arg ( 'paged' , ( int ) $_REQUEST [ 'paged' ], $referer );
}
2010-10-21 14:35:52 -04:00
$id = isset ( $_REQUEST [ 'id' ] ) ? intval ( $_REQUEST [ 'id' ] ) : 0 ;
if ( ! $id )
wp_die ( __ ( 'Invalid site ID.' ) );
$details = get_blog_details ( $id );
2015-07-09 12:29:24 -04:00
if ( ! $details ) {
2015-07-09 12:33:25 -04:00
wp_die ( __ ( 'The requested site does not exist.' ) );
2015-07-09 12:29:24 -04:00
}
2012-08-03 13:51:42 -04:00
if ( ! can_edit_network ( $details -> site_id ) )
2015-04-19 23:27:27 -04:00
wp_die ( __ ( 'You do not have permission to access this page.' ), 403 );
2010-10-21 14:35:52 -04:00
$is_main_site = is_main_site ( $id );
2012-08-03 13:51:42 -04:00
switch_to_blog ( $id );
2010-11-17 14:45:10 -05:00
2010-11-24 00:31:25 -05:00
$action = $wp_list_table -> current_action ();
2010-10-21 14:35:52 -04:00
2010-11-24 00:31:25 -05:00
if ( $action ) {
2011-12-08 18:02:33 -05:00
2010-11-24 00:31:25 -05:00
switch ( $action ) {
2010-11-25 06:12:33 -05:00
case 'newuser' :
2010-12-24 17:37:51 -05:00
check_admin_referer ( 'add-user' , '_wpnonce_add-new-user' );
2010-11-25 06:12:33 -05:00
$user = $_POST [ 'user' ];
2012-08-03 13:51:42 -04:00
if ( ! is_array ( $_POST [ 'user' ] ) || empty ( $user [ 'username' ] ) || empty ( $user [ 'email' ] ) ) {
2010-11-25 06:12:33 -05:00
$update = 'err_new' ;
} else {
$password = wp_generate_password ( 12 , false );
$user_id = wpmu_create_user ( esc_html ( strtolower ( $user [ 'username' ] ) ), $password , esc_html ( $user [ 'email' ] ) );
2015-06-12 13:19:27 -04:00
if ( false === $user_id ) {
2010-11-25 06:12:33 -05:00
$update = 'err_new_dup' ;
} else {
2015-08-17 10:25:27 -04:00
wp_new_user_notification ( $user_id , 'both' );
2010-11-25 06:12:33 -05:00
add_user_to_blog ( $id , $user_id , $_POST [ 'new_role' ] );
$update = 'newuser' ;
}
}
break ;
2010-11-24 00:31:25 -05:00
case 'adduser' :
2010-12-24 17:37:51 -05:00
check_admin_referer ( 'add-user' , '_wpnonce_add-user' );
2010-11-24 00:31:25 -05:00
if ( ! empty ( $_POST [ 'newuser' ] ) ) {
2010-11-25 06:12:33 -05:00
$update = 'adduser' ;
2011-12-08 18:02:33 -05:00
$newuser = $_POST [ 'newuser' ];
2013-04-12 09:35:45 -04:00
$user = get_user_by ( 'login' , $newuser );
2013-06-25 10:24:18 -04:00
if ( $user && $user -> exists () ) {
2013-04-12 09:35:45 -04:00
if ( ! is_user_member_of_blog ( $user -> ID , $id ) )
add_user_to_blog ( $id , $user -> ID , $_POST [ 'new_role' ] );
2010-11-25 04:13:38 -05:00
else
$update = 'err_add_member' ;
} else {
$update = 'err_add_notfound' ;
2010-11-24 00:31:25 -05:00
}
2010-11-25 04:13:38 -05:00
} else {
$update = 'err_add_notfound' ;
2010-11-24 00:31:25 -05:00
}
break ;
2011-12-08 18:02:33 -05:00
2010-11-24 00:31:25 -05:00
case 'remove' :
2012-08-03 13:51:42 -04:00
if ( ! current_user_can ( 'remove_users' ) )
2010-11-24 00:31:25 -05:00
die ( __ ( 'You can’t remove users.' ));
2010-12-24 17:37:51 -05:00
check_admin_referer ( 'bulk-users' );
2011-12-08 18:02:33 -05:00
2010-11-25 04:13:38 -05:00
$update = 'remove' ;
2010-11-24 00:31:25 -05:00
if ( isset ( $_REQUEST [ 'users' ] ) ) {
$userids = $_REQUEST [ 'users' ];
foreach ( $userids as $user_id ) {
$user_id = ( int ) $user_id ;
remove_user_from_blog ( $user_id , $id );
}
2010-11-25 04:13:38 -05:00
} elseif ( isset ( $_GET [ 'user' ] ) ) {
2010-11-24 00:31:25 -05:00
remove_user_from_blog ( $_GET [ 'user' ] );
2010-11-25 04:13:38 -05:00
} else {
$update = 'err_remove' ;
2010-11-24 00:31:25 -05:00
}
break ;
2010-10-21 14:35:52 -04:00
2010-11-24 00:31:25 -05:00
case 'promote' :
2010-12-24 17:37:51 -05:00
check_admin_referer ( 'bulk-users' );
2010-11-24 00:31:25 -05:00
$editable_roles = get_editable_roles ();
if ( empty ( $editable_roles [ $_REQUEST [ 'new_role' ]] ) )
wp_die ( __ ( 'You can’t give users that role.' ));
2010-10-21 14:35:52 -04:00
2010-11-25 04:13:38 -05:00
if ( isset ( $_REQUEST [ 'users' ] ) ) {
$userids = $_REQUEST [ 'users' ];
$update = 'promote' ;
foreach ( $userids as $user_id ) {
$user_id = ( int ) $user_id ;
2010-10-21 14:35:52 -04:00
2010-11-25 04:13:38 -05:00
// If the user doesn't already belong to the blog, bail.
2015-09-03 05:03:24 -04:00
if ( ! is_user_member_of_blog ( $user_id ) ) {
wp_die (
'<h1>' . __ ( 'Cheatin’ uh?' ) . '</h1>' .
'<p>' . __ ( 'One of the selected users is not a member of this site.' ) . '</p>' ,
403
);
}
2010-10-21 14:35:52 -04:00
2012-08-02 21:06:05 -04:00
$user = get_userdata ( $user_id );
2010-11-25 04:13:38 -05:00
$user -> set_role ( $_REQUEST [ 'new_role' ] );
}
} else {
$update = 'err_promote' ;
2010-11-24 00:31:25 -05:00
}
break ;
2010-10-21 14:35:52 -04:00
}
2011-12-08 18:02:33 -05:00
2011-12-10 13:26:48 -05:00
wp_safe_redirect ( add_query_arg ( 'update' , $update , $referer ) );
2010-11-25 04:25:50 -05:00
exit ();
}
2012-08-03 13:51:42 -04:00
restore_current_blog ();
2010-11-25 04:25:50 -05:00
if ( isset ( $_GET [ 'action' ] ) && 'update-site' == $_GET [ 'action' ] ) {
2011-12-10 13:26:48 -05:00
wp_safe_redirect ( $referer );
2010-11-25 04:25:50 -05:00
exit ();
2010-10-21 14:35:52 -04:00
}
2015-03-10 11:32:27 -04:00
add_screen_option ( 'per_page' );
2011-10-02 02:59:36 -04:00
2015-07-12 20:27:24 -04:00
$title = sprintf ( __ ( 'Edit Site: %s' ), esc_html ( $details -> blogname ) );
2011-06-03 11:35:45 -04:00
2010-10-21 14:35:52 -04:00
$parent_file = 'sites.php' ;
$submenu_file = 'sites.php' ;
2013-10-26 16:33:09 -04:00
/**
* Filter whether to show the Add Existing User form on the Multisite Users screen .
*
* @ since 3.1 . 0
*
* @ param bool $bool Whether to show the Add Existing User form . Default true .
*/
2012-03-24 00:54:58 -04:00
if ( ! wp_is_large_network ( 'users' ) && apply_filters ( 'show_network_site_users_add_existing_form' , true ) )
2012-06-05 14:51:33 -04:00
wp_enqueue_script ( 'user-suggest' );
2012-02-10 03:45:17 -05:00
2013-09-24 20:18:11 -04:00
require ( ABSPATH . 'wp-admin/admin-header.php' ); ?>
2010-10-21 14:35:52 -04:00
2014-05-18 21:59:15 -04:00
< script type = " text/javascript " >
2012-02-10 03:45:17 -05:00
var current_site_id = < ? php echo $id ; ?> ;
</ script >
2010-10-21 14:35:52 -04:00
< div class = " wrap " >
2015-07-12 20:27:24 -04:00
< h1 id = " edit-site " >< ? php echo $title ; ?> </h1>
2015-08-10 14:11:25 -04:00
< p class = " edit-site-actions " >< a href = " <?php echo esc_url( get_home_url( $id , '/' ) ); ?> " >< ? php _e ( 'Visit' ); ?> </a> | <a href="<?php echo esc_url( get_admin_url( $id ) ); ?>"><?php _e( 'Dashboard' ); ?></a></p>
2010-10-25 16:45:58 -04:00
< h3 class = " nav-tab-wrapper " >
2010-10-21 14:35:52 -04:00
< ? php
2010-12-16 02:13:01 -05:00
$tabs = array (
'site-info' => array ( 'label' => __ ( 'Info' ), 'url' => 'site-info.php' ),
'site-users' => array ( 'label' => __ ( 'Users' ), 'url' => 'site-users.php' ),
'site-themes' => array ( 'label' => __ ( 'Themes' ), 'url' => 'site-themes.php' ),
'site-settings' => array ( 'label' => __ ( 'Settings' ), 'url' => 'site-settings.php' ),
);
2010-10-21 14:35:52 -04:00
foreach ( $tabs as $tab_id => $tab ) {
$class = ( $tab [ 'url' ] == $pagenow ) ? ' nav-tab-active' : '' ;
2011-12-13 18:45:31 -05:00
echo '<a href="' . $tab [ 'url' ] . '?id=' . $id . '" class="nav-tab' . $class . '">' . esc_html ( $tab [ 'label' ] ) . '</a>' ;
2010-10-21 14:35:52 -04:00
}
?>
2010-11-25 04:13:38 -05:00
</ h3 >< ? php
if ( isset ( $_GET [ 'update' ]) ) :
switch ( $_GET [ 'update' ]) {
2010-11-25 06:12:33 -05:00
case 'adduser' :
2015-04-01 18:06:28 -04:00
echo '<div id="message" class="updated notice is-dismissible"><p>' . __ ( 'User added.' ) . '</p></div>' ;
2010-11-25 04:13:38 -05:00
break ;
case 'err_add_member' :
2015-04-01 18:06:28 -04:00
echo '<div id="message" class="error notice is-dismissible"><p>' . __ ( 'User is already a member of this site.' ) . '</p></div>' ;
2010-11-25 04:13:38 -05:00
break ;
case 'err_add_notfound' :
2015-04-01 18:06:28 -04:00
echo '<div id="message" class="error notice is-dismissible"><p>' . __ ( 'Enter the username of an existing user.' ) . '</p></div>' ;
2010-11-25 04:13:38 -05:00
break ;
case 'promote' :
2015-04-01 18:06:28 -04:00
echo '<div id="message" class="updated notice is-dismissible"><p>' . __ ( 'Changed roles.' ) . '</p></div>' ;
2010-11-25 04:13:38 -05:00
break ;
case 'err_promote' :
2015-04-01 18:06:28 -04:00
echo '<div id="message" class="error notice is-dismissible"><p>' . __ ( 'Select a user to change role.' ) . '</p></div>' ;
2010-11-25 04:13:38 -05:00
break ;
case 'remove' :
2015-04-01 18:06:28 -04:00
echo '<div id="message" class="updated notice is-dismissible"><p>' . __ ( 'User removed from this site.' ) . '</p></div>' ;
2010-11-25 04:13:38 -05:00
break ;
case 'err_remove' :
2015-04-01 18:06:28 -04:00
echo '<div id="message" class="error notice is-dismissible"><p>' . __ ( 'Select a user to remove.' ) . '</p></div>' ;
2010-11-25 04:13:38 -05:00
break ;
2010-11-25 06:12:33 -05:00
case 'newuser' :
2015-04-01 18:06:28 -04:00
echo '<div id="message" class="updated notice is-dismissible"><p>' . __ ( 'User created.' ) . '</p></div>' ;
2010-11-25 06:12:33 -05:00
break ;
case 'err_new' :
2015-04-01 18:06:28 -04:00
echo '<div id="message" class="error notice is-dismissible"><p>' . __ ( 'Enter the username and email.' ) . '</p></div>' ;
2010-11-25 06:12:33 -05:00
break ;
case 'err_new_dup' :
2015-04-01 18:06:28 -04:00
echo '<div id="message" class="error notice is-dismissible"><p>' . __ ( 'Duplicated username or email address.' ) . '</p></div>' ;
2010-11-25 06:12:33 -05:00
break ;
2010-11-25 04:13:38 -05:00
}
endif ; ?>
2015-01-15 23:16:24 -05:00
< form class = " search-form " method = " get " >
2010-12-16 15:45:10 -05:00
< ? php $wp_list_table -> search_box ( __ ( 'Search Users' ), 'user' ); ?>
2011-01-15 16:25:33 -05:00
< input type = " hidden " name = " id " value = " <?php echo esc_attr( $id ) ?> " />
2010-11-24 00:31:25 -05:00
</ form >
< ? php $wp_list_table -> views (); ?>
2012-09-18 19:06:22 -04:00
< form method = " post " action = " site-users.php?action=update-site " >
2010-10-21 14:35:52 -04:00
< input type = " hidden " name = " id " value = " <?php echo esc_attr( $id ) ?> " />
2010-11-24 00:31:25 -05:00
< ? php $wp_list_table -> display (); ?>
2010-10-21 14:35:52 -04:00
</ form >
2013-10-26 16:33:09 -04:00
< ? php
/**
* Fires after the list table on the Users screen in the Multisite Network Admin .
*
* @ since 3.1 . 0
*/
do_action ( 'network_site_users_after_list_table' );
2010-12-13 06:58:49 -05:00
2013-10-26 16:33:09 -04:00
/** This filter is documented in wp-admin/network/site-users.php */
if ( current_user_can ( 'promote_users' ) && apply_filters ( 'show_network_site_users_add_existing_form' , true ) ) : ?>
2012-09-15 15:38:23 -04:00
< h3 id = " add-existing-user " >< ? php _e ( 'Add Existing User' ); ?> </h3>
2010-11-25 06:12:33 -05:00
< form action = " site-users.php?action=adduser " id = " adduser " method = " post " >
2010-11-17 14:45:10 -05:00
< input type = " hidden " name = " id " value = " <?php echo esc_attr( $id ) ?> " />
< table class = " form-table " >
< tr >
2015-02-22 21:29:26 -05:00
< th scope = " row " >< label for = " newuser " >< ? php _e ( 'Username' ); ?> </label></th>
2012-06-05 14:51:33 -04:00
< td >< input type = " text " class = " regular-text wp-suggest-user " name = " newuser " id = " newuser " /></ td >
2010-11-17 14:45:10 -05:00
</ tr >
< tr >
2015-02-22 21:29:26 -05:00
< th scope = " row " >< label for = " new_role_adduser " >< ? php _e ( 'Role' ); ?> </label></th>
< td >< select name = " new_role " id = " new_role_adduser " >
2014-02-27 05:22:14 -05:00
< ? php wp_dropdown_roles ( get_option ( 'default_role' ) ); ?>
2010-11-17 14:45:10 -05:00
</ select ></ td >
</ tr >
</ table >
2010-12-24 17:37:51 -05:00
< ? php wp_nonce_field ( 'add-user' , '_wpnonce_add-user' ) ?>
2012-09-15 15:38:23 -04:00
< ? php submit_button ( __ ( 'Add User' ), 'primary' , 'add-user' , true , array ( 'id' => 'submit-add-existing-user' ) ); ?>
2010-11-25 06:12:33 -05:00
</ form >
2010-12-13 06:58:49 -05:00
< ? php endif ; ?>
2010-11-25 06:12:33 -05:00
2013-10-26 16:33:09 -04:00
< ? php
/**
* Filter whether to show the Add New User form on the Multisite Users screen .
*
* @ since 3.1 . 0
*
* @ param bool $bool Whether to show the Add New User form . Default true .
*/
if ( current_user_can ( 'create_users' ) && apply_filters ( 'show_network_site_users_add_new_form' , true ) ) : ?>
2012-09-15 15:38:23 -04:00
< h3 id = " add-new-user " >< ? php _e ( 'Add New User' ); ?> </h3>
2010-11-25 06:12:33 -05:00
< form action = " <?php echo network_admin_url('site-users.php?action=newuser'); ?> " id = " newuser " method = " post " >
< input type = " hidden " name = " id " value = " <?php echo esc_attr( $id ) ?> " />
< table class = " form-table " >
< tr >
2015-02-22 21:29:26 -05:00
< th scope = " row " >< label for = " user_username " >< ? php _e ( 'Username' ) ?> </label></th>
< td >< input type = " text " class = " regular-text " name = " user[username] " id = " user_username " /></ td >
2010-11-25 06:12:33 -05:00
</ tr >
< tr >
2015-02-22 21:29:26 -05:00
< th scope = " row " >< label for = " user_email " >< ? php _e ( 'Email' ) ?> </label></th>
< td >< input type = " text " class = " regular-text " name = " user[email] " id = " user_email " /></ td >
2010-11-25 06:12:33 -05:00
</ tr >
< tr >
2015-02-22 21:29:26 -05:00
< th scope = " row " >< label for = " new_role_newuser " >< ? php _e ( 'Role' ); ?> </label></th>
< td >< select name = " new_role " id = " new_role_newuser " >
2014-02-27 05:22:14 -05:00
< ? php wp_dropdown_roles ( get_option ( 'default_role' ) ); ?>
2010-11-25 06:12:33 -05:00
</ select ></ td >
</ tr >
< tr class = " form-field " >
2015-07-29 15:04:25 -04:00
< td colspan = " 2 " >< ? php _e ( 'A password reset link will be sent to the user via email.' ) ?> </td>
2010-11-25 06:12:33 -05:00
</ tr >
</ table >
2010-12-24 17:37:51 -05:00
< ? php wp_nonce_field ( 'add-user' , '_wpnonce_add-new-user' ) ?>
2012-09-15 15:38:23 -04:00
< ? php submit_button ( __ ( 'Add New User' ), 'primary' , 'add-user' , true , array ( 'id' => 'submit-add-user' ) ); ?>
2010-11-25 06:12:33 -05:00
</ form >
2010-12-13 06:58:49 -05:00
< ? php endif ; ?>
2010-12-15 04:05:10 -05:00
</ div >
2010-10-21 14:35:52 -04:00
< ? php
2013-09-24 20:18:11 -04:00
require ( ABSPATH . 'wp-admin/admin-footer.php' );