WordPress.org

Make WordPress Core

Changeset 16440


Ignore:
Timestamp:
11/17/2010 07:45:10 PM (11 years ago)
Author:
ryan
Message:

Add existing user to site form. Props PeteMall, ocean90. see #15342

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/network/site-users.php

    r16370 r16440  
    2828$is_main_site = is_main_site( $id );
    2929
     30// get blog prefix
     31$blog_prefix = $wpdb->get_blog_prefix( $id );
     32
     33// @todo This is a hack. Eventually, add API to WP_Roles allowing retrieval of roles for a particular blog.
     34if ( ! empty($wp_roles->use_db) ) {
     35    $editblog_roles = get_blog_option( $id, "{$blog_prefix}user_roles" );
     36} else {
     37    // Roles are stored in memory, not the DB.
     38    $editblog_roles = $wp_roles->roles;
     39}
     40
    3041if ( isset($_REQUEST['action']) && 'update-site' == $_REQUEST['action'] ) {
    3142    check_admin_referer( 'edit-site' );
    3243
    3344    switch_to_blog( $id );
    34 
    35     // get blog prefix
    36     $blog_prefix = $wpdb->get_blog_prefix( $id );
    3745
    3846    // user roles
     
    131139<?php
    132140$blogusers = get_users( array( 'blog_id' => $id, 'number' => 20 ) );
     141
    133142if ( is_array( $blogusers ) ) {
    134143    echo '<table class="form-table">';
    135144    echo "<tr><th>" . __( 'User' ) . "</th><th>" . __( 'Role' ) . "</th><th>" . __( 'Password' ) . "</th><th>" . __( 'Remove' ) . "</th></tr>";
    136145    $user_count = 0;
    137     // @todo This is a hack. Eventually, add API to WP_Roles allowing retrieval of roles for a particular blog.
    138     if ( ! empty($wp_roles->use_db) ) {
    139         // If using the DB to store roles, consult the user_roles option.
    140         $blog_prefix = $wpdb->get_blog_prefix( $id );
    141         $editblog_roles = get_blog_option( $id, "{$blog_prefix}user_roles" );
    142     } else {
    143         // Roles are stored in memory, not the DB.
    144         $editblog_roles = $wp_roles->roles;
    145     }
    146146
    147147    foreach ( $blogusers as $user_id => $user_object ) {
     
    181181</form>
    182182
     183<h3 id="add-new-user"><?php _e('Add Existing User') ?></h3>
     184<p class="description"><?php _e( 'Enter the username of an existing user.' ) ?></p>
     185    <form action="site-users.php?action=update-site" id="adduser" method="post">
     186    <?php wp_nonce_field( 'edit-site' ); ?>
     187    <input type="hidden" name="id" value="<?php echo esc_attr( $id ) ?>" />
     188    <table class="form-table">
     189        <tr>
     190            <th scope="row"><?php _e( 'Username' ); ?></th>
     191            <td><input type="text" name="newuser" id="newuser" /></td>
     192        </tr>
     193        <tr>
     194            <th scope="row"><?php _e( 'Role'); ?></th>
     195            <td><select name="new_role" id="new_role_0">
     196            <?php
     197            $default_role = $wpdb->get_var( "SELECT `option_value` FROM {$blog_prefix}options WHERE option_name = 'default_role'" );
     198            var_dump( $default_role );
     199            reset( $editblog_roles );
     200            foreach ( $editblog_roles as $role => $role_assoc ){
     201                $name = translate_user_role( $role_assoc['name'] );
     202                $selected = ( $role == $default_role ) ? 'selected="selected"' : '';
     203                echo '<option ' . $selected . ' value="' . esc_attr( $role ) . '">' . esc_html( $name ) . '</option>';
     204            }
     205            ?>
     206            </select></td>
     207        </tr>
     208    </table>
     209    <?php submit_button( __('Add User'), 'primary', 'add-user' ); ?>
     210    </form>
    183211</div>
    184212<?php
Note: See TracChangeset for help on using the changeset viewer.