Monthly Archives: February 2012

Salvaging content from a corrupted WordPress installation

Yesterday a friend emailed me asking for help. Her old WP installation had become corrupt – through a bad plugin or something – and she couldn’t bring it back to life. So she decided to start fresh, with a new WP installation on a new server. She wanted to know if it was possible to salvage her old posts, which (as she could see in PHPMyAdmin) were still in the old database. Here’s a copy of the email I wrote to her, on the off chance that it helps someone else.

Note that this technique should be used as a last resort. Generally, WP installations can be saved with a little bit of know-how and elbow grease. Also note that it assumes that you’re switching domain names in the process. Also note that I wrote this in 10 minutes, off the top of my head – amendments or corrections welcome.

===

For shorthand:
WPA is your old, corrupted installation
WPB is a brand new, totally empty installation of WP
WPC is your new production installation, on the new domain

The first step is to get your content out of WPA and into WPB. WPB should be a totally new, throwaway installation – a local installation would be ideal, but a fresh one on your webhost would be fine. (This should NOT be the same as WPC!!) Visit your WPA database (using PHPMyAdmin or whatever tool you’ve got), and export the following tables:
wp_posts
wp_postmeta
wp_comments
wp_commentmeta

In PHPMyAdmin, that usually just means checking the boxes next to those tables, and clicking an Export button somewhere in the interface.

Next, use PHPMyAdmin to view the database of WPB. Drop/delete the four tables corresponding to the ones you exported (wp_posts, wp_postmeta, wp_comments, wp_commentmeta).

Once these four tables are dropped, use PHPMyAdmin to import the versions you exported from WPA into WPB.

At this point, the posts should be safe and sound in WPB. You can verify by visiting WPB in your web browser. The next step is to use the WP export feature of WPB to get the posts out, in a format that WPC will be able to understand. Go to wp-admin on WPB > Tools > Export. Export everything to a local file. Then go to WPC Dashboard > Tools > Import (you may have to install the WP importer plugin) and import. This process should pull your old posts and pages in, without overwriting anything currently in your system.

It’s also a nice idea to set up a redirect from your old domain to your new one. (That will ensure that links to your old blog by other sites will continue to work, as well as any times you may have linked to your own old content.) Two steps:
1) At your domain registrar, make sure that your old WPA domain points to your WPC installation; this usually means putting the WPC domain as the CNAME attribute on the DNS tab.
2) FTP to WPC, and look for a file in the main WP directory called .htaccess (you may have to enable View Hidden Files or something like that). Near the top of the file, put the following lines:

[code]RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^myOLDdomain.com$ [NC]
RewriteRule ^.*$ http://myNEWdomain.com%{REQUEST_URI} [R=301,L][/code]

Make sure to replace myOLDdomain and myNEWdomain with the relevant domain names. This will redirect any request to myolddomain.com to the corresponding URL on mynewdomain.com, meaning that all your old permalinks should continue to work.

Using init callbacks with TinyMCE and wp_editor() in WordPress

WordPress 3.3 introduced wp_editor(). It’s a big improvement over the earlier hacks needed to get a TinyMCE instance on the WP front end. But it broke the feature in my BuddyPress Docs that detected idle time. The problem, in short, was two-fold: my idle-detection JavaScript was loading before the editor was initialized, and it wasn’t detecting key presses inside of the TinyMCE iframe. The solution to both parts of the problem required passing callbacks to the TinyMCE initialization array, in the setup array. It took me a long time to figure out how to do this, so for posterity’s sake, here are some takeaways.

First, the code:

[code language=”php”]
function bp_docs_add_idle_function_to_tinymce( $initArray ) {
if ( bp_docs_is_bp_docs_page() ) {

$initArray[‘setup’] = ‘function(ed) {
ed.onInit.add(
function(ed) {
_initJQuery();

// Set up listeners
jQuery(‘#’ + ed.id + ‘_parent’).bind(‘mousemove’,function (evt){
_active(evt);
});

bp_docs_load_idle();

}
);

ed.onKeyDown.add(
function(ed) {
_active();
}
);
}’;
}

return $initArray;
}
add_filter( ‘tiny_mce_before_init’, ‘bp_docs_add_idle_function_to_tinymce’ );
[/code]

Some notes:

  • I’m passing a ‘setup’ parameter to the TinyMCE init array by filtering tiny_mce_before_init
  • Only do this when you’re editing a BuddyPress Doc – that’s the bp_docs_is_bp_docs_page() check. I don’t want to mess with every instance of TinyMCE on the installation.
  • The setup parameter has to be a string. This gets tricky when the string is supposed to define an unnamed JS callback, because you have to be very careful about escaping quotes. As a string, your callback has to be wrapped in quotes. Also, when WP prints the TinyMCE parameters (and when it sees that your paramater begins with the string ‘function’) it’s going to wrap it in double-quotes. After lots of messing around, I was able to get this to work by using escaped single-quotes. (If you need to double-embed quotes – like a chain of callbacks – use escaped double-quotes.)
  • Where possible, use TinyMCE’s native events. ed.onKeyDown is one of them. It allows me to call my _active() function whenever a key is pressed inside the editor.
  • There are some kinds of actions that aren’t really detectable using TinyMCE’s events. For instance, I wanted to be able to detect when someone was moving their mouse around the iframe and especially TinyMCE’s toolbar. You can see this where I’m binding my callback to mousemove in the TinyMCE _parent element.
  • _initJQuery() and bp_docs_load_idle() are my own functions that need to run after the editor has finished setting up. That’s why they, along with the bind, are called in a callback of ed.onInit – that’s the generic place to put things that need to happen once the editor is up and running.

SOPA, Media Conglomerates, and the Moral Obligation to Boycott

SOPA, in its current form, is dead. But the fight to keep the internet an open platform for communication, creativity, and commerce is far from over. Pacts like ACTA are in some ways more troubling than SOPA/PIPA, as they represent attempts of copyright extremists to do an end-run around the US Congress. (Rep. Daniel Issa has spoken about this recently.) The root problem is not a specific piece of legislation, or even a single piece of technology, but fundamental disagreements about the nature of intellectual property, the relationship between the producers and consumers of media, and the role of government regulation in shaping and enforcing worldviews (be they conservative and profit-focused, or progressive and individual-focused). The fight will continue for as long as these disagreements persist. And the copyright extremists will continue to have sway as long as they have enormous amounts of money, and as long as the political system is arranged in such a way that deep pockets dictate legislative agendas.

This conception of the problem suggests two broad strategies. First: attempt to change the political structures that allow campaign and lobbying money to play such a significant role in the legislative process. Primarily, this is an argument about campaign finance reform. For a very readable outline of the problem, as well as the sketch of a few specific strategies for combatting it, I highly recommend Lawrence Lessig’s recent book Republic, Lost. Needless to say, solving the problems of money in politics is enormously difficult and complex, so I’ll set it aside for the moment.

The strategy that I want to consider here focuses more directly on the fact that media companies are very rich, and can afford political canoodling. (Operating here on the admittedly oversimplified assumption that media companies – TV, movie, music, book publishers – are driving the legislation.) These companies get their money from the people who buy their wares. So, in theory, if everyone stopped going to the movies, buying music, watching TV, etc, then they’d have no money. In other words, a boycott.

A few days ago, I tweeted something suggestive along these lines:

When you buy music, watch TV, or see a movie, don’t forget: the makers hate the free internet & will spend huge amounts of money to kill it.

Assume that the premise here is right (namely, that the people who make media – by which I mean, those who choose which media gets created in the first place, who fund its creation, who are responsible for its distribution and marketing, etc – hate the internet as it currently stands). That means that when you make them richer by buying their stuff, you are increasing their ability to fight the internet. All things being equal, then, someone who values the open internet should not spend money in this way – that is, you’d be morally obligated to boycott.

But all things are not equal. (Such is life.) There are some factors that may mitigate the obligation to boycott:

  • How valuable is the open internet, really?

    I’m assuming that an open internet is valuable enough to defend. I may be totally wrong about this, or I may be overestimating how valuable it is. The less valuable the internet, the less obliged we are to fight against the forces that would wreck it.

  • How much collateral damage would a boycott cause?

    The supporters of SOPA/PIPA talked a lot about the zillions of Americans who make their livings working for media conglomerates. If boycotting media companies would put them all out of work and out on the street, that’d be a bad thing. Of course, this is a complete caricature. For one thing, you can (and should, and hopefully did) make the very same argument about the zillions of Internet professionals who would be harmed by stifling legislation. More importantly, it’s not as if SOPA vs non-SOPA is a zero-sum game, where media professionals all lose their jobs if SOPAesque bills don’t pass. It’s likely that piracy is not as financially harmful as these companies complain, and it’s likely that there are anti-piracy measures that would not harm Internet professionals.

    There’s another kind of collateral damage you might be worried about: the damage caused to the creative people (musicians, writers, actors) who are directly responsible for the media that people love, and the subsequent damage to the “art” itself. In addition to the general points made in the foregoing paragraph, I’ll add that this assumes that the stuff produced by these companies is worth saving. For every The Wire (or whatever your favorite piece of popular media is), there are thousands upon thousands of pieces of trash. Taking these turds out of circulation is probably a *good* thing. Moreover, new models of direct funding for quality art (think Radiohead, Louis CK, projects taking place on Kickstarter) reduce collateral damage even further.

  • How much do you value the media produced by these companies?

    If you’re a TV junkie, or you love the movies, then it’s certainly rational for you to cling to them a bit more than someone who doesn’t care about these media (see the ‘turd’ comment above).

  • How likely is it that a boycott will make a difference?

    Probably hundreds of millions of Americans are consumers of TV, movies, books, and music. For a company like NBC Universal to take notice of a boycott, much less to change corporate policies as a result of the boycott, would require huge numbers of boycotters. You might thus argue that your individual boycott would have no positive value.

    Sadly, this is at least partly true – I’m sure there are many times more people who would go to bat for their TV shows than for the kind of heady internet freedoms that intellectuals get excited about. That said, January’s blackouts demonstrated a deep dependence on the Internet for a broader swath of Americans than I might have guessed. In any case, even a single dollar kept out of media company coffers is one dollar they can’t use to fight the open internet. The “everybody else is buying media anyway” argument is the same kind of reasoning that leads to looting during blackouts. (See also Kant.)

So what does this all mean? I think that there are a couple of takeaways:

  1. I think there’s a decent case to be made for a broad boycott.
  2. Even in the absence of an organized boycott, I think there’s a decent case to be made for individuals to boycott.
  3. If you care about the internet (if you’re reading this blog post, you probably do), you cannot continue to patronize these media companies without at least recognizing the indirect effects of your actions.

This last point is the most important. Every meaningful decision that you make is an ethical trade-off, and this one is no different. When you continue to patronize media conglomerates, you are saying that what you get from them is worth the damage that you thereby do to the cause of an open internet. You may be right about the value of this trade-off, or you may be wrong, but you can’t in good faith continue to consume without at least thinking about it.

Ning nonsense is an opportunity for WordPress and BuddyPress developers

Another chapter in the Ning saga (see my previous posts on the subject): In the past few days, Ning has been sending out emails indicating that they’ll be wiping out non-premium networks in the course of the next couple weeks (see, for example, this blog post).

It’s no coincidence, of course, that I’ve gotten a number of emails in the last few days about support and/or paid consultation for Ning -> BuddyPress migrations, based on my free plugin Import From Ning. Unfortunately, I’m currently swamped with work, and I’m not available for active plugin support or for paid migration gigs related to Ning.

If you are a WordPress developer looking for work, this is a golden opportunity. For one thing, you can make a good amount of money helping folks to migrate their Ning data to BuddyPress, and generally helping to customize their BuddyPress installations. Most of the hard work is done for you: my Import From Ning plugin, while buggy and in need of some updates for recent versions of WordPress (in particular, the plugin has crummy error handling), has all of the logic you’ll need to parse Ning’s JSON files and process them for BP import. Even if you don’t know much about BuddyPress, you’ll find that the BuddyPress parts of the process are already spelled out for you. You might even learn something about BP along the way!

Furthermore, those developers who are really intrepid could take this opportunity to help the Ning/BP users more generally by taking over development on Import From Ning. If you are doing client work anyway, which may require fixing bugs and adding improvements in the plugin, why not contribute it back to the distribution version? By doing so, you’ll not only be helping to grow the BP community (and the cause of free software over proprietary services!), but you’ll be making a name for yourself as a contributor/committer to a popular plugin. In other words, it’s great publicity, and you’ll be creating a market for your services down the road.

If you are a WordPress or BuddyPress developer who is interested in receiving referrals for Ning migrations, and/or if you’re interested in making contributions to Import From Ning itself, let me know and I’ll add you to my list. (You can leave a comment below, or send me an email – boone <at> gorg <dot> es.)