<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[6559] sites/trunk/wordpress.org/public_html/wp-content/plugins: WP.org: Open-source dotorg importer.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="http://meta.trac.wordpress.org/changeset/6559">6559</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"http://meta.trac.wordpress.org/changeset/6559","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>obenland</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2018-02-06 23:07:30 +0000 (Tue, 06 Feb 2018)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>WP.org: Open-source dotorg importer.
It's an extension of the existing WordPress Importer plugin, mapping users to wp.org users across the network.
Props nacin.</pre>
<h3>Added Paths</h3>
<ul>
<li>sites/trunk/wordpress.org/public_html/wp-content/plugins/wordpress-importer-map-users/</li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginswordpressimportermapusersclasswordpressmapusersimportphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/wordpress-importer-map-users/class-wordpress-map-users-import.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginswordpressimportermapuserswordpressimportermapusersphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/wordpress-importer-map-users/wordpress-importer-map-users.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginswordpressimportermapusersclasswordpressmapusersimportphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: sites/trunk/wordpress.org/public_html/wp-content/plugins/wordpress-importer-map-users/class-wordpress-map-users-import.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/wordpress-importer-map-users/class-wordpress-map-users-import.php (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/wordpress-importer-map-users/class-wordpress-map-users-import.php 2018-02-06 23:07:30 UTC (rev 6559)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,220 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+/**
+ * User mapping class.
+ *
+ * @package WPImporterMapUsers
+ */
+
+/**
+ * Class WordPress_Map_Users_Import
+ */
+class WordPress_Map_Users_Import extends WP_Import {
+
+ /**
+ * The schema for mapping old authors to new authors.
+ *
+ * @var array
+ */
+ public $author_mapping = [];
+
+ /**
+ * Authors that could not be mapped.
+ *
+ * @var array
+ */
+ protected $unmatched_authors = [];
+
+ /**
+ * Displays an introductory text and an upload form.
+ */
+ public function greet() {
+ echo '<div class="narrow">';
+ echo '<p>' . esc_html__( 'Howdy! Upload your WordPress eXtended RSS (WXR) file and we’ll import the posts, pages, comments, custom fields, categories, and tags into this site.', 'wordpress-importer' ) . '</p>';
+ echo '<p>' . esc_html__( 'Choose a WXR (.xml) file to upload, then click Upload file and import.', 'wordpress-importer' ) . '</p>';
+ wp_import_upload_form( 'admin.php?import=wordpress-user-map&step=1' );
+ echo '</div>';
+ }
+
+ /**
+ * Displays pre-import options, author importing/mapping and option to fetch attachments.
+ */
+ public function import_options() {
+ $this->get_author_mapping();
+
+ $matched = count( $this->authors ) - count( $this->unmatched_authors );
+ ?>
+ <form action="<?php echo esc_url( admin_url( 'admin.php?import=wordpress-user-map&step=2' ) ); ?>" method="post">
+ <?php wp_nonce_field( 'import-wordpress' ); ?>
+ <input type="hidden" name="import_id" value="<?php echo esc_attr( $this->id ); ?>"/>
+
+ <?php if ( $this->unmatched_authors ) : ?>
+ <h3><?php esc_html_e( 'Map Authors' ); ?></h3>
+ <script>
+ jQuery( function( $ ) {
+ $( '.same-name' ).change( function() {
+ var checkbox = $( this );
+
+ if ( checkbox.prop( 'checked' ) ) {
+ checkbox.parent().prev().val( checkbox.attr( 'value' ) );
+ } else if ( checkbox.parent().prev().val() === checkbox.attr( 'value' ) ) {
+ checkbox.parent().prev().val( '' );
+ }
+ } );
+
+ $( '.gimme-a-box' ).change( function() {
+ var checked = $( this ).prop( 'checked' );
+
+ $( '.map-users' ).toggle( ! checked );
+ $( '.freeform-map' ).toggle( checked );
+ } );
+ } );
+ </script>
+ <p>
+ <?php
+ if ( $matched ) :
+ /* translators: Number of matched authors. */
+ printf( esc_html( _n( 'We were able to match %s author to a WordPress.org account using email addresses.', 'We were able to match %s authors to a WordPress.org account using email addresses.', $matched ) ), esc_html( $matched ) );
+ else :
+ esc_html_e( 'We couldn’t find any users to match. You’ll have to do it live.', 'wordpress-importer' );
+ endif; // $matched.
+ ?>
+ </p>
+ <strong><?php esc_html_e( 'Specify a catch-all user for any users that do not have a username specified below:', 'wordpress-importer' ); ?></strong>
+ <?php
+ wp_dropdown_users( [
+ 'name' => 'user_catchall',
+ 'show_option_all' => __( '- Select -', 'wordpress-importer' ),
+ ] );
+ ?>
+
+ <div class="map-users">
+ <p><?php esc_html_e( 'Map individual users:', 'wordpress-importer' ); ?></p>
+ <?php
+ foreach ( $this->unmatched_authors as $author ) :
+ $format = $author['author_display_name'] ? '%s (%s)' : '%s';
+ ?>
+ <p>
+ <strong><?php printf( esc_html( $format ), esc_html( $author['author_login'] ), esc_html( $author['author_display_name'] ) ); ?></strong><br />
+ <?php esc_html_e( 'Map to WP.org username:', 'wordpress-importer' ); ?>
+ <input type="text" name="unmatched_authors[<?php echo esc_attr( $author['author_id'] ); ?>]" />
+ <label>
+ <input value="<?php echo esc_attr( $author['author_login'] ); ?>" class="same-name" type="checkbox" />
+ <?php esc_html_x( 'Same', 'map to same author', 'wordpress-importer' ); ?>
+ </label>
+ </p>
+ <?php endforeach; // $this->unmatched_authors. ?>
+ </div>
+ <p>
+ <label>
+ <input type="checkbox" class="gimme-a-box" name="freeform"/>
+ <?php esc_html_e( 'Nah man, let me freestyle this.', 'wordpress-importer' ); ?>
+ </label>
+ </p>
+ <div class="freeform-map" style="display:none">
+ <p class="description"><?php echo wp_kses_post( __( 'One mapping per line. Use the format <code>old username > new username</code>', 'wordpress-importer' ) ); ?></p>
+ <textarea class="code large-text" rows="30" cols="40" name="freeform_user_map"></textarea>
+ </div>
+ <?php endif; // $this->unmatched_authors. ?>
+
+ <?php if ( $this->allow_fetch_attachments() ) : ?>
+ <h3><?php esc_html_e( 'Import Attachments', 'wordpress-importer' ); ?></h3>
+ <p>
+ <input type="checkbox" value="1" name="fetch_attachments" id="import-attachments"/>
+ <label for="import-attachments"><?php esc_html_e( 'Download and import file attachments', 'wordpress-importer' ); ?></label>
+ </p>
+ <?php endif; ?>
+
+ <?php submit_button(); ?>
+ </form>
+ <?php
+ }
+
+ /**
+ * Maps authors.
+ *
+ * @access protected
+ *
+ * @global wpdb $wpdb The WordPress database class.
+ */
+ public function get_author_mapping() {
+ global $wpdb;
+
+ $old_emails_by_login = [];
+ $old_logins_by_email = [];
+ $old_logins_by_id = [];
+ $logins_by_lowercase_login = [];
+
+ foreach ( $this->authors as $author_login => $author ) {
+ $old_logins_by_email[ $author['author_email'] ] = $author_login; // Case sensitive result.
+ $old_logins_by_id[ $author['author_id'] ] = $author_login;
+ $logins_by_lowercase_login[ strtolower( $author_login ) ] = $author_login;
+
+ $old_emails_by_login[ strtolower( $author_login ) ] = $author['author_email']; // Case insensitive lookup.
+ }
+
+ $prepared_emails = array_map( 'esc_sql', $old_emails_by_login );
+ $prepared_emails = "'" . implode( "', '", $prepared_emails ) . "'";
+
+ // phpcs:disable WordPress.VIP, WordPress.CSRF.NonceVerification.NoNonceVerification
+ // phpcs:ignore WordPress.WP.PreparedSQL.NotPrepared
+ $old_emails_with_match = $wpdb->get_results( "SELECT user_email, ID FROM $wpdb->users WHERE user_email IN ($prepared_emails) ORDER BY ID", OBJECT_K );
+ foreach ( $old_emails_with_match as $user_email => $user ) {
+ $this->author_mapping[ $old_logins_by_email[ $user_email ] ] = $user->ID;
+ }
+
+ $this->unmatched_authors = array_diff_key( $this->authors, $this->author_mapping );
+ ksort( $this->unmatched_authors );
+
+ if ( ! isset( $_POST['user_catchall'] ) ) {
+ return;
+ }
+
+ $catchall_user_id = absint( $_POST['user_catchall'] );
+
+ $username_mapping = [];
+ if ( ! empty( $_POST['freeform'] ) ) {
+ $raw_mapping = $_POST['freeform_user_map'];
+ $raw_mapping = explode( "\n", $raw_mapping );
+
+ foreach ( $raw_mapping as $line ) {
+ if ( empty( $line ) ) {
+ continue;
+ }
+
+ $line = array_map( 'trim', explode( '>', $line, 2 ) );
+ $username_mapping[ $line[0] ] = $line[1];
+ }
+ } else {
+ $raw_mapping = $_POST['unmatched_authors'];
+ foreach ( $raw_mapping as $old_id => $new_name ) {
+ $username_mapping[ $old_logins_by_id[ $old_id ] ] = $new_name;
+ }
+ }
+
+ // $username_mapping is arrays of array( 'old username' => 'new username' ).
+ $new_usernames_prepared = array_map( 'esc_sql', $username_mapping );
+ $new_usernames_prepared = "'" . implode( "', '", $new_usernames_prepared ) . "'";
+
+ // phpcs:ignore WordPress.WP.PreparedSQL.NotPrepared
+ $new_usernames_with_match = $wpdb->get_results( "SELECT user_login, ID FROM $wpdb->users WHERE user_login IN ($new_usernames_prepared) ORDER BY ID", OBJECT_K );
+ $new_usernames_with_match = array_change_key_case( $new_usernames_with_match );
+
+ // phpcs:enable
+
+ foreach ( $username_mapping as $old_username => $new_username ) {
+ $old_username = strtolower( $old_username );
+
+ if ( isset( $new_usernames_with_match[ strtolower( $new_username ) ] ) && isset( $logins_by_lowercase_login[ $old_username ] ) ) {
+ $this->author_mapping[ $logins_by_lowercase_login[ $old_username ] ] = $new_usernames_with_match[ $new_username ]->ID;
+ }
+ }
+
+ if ( $catchall_user_id ) {
+ foreach ( $this->unmatched_authors as $old_username => $author ) {
+ if ( ! isset( $this->author_mapping[ $old_username ] ) ) {
+ $this->author_mapping[ $old_username ] = $catchall_user_id;
+ }
+ }
+ }
+ }
+}
</ins></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginswordpressimportermapuserswordpressimportermapusersphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: sites/trunk/wordpress.org/public_html/wp-content/plugins/wordpress-importer-map-users/wordpress-importer-map-users.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/wordpress-importer-map-users/wordpress-importer-map-users.php (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/wordpress-importer-map-users/wordpress-importer-map-users.php 2018-02-06 23:07:30 UTC (rev 6559)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,36 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+/**
+ * Plugin Name: Importing to WordPress.org
+ * Description: A plugin that extends the WordPress Importer to map users to WordPress.org accounts by matching email addresses.
+ * Author: Andrew Nacin
+ *
+ * @package WPImporterMapUsers
+ */
+
+if ( ! defined( 'WP_LOAD_IMPORTERS' ) ) {
+ return;
+}
+
+/**
+ * Sets up the plugin.
+ *
+ * @globals WordPress_Map_Users_Import $wordpress_map_import
+ */
+function wordpress_importer_map_users_init() {
+ if ( ! class_exists( 'WP_Import' ) ) {
+ return;
+ }
+ global $wordpress_map_import;
+
+ require_once dirname( __FILE__ ) . '/class-wordpress-map-users-import.php';
+
+ $wordpress_map_import = new WordPress_Map_Users_Import();
+
+ register_importer(
+ 'wordpress-user-map',
+ 'WordPress.org',
+ 'Map users to WP.org users based on email-address during a WordPress import (good for importing from WP.org or WP.com)',
+ [ $wordpress_map_import, 'dispatch' ]
+ );
+}
+add_action( 'admin_init', 'wordpress_importer_map_users_init' );
</ins></span></pre>
</div>
</div>
</body>
</html>