Edit File by line
/home/barbar84/public_h.../wp-admin/network
File: site-users.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Edit Site Users Administration Screen
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
* @subpackage Multisite
[5] Fix | Delete
* @since 3.1.0
[6] Fix | Delete
*/
[7] Fix | Delete
[8] Fix | Delete
/** Load WordPress Administration Bootstrap */
[9] Fix | Delete
require_once __DIR__ . '/admin.php';
[10] Fix | Delete
[11] Fix | Delete
if ( ! current_user_can( 'manage_sites' ) ) {
[12] Fix | Delete
wp_die( __( 'Sorry, you are not allowed to edit this site.' ), 403 );
[13] Fix | Delete
}
[14] Fix | Delete
[15] Fix | Delete
$wp_list_table = _get_list_table( 'WP_Users_List_Table' );
[16] Fix | Delete
$wp_list_table->prepare_items();
[17] Fix | Delete
[18] Fix | Delete
get_current_screen()->add_help_tab( get_site_screen_help_tab_args() );
[19] Fix | Delete
get_current_screen()->set_help_sidebar( get_site_screen_help_sidebar_content() );
[20] Fix | Delete
[21] Fix | Delete
get_current_screen()->set_screen_reader_content(
[22] Fix | Delete
array(
[23] Fix | Delete
'heading_views' => __( 'Filter site users list' ),
[24] Fix | Delete
'heading_pagination' => __( 'Site users list navigation' ),
[25] Fix | Delete
'heading_list' => __( 'Site users list' ),
[26] Fix | Delete
)
[27] Fix | Delete
);
[28] Fix | Delete
[29] Fix | Delete
$_SERVER['REQUEST_URI'] = remove_query_arg( 'update', $_SERVER['REQUEST_URI'] );
[30] Fix | Delete
$referer = remove_query_arg( 'update', wp_get_referer() );
[31] Fix | Delete
[32] Fix | Delete
if ( ! empty( $_REQUEST['paged'] ) ) {
[33] Fix | Delete
$referer = add_query_arg( 'paged', (int) $_REQUEST['paged'], $referer );
[34] Fix | Delete
}
[35] Fix | Delete
[36] Fix | Delete
$id = isset( $_REQUEST['id'] ) ? (int) $_REQUEST['id'] : 0;
[37] Fix | Delete
[38] Fix | Delete
if ( ! $id ) {
[39] Fix | Delete
wp_die( __( 'Invalid site ID.' ) );
[40] Fix | Delete
}
[41] Fix | Delete
[42] Fix | Delete
$details = get_site( $id );
[43] Fix | Delete
if ( ! $details ) {
[44] Fix | Delete
wp_die( __( 'The requested site does not exist.' ) );
[45] Fix | Delete
}
[46] Fix | Delete
[47] Fix | Delete
if ( ! can_edit_network( $details->site_id ) ) {
[48] Fix | Delete
wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 );
[49] Fix | Delete
}
[50] Fix | Delete
[51] Fix | Delete
$is_main_site = is_main_site( $id );
[52] Fix | Delete
[53] Fix | Delete
switch_to_blog( $id );
[54] Fix | Delete
[55] Fix | Delete
$action = $wp_list_table->current_action();
[56] Fix | Delete
[57] Fix | Delete
if ( $action ) {
[58] Fix | Delete
[59] Fix | Delete
switch ( $action ) {
[60] Fix | Delete
case 'newuser':
[61] Fix | Delete
check_admin_referer( 'add-user', '_wpnonce_add-new-user' );
[62] Fix | Delete
$user = $_POST['user'];
[63] Fix | Delete
if ( ! is_array( $_POST['user'] ) || empty( $user['username'] ) || empty( $user['email'] ) ) {
[64] Fix | Delete
$update = 'err_new';
[65] Fix | Delete
} else {
[66] Fix | Delete
$password = wp_generate_password( 12, false );
[67] Fix | Delete
$user_id = wpmu_create_user( esc_html( strtolower( $user['username'] ) ), $password, esc_html( $user['email'] ) );
[68] Fix | Delete
[69] Fix | Delete
if ( false === $user_id ) {
[70] Fix | Delete
$update = 'err_new_dup';
[71] Fix | Delete
} else {
[72] Fix | Delete
$result = add_user_to_blog( $id, $user_id, $_POST['new_role'] );
[73] Fix | Delete
[74] Fix | Delete
if ( is_wp_error( $result ) ) {
[75] Fix | Delete
$update = 'err_add_fail';
[76] Fix | Delete
} else {
[77] Fix | Delete
$update = 'newuser';
[78] Fix | Delete
[79] Fix | Delete
/**
[80] Fix | Delete
* Fires after a user has been created via the network site-users.php page.
[81] Fix | Delete
*
[82] Fix | Delete
* @since 4.4.0
[83] Fix | Delete
*
[84] Fix | Delete
* @param int $user_id ID of the newly created user.
[85] Fix | Delete
*/
[86] Fix | Delete
do_action( 'network_site_users_created_user', $user_id );
[87] Fix | Delete
}
[88] Fix | Delete
}
[89] Fix | Delete
}
[90] Fix | Delete
break;
[91] Fix | Delete
[92] Fix | Delete
case 'adduser':
[93] Fix | Delete
check_admin_referer( 'add-user', '_wpnonce_add-user' );
[94] Fix | Delete
if ( ! empty( $_POST['newuser'] ) ) {
[95] Fix | Delete
$update = 'adduser';
[96] Fix | Delete
$newuser = $_POST['newuser'];
[97] Fix | Delete
$user = get_user_by( 'login', $newuser );
[98] Fix | Delete
if ( $user && $user->exists() ) {
[99] Fix | Delete
if ( ! is_user_member_of_blog( $user->ID, $id ) ) {
[100] Fix | Delete
$result = add_user_to_blog( $id, $user->ID, $_POST['new_role'] );
[101] Fix | Delete
[102] Fix | Delete
if ( is_wp_error( $result ) ) {
[103] Fix | Delete
$update = 'err_add_fail';
[104] Fix | Delete
}
[105] Fix | Delete
} else {
[106] Fix | Delete
$update = 'err_add_member';
[107] Fix | Delete
}
[108] Fix | Delete
} else {
[109] Fix | Delete
$update = 'err_add_notfound';
[110] Fix | Delete
}
[111] Fix | Delete
} else {
[112] Fix | Delete
$update = 'err_add_notfound';
[113] Fix | Delete
}
[114] Fix | Delete
break;
[115] Fix | Delete
[116] Fix | Delete
case 'remove':
[117] Fix | Delete
if ( ! current_user_can( 'remove_users' ) ) {
[118] Fix | Delete
wp_die( __( 'Sorry, you are not allowed to remove users.' ), 403 );
[119] Fix | Delete
}
[120] Fix | Delete
[121] Fix | Delete
check_admin_referer( 'bulk-users' );
[122] Fix | Delete
[123] Fix | Delete
$update = 'remove';
[124] Fix | Delete
if ( isset( $_REQUEST['users'] ) ) {
[125] Fix | Delete
$userids = $_REQUEST['users'];
[126] Fix | Delete
[127] Fix | Delete
foreach ( $userids as $user_id ) {
[128] Fix | Delete
$user_id = (int) $user_id;
[129] Fix | Delete
remove_user_from_blog( $user_id, $id );
[130] Fix | Delete
}
[131] Fix | Delete
} elseif ( isset( $_GET['user'] ) ) {
[132] Fix | Delete
remove_user_from_blog( $_GET['user'] );
[133] Fix | Delete
} else {
[134] Fix | Delete
$update = 'err_remove';
[135] Fix | Delete
}
[136] Fix | Delete
break;
[137] Fix | Delete
[138] Fix | Delete
case 'promote':
[139] Fix | Delete
check_admin_referer( 'bulk-users' );
[140] Fix | Delete
$editable_roles = get_editable_roles();
[141] Fix | Delete
$role = $_REQUEST['new_role'];
[142] Fix | Delete
[143] Fix | Delete
if ( empty( $editable_roles[ $role ] ) ) {
[144] Fix | Delete
wp_die( __( 'Sorry, you are not allowed to give users that role.' ), 403 );
[145] Fix | Delete
}
[146] Fix | Delete
[147] Fix | Delete
if ( isset( $_REQUEST['users'] ) ) {
[148] Fix | Delete
$userids = $_REQUEST['users'];
[149] Fix | Delete
$update = 'promote';
[150] Fix | Delete
foreach ( $userids as $user_id ) {
[151] Fix | Delete
$user_id = (int) $user_id;
[152] Fix | Delete
[153] Fix | Delete
// If the user doesn't already belong to the blog, bail.
[154] Fix | Delete
if ( ! is_user_member_of_blog( $user_id ) ) {
[155] Fix | Delete
wp_die(
[156] Fix | Delete
'<h1>' . __( 'Something went wrong.' ) . '</h1>' .
[157] Fix | Delete
'<p>' . __( 'One of the selected users is not a member of this site.' ) . '</p>',
[158] Fix | Delete
403
[159] Fix | Delete
);
[160] Fix | Delete
}
[161] Fix | Delete
[162] Fix | Delete
$user = get_userdata( $user_id );
[163] Fix | Delete
$user->set_role( $role );
[164] Fix | Delete
}
[165] Fix | Delete
} else {
[166] Fix | Delete
$update = 'err_promote';
[167] Fix | Delete
}
[168] Fix | Delete
break;
[169] Fix | Delete
default:
[170] Fix | Delete
if ( ! isset( $_REQUEST['users'] ) ) {
[171] Fix | Delete
break;
[172] Fix | Delete
}
[173] Fix | Delete
check_admin_referer( 'bulk-users' );
[174] Fix | Delete
$userids = $_REQUEST['users'];
[175] Fix | Delete
[176] Fix | Delete
/** This action is documented in wp-admin/network/site-themes.php */
[177] Fix | Delete
$referer = apply_filters( 'handle_network_bulk_actions-' . get_current_screen()->id, $referer, $action, $userids, $id ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
[178] Fix | Delete
[179] Fix | Delete
$update = $action;
[180] Fix | Delete
break;
[181] Fix | Delete
}
[182] Fix | Delete
[183] Fix | Delete
wp_safe_redirect( add_query_arg( 'update', $update, $referer ) );
[184] Fix | Delete
exit;
[185] Fix | Delete
}
[186] Fix | Delete
[187] Fix | Delete
restore_current_blog();
[188] Fix | Delete
[189] Fix | Delete
if ( isset( $_GET['action'] ) && 'update-site' === $_GET['action'] ) {
[190] Fix | Delete
wp_safe_redirect( $referer );
[191] Fix | Delete
exit;
[192] Fix | Delete
}
[193] Fix | Delete
[194] Fix | Delete
add_screen_option( 'per_page' );
[195] Fix | Delete
[196] Fix | Delete
/* translators: %s: Site title. */
[197] Fix | Delete
$title = sprintf( __( 'Edit Site: %s' ), esc_html( $details->blogname ) );
[198] Fix | Delete
[199] Fix | Delete
$parent_file = 'sites.php';
[200] Fix | Delete
$submenu_file = 'sites.php';
[201] Fix | Delete
[202] Fix | Delete
/**
[203] Fix | Delete
* Filters whether to show the Add Existing User form on the Multisite Users screen.
[204] Fix | Delete
*
[205] Fix | Delete
* @since 3.1.0
[206] Fix | Delete
*
[207] Fix | Delete
* @param bool $bool Whether to show the Add Existing User form. Default true.
[208] Fix | Delete
*/
[209] Fix | Delete
if ( ! wp_is_large_network( 'users' ) && apply_filters( 'show_network_site_users_add_existing_form', true ) ) {
[210] Fix | Delete
wp_enqueue_script( 'user-suggest' );
[211] Fix | Delete
}
[212] Fix | Delete
[213] Fix | Delete
require_once ABSPATH . 'wp-admin/admin-header.php'; ?>
[214] Fix | Delete
[215] Fix | Delete
<script type="text/javascript">
[216] Fix | Delete
var current_site_id = <?php echo absint( $id ); ?>;
[217] Fix | Delete
</script>
[218] Fix | Delete
[219] Fix | Delete
[220] Fix | Delete
<div class="wrap">
[221] Fix | Delete
<h1 id="edit-site"><?php echo $title; ?></h1>
[222] Fix | Delete
<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>
[223] Fix | Delete
<?php
[224] Fix | Delete
[225] Fix | Delete
network_edit_site_nav(
[226] Fix | Delete
array(
[227] Fix | Delete
'blog_id' => $id,
[228] Fix | Delete
'selected' => 'site-users',
[229] Fix | Delete
)
[230] Fix | Delete
);
[231] Fix | Delete
[232] Fix | Delete
if ( isset( $_GET['update'] ) ) :
[233] Fix | Delete
switch ( $_GET['update'] ) {
[234] Fix | Delete
case 'adduser':
[235] Fix | Delete
echo '<div id="message" class="updated notice is-dismissible"><p>' . __( 'User added.' ) . '</p></div>';
[236] Fix | Delete
break;
[237] Fix | Delete
case 'err_add_member':
[238] Fix | Delete
echo '<div id="message" class="error notice is-dismissible"><p>' . __( 'User is already a member of this site.' ) . '</p></div>';
[239] Fix | Delete
break;
[240] Fix | Delete
case 'err_add_fail':
[241] Fix | Delete
echo '<div id="message" class="error notice is-dismissible"><p>' . __( 'User could not be added to this site.' ) . '</p></div>';
[242] Fix | Delete
break;
[243] Fix | Delete
case 'err_add_notfound':
[244] Fix | Delete
echo '<div id="message" class="error notice is-dismissible"><p>' . __( 'Enter the username of an existing user.' ) . '</p></div>';
[245] Fix | Delete
break;
[246] Fix | Delete
case 'promote':
[247] Fix | Delete
echo '<div id="message" class="updated notice is-dismissible"><p>' . __( 'Changed roles.' ) . '</p></div>';
[248] Fix | Delete
break;
[249] Fix | Delete
case 'err_promote':
[250] Fix | Delete
echo '<div id="message" class="error notice is-dismissible"><p>' . __( 'Select a user to change role.' ) . '</p></div>';
[251] Fix | Delete
break;
[252] Fix | Delete
case 'remove':
[253] Fix | Delete
echo '<div id="message" class="updated notice is-dismissible"><p>' . __( 'User removed from this site.' ) . '</p></div>';
[254] Fix | Delete
break;
[255] Fix | Delete
case 'err_remove':
[256] Fix | Delete
echo '<div id="message" class="error notice is-dismissible"><p>' . __( 'Select a user to remove.' ) . '</p></div>';
[257] Fix | Delete
break;
[258] Fix | Delete
case 'newuser':
[259] Fix | Delete
echo '<div id="message" class="updated notice is-dismissible"><p>' . __( 'User created.' ) . '</p></div>';
[260] Fix | Delete
break;
[261] Fix | Delete
case 'err_new':
[262] Fix | Delete
echo '<div id="message" class="error notice is-dismissible"><p>' . __( 'Enter the username and email.' ) . '</p></div>';
[263] Fix | Delete
break;
[264] Fix | Delete
case 'err_new_dup':
[265] Fix | Delete
echo '<div id="message" class="error notice is-dismissible"><p>' . __( 'Duplicated username or email address.' ) . '</p></div>';
[266] Fix | Delete
break;
[267] Fix | Delete
}
[268] Fix | Delete
endif;
[269] Fix | Delete
?>
[270] Fix | Delete
[271] Fix | Delete
<form class="search-form" method="get">
[272] Fix | Delete
<?php $wp_list_table->search_box( __( 'Search Users' ), 'user' ); ?>
[273] Fix | Delete
<input type="hidden" name="id" value="<?php echo esc_attr( $id ); ?>" />
[274] Fix | Delete
</form>
[275] Fix | Delete
[276] Fix | Delete
<?php $wp_list_table->views(); ?>
[277] Fix | Delete
[278] Fix | Delete
<form method="post" action="site-users.php?action=update-site">
[279] Fix | Delete
<input type="hidden" name="id" value="<?php echo esc_attr( $id ); ?>" />
[280] Fix | Delete
[281] Fix | Delete
<?php $wp_list_table->display(); ?>
[282] Fix | Delete
[283] Fix | Delete
</form>
[284] Fix | Delete
[285] Fix | Delete
<?php
[286] Fix | Delete
/**
[287] Fix | Delete
* Fires after the list table on the Users screen in the Multisite Network Admin.
[288] Fix | Delete
*
[289] Fix | Delete
* @since 3.1.0
[290] Fix | Delete
*/
[291] Fix | Delete
do_action( 'network_site_users_after_list_table' );
[292] Fix | Delete
[293] Fix | Delete
/** This filter is documented in wp-admin/network/site-users.php */
[294] Fix | Delete
if ( current_user_can( 'promote_users' ) && apply_filters( 'show_network_site_users_add_existing_form', true ) ) :
[295] Fix | Delete
?>
[296] Fix | Delete
<h2 id="add-existing-user"><?php _e( 'Add Existing User' ); ?></h2>
[297] Fix | Delete
<form action="site-users.php?action=adduser" id="adduser" method="post">
[298] Fix | Delete
<input type="hidden" name="id" value="<?php echo esc_attr( $id ); ?>" />
[299] Fix | Delete
<table class="form-table" role="presentation">
[300] Fix | Delete
<tr>
[301] Fix | Delete
<th scope="row"><label for="newuser"><?php _e( 'Username' ); ?></label></th>
[302] Fix | Delete
<td><input type="text" class="regular-text wp-suggest-user" name="newuser" id="newuser" /></td>
[303] Fix | Delete
</tr>
[304] Fix | Delete
<tr>
[305] Fix | Delete
<th scope="row"><label for="new_role_adduser"><?php _e( 'Role' ); ?></label></th>
[306] Fix | Delete
<td><select name="new_role" id="new_role_adduser">
[307] Fix | Delete
<?php
[308] Fix | Delete
switch_to_blog( $id );
[309] Fix | Delete
wp_dropdown_roles( get_option( 'default_role' ) );
[310] Fix | Delete
restore_current_blog();
[311] Fix | Delete
?>
[312] Fix | Delete
</select></td>
[313] Fix | Delete
</tr>
[314] Fix | Delete
</table>
[315] Fix | Delete
<?php wp_nonce_field( 'add-user', '_wpnonce_add-user' ); ?>
[316] Fix | Delete
<?php submit_button( __( 'Add User' ), 'primary', 'add-user', true, array( 'id' => 'submit-add-existing-user' ) ); ?>
[317] Fix | Delete
</form>
[318] Fix | Delete
<?php endif; ?>
[319] Fix | Delete
[320] Fix | Delete
<?php
[321] Fix | Delete
/**
[322] Fix | Delete
* Filters whether to show the Add New User form on the Multisite Users screen.
[323] Fix | Delete
*
[324] Fix | Delete
* @since 3.1.0
[325] Fix | Delete
*
[326] Fix | Delete
* @param bool $bool Whether to show the Add New User form. Default true.
[327] Fix | Delete
*/
[328] Fix | Delete
if ( current_user_can( 'create_users' ) && apply_filters( 'show_network_site_users_add_new_form', true ) ) :
[329] Fix | Delete
?>
[330] Fix | Delete
<h2 id="add-new-user"><?php _e( 'Add New User' ); ?></h2>
[331] Fix | Delete
<form action="<?php echo network_admin_url( 'site-users.php?action=newuser' ); ?>" id="newuser" method="post">
[332] Fix | Delete
<input type="hidden" name="id" value="<?php echo esc_attr( $id ); ?>" />
[333] Fix | Delete
<table class="form-table" role="presentation">
[334] Fix | Delete
<tr>
[335] Fix | Delete
<th scope="row"><label for="user_username"><?php _e( 'Username' ); ?></label></th>
[336] Fix | Delete
<td><input type="text" class="regular-text" name="user[username]" id="user_username" /></td>
[337] Fix | Delete
</tr>
[338] Fix | Delete
<tr>
[339] Fix | Delete
<th scope="row"><label for="user_email"><?php _e( 'Email' ); ?></label></th>
[340] Fix | Delete
<td><input type="text" class="regular-text" name="user[email]" id="user_email" /></td>
[341] Fix | Delete
</tr>
[342] Fix | Delete
<tr>
[343] Fix | Delete
<th scope="row"><label for="new_role_newuser"><?php _e( 'Role' ); ?></label></th>
[344] Fix | Delete
<td><select name="new_role" id="new_role_newuser">
[345] Fix | Delete
<?php
[346] Fix | Delete
switch_to_blog( $id );
[347] Fix | Delete
wp_dropdown_roles( get_option( 'default_role' ) );
[348] Fix | Delete
restore_current_blog();
[349] Fix | Delete
?>
[350] Fix | Delete
</select></td>
[351] Fix | Delete
</tr>
[352] Fix | Delete
<tr class="form-field">
[353] Fix | Delete
<td colspan="2" class="td-full"><?php _e( 'A password reset link will be sent to the user via email.' ); ?></td>
[354] Fix | Delete
</tr>
[355] Fix | Delete
</table>
[356] Fix | Delete
<?php wp_nonce_field( 'add-user', '_wpnonce_add-new-user' ); ?>
[357] Fix | Delete
<?php submit_button( __( 'Add New User' ), 'primary', 'add-user', true, array( 'id' => 'submit-add-user' ) ); ?>
[358] Fix | Delete
</form>
[359] Fix | Delete
<?php endif; ?>
[360] Fix | Delete
</div>
[361] Fix | Delete
<?php
[362] Fix | Delete
require_once ABSPATH . 'wp-admin/admin-footer.php';
[363] Fix | Delete
[364] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function