~canonical-sysadmins/wordpress/upstream-4.1

« back to all changes in this revision

Viewing changes to wp-admin/network/user-new.php

  • Committer: Jacek Nykis
  • Date: 2015-01-05 16:17:05 UTC
  • Revision ID: jacek.nykis@canonical.com-20150105161705-w544l1h5mcg7u4w9
Initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * Add New User network administration panel.
 
4
 *
 
5
 * @package WordPress
 
6
 * @subpackage Multisite
 
7
 * @since 3.1.0
 
8
 */
 
9
 
 
10
/** Load WordPress Administration Bootstrap */
 
11
require_once( dirname( __FILE__ ) . '/admin.php' );
 
12
 
 
13
if ( ! is_multisite() )
 
14
        wp_die( __( 'Multisite support is not enabled.' ) );
 
15
 
 
16
if ( ! current_user_can('create_users') )
 
17
        wp_die(__('You do not have sufficient permissions to add users to this network.'));
 
18
 
 
19
get_current_screen()->add_help_tab( array(
 
20
        'id'      => 'overview',
 
21
        'title'   => __('Overview'),
 
22
        'content' =>
 
23
                '<p>' . __('Add User will set up a new user account on the network and send that person an email with username and password.') . '</p>' .
 
24
                '<p>' . __('Users who are signed up to the network without a site are added as subscribers to the main or primary dashboard site, giving them profile pages to manage their accounts. These users will only see Dashboard and My Sites in the main navigation until a site is created for them.') . '</p>'
 
25
) );
 
26
 
 
27
get_current_screen()->set_help_sidebar(
 
28
        '<p><strong>' . __('For more information:') . '</strong></p>' .
 
29
        '<p>' . __('<a href="http://codex.wordpress.org/Network_Admin_Users_Screen" target="_blank">Documentation on Network Users</a>') . '</p>' .
 
30
        '<p>' . __('<a href="https://wordpress.org/support/forum/multisite/" target="_blank">Support Forums</a>') . '</p>'
 
31
);
 
32
 
 
33
if ( isset($_REQUEST['action']) && 'add-user' == $_REQUEST['action'] ) {
 
34
        check_admin_referer( 'add-user', '_wpnonce_add-user' );
 
35
        if ( ! current_user_can( 'manage_network_users' ) )
 
36
                wp_die( __( 'You do not have permission to access this page.' ) );
 
37
 
 
38
        if ( ! is_array( $_POST['user'] ) )
 
39
                wp_die( __( 'Cannot create an empty user.' ) );
 
40
 
 
41
        $user = $_POST['user'];
 
42
 
 
43
        $user_details = wpmu_validate_user_signup( $user['username'], $user['email'] );
 
44
        if ( is_wp_error( $user_details[ 'errors' ] ) && ! empty( $user_details[ 'errors' ]->errors ) ) {
 
45
                $add_user_errors = $user_details[ 'errors' ];
 
46
        } else {
 
47
                $password = wp_generate_password( 12, false);
 
48
                $user_id = wpmu_create_user( esc_html( strtolower( $user['username'] ) ), $password, esc_html( $user['email'] ) );
 
49
 
 
50
                if ( ! $user_id ) {
 
51
                        $add_user_errors = new WP_Error( 'add_user_fail', __( 'Cannot add user.' ) );
 
52
                } else {
 
53
                        wp_new_user_notification( $user_id, $password );
 
54
                        wp_redirect( add_query_arg( array('update' => 'added'), 'user-new.php' ) );
 
55
                        exit;
 
56
                }
 
57
        }
 
58
}
 
59
 
 
60
if ( isset($_GET['update']) ) {
 
61
        $messages = array();
 
62
        if ( 'added' == $_GET['update'] )
 
63
                $messages[] = __('User added.');
 
64
}
 
65
 
 
66
$title = __('Add New User');
 
67
$parent_file = 'users.php';
 
68
 
 
69
require( ABSPATH . 'wp-admin/admin-header.php' ); ?>
 
70
 
 
71
<div class="wrap">
 
72
<h2 id="add-new-user"><?php _e('Add New User') ?></h2>
 
73
<?php
 
74
if ( ! empty( $messages ) ) {
 
75
        foreach ( $messages as $msg )
 
76
                echo '<div id="message" class="updated"><p>' . $msg . '</p></div>';
 
77
}
 
78
 
 
79
if ( isset( $add_user_errors ) && is_wp_error( $add_user_errors ) ) { ?>
 
80
        <div class="error">
 
81
                <?php
 
82
                        foreach ( $add_user_errors->get_error_messages() as $message )
 
83
                                echo "<p>$message</p>";
 
84
                ?>
 
85
        </div>
 
86
<?php } ?>
 
87
        <form action="<?php echo network_admin_url('user-new.php?action=add-user'); ?>" id="adduser" method="post">
 
88
        <table class="form-table">
 
89
                <tr class="form-field form-required">
 
90
                        <th scope="row"><?php _e( 'Username' ) ?></th>
 
91
                        <td><input type="text" class="regular-text" name="user[username]" /></td>
 
92
                </tr>
 
93
                <tr class="form-field form-required">
 
94
                        <th scope="row"><?php _e( 'Email' ) ?></th>
 
95
                        <td><input type="text" class="regular-text" name="user[email]" /></td>
 
96
                </tr>
 
97
                <tr class="form-field">
 
98
                        <td colspan="2"><?php _e( 'Username and password will be mailed to the above email address.' ) ?></td>
 
99
                </tr>
 
100
        </table>
 
101
        <?php wp_nonce_field( 'add-user', '_wpnonce_add-user' ); ?>
 
102
        <?php submit_button( __('Add User'), 'primary', 'add-user' ); ?>
 
103
        </form>
 
104
</div>
 
105
<?php
 
106
require( ABSPATH . 'wp-admin/admin-footer.php' );