WordPress.org

Plugin Directory

Changeset 345382 for wordpress-importer


Ignore:
Timestamp:
02/14/11 15:30:19 (3 years ago)
Author:
duck_
Message:

Better UI/UX for author import, creation and mapping

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wordpress-importer/trunk/wordpress-importer.php

    r344748 r345382  
    66Author: wordpressdotorg 
    77Author URI: http://wordpress.org/ 
    8 Version: 0.3-beta8 
     8Version: 0.3-rc1 
    99License: GPL version 2 or later - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html 
    1010*/ 
     
    4141 
    4242    // information to import from WXR file 
     43    var $version; 
    4344    var $authors = array(); 
    4445    var $posts = array(); 
     
    144145        } 
    145146 
     147        $this->version = $import_data['version']; 
    146148        $this->get_authors_from_import( $import_data ); 
    147149        $this->posts = $import_data['posts']; 
     
    201203        } 
    202204 
    203         if ( $import_data['version'] > $this->max_wxr_version ) { 
     205        $this->version = $import_data['version']; 
     206        if ( $this->version > $this->max_wxr_version ) { 
    204207            echo '<div class="error"><p><strong>'; 
    205208            printf( __( 'This WXR file (version %s) may not be supported by this version of the importer. Please consider updating.', 'wordpress-importer' ), esc_html($import_data['version']) ); 
     
    288291    function author_select( $n, $author ) { 
    289292        _e( 'Import author:', 'wordpress-importer' ); 
    290         echo ' <strong>' . esc_html( $author['author_display_name'] . ' (' . $author['author_login'] . ')' ) . '</strong><br />'; 
    291  
    292         if ( $this->allow_create_users() ) { 
    293             _e( 'Create new user with login name', 'wordpress-importer' ); 
    294             echo ' <input type="text" name="user_new['.$n.']" value="'. esc_attr( sanitize_user( $author['author_login'], true ) ) .'" /><br />'; 
    295         } 
    296  
    297         _e( 'Map to existing user', 'wordpress-importer' ); 
     293        echo ' <strong>' . esc_html( $author['author_display_name'] ); 
     294        if ( $this->version != '1.0' ) echo ' (' . esc_html( $author['author_login'] ) . ')'; 
     295        echo '</strong><br />'; 
     296 
     297        if ( $this->version != '1.0' ) 
     298            echo '<div style="margin-left:18px">'; 
     299 
     300        $create_users = $this->allow_create_users(); 
     301        if ( $create_users ) { 
     302            if ( $this->version != '1.0' ) { 
     303                _e( 'or create new user with login name:', 'wordpress-importer' ); 
     304                $value = ''; 
     305            } else { 
     306                _e( 'as a new user:', 'wordpress-importer' ); 
     307                $value = esc_attr( sanitize_user( $author['author_login'], true ) ); 
     308            } 
     309 
     310            echo ' <input type="text" name="user_new['.$n.']" value="'. $value .'" /><br />'; 
     311        } 
     312 
     313        if ( ! $create_users && $this->version == '1.0' ) 
     314            _e( 'assign posts to an existing user:', 'wordpress-importer' ); 
     315        else 
     316            _e( 'or assign posts to an existing user:', 'wordpress-importer' ); 
    298317        wp_dropdown_users( array( 'name' => "user_map[$n]", 'multi' => true, 'show_option_all' => __( '- Select -', 'wordpress-importer' ) ) ); 
    299318        echo '<input type="hidden" name="imported_authors['.$n.']" value="' . esc_attr( $author['author_login'] ) . '" />'; 
     319 
     320        if ( $this->version != '1.0' ) 
     321            echo '</div>'; 
    300322    } 
    301323 
     
    308330        if ( ! isset( $_POST['imported_authors'] ) ) 
    309331            return; 
     332 
     333        $create_users = $this->allow_create_users(); 
    310334 
    311335        foreach ( (array) $_POST['imported_authors'] as $i => $old_login ) { 
     
    319343                    $this->author_mapping[$old_login] = $user->ID; 
    320344                } 
    321             } else if ( $this->allow_create_users() && ! empty($_POST['user_new'][$i]) ) { 
    322                 $login = sanitize_user( $_POST['user_new'][$i], true ); 
    323                 $user_id = username_exists( $login ); 
    324                 if ( ! $user_id ) { 
     345            } else if ( $create_users ) { 
     346                if ( ! empty($_POST['user_new'][$i]) ) { 
     347                    $user_id = wp_create_user( $_POST['user_new'][$i], wp_generate_password() ); 
     348                } else if ( $this->version != '1.0' ) { 
    325349                    $user_data = array( 
    326                         'user_login' => $login, 
     350                        'user_login' => $old_login, 
    327351                        'user_pass' => wp_generate_password(), 
    328352                        'user_email' => isset( $this->authors[$old_login]['author_email'] ) ? $this->authors[$old_login]['author_email'] : '', 
Note: See TracChangeset for help on using the changeset viewer.