Make WordPress Core

Ticket #19810: 19810.patch

File 19810.patch, 8.5 KB (added by Japh, 13 years ago)

Modified patch from #18160 for better styling and closer appearance to Tags autocomplete UI

  • wp-includes/script-loader.php

     
    260260
    261261        $scripts->add( 'user-profile', "/wp-admin/js/user-profile$suffix.js", array( 'jquery', 'password-strength-meter' ), false, 1 );
    262262
     263        $scripts->add( 'user-new', "/wp-admin/js/user-new$suffix.js", array( 'jquery', 'jquery-ui-autocomplete' ), '20120115', 1 );
     264
    263265        $scripts->add( 'admin-bar', "/wp-includes/js/admin-bar$suffix.js", array(), false, 1 );
    264266
    265267        $scripts->add( 'wplink', "/wp-includes/js/wplink$suffix.js", array( 'jquery', 'wpdialogs' ), false, 1 );
  • wp-admin/admin-ajax.php

     
    169169        $return = ( $wp_embed->cache_oembed( $_GET['post'] ) ) ? '1' : '0';
    170170        die( $return );
    171171        break;
     172case 'add-existing-user-ac' :
     173        $return = array();
     174
     175        // Exclude current users of this blog
     176        $this_blog_users = new WP_User_Query( array(
     177                'blog_id' => get_current_blog_id()
     178        ) );
     179       
     180        $tbu_ids = array();
     181        if ( !empty( $this_blog_users->results ) ) {
     182                foreach( $this_blog_users->results as $this_blog_user ) {
     183                        $tbu_ids[] = $this_blog_user->ID;
     184                }
     185        }
     186
     187        $users = new WP_User_Query( array(
     188                'blog_id' => false,
     189                'search'  => '*' . $_REQUEST['term'] . '*',
     190                'exclude' => $tbu_ids
     191        ) );
     192       
     193        if ( empty( $users->results ) ) {
     194                $return[] = array();
     195        } else {
     196                foreach ( $users->results as $user ) {
     197                        $user_data          = array();
     198                        $user_data['label'] = $user->user_login . ' (' . $user->user_email . ')';
     199                        $user_data['id']    = $user->ID;
     200                        $return[]           = $user_data;
     201                }
     202        }
     203       
     204        die( json_encode( $return ) );
     205        break;
    172206default :
    173207        do_action( 'wp_ajax_' . $_GET['action'] );
    174208        die('0');
  • wp-admin/user-new.php

     
    3838if ( isset($_REQUEST['action']) && 'adduser' == $_REQUEST['action'] ) {
    3939        check_admin_referer( 'add-user', '_wpnonce_add-user' );
    4040
    41         $user_details = null;
    42         if ( false !== strpos($_REQUEST[ 'email' ], '@') ) {
    43                 $user_details = get_user_by('email', $_REQUEST[ 'email' ]);
     41        $add_users = isset( $_REQUEST['add_ids'] ) ? (array)$_REQUEST['add_ids'] : $_REQUEST['email'];
     42
     43        $add_users_data = array();
     44        if ( is_array( $add_users ) ) {
     45                foreach( $add_users as $add_id ) {
     46                        if ( current_user_can( 'promote_user', $add_id ) ) {
     47                                $add_users_data[] = get_userdata( (int)$add_id );
     48                        }
     49                }
    4450        } else {
    45                 if ( is_super_admin() ) {
    46                         $user_details = get_user_by('login', $_REQUEST[ 'email' ]);
     51                if ( false !== strpos($add_users, '@') ) {
     52                        $add_users_data[] = get_user_by('email', $add_users);
    4753                } else {
    48                         wp_redirect( add_query_arg( array('update' => 'enter_email'), 'user-new.php' ) );
    49                         die();
     54                        if ( is_super_admin() ) {
     55                                $add_users_data[] = get_user_by('login', $add_users);
     56                        } else {
     57                                wp_redirect( add_query_arg( array('update' => 'enter_email'), 'user-new.php' ) );
     58                                die();
     59                        }
    5060                }
     61               
     62                if ( ! current_user_can('promote_user', $add_users_data[0]->ID) )
     63                        wp_die(__('Cheatin’ uh?'));
    5164        }
    5265
    53         if ( !$user_details ) {
     66        if ( empty( $add_users_data ) ) {
    5467                wp_redirect( add_query_arg( array('update' => 'does_not_exist'), 'user-new.php' ) );
    5568                die();
    5669        }
    57 
    58         if ( ! current_user_can('promote_user', $user_details->ID) )
    59                 wp_die(__('Cheatin’ uh?'));
    60 
    61         // Adding an existing user to this blog
    62         $new_user_email = $user_details->user_email;
    63         $redirect = 'user-new.php';
    64         $username = $user_details->user_login;
    65         $user_id = $user_details->ID;
    66         if ( ( $username != null && !is_super_admin( $user_id ) ) && ( array_key_exists($blog_id, get_blogs_of_user($user_id)) ) ) {
    67                 $redirect = add_query_arg( array('update' => 'addexisting'), 'user-new.php' );
    68         } else {
    69                 if ( isset( $_POST[ 'noconfirmation' ] ) && is_super_admin() ) {
    70                         add_existing_user_to_blog( array( 'user_id' => $user_id, 'role' => $_REQUEST[ 'role' ] ) );
    71                         $redirect = add_query_arg( array('update' => 'addnoconfirmation'), 'user-new.php' );
     70       
     71        foreach( $add_users_data as $user_details ) {
     72                // Adding an existing user to this blog
     73                $new_user_email = $user_details->user_email;
     74                $redirect = 'user-new.php';
     75                $username = $user_details->user_login;
     76                $user_id = $user_details->ID;
     77                if ( ( $username != null && !is_super_admin( $user_id ) ) && ( array_key_exists($blog_id, get_blogs_of_user($user_id)) ) ) {
     78                        $redirect = add_query_arg( array('update' => 'addexisting'), 'user-new.php' );
    7279                } else {
    73                         $newuser_key = substr( md5( $user_id ), 0, 5 );
    74                         add_option( 'new_user_' . $newuser_key, array( 'user_id' => $user_id, 'email' => $user_details->user_email, 'role' => $_REQUEST[ 'role' ] ) );
    75                         /* translators: 1: Site name, 2: site URL, 3: role, 4: activation URL */
    76                         $message = __( 'Hi,
    77 
     80                        if ( isset( $_POST[ 'noconfirmation' ] ) && is_super_admin() ) {
     81                                add_existing_user_to_blog( array( 'user_id' => $user_id, 'role' => $_REQUEST[ 'role' ] ) );
     82                                $redirect = add_query_arg( array('update' => 'addnoconfirmation'), 'user-new.php' );
     83                        } else {
     84                                $newuser_key = substr( md5( $user_id ), 0, 5 );
     85                                add_option( 'new_user_' . $newuser_key, array( 'user_id' => $user_id, 'email' => $user_details->user_email, 'role' => $_REQUEST[ 'role' ] ) );
     86                                /* translators: 1: Site name, 2: site URL, 3: role, 4: activation URL */
     87                                $message = __( 'Hi,
     88       
    7889You\'ve been invited to join \'%1$s\' at
    7990%2$s with the role of %3$s.
    8091
    8192Please click the following link to confirm the invite:
    8293%4$s' );
    83                         wp_mail( $new_user_email, sprintf( __( '[%s] Joining confirmation' ), get_option( 'blogname' ) ), sprintf($message, get_option('blogname'), home_url(), $_REQUEST[ 'role' ], home_url("/newbloguser/$newuser_key/")));
    84                         $redirect = add_query_arg( array('update' => 'add'), 'user-new.php' );
     94                                wp_mail( $new_user_email, sprintf( __( '[%s] Joining confirmation' ), get_option( 'blogname' ) ),  sprintf($message, get_option('blogname'), site_url(), $_REQUEST[ 'role' ], site_url("/newbloguser/$newuser_key/")));
     95                                $redirect = add_query_arg( array('update' => 'add'), 'user-new.php' );
     96                        }
    8597                }
    8698        }
    8799        wp_redirect( $redirect );
     
    178190
    179191wp_enqueue_script('wp-ajax-response');
    180192wp_enqueue_script('user-profile');
     193wp_enqueue_script('user-new');
     194wp_enqueue_script('jquery-ui-autocomplete');
    181195
    182196require_once ('admin-header.php');
    183197
     
    265279<table class="form-table">
    266280        <tr class="form-field form-required">
    267281                <th scope="row"><label for="adduser-email"><?php echo $label; ?></label></th>
    268                 <td><input name="email" type="text" id="adduser-email" value="" /></td>
     282                <td><input name="email" type="text" id="adduser-email" value="" /><ul id="add-to-blog-users"></ul></td>
    269283        </tr>
    270284        <tr class="form-field">
    271285                <th scope="row"><label for="adduser-role"><?php _e('Role'); ?></label></th>
  • wp-admin/css/wp-admin.dev.css

     
    892892        margin: 0;
    893893}
    894894
     895#wpcontent input[type="text"].ajax-loading {
     896        background: transparent url('../images/loading.gif') no-repeat right center;
     897        visibility: visible;
     898}
    895899
     900ul#add-to-blog-users {
     901        margin: 0 0 0 14px;
     902}
     903
     904form#adduser ul.ui-autocomplete {
     905        padding: 0;
     906        margin: 0;
     907        list-style: none;
     908        position: absolute;
     909        z-index: 10000;
     910        border-width: 1px;
     911        border-style: solid;
     912
     913        background-color: #ffffff;
     914        border-color: gray;
     915}
     916
     917form#adduser .ui-widget-content {
     918        background: #ececec;
     919}
     920
     921form#adduser .ui-widget-content li {
     922        padding: 2px 5px;
     923        white-space: nowrap;
     924        text-align: left;
     925        color: #101010;
     926}
     927
     928form#adduser .ui-widget-content li a {
     929        display: block;
     930        height: 100%;
     931        padding: 2px 5px;
     932        color: #333;
     933}
     934
     935form#adduser .ui-widget-content li a.ui-state-hover {
     936        background-color: #f0f0b8;
     937}
     938
     939form#adduser a.remove {
     940        margin: 6px 0pt 0pt -12px;
     941        cursor: pointer;
     942        width: 10px;
     943        height: 10px;
     944        display: block;
     945        float: left;
     946        text-indent: -9999px;
     947        overflow: hidden;
     948        position: absolute;
     949        background: transparent url(../images/xit.gif) no-repeat;
     950}
     951
     952form#adduser a.remove:hover {
     953        background: transparent url(../images/xit.gif) no-repeat -10px 0;
     954}
     955
     956
    896957/*------------------------------------------------------------------------------
    897958  3.0 - Actions
    898959------------------------------------------------------------------------------*/