Importing Posts Check if user exists already
-
Hello,
After using this plugin for a while it got to the point when importing several .xml backups from a site required a lot of time assigning the posts to a author when the author was identical from both sites.
I made a change to the plugin itself to ensure that this checked if the user existed within the current pool and then selecting that automatically without requiring any human input unless they don’t exist. Saved me a fair bit of time and taught it would be useful for you guys to have this change if your importing large number of posts from many authors.
The code is found from line 298 in wordpress-importer.php
function author_select( $n, $author ) { _e( 'Import author:', 'wordpress-importer' ); echo ' <strong>' . esc_html( $author['author_display_name'] ); if ( $this->version != '1.0' ) echo ' (' . esc_html( $author['author_login'] ) . ')'; echo '</strong><br />'; if ( $this->version != '1.0' ) echo '<div style="margin-left:18px">'; $create_users = $this->allow_create_users(); if ( $create_users ) { if ( $this->version != '1.0' ) { _e( 'or create new user with login name:', 'wordpress-importer' ); $value = ''; } else { _e( 'as a new user:', 'wordpress-importer' ); $value = esc_attr( sanitize_user( $author['author_login'], true ) ); } echo ' <input type="text" name="user_new['.$n.']" value="'. $value .'" /><br />'; } if ( ! $create_users && $this->version == '1.0' ) _e( 'assign posts to an existing user:', 'wordpress-importer' ); else _e( 'or assign posts to an existing user:', 'wordpress-importer' ); if ( username_exists( esc_attr( $author['author_login'] ) ) ){ wp_dropdown_users( array( 'name' => "user_map[$n]", 'multi' => true, 'show_option_all' => __( '- Select -', 'wordpress-importer' ), 'selected'=> get_user_by( 'login', esc_attr($author['author_login']) )->ID ) ); }else{ wp_dropdown_users( array( 'name' => "user_map[$n]", 'multi' => true, 'show_option_all' => __( '- Select -', 'wordpress-importer' ) ) ); } echo '<input type="hidden" name="imported_authors['.$n.']" value="' . esc_attr( $author['author_login'] ) . '" />'; if ( $this->version != '1.0' ) echo '</div>'; }
Hope this helps,
**– Note, this adds more server overhead for importing posts –**
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Importing Posts Check if user exists already’ is closed to new replies.