2003-12-08 02:28:41 +01:00
< ? php
2004-10-19 05:03:06 +02:00
require_once ( 'admin.php' );
2005-07-09 03:27:46 +02:00
require_once ( ABSPATH . WPINC . '/registration-functions.php' );
2004-04-25 06:24:06 +02:00
$title = __ ( 'Users' );
2004-12-24 21:55:36 +01:00
$parent_file = 'profile.php' ;
2003-12-08 02:28:41 +01:00
2005-07-09 03:27:46 +02:00
$action = $_REQUEST [ 'action' ];
2003-12-08 02:28:41 +01:00
switch ( $action ) {
2003-12-23 21:21:29 +01:00
case 'adduser' :
2004-05-18 05:58:05 +02:00
check_admin_referer ();
2004-05-17 22:34:05 +02:00
2005-03-16 22:09:11 +01:00
$user_login = wp_specialchars ( trim ( $_POST [ 'user_login' ]));
2004-12-12 21:41:19 +01:00
$pass1 = $_POST [ 'pass1' ];
$pass2 = $_POST [ 'pass2' ];
2005-03-16 22:09:11 +01:00
$user_email = wp_specialchars ( trim ( $_POST [ 'email' ]));
$user_firstname = wp_specialchars ( trim ( $_POST [ 'firstname' ]));
$user_lastname = wp_specialchars ( trim ( $_POST [ 'lastname' ]));
$user_uri = wp_specialchars ( trim ( $_POST [ 'uri' ]));
2003-12-23 21:21:29 +01:00
2005-03-13 18:06:18 +01:00
/* checking that username has been typed */
2005-03-09 23:49:42 +01:00
if ( $user_login == '' )
2005-03-13 18:06:18 +01:00
die ( __ ( '<strong>ERROR</strong>: Please enter a username.' ));
2003-12-23 21:21:29 +01:00
/* checking the password has been typed twice */
2005-03-09 23:49:42 +01:00
do_action ( 'check_passwords' , array ( $user_login , & $pass1 , & $pass2 ));
if ( $pass1 == '' || $pass2 == '' )
2004-04-25 06:24:06 +02:00
die ( __ ( '<strong>ERROR</strong>: Please enter your password twice.' ));
2003-12-23 21:21:29 +01:00
/* checking the password has been typed twice the same */
2005-03-09 23:49:42 +01:00
if ( $pass1 != $pass2 )
2004-04-25 06:24:06 +02:00
die ( __ ( '<strong>ERROR</strong>: Please type the same password in the two password fields.' ));
2005-03-09 23:49:42 +01:00
2003-12-23 21:21:29 +01:00
$user_nickname = $user_login ;
2005-07-09 03:27:46 +02:00
if ( username_exists ( $user_login ) )
2005-03-13 18:06:18 +01:00
die ( __ ( '<strong>ERROR</strong>: This username is already registered, please choose another one.' ));
2003-12-23 21:21:29 +01:00
2004-05-17 14:38:19 +02:00
/* checking e-mail address */
2005-07-09 03:27:46 +02:00
if ( empty ( $user_email )) {
2004-05-17 14:38:19 +02:00
die ( __ ( " <strong>ERROR</strong>: please type an e-mail address " ));
return false ;
2005-07-09 03:27:46 +02:00
} else if ( ! is_email ( $user_email )) {
2004-05-17 14:38:19 +02:00
die ( __ ( " <strong>ERROR</strong>: the email address isn't correct " ));
return false ;
}
2003-12-23 21:21:29 +01:00
2005-07-09 03:27:46 +02:00
$user_ID = create_user ( $user_login , $pass1 , $user_email , 0 );
2003-12-23 21:21:29 +01:00
2005-07-09 03:27:46 +02:00
update_usermeta ( $user_ID , 'first_name' , $user_firstname );
update_usermeta ( $user_ID , 'last_name' , $user_lastname );
update_usermeta ( $user_ID , 'first_name' , $user_firstname );
2003-12-08 02:28:41 +01:00
2003-12-23 21:21:29 +01:00
$stars = '' ;
2005-03-09 23:49:42 +01:00
for ( $i = 0 ; $i < strlen ( $pass1 ); $i = $i + 1 )
2003-12-23 21:21:29 +01:00
$stars .= '*' ;
2005-03-09 23:49:42 +01:00
$user_login = stripslashes ( $user_login );
2005-03-25 22:41:45 +01:00
$message = sprintf ( __ ( 'New user registration on your blog %s:' ), get_settings ( 'blogname' )) . " \r \n \r \n " ;
$message .= sprintf ( __ ( 'Username: %s' ), $user_login ) . " \r \n \r \n " ;
$message .= sprintf ( __ ( 'E-mail: %s' ), $user_email ) . " \r \n " ;
2003-12-23 21:21:29 +01:00
2005-03-25 22:41:45 +01:00
@ wp_mail ( get_settings ( 'admin_email' ), sprintf ( __ ( '[%s] New User Registration' ), get_settings ( 'blogname' )), $message );
2003-12-23 21:21:29 +01:00
header ( 'Location: users.php' );
break ;
2003-12-08 02:28:41 +01:00
case 'promote' :
2004-05-18 05:58:05 +02:00
check_admin_referer ();
2004-05-17 22:34:05 +02:00
2004-04-21 00:56:47 +02:00
if ( empty ( $_GET [ 'prom' ])) {
2003-12-08 02:28:41 +01:00
header ( 'Location: users.php' );
}
2005-07-09 03:27:46 +02:00
$id = ( int ) $_GET [ 'id' ];
2004-04-21 00:56:47 +02:00
$prom = $_GET [ 'prom' ];
2003-12-08 02:28:41 +01:00
$user_data = get_userdata ( $id );
2005-07-09 03:27:46 +02:00
2003-12-08 02:28:41 +01:00
$usertopromote_level = $user_data -> user_level ;
2005-07-09 03:27:46 +02:00
if ( $user_level <= $usertopromote_level )
2004-04-25 06:24:06 +02:00
die ( __ ( 'Can’t change the level of a user whose level is higher than yours.' ));
2003-12-08 02:28:41 +01:00
if ( 'up' == $prom ) {
2003-12-30 17:02:27 +01:00
$new_level = $usertopromote_level + 1 ;
2003-12-08 02:28:41 +01:00
} elseif ( 'down' == $prom ) {
2003-12-30 17:02:27 +01:00
$new_level = $usertopromote_level - 1 ;
2003-12-08 02:28:41 +01:00
}
2005-07-09 03:27:46 +02:00
update_usermeta ( $id , $wpdb -> prefix . 'user_level' , $new_level );
2003-12-08 02:28:41 +01:00
header ( 'Location: users.php' );
break ;
case 'delete' :
2004-05-18 05:58:05 +02:00
check_admin_referer ();
2004-05-17 22:34:05 +02:00
2004-12-12 21:41:19 +01:00
$id = ( int ) $_GET [ 'id' ];
2003-12-08 02:28:41 +01:00
if ( ! $id ) {
header ( 'Location: users.php' );
}
$user_data = get_userdata ( $id );
$usertodelete_level = $user_data -> user_level ;
if ( $user_level <= $usertodelete_level )
2004-04-25 06:24:06 +02:00
die ( __ ( 'Can’t delete a user whose level is higher than yours.' ));
2003-12-08 02:28:41 +01:00
2005-07-05 00:03:42 +02:00
wp_delete_user ( $id );
2004-04-30 06:41:47 +02:00
2004-04-14 20:00:16 +02:00
header ( 'Location: users.php?deleted=true' );
2003-12-08 02:28:41 +01:00
break ;
default :
2003-12-11 01:22:36 +01:00
include ( 'admin-header.php' );
2003-12-08 02:28:41 +01:00
?>
2004-07-21 09:23:45 +02:00
2004-05-08 01:56:33 +02:00
< ? php if ( isset ( $_GET [ 'deleted' ])) : ?>
2004-04-25 06:24:06 +02:00
< div class = " updated " >< p >< ? php _e ( 'User deleted.' ) ?> </p></div>
2004-04-14 20:00:16 +02:00
< ? php endif ; ?>
2003-12-08 02:28:41 +01:00
< div class = " wrap " >
2004-04-25 06:24:06 +02:00
< h2 >< ? php _e ( 'Authors' ) ?> </h2>
2003-12-08 09:12:09 +01:00
< table cellpadding = " 3 " cellspacing = " 3 " width = " 100% " >
2003-12-08 02:28:41 +01:00
< tr >
2004-04-25 06:24:06 +02:00
< th >< ? php _e ( 'ID' ) ?> </th>
< th >< ? php _e ( 'Nickname' ) ?> </th>
< th >< ? php _e ( 'Name' ) ?> </th>
< th >< ? php _e ( 'E-mail' ) ?> </th>
2004-05-05 10:27:43 +02:00
< th >< ? php _e ( 'Website' ) ?> </th>
2004-04-25 06:24:06 +02:00
< th >< ? php _e ( 'Level' ) ?> </th>
< th >< ? php _e ( 'Posts' ) ?> </th>
2004-08-01 11:13:50 +02:00
< th >& nbsp ; </ th >
2003-12-08 02:28:41 +01:00
</ tr >
< ? php
2005-07-09 03:27:46 +02:00
$authors =
$users = get_author_user_ids ();
2004-05-08 01:56:33 +02:00
$style = '' ;
2003-12-08 02:28:41 +01:00
foreach ( $users as $user ) {
2005-07-09 03:27:46 +02:00
$user_data = get_userdata ( $user );
2003-12-08 02:28:41 +01:00
$email = $user_data -> user_email ;
$url = $user_data -> user_url ;
2004-06-18 02:22:09 +02:00
$short_url = str_replace ( 'http://' , '' , $url );
2003-12-08 02:28:41 +01:00
$short_url = str_replace ( 'www.' , '' , $short_url );
if ( '/' == substr ( $short_url , - 1 ))
$short_url = substr ( $short_url , 0 , - 1 );
if ( strlen ( $short_url ) > 35 )
$short_url = substr ( $short_url , 0 , 32 ) . '...' ;
2003-12-08 09:12:09 +01:00
$style = ( 'class="alternate"' == $style ) ? '' : 'class="alternate"' ;
2005-07-09 03:27:46 +02:00
$numposts = $wpdb -> get_var ( " SELECT COUNT(*) FROM $wpdb->posts WHERE post_author = ' $user ' and post_status = 'publish' " );
2004-04-25 06:24:06 +02:00
if ( 0 < $numposts ) $numposts = " <a href='edit.php?author= $user_data->ID ' title=' " . __ ( 'View posts' ) . " '> $numposts </a> " ;
2003-12-08 02:28:41 +01:00
echo "
2003-12-08 09:12:09 +01:00
< tr $style >
< td align = 'center' > $user_data -> ID </ td >
2005-06-13 10:32:44 +02:00
< td >< strong > $user_data -> user_login </ strong ></ td >
< td > $user_data -> first_name $user_data -> last_name </ td >
2004-04-25 06:24:06 +02:00
< td >< a href = 'mailto:$email' title = '" . sprintf(__(' e - mail : % s '), $email) . "' > $email </ a ></ td >
2003-12-08 02:28:41 +01:00
< td >< a href = '$url' title = 'website: $url' > $short_url </ a ></ td >
< td align = 'center' > " ;
if (( $user_level >= 2 ) and ( $user_level > $user_data -> user_level ) and ( $user_data -> user_level > 0 ))
2004-06-11 20:23:12 +02:00
echo " <a href= \" users.php?action=promote&id= " . $user_data -> ID . " &prom=down \" >-</a> " ;
2003-12-08 02:28:41 +01:00
echo $user_data -> user_level ;
if (( $user_level >= 2 ) and ( $user_level > ( $user_data -> user_level + 1 )))
2004-06-11 20:23:12 +02:00
echo " <a href= \" users.php?action=promote&id= " . $user_data -> ID . " &prom=up \" >+</a> " ;
echo " </td><td align='right'> $numposts </td> " ;
2004-08-01 11:13:50 +02:00
echo '<td>' ;
if (( $user_level >= 2 ) and ( $user_level > $user_data -> user_level ))
2004-11-25 05:11:57 +01:00
echo " <a href='user-edit.php?user_id= $user_data->ID ' class='edit'> " . __ ( 'Edit' ) . " </a> " ;
2004-08-01 11:13:50 +02:00
echo '</td>' ;
2003-12-08 02:28:41 +01:00
echo '</tr>' ;
}
?>
</ table >
</ div >
< ? php
2005-07-09 03:27:46 +02:00
$users = get_nonauthor_user_ids ();
2004-12-12 21:41:19 +01:00
if ( $users ) {
2003-12-08 02:28:41 +01:00
?>
< div class = " wrap " >
2004-09-22 01:41:27 +02:00
< h2 >< ? php _e ( 'Registered Users' ) ?> </h2>
2003-12-08 09:12:09 +01:00
< table cellpadding = " 3 " cellspacing = " 3 " width = " 100% " >
2003-12-08 02:28:41 +01:00
< tr >
2004-04-25 06:24:06 +02:00
< th >< ? php _e ( 'ID' ) ?> </th>
< th >< ? php _e ( 'Nickname' ) ?> </th>
< th >< ? php _e ( 'Name' ) ?> </th>
< th >< ? php _e ( 'E-mail' ) ?> </th>
2004-05-05 10:27:43 +02:00
< th >< ? php _e ( 'Website' ) ?> </th>
2004-09-22 01:41:27 +02:00
< th ></ th >
2004-08-01 11:13:50 +02:00
< th ></ th >
2004-09-22 01:36:27 +02:00
< th ></ th >
2003-12-08 02:28:41 +01:00
</ tr >
2004-07-21 09:44:55 +02:00
< ? php
$style = '' ;
foreach ( $users as $user ) {
2005-07-09 03:27:46 +02:00
$user_data = get_userdata ( $user );
2004-07-21 09:44:55 +02:00
$email = $user_data -> user_email ;
$url = $user_data -> user_url ;
$short_url = str_replace ( 'http://' , '' , $url );
$short_url = str_replace ( 'www.' , '' , $short_url );
if ( '/' == substr ( $short_url , - 1 ))
$short_url = substr ( $short_url , 0 , - 1 );
if ( strlen ( $short_url ) > 35 )
$short_url = substr ( $short_url , 0 , 32 ) . '...' ;
$style = ( 'class="alternate"' == $style ) ? '' : 'class="alternate"' ;
2003-12-08 09:12:09 +01:00
echo " \n <tr $style >
< td align = 'center' > $user_data -> ID </ td >
2005-06-13 10:32:44 +02:00
< td >< strong > $user_data -> user_login </ strong ></ td >
< td > $user_data -> first_name $user_data -> last_name </ td >
2004-04-25 06:24:06 +02:00
< td >< a href = 'mailto:$email' title = '" . sprintf(__(' e - mail : % s '), $email) . "' > $email </ a ></ td >
2003-12-08 09:12:09 +01:00
< td >< a href = '$url' title = 'website: $url' > $short_url </ a ></ td >
< td align = 'center' > " ;
2004-09-22 01:36:27 +02:00
if ( $user_level >= 6 )
2004-09-22 01:41:27 +02:00
echo " <a href='users.php?action=promote&id= $user_data->ID &prom=up' class='edit'> " . __ ( 'Promote' ) . '</a>' ;
2004-08-01 11:13:50 +02:00
echo " </td> \n " ;
echo '<td>' ;
2004-09-22 01:36:27 +02:00
if (( $user_level >= 6 ) and ( $user_level > $user_data -> user_level ))
2004-11-29 20:46:20 +01:00
echo " <a href='user-edit.php?user_id= $user_data->ID ' class='edit'> " . __ ( 'Edit' ) . " </a> " ;
2004-09-22 01:36:27 +02:00
echo '</td><td>' ;
if ( $user_level >= 6 )
2005-02-11 02:43:13 +01:00
echo " <a href='users.php?action=delete&id= $user_data->ID ' class='delete' onclick='return confirm( \" " . __ ( 'You are about to delete this user \n OK to delete, Cancel to stop.' ) . " \" )'> " . __ ( 'Delete' ) . '</a>' ;
2004-09-22 01:36:27 +02:00
echo '</td></tr>' ;
}
2004-07-21 09:44:55 +02:00
?>
2003-12-08 02:28:41 +01:00
</ table >
2004-09-22 01:36:27 +02:00
< p >< ? php _e ( 'Deleting a user also deletes all posts made by that user.' ) ?> </p>
2003-12-08 02:28:41 +01:00
</ div >
< ? php
} ?>
< div class = " wrap " >
2004-07-21 09:44:55 +02:00
< h2 >< ? php _e ( 'Add New User' ) ?> </h2>
2004-04-25 06:24:06 +02:00
< ? php printf ( __ ( '<p>Users can <a href="%s/wp-register.php">register themselves</a> or you can manually create users here.</p>' ), get_settings ( 'siteurl' )); ?>
2003-12-23 21:21:29 +01:00
< form action = " " method = " post " name = " adduser " id = " adduser " >
2004-05-05 10:27:43 +02:00
< table class = " editform " width = " 100% " cellspacing = " 2 " cellpadding = " 5 " >
2003-12-23 21:21:29 +01:00
< tr >
2004-05-05 10:27:43 +02:00
< th scope = " row " width = " 33% " >< ? php _e ( 'Nickname' ) ?>
2003-12-23 21:21:29 +01:00
< input name = " action " type = " hidden " id = " action " value = " adduser " /></ th >
2004-05-05 10:27:43 +02:00
< td width = " 66% " >< input name = " user_login " type = " text " id = " user_login " /></ td >
2003-12-23 21:21:29 +01:00
</ tr >
< tr >
2004-04-25 06:24:06 +02:00
< th scope = " row " >< ? php _e ( 'First Name' ) ?> </th>
2003-12-23 21:21:29 +01:00
< td >< input name = " firstname " type = " text " id = " firstname " /></ td >
</ tr >
< tr >
2004-04-25 06:24:06 +02:00
< th scope = " row " >< ? php _e ( 'Last Name' ) ?> </th>
2003-12-23 21:21:29 +01:00
< td >< input name = " lastname " type = " text " id = " lastname " /></ td >
</ tr >
< tr >
2004-05-05 10:27:43 +02:00
< th scope = " row " >< ? php _e ( 'E-mail' ) ?> </th>
2003-12-23 21:21:29 +01:00
< td >< input name = " email " type = " text " id = " email " /></ td >
</ tr >
< tr >
2004-05-05 10:27:43 +02:00
< th scope = " row " >< ? php _e ( 'Website' ) ?> </th>
2003-12-23 21:21:29 +01:00
< td >< input name = " uri " type = " text " id = " uri " /></ td >
</ tr >
2005-03-09 23:49:42 +01:00
< ? php
$show_password_fields = apply_filters ( 'show_password_fields' , true );
if ( $show_password_fields ) :
?>
2003-12-23 21:21:29 +01:00
< tr >
2004-04-25 06:24:06 +02:00
< th scope = " row " >< ? php _e ( 'Password (twice)' ) ?> </th>
2004-01-21 23:44:28 +01:00
< td >< input name = " pass1 " type = " password " id = " pass1 " />
2003-12-23 21:21:29 +01:00
< br />
2004-01-21 23:44:28 +01:00
< input name = " pass2 " type = " password " id = " pass2 " /></ td >
2003-12-23 21:21:29 +01:00
</ tr >
2005-03-09 23:49:42 +01:00
< ? php endif ; ?>
2003-12-23 21:21:29 +01:00
</ table >
2004-04-28 06:59:54 +02:00
< p class = " submit " >
2004-06-11 20:23:12 +02:00
< input name = " adduser " type = " submit " id = " adduser " value = " <?php _e('Add User') ?> » " />
2003-12-23 21:21:29 +01:00
</ p >
</ form >
2003-12-08 02:28:41 +01:00
</ div >
< ? php
break ;
}
2004-08-23 01:24:50 +02:00
2003-12-11 01:22:36 +01:00
include ( 'admin-footer.php' );
2004-12-24 21:55:36 +01:00
?>