Automatically Assigning Users with WordPress Importer

Recently, one of our clients enlisted our help with migrating thousands of WordPress posts to another server. At 515 Media, we like to use the official WordPress Importer plugin for such assignments – it reliably preserves all content formatting, and works perfectly in tandem with WordPress’ native XML generator.

Here’s the problem…

As much as we like the WordPress Importer, we ran into a frustrating limitation of the software this time around. You see, our client’s posts were authored by nearly 300 different user accounts, and the WordPress Importer tool did not automatically map these accounts to our new database.

Instead, the plugin will prompt you to create associations for each user by hand:

WordPress Importer

As you can imagine, this is quite a laborious process if you’re dealing with a database containing dozens or hundreds of published users! Our hearts go out to those of you who have had to map this many fields by hand – we’ve definitely been there before!

That’s why we came up with a simple JavaScript-based solution to completely automate the user assignment process. Today, we would like to share our code with all of you:

Our solution

// ==UserScript==
// @name         Import WordPress - Auto Assign Authors
// @namespace    https://515.media
// @version      0.1
// @description  Quickly fill out post authors
// @author       Eric Black of 515 Media
// @include       */wp-admin/admin.php?import=wordpress*
// @grant        none
// ==/UserScript==
var $ = window.jQuery;
$(document).ready(function() {
    $("#authors").before("<input type='button' id='auto-assign-authors' value='Automatically assign authors'>");
    $("#auto-assign-authors").click(function() {
        var missing = 0;
        $("#authors > li").each(function() {
            var full_author = $("strong",this).text();
            var this_author = full_author.substr(0, full_author.indexOf(' ('));
            var is_missing = true;
            $("select option",this).each(function(){
                if ($(this).text() == this_author) {
                    $(this).attr('selected', true);
                    is_missing = false;
                    return false;
                }
            });
            if (is_missing) missing++;
        });
        $("#auto-assign-authors").after("<p>Finished! Total fields without matches: " + missing + "</p>");
    });
});

 

You may install our code to any major web browser with an extension that manages userscripts. We recommend TamperMonkey for this purpose (Firefox / Chrome).

Simply choose to “Create a New Script” and paste our code into the TamperMonkey editor.

The next time WordPress Importer prompts you for user assignment, you will find a new button at the top of the page to fully automate the procedure:

In a matter of seconds, our script will populate every field without any further input.

Plus, in the event that some of your database’s usernames don’t quite match those from your imported XML, our script will tell you how many fields are still blank after the operation is complete (# of unmatched fields.)

You are more than welcome to use this script for free and adapt it to your needs. (We only ask that you don’t claim it as your own or try to profit from it!)

If you have any questions about the installation process or general usage, feel free to get in touch with us today. Also, don’t forget to check out our managed hosting plans if you want our help developing custom scripts for your own projects!

Our First WordPress Theme Is Now Available

RedPoint has officially been released!

WordPress Theme

The wait has been well worth it! We are proud to introduce RedPoint, our first free WordPress theme fully designed and developed in-house. Named after a challenging rock-climbing technique, this theme is durable, flashy, extremely customizable and ready to be tailored to your business.

A child theme of WordPress’ own Twenty-Nineteen theme (which currently has over 1 million downloads), RedPoint serves as a framework that you can rapidly build upon. That makes this theme ideal for authors, bloggers, agents, physicians…  In short, any small to medium-sized online brand.

If you are ready for your business website to stand out from other WordPress sites, this is a great place to start. You can download the latest release of the RedPoint framework below for use in your website free of charge or see a demo!

See Demo   Download Now

NOTE: If you would like to use the styles from our demo site, you must download this redpoint_custom attachment and place the folder in /wp-content/themes/, sibling to twentynineteen_redpoint!

RedPoint comes with a number of fantastic features including:

  • Powerful layout controls
  • Assign “Featured Pages” to appear on the top or bottom of all other pages
  • Easily select your theme colors
  • Easily override your theme colors on specific pages
  • Ability to choose custom fonts from Google…or use your own!
  • Flexible Mega Menus baked right into the WordPress menu editor
  • Enhanced with Advanced Custom Fields
  • Define background images on a per-page basis
  • Mix full-width and normal content within the same page
  • Lean, clean CSS – enhanced with SASS

As a result, some of our clients are already reaping the benefits of a more durable and customizable site. Contact us for help in installing or utilizing this amazing framework for your business site!