Mystery WordPress/Markdown Problem: Troubleshooting [en]

[fr] Description d'un vilain problème WordPress avec PHP Markdown Extra. Certains billets refusaient de s'afficher et faisaient tout simplement planter la suite du chargement de la page (donc, pages archives incomplètes, billets disparus). J'ai résolu (plus ou moins) le problème en remplçant PHP Markdown Extra par Markdown tout court, mais je n'ai toujours pas compris le fond du problème. Ce billet donne quelques détails sur les symptômes et mes déductions.

If you’re a WordPress person and you feel like a bit of juicy troubleshooting, this one is for you. I’ve narrowed down part of the problem, but have failed to identify clearly the cause of the problem. I’ve found a workaround by replacing a plugin by another similar one, however. I’ve made screenshots so that even once this problem is fixed (hopefully very quickly) you can make sense of this post.

Symptoms:

Some posts on the VibrationsMusic website fail to display their content, or display incompletely. When this happens, the page stops loading altogether, resulting in a truncated page. (So we have vanishing posts and incomplete aborted archive pages where they should appear.) No error messages in source, HTML code just stops.

Narrowing it down:

Removing post content makes the post display OK, so I figured it had something to do with the content. Removing the PHP Markdown Extra plugin removed the problem, to. So it has something to do with a combination of certain things in the content and the PHP Markdown Extra plugin. (Removing other plugins didn’t change a thing, so I deduce from that it isn’t a plugin interaction issue.)

Using the “cut-half-out” technique I tried to narrow down the problem to a certain type of post content. At first, it seemed to be caused by either (a) HTML links in Markdown lists or (b) embedded YouTube players (<object>). However, some posts with either (a) or (b) were displaying correctly. In one faulty post, replacing the embedded YouTube video with another removed the problem.

However, it seems more subtle than that. In some cases, removing the other half of the post also removes the problem. => post length? Not really either. In a quite weird case, one post stops displaying right at the end of the content (Technorati tags and closing divs don’t appear) and if changes are made to the next post (like removing its content) then the first post displays correctly (and the second one too).

This seems (to me) to point to some problem in the query-array-manipulation area (but I don’t know how things work well enough in that department to make a more precise hypothesis).

Workaround:

I replaced the PHP Markdown Extra plugin with the “normal” Markdown plugin, and everything displays fine.

BlogCamp: Multilingual Blogging Session [en]

[fr] Mise par écrit des notes de préparation pour ma présentation hier au sujet des blogs multilingues, lors du BlogCamp à Zürich. En deux mots: il faut des gens pour faire le pont entre les îles linguistiques sur internet, et la façon dont sont conçus nos outils n'encourage pas les gens à être multingues sur leurs blogs. C'est pourtant à mon avis la formule la plus viable pour avoir de bons ponts.

I presented a session about multilingual blogging at BlogCamp yesterday in Zürich. Thanks to all of you who attended (particularly as I was competing with Xing’s Nicolas Berg!) and wrote about the session (Bruno of course, Sarah, Sandra, Maira, Jens-Rainer, Waltraut, Jokerine, Antoine…let me know if I need to add you here), and to Greg in particular for filming the session.

Although I’m rather used to giving talks, this was the first time my audience was a bloggy-geek crowd, so it was particularly exciting for me. I prepared my talk on the train between Lausanne and Bern, and unfortunately prepared way too many notes (I’m used to talking with next to no notes), so I got a bit confused at times during my presentation — and, of course, left stuff out. Here’s a rough transcript of what I prepared. Oh, and don’t forget to look at this photo of my cat Bagha from time to time to get the whole “experience”.

Steph giving her talk.
Photo by Henning

Talk notes

In the beginning there was the Big Bang. Space, time and matter came to exist. (Physicists in the audience, please forgive me for this.) We know it might end with a Big Crunch. Internet looks a bit like this Big Crunch, because it gets rid of space. With the right link to click on, the right URI, anybody can be anywhere at any time.

However, we often perceive the internet as a kind of “space”, or at least as having some sort of organisation or structure that we tend to translate into spatial terms or sensations. One way in which the internet is organised (and if you’re a good 2.0 person you’re acutely aware of this) is communities.

Communities are like gravity wells: people tend to stay “in” them. It very easy to be completely oblivious to what is going on in other communities. Barrier to entry: culture. Language is part of a culture, and even worse, it’s the vehicle for communication.

What is going on in the other languageospheres? I know almost nothing of what’s going on in the German-speaking blogosphere. The borders on the internet are linguistic. How do we travel? There is no digital equivalent of walking around town in a foreign country without understanding a word people say. Note: cultural divides are a general problem — I’m trying to focus here on one of the components of the cultural divide: language.

Who speaks more than one language? In the audience, (almost) everyone. This is doubly not surprising:

  • Switzerland is a multilingual country
  • this is the “online” crowd (cosmopolitan, highly educated, English-speaking — though English is not a national language here)

Two episodes that made me aware of how strong language barriers can be online, and how important it is to encourage people to bridge the language barriers:

  • launching Pompage.net because at the time of the browser upgrade initiative I realised that many French-speaking people didn’t have access to all the material that was available in Anglophonia, because they just didn’t understand English well enough;
  • the very different feelings bloggers had about Loïc Le Meur when he first started being active in the blogosphere, depending on if they were French- or English-speaking, particularly around the time of the Ublog story.

A few questions I asked the audience (mini-survey):

  • who reads blogs in more than one language? (nearly everyone)
  • who blogs in more than one language?
  • who has different blogs for different languages?
  • who has one blog with translated content in both languages? (two courageous people)
  • who has one blog with posts in various languages, mixed? (half a dozen people if my memory serves me right)
  • who feels they act as a bridge between languages?

So, let’s have a look at a few multilingual blogging issues (from the perspective of a biased bilingual person). Despite the large number of people out there who are comfortable writing in more than one language (and the even larger number who are more or less comfortable reading in more than one language), and the importance of bridging cultural/linguistic gaps, blogging tools still assume you are going to be blogging in one language (even though it is now accepted that this language may not be English).

What strategies are there for using more than one language on a blog, or being a good bridge? Concentrate first on strategy and then worry about technical issues. Usage is our best hope to make tool development evolve, here.

A. Two (or more) separate blogs

  • not truly “multilingual blogging”, it’s “monolingual blogging” twice
  • caters well to monolingual audiences
  • not so hot for multilingual audiences: must follow multiple blogs, with unpredictable duplication of content

B. Total translation

  • a lot of work! goes against the “low activation energy for publiction” thing that makes blogging work (=> less blogging)
  • good for multilingual and monolingual audiences
  • technical issues with non-monolingual page (a web page is assumed to be in a single language…)

C. Machine translation!

  • getting rid of the “effort” that makes B. fail as a large-scale solution, but retaining the benefiits!
  • problem: machine translation sucks
  • too imprecise, we don’t want more misunderstanding

D. A single blog, more than one language (my solution)

  • easy for the blogger, who just chooses the language to blog in depending on mood, bridge requirements, etc.
  • good for the right multilingual audience
  • technical issues with non-monolingual pages
  • how do you take care of monolingual audiences? provide a summary in the non-post language

“Monolingual” audiences are often not 100% monolingual. If the number of people who are perfectly comfortable writing in more than one language is indeed rather small, many people have some “understanding” skills in languages other than their mother tongue. Important to reach out to these skills.

For example, I’ve studied German at school, but I’m not comfortable enough with it to read German-language blogs. However, if I know that a particular post is going to be really interesting to me, I might go through the trouble of reading it, maybe with the help of some machine translation, or by asking a German-speaking friend.

A summary of the post in the language it is not written in can help the reader decide if it’s worth the trouble. Writing in a simple language will help non-native speakers understand. Making sure the number of typos and grammar mistakes are minimal will help machine translation be helpful. And machine translation, though it is often comical, can help one get the gist of what the post is about.

Even if the reader is totally helpless with the language at hand, the summary will help him know what he’s missing. Less frustrating. And if it’s too frustrating, then might give motivation to hunt down a native speaker or do what’s required to understand what the post is about.

Other bridging ideas:

  • translation networks (translate a post or two a month from other bloggers in the network, into your native language)
  • translation portal (“news of the world” with editorial and translation work done) — check out Blogamundo

Problem I see: bloggers aren’t translators. Bloggers like writing about their own ideas, they’re creative people. Translating is boring — and a difficult task.

Some more techy thoughts:

  • use the lang= attribute, particularly when mixing languages on a web page (and maybe someday tools will start parsing that)
  • CSS selectors to make different languages look different (FR=pink, EN=blue for example)
  • language needs to be a post (or even post element) attribute in blogging tools
  • WordPress plugins: language picker Polyglot and Basic Bilingual
  • excerpt in another language: what status in RSS/atom? Part of the post content or not? Can RSS/atom deal with more than one language in a feed, or do they assume “monolingualism”?
  • indicating the language of the destination page a link points to

Extra reading

The nice thing about having a blog is that you can dive back into time and watch your thinking evolve or take place. Here is a collection of posts which gravitate around language issues (in a “multilingual” sense). The Languages/Linguistics category is a bit wider than that, however.

Blogging in more than one language:

About the importance of language, etc.:

Promote Comments Plugin Idea [en]

[fr] Une idée de plugin que m'a soufflée Bruno Giussani: pouvoir "promouvoir" un commentaire et l'intégrer sans peine au contenu du billet.

A few days before LIFT’07, I had dinner with Bruno Giussani, who now happens to be one of the lucky people to live in beautiful Lausanne.

Amongst other things, he told of his frustrations with current blogging software (he’s using TypePad) and how the perfect tool didn’t seem to exist. I guess one simple reason this is so is that “perfect” means different things to different people.

I use WordPress, like it, and generally recommend it around me, because to my mind it’s the most complete and user-friendly platform out there, and because the plugin architecture allows for nearly any functionality to be added to it if somebody takes the trouble to code it.

Bruno shared with me one shortcoming of today’s blogging technology that he and Robert Scoble were talking about at LIFT last year (so this is not a “new” idea). Here is a write-up of this idea (with his permission of course), with a few implementation and interface details, in the hope that someone out there will pick it up and write the plugin. (I’ve heard enough people recently asking for plugin ideas to work their mad coding skillz on…)

Here’s the basic idea: there are often valuable contributions in the comments of a post, and we would like a way to be able to effortlessly “promote” a comment (or part of it) into the body of a post. This allows the blogger to easily act as an editor for the conversations taking place on his blog.

All this, of course, would have to be nice and ajaxy. Here’s how I could imagine it happening.

First of all, the plugin recognises that the author of the post is logged in, and adds a “promote” link next to each comment, in addition to the “edit” link. If that link is clicked, the comment text is automagically appended to the post content in a blockquote, complete with author name and link to original comment.

If part of the comment is selected when the promote link/button is clicked, then only that excerpt is quoted in the post.

Instead of the dreaded confirmation pop-up, a nice confirmation message should appear alongside the promoted comment in the post body, with an undo link.

From a back-end perspective, the promote link “knows” which post it belongs to (check the ID of the comment <div> it’s in). It shouldn’t be very difficult to grab author name, author url, comment permalink, format them all nicely (blockquotes, credit, microformats), edit the post, and add it to the end of the content with some introductory text (like “promoted comment”) and an “edited” stamp with time/date of promotion.

Possible problems:

  • if part of a comment is selected and the wrong “promote” link is clicked, what behaviour would be expected? Probably an error message of some sort, or even better (but probably trickier to implement), a choice: promote the whole post (based on link clicked) or the excerpt (based on selection)?
  • should promoted comments really be added into the post content, or stored as post meta data?

Taking this a step futher: wouldn’t it be nice to let the blogger introduce the promoted comment, or write a few lines after it? In this case, pressing the promote button/link would bring up a pop-up where more text can be added, with the option of displaying it before or after the quoted text.

And even another step futher (but I’m not sure it’s an interesting one): how about allowing the blogger to make a new post out of the promoted comment, instead of just appending it to the current post? Would this be interesting?

Additional thoughts on this basic idea are welcome (Bruno, let me know if I forgot something, it’s been a while since our conversation). If you’re a plugin author and you feel upto it, go for it (just make sure you give Bruno credit for the idea). I’ll be happy to try it out.

Excluding One Category From Blog Homepage (WordPress) [en]

[fr] Comment exclure une catégorie de la première page de votre blog WordPress tout en la gardant dans les archives.

The simplest method I’ve found up to now (and I’ve only just found it) if there are certain categories of posts you do not want to see appear on your main blog page, but that you still want to see in the archives, is to use query_posts().

Here’s an example:

This needs to come in right before the while ( have_posts() ) { line. The $query_string parameter means that you can still pass parameters in the URL, so things like special Event Calendar pages will still work.

Careful, though, this only works for one category at a time. You need to use WP_Query for that, and build a separate loop for the homepage.

Events in WordPress [en]

[fr] Prise de tête pour trouver un moyen d'utiliser WordPress pour afficher des événements (des billets spéciaux, mais pour lesquels on précise aussi une date de début et de fin d'événement). Il faudrait qu'on puisse afficher les "événements encore pas terminés" sur une page spéciale.

Deux plugins m'offrent des solutions partielles, mais je suis incapable de les transformer en solutions totales. Toute aide serait bienvenue.

Besides using WordPress as a blogging tool, a client of mine would like to use it to display a page of upcoming events. I’ve dug out a number of plugins which somewhat do the job, but getting things to work exactly as we want is proving to be a pain in the neck.

As I’ve been stuck on this for a few weeks now and still see no light, I’m offering this problem to the collective mind out there in hope that a bright solution pops up somewhere before we go live (which is… very soon — hear my desperate plea for help).

Here’s what we want

  • events should be posts (this rules out Shrikee’s Events Plugin)
  • events have a start date, and an end date — time is unnecessary (this rules out RS Event)
  • events should show up in the normal flow of posts and on their own category page (we don’t want them on the home page, but I can exclude the category manually, so that’s a non-issue)
  • we should be able to display upcoming events on a WordPress page (I’ll stick whatever code is needed in the template for that page) — “upcoming”, here, meaning events whose end date is not yet past.

Partial solutions

At first, I thought about using upcoming or eventful, but for quite a few reasons this won’t work out in our situation.

Event Calendar seemed like a good candidate, although we didn’t really need the “calendar” itself. I hacked the layout of the event posts so they displayed OK. However, the main bit is missing. Event Calendar provides a way to list all the events “after today”, by calling http://blog.address/?ec3_after=today for example. Unfortunately, this doesn’t work on our setup (probably something we did to the rather hacked theme. I’ve had a look at the source code but couldn’t really figure out what happened when that variable was passed, so was unable to reproduce anything ressembling it in a Page template.

Another problem is that this will not show events which have started yesterday but which are not yet over, if I’m not mistaken.

Last but not least, we have two event subcategories, so I’d have to create two (or even three) separate event pages — but I guess that if I manage to make one, filtering posts by category shouldn’t be too hard.

Another solution would be to use Posts Expire and Posts Begin as described in this forum post I stumbled upon yesterday. Again, these plugins provide a way to call “posts which have not yet expired” with a particular URL: home/?orderby=post_end_date. Again, I haven’t manage to dig out the code and stick it in a Page template — trying to rewrite a pretty URL to that one is source of much hair-tearing upon this server I have very little control on, and I haven’t found a way to make it work.

The other problem I’d have to work around if using these plugins is that expired posts are not displayed in the blog anymore. I’m not sure what code in the plugin takes care of that, but it would have to be commented out.

Help

So, I have two partial solutions here, but I’m stuck making progress on either. Do you have any ideas which could help me out — either to make one of my partial solutions a working one or to find a third one?

I’d really really appreciate help on this one. Thanks a lot.

Remove Paging From WordPress Archives [en]

[fr] Pour supprimer les "pages" de vos archives WordPress, utilisez le code ci-dessous dans le fichier functions.php du thème que vous utilisez.

Thanks a lot to Matt for giving me the code which allows me to remove paging from the archives on this blog. I’ve been wanting to do that for a long time, but didn’t know where to start.

Just add the following code to the functions.php file of your theme.

function yay_nopaging($query) {
if ( !is_home() &amp;&amp; !is_feed() &amp;&amp; '' === $query-&gt;get('nopaging') )
    $query-&gt;set('nopaging', 1);
}

add_action('parse_query', 'yay_nopaging');

Unfortunately, this breaks the Recent Posts widget, which starts displaying… all the posts (that’s a lot of them, here). I removed the widget, but if you have a solution, I’d be happy to hear it.

English Only: Barrier to Adoption [en]

Foreword: this turned into a rather longer post than I had expected. The importance of language and localization online is one of my pet topics (I’ve just decided that it would be what I’d talk about at BlogCamp, rather than teenagers and stuff), so I do tend to get carried away a little.

I was surprised last night to realise that this wasn’t necessarily obvious — so I think it’s probably worth a blog post.

The fact a service is in English only is a showstopper for many non-native speakers, hence a barrier to wider adoption in Europe.

But doesn’t everybody speak English, more or less? Isn’t it the lingua franca of today that everybody speaks? It isn’t. At least not in the French-speaking part of Switzerland, and I’m certain there are many other places in Europe where the situation is similar.

Come and spend a little time in Lausanne, for example, and try communicating in English with the man on the street. Even if many people have done a couple of years of English at school, most have never had any use for it after that and have promptly forgotten it. German is a way more important “foreign language” around here, as it is the linguistic majority in Switzerland, and most administrative centers of big companies (and the government) are in the German-speaking part of the country (which doesn’t mean that everybody speaks German, either).

The people who are reasonably comfortable with English around here will most often be those who have taken up higher academic studies, particularly in scientific subjects (“soft” and “hard” science alike).

And if I’m the person who comes to your mind when you think “Swiss”, think again — my father is British, I was born in England, went to an English medium school and spoke English at home until I was 8, conversed regularly with English-speaking grandparents during my growing years, and never stopped reading in English: all that gave me enough of a headstart that even though my English had become very rusty at the end of my teens, I dove into the English-speaking internet with a passion, and spent an anglophone year in India. So, no. I’m not your average Lausanne-living French-speaker. I’m a strange bilingual beast.

Imagine somebody whose native language is not English, even though they may theoretically know enough English to get around if you parachuted them into London. (Let’s forget about the man on the street who barely understands you when you ask where the station is.) I like to think of my (step-)sister as a good test-case (not that I want to insist on the “step-“, but it explains why she isn’t bilingual). She took up the “modern languages” path at school, which means she did German, English, and Italian during her teenage years, and ended up being quite proficient in all three (she’s pretty good with languages). She went to university after that and used some English during her studies. But since then, she honestly hasn’t had much use for the language. She’ll read my blog in English, can converse reasonably comfortably, but will tend to watch the TV series I lend her in the dubbed French version.

I’m telling you this to help paint a picture of somebody which you might (legitimately) classify as “speaks English”, but for whom it represents an extra effort. And again, I’d like to insist, my sister would be very representative of most people around here who “speak English but don’t use it regularly at work”. That is already not representative of the general population, who “did a bit of English at school but forgot it all” and can barely communicate with the lost English-speaking tourist. Oh, and forget about the teenagers: they start English at school when they’re 13, and by the time they’re 15-16 they might (if they are lucky) have enough knowledge of it to converse on everyday topics (again: learning German starts a few years before that, and is more important in the business world). This is the state of “speaking English” around here.

A service or tool which is not available in French faces a barrier to adoption in the Suisse Romande on two levels:

  • first of all, there are people who simply don’t know enough English to understand what’s written on the sign-up page;
  • second, there are people who would understand most of what’s on the sign-up page, but for whom it represents and extra effort.

Let’s concentrate on the second batch. An *extra effort”?! Lazy people! Think of it. All this talk about making applications more usable, about optimizing the sign-up process to make it so painless that people can do it with their eyes closed? Well, throw a page in a foreign language at most normal people and they’ll perceive it as an extra difficulty. And it may very well be the one that just makes them navigate away from the page and never come back. Same goes for using the service or application once they have signed up: it makes everything more complicated, and people anticipate that.

Let’s look at some examples.

The first example isn’t exactly about a web service or application, but it shows how important language is for the adoption of new ideas (this isn’t anything groundbreaking if you look at human history, but sometimes the web seems to forget that the world hasn’t changed that much…). Thanks for bearing with me while I ramble on.

In February 2001, I briefly mentioned the WaSP Browser Push and realised that the French-speaking web was really “behind” on design and web standards ressources. I also realised that although there was interest for web standards, many French-speaking people couldn’t read the original English material. This encouraged me to blog in French about it, translate Zeldman’s article, launching the translation site pompage.net in the process. Pompage.net, and the associated mailing-list, followed a year or so later by OpenWeb, eventually became a hub for the budding francophone web standards community, which is still very active to this day.

(What happened with the Swiss Blog Awards is in my opinion another example of how important language issues are.)

Back to web applications proper. Flickr is an application I love, but I have a hard time getting people to sign up and use it, even when I’ve walked them through the lengthy Yahoo-ID process. WordPress.com, on the other hand, exists in French, and I can now easily persuade my friends and clients to open blogs there. There is a strong French-speaking WordPress community too. A few years ago, when the translation and support were not what they are now, a very nice little blogging tool named DotClear became hugely popular amongst francophone bloggers (and it still is!) in part because it was in French when other major blogging solutions were insufficient in that respect.

Regarding WordPress, I’d like to point out the community-driven translation effort to which everybody can contribute. Such an open way of doing things has its pitfalls (like dreadful, dreadful translations which linger on the home page until somebody comes along to correct them) but overall, I think the benefits outweigh the risks. In almost no time, dozens of localized versions can be made available, maintained by those who know the language best.

Let’s look at teenagers. When MySpace was all that was being talked about in the US, French-speaking teenagers were going wild on skyblog. MySpace is catching up a bit now because it also exists in French. Facebook? In English, nobody here has heard of it. Live Messenger aka MSN? Very much in French, unlike ICQ, which is only used here by anglophile early adopters.

Skype and GMail/GTalk are really taking off here now that they are available in French.

Learning to use a new service, or just trying out the latest toy, can be challenging enough an experience for the average user without adding the extra hurdle of having to struggle with an unfamiliar language. Even though a non-localized service like Flickr may be the home to various linguistic groups, it’s important to keep in mind that their members will tend to be the more “anglophone” of this language group, and are not representative.

The bottom line is that even with a lot of encouragement, most local people around here are not going to use a service which doesn’t talk to them in their language.

9:52 Afterthought credit:

I just realised that this article on why startups condense in America was the little seed planted a few days ago which finally brought me to writing this post. I haven’t read all the article, but this little part of it struck me and has been working in the background ever since:

What sustains a startup in the beginning is the prospect of getting their initial product out. The successful ones therefore make the first version as simple as possible. In the US they usually begin by making something just for the local market.

This works in America, because the local market is 300 million people. It wouldn’t work so well in Sweden. In a small country, a startup has a harder task: they have to sell internationally from the start.

The EU was designed partly to simulate a single, large domestic market. The problem is that the inhabitants still speak many different languages. So a software startup in Sweden is still at a disadvantage relative to one in the US, because they have to deal with internationalization from the beginning. It’s significant that the most famous recent startup in Europe, Skype, worked on a problem that was intrinsically international.

WordPress not Sending Pings Anymore [en]

[fr] WordPress fait des caprices et a arrêté d'envoyer des pings automatiques (trackback, pingback) sans me prévenir. Grinche.

Once upon a time, I loved WordPress because I didn’t have to enter trackback addresses manually anymore — at least, not when I was linking other WordPress blogs, or pingback-enabled blogging tools.

Those days are gone, and I’m not quite sure when it started. I’ve been having a creepy feeling for sometime that I wasn’t getting as many “internal” (CTTS to CTTS) trackbacks as I should. Today, I checked.

Heck.

You know me, I specialize in weird, not-so-reproducible issues. So, it wouldn’t be that WordPress has stopped sending pings altogether, no, that would be too simple.

WordPress has stopped sending pings *most of the time*. But sometimes, every now and again, it sends one. Or a couple. Or three.

What is going on, would you say?

Basic Bilingual and Bunny's Technorati Tags Plugins Updated for WordPress 2.1 [en]

[fr] Mise à jour de mes deux plugins pour WP2.1 qui les cassait gravement. Mises à jour pas testées, à manier avec précaution.

Thanks to Sudar, who took the trouble to fix Bunny’s Technorati Tags so that it worked with WP2.1, here are up-to-date version of these two plugins, Bunny’s Technorati Tags and Basic Bilingual:

The previous, WordPress 2.0-compatible versions are still available:

Warning: these old versions suffer from the empties custom fields problem. Don’t use them with 2.1.

Disclaimer: I’m swamped with work, haven’t upgraded yet, and haven’t tested the new versions of the plugins. Use carefully. Let me know if there are glitches. Bunny’s Technorati Tags is the very version Sudar put online (I’m making it available here mainly as there are links to it out there beyond my control, not the least from the wp-plugins.org wiki which has been closed to editing due to spam.) For Basic Bilingual, however, I adapted the code Sudar had added to Bunny Tags, but I don’t fully understand if it works. Backup, try gingerly, and please leave comments here to let others (and myself) know if it works or breaks.

Thanks.

Invalid argument supplied for foreach() in wp-capabilities.php: Case Cracked! [en]

[fr] Le problème avec wp-capabilities.php qui fait qu'on peut se retrouver "exfermé" (enfermé dehors) de son blog WordPress (typiquement en cas de changement de serveur) semble avoir sa source dans le contenu du champ wp_user_roles dans la table wp_options. En particulier, pour la version française, "Abonné" est un rôle d'utilisateur, et en cas de problèmes d'encodage MySQL, le caractère accentué sera corrompu, causant ainsi l'erreur.

Il suffit de remplacer le caractère fautif dans PhpMyAdmin, et on retrouve l'accès à son blog. Bon, reste ensuite à régler les questions d'encodage... mais c'est déjà ça!

Finally. At last. Endlich. Enfin.

Once more, while trying to transfer a WordPress installation from one server to another, I found myself facing the dreaded problem which locks me out of my WordPress install with a rather cryptic message:

Warning: Invalid argument supplied for foreach() in /home/user/wp/wp-includes/capabilities.php on line 31

(Your lineage may vary.)

What happens is that WordPress cannot read user roles, and therefore, even though your password is accepted, you get a message telling you that you’re not welcome in the wp-admin section:

Vous n’avez pas les droits suffisants pour accéder à cette page.

Or, in English:

You do not have sufficient permissions to access this page.

A quick search on the WordPress forums told me that I was not alone in my fight with wp-capabilities.php, but that many problems had not been resolved, and more importantly, that suggested solutions often did not work for everyone.

I’ve bumped into this problem a couple of times before, and I knew that it was linked to encoding problems in the database. (I’ve had my share of encoding problems: once, twice, thrice — “once” being on of the most-visited posts on this blog, by the way, proof if needed that I’m not alone with mysql encoding issues either.)

I’ll leave the detailed resolution of how to avoid/cure the MySQL problems later (adding
mysql_query("SET NAMES 'utf8'");
to wp-db.php as detailed in this thread, and as zedrdave had already previously told me to do — should have listened! — should prevent them). So anyway, adding that line to my working WordPress install showed me that the problem was not so much in the database dumping process than in the way WordPress itself interacted with the database, because the dreaded wp-capabilities.php problem suddenly appeared on the original blog.

Now, this is where I got lucky. Browsing quickly through the first dozen or so of forum threads about wp-capability.php problems, this response caught my eye. It indicated that the source of the problem was the content of the wp_user_roles field (your prefix may vary). In this case, it had been split on more than one line.

I headed for the database, looked at the field, and didn’t see anything abnormal about it at first. All on one line, no weird characters… just before giving up, I moved the horizontal scrollbar to the end of the line, and there — Eurêka! I saw it.

Abonné

“Contributor”, in French, is “abonné”, with an accent. Accent which got horribly mangled by the MySQL problems which I’ll strive to resolve shorty. Mangled character which caused the foreach() loop to break in wp-capabilities.php, which caused the capabilities to not be loaded, which caused me to be locked out of my blog.

So, in summary: if you’re locked out of your blog and get a warning/error about wp-capabilities and some invalid foreach() loop thingy, head for PhpMyAdmin, and look carefully through the wp_user_roles field in the wp_options table. If it’s split over two or more lines, or contains funky characters, you have probably found the source of your problem.

Good luck!