<p><?php _e( 'To make it easier for you to edit and save the imported content, you may want to reassign the author of the imported item to an existing user of this site. For example, you may want to import all the entries as <code>admin</code>s entries.', 'wordpress-importer' ); ?></p>

<p><?php printf( __( 'If a new user is created by WordPress, a new password will be randomly generated and the new user&#8217;s role will be set as %s. Manually changing the new user&#8217;s details will be necessary.', 'wordpress-importer' ), esc_html( get_option('default_role') ) ); ?></p>

// We need to find unique values of author names, while preserving the order, so this function emulates the unique_value(); php function, without the sorting.

175

$temp = $this->allauthornames;

176

$authors[0] = array_shift($temp);

177

$y = count($temp) + 1;

178

for ($x = 1; $x < $y; $x ++) {

179

$next = array_shift($temp);

180

if (!(in_array($next, $authors)))

181

array_push($authors, $next);

182

}

183

184

return $authors;

185

}

186

187

function get_authors_from_post() {

188

global $current_user;

189

190

// this will populate $this->author_ids with a list of author_names => user_ids

191

192

foreach ( (array) $_POST['author_in'] as $i => $in_author_name ) {

193

194

if ( !empty($_POST['user_select'][$i]) ) {

195

// an existing user was selected in the dropdown list

196

$user = get_userdata( intval($_POST['user_select'][$i]) );

197

if ( isset($user->ID) )

198

$this->author_ids[$in_author_name] = $user->ID;

199

}

200

elseif ( $this->allow_create_users() ) {

201

// nothing was selected in the dropdown list, so we'll use the name in the text field

202

203

$new_author_name = trim($_POST['user_create'][$i]);

204

// if the user didn't enter a name, assume they want to use the same name as in the import file

205

if ( empty($new_author_name) )

206

$new_author_name = $in_author_name;

207

208

$user_id = username_exists($new_author_name);

209

if ( !$user_id ) {

210

$user_id = wp_create_user($new_author_name, wp_generate_password());

211

}

212

213

if ( !is_wp_error( $user_id ) ) {

214

$this->author_ids[$in_author_name] = $user_id;

215

}

216

}

217

218

// failsafe: if the user_id was invalid, default to the current user

219

if ( empty($this->author_ids[$in_author_name]) ) {

220

$this->author_ids[$in_author_name] = intval($current_user->ID);

221

}

222

}

223

224

}

225

226

function wp_authors_form() {

227

?>

228

<h2><?php _e('Assign Authors', 'wordpress-importer'); ?></h2>

229

<p><?php _e('To make it easier for you to edit and save the imported posts and drafts, you may want to change the name of the author of the posts. For example, you may want to import all the entries as <code>admin</code>s entries.', 'wordpress-importer'); ?></p>

230

<?php

231

if ( $this->allow_create_users() ) {

232

echo '<p>'.__('If a new user is created by WordPress, a password will be randomly generated. Manually change the user&#8217;s details if necessary.', 'wordpress-importer')."</p>\n";