Henrik Carlsson's Blog

All things me.

posted this note on and tagged it with WordPress

Question for self-hosted WordPress users: How do you handle backups och your blog/site?

Replies and comments

Some more information on the WordPress bug that I think that I’ve found #wordpress

posted this on and tagged it with Narrating my work WordPress

Yesterday I wrote about a problem that I’m having with a WordPress plugin that I’m working on, and I said that I think it’s a bug in WordPress. Here are some more information about it.

What the plugin is supposed to do

The plugin should cross-post/syndicate any new post to Twitter. There are a lot of plugins already that does this, but I wanted a few special features.

So far so good. This all works as intended. There is however one more thing that it’s supposed to do:

The technical part

The plugin hooks into the publish_post action and early on in its code it checks if ( get_post_format( $ID ) == 'link' ). If it returns true an XPath query retrieves the href of the first <a> element and uses this instead of the permalink in the Twitter post.

The XPath part works just fine in all my tests.

The problem

As long as I post from the WordPress Admin interface, everything works as intended. The problem occurs when I post using the Press This bookmarklet. When I post this way, if ( get_post_format( $ID ) == 'link' ) never returns true, regardless of the post format.

If I create the post using Press This but instead of publishing I save it as a draft and then publish from the Admin panel, it works as intended.

Do you have a solution?

If so, please let me know.

The code is available on GitHub but I’ve kept the repository private since I’m a little bit embraced by the code, but let me know if you’d like to check it out and I’ll add you to the repo.

Replies and comments

Is this a bug in WordPress?

posted this on and tagged it with Narrating my work WordPress

I’m working on a WordPress plugin to syndicate my posts to Twitter. I know, there are lots of plugins that does that already but none of the ones I’ve found does it the way I want, so I decided to roll my own. I’ve got the basics working and have been using it on my site for quite some time now. However, I’ve encountered a problem. Here’s how I want it to work:

When I publish a link post, instead of posting a link back to my site to Twitter, it should post the link to the site that I’m linking to. The plugin ”knows” whether it’s a link post or not based on

At first glance this works fine and it worked in development. However, ones I started using it on my site I realized that it only worked some of the times and other times it wouldn’t recognize a link post.

Tonight I’ve managed to narrow it down. It seems like the problem occurs when I post with the ”Press this” bookmarklet. If I do that, even a post that clearly has been givet the ”link” post format still returns false for if ( get_post_format( $ID ) == 'link' ). If I post the exact same content using the WordPress dashboard the post is recognized as a link post and everything else works as intended.

Is this a bug in WordPress? I should investigate this further but right now I need to go to bed, so I’m throwing the question out to you, smart people on the internet, instead.

Replies and comments

How I manage what goes into my news rivers

posted this on and tagged it with River of News WordPress

Almost a year ago I wrote about WordPress’ Link Manager. It’s an old feature of WP that seems to get very little use these days. But it is a way to collect links to websites and, this is the important part, their corresponding RSS/Atom feeds, and get an OPML file os the websites in question.

Collected links can be put in categories and every category has its own OPML. You can find the OPML for all my links here.

OPML is one of the file formats that can feed a river in River 5. As far as I know the OPML that River 5 reads needs to be in the lists folder in your River 5 installation, so at first glance that seems to rule out using WordPress’ OPML feature.

The not so secret sauce that makes it work is the ”include” node in OPML. In my lists folder I have and OPML file for each and every river I want River 5 to generate. Each of those files contain a single <outline> node that links to the corresponding category among my WP links.

For example, my ”Everything feed”:

This tells River 5 to include everything it finds at the URL http://blog.henrikcarlsson.se/wp-links-opml.php which, as I just mentioned, is the full list of links that I collect in my sites link manager.

So whenever I want to add or remove a link (site/blog/etc) I just use WordPress’ link manager. That makes it very simple to add and remove stuff and therefore I’m more likely to try to add new sites to the mix and see if they add to my satisfaction or not.

Building a WordPress plugin

posted this on and tagged it with Narrating my work WordPress WP River (.js) Reader

Today I started working on a WordPress plugin (I’ll tell you more about it soon). To do that I needed to brush up a bit on my plugin-writing skills. I’ve always found making WordPress plugins unnecessary frustrating but as I searched for some articles about it today I found this:

Since WordPress 2.8, building widgets has been a matter of extending WordPress’ own widget class, WP_Widget, resulting in your custom widget only having to focus on 4 main functions:

  1. Initialisation (__construct) – handles actions to take when the widget is first created such as enqueueing specific javascript or stylesheets in the output
  2. Front-end display (widget) – handles the generation of the widget’s HTML output
  3. Back-end form (form) – handles the generation of the form controls that make up the widgets edit interface in the Admin interface
  4. Update (update) – handles the form submission from the back-end form, updating stored data as necessary

How To Build WordPress Widgets Like A Pro – WPMU DEV

I had completely missed this. In my mind plugins was still this boiler-plate filled bag of hurt. Instead all you got to do is subclassing WP_Widget and replacing a couple of methods. Wow!

As I took the approach suggested in the article and based my code on the sample code in it, I got up and running super-quick. A beta version of the plugin is actually running on my local machine already, after maybe an hours worth of work. The fact that it was so easy makes me very happy and gives me the urge to write more plugins.

Use your own ”printing press” from time to time

posted this on and tagged it with Blogging Social Networks WordPress

I think Dave Winer really nails it with this quote and elaboration:1

A.J. Liebling said, famously: ”Freedom of the press is guaranteed only to those who own one.” That’s so true, and with blogging everyone can own their own, and therefore be free. However, we’re trading that in for a bit more engagement.

Dave Winer. (2015)

I will link to this post on twitter so likely most of you who read it will find it there. You’re likely tweeting quite a lot yourself, and that is a good thing. I don’t think you should stop tweeting, and I’m pretty sure Dave doesn’t think that either. I am, however, saying that you should also use your own ”printing press” from time to time.

Use your blog for some of your writing!2 Don’t have a blog? Get one!

I have a lot of bad things to say about WordPress, but if you want an easy-to-setup, easy-to-manage blog you should give it a try. (This site is a WordPress site.) It’s optimal if you self-host it. That way you definitely own every word on it.

Don’t feel like self-hosting? Get an account at WordPress.com. Yes, you are using somebody else’s ”printing press” but at least that somebody is somebody who is dedicated to open publishing and to ensure that you own what you write and that you can write whatever the hell you want.

Afraid that nobody will read what you write if it’s not on Twitter or Facebook or Instagram or [insert whatever]? Write in on your blog and then link to it on your social networks of choice?

You can even use a tool such as Dave’s Radio3 that allows you to make a link blog, or a list of short status updates, and simultaneously publish to Twitter, Facebook, WordPress and an RSS-feed. It’s a great tool that I use for most of my tweeting these days. That way, what I tweet also ends of as link-posts or status-posts here on the blog as well.

But what if I really don’t like WordPress?

There are other options, for both self-hosted and hosted solutions. If you decide to go with a hosted one, the most important thing is to make sure that it has a clear and easy way for you to export everything you write in full fidelity.


  1. I should admit that I’d never heard of neither Liebling nor the famous saying before. 
  2. If you find yourself writing more than two consecutive tweets about the same thing, maybe it is not something that you be tweeted. Maybe it should be written as a blog post instead. 

Markdown (The Greatest Invention Since Sliced Bread)

posted this on and tagged it with Blogging Markdown WordPress

Well, maybe I’m exaggerating a bit, but today (or yesterday since it’s passed midnight here) I did what I should have done long before and checked out Markdown. According to its creator John Gruber it’s

a text-to-HTML conversion tool for web writers. Markdown allows you to write using an easy-to-read, easy-to-write plain text format, then convert it to structurally valid XHTML (or HTML).

It is both a way to write plain text documents so that their content is somewhat formatted and a tool to convert this text to xhtml.

The reason I checked this out today (or was it yesterday?) was an article in Macworld called Forget fancy formatting: Why plain text is best. It made some good points about why plain text is almost always better than something written in for example Microsoft Word or Apple Pages.

[Plain text is] timeless. My grandchildren will be able to read a text file I create today, long after anybody can remember what the heck a .dotx file is.

The article then mentioned some tools that was great for plain text writing, among them Byword which according to the article ”has baked-in support for Markdown”. I’d heard about Markdown before, mostly from Merlin Mann in the Back To Work podcast so now I finally made myself find out what it was. (Finding out was as easy as clicking the link in the Macworld article.)

The concept behind Markdown seemed really great, so I decided to try it, and to buy Byword. So far I’ve just made some test documents with the Byword/Markdown combination (as well as writing this blog post) and I must say it seems pretty great. I do a whole lot of writing in my work and most of it is just simple text documents that I’ve used to write in Microsoft Word (yes, I actually do like Word) but I guess the bulk of my writing this upcoming semester will be done full-screen in Byword using Markdown and then exporting the appropriate format. (Apart from xhtml, Byword also exports as .doc, .pdf, .rtf and Latex.)

One more thing

I also found out that although Markdown is written in Perl there is a php version and that version also works as a WordPress plugin. So this very blogpost is written in Byword, marked up (or down?) with Markdown and will then be pasted into a post in my blog, where you will read it.

Replies and comments

I’m using an old browser?

posted this on and tagged it with Browsers WordPress

I just picked up my secondary computer and logged in on this blog. The first thing I saw was WordPress telling me that I use an old browser. Since Safari 5.1 is out, apparently 5.0.5 is considered old. This is a fairly aggressive mode (I prefer to see things like IE6/7/8 and Firefox 3 as old) but I love it.

Good work WordPress! Anything that make people update their browsers more often is great.

The blog now has WP Super Cache

posted this on and tagged it with Status WordPress

I’ve just enabled WP Super Cache on this blog. This is the first time I use a static cache on a WordPress blog. Hopefully it will speed things up and make it more fail safe.

Problem med autouppdatering av WordPress hos Binero?

posted this note on and tagged it with Binero Johan Eckman Scorpion Data Tekniksupport WordPress

I somras bytte jag webbhotell, från dåliga Scorpion Data till bra Binero. Det gjorde mitt liv lättare på alla sätt och vis, bortsett från en detalj. Helt plötsligt slutade autouppdateringen av WordPress att fungera för mig.

När WordPress släpps i en ny version så talar alla WordPress-bloggars kontrollpanel om detta för sina administratörer och frågar om en uppdatering ska göras. Det finns två sätt att göra detta på. Antingen genom att ladda ner WP och sedan ersätta den befintliga installationen på din webbserver. Detta är en inte helt självklar process eftersom du måste se till att inte råka radera filer du vill behålla (teman, uppladdad media etc).

Den enklare lösningen är att låta WordPress autouppdatera sig själv vilket har fungerat ypperligt, tills jag bytte till Binero. Jag har provat att söka efter en lösning i deras WIKI och FAQ men utan att lyckas. Dock hade jag fram tills idag inte brytt mig om att maila eller twittra till deras support.

Idag frågade JohanTwitter om någon annan hade problem med att uppdatera till WordPress 3.0.4. Eftersom jag vet att Johan också använder Binero så passade jag på att vidarebefordra frågan till @binero, kontot på twitter som de använder för support. Vi fick mycket snabbt ett svar som löste Johans problem. Jag antar att det även kommer lösa problemet för mig.

Om du har samma problem så kan du läsa lösningen här. I korthet så går det ut på att lägga in följande kod någonstans i din wp-config.php-fil.

define( 'FS_METHOD', 'direct' );
define( 'FS_CHMOD_DIR', 0755 );
define( 'FS_CHMOD_FILE', 0644 );

Replies and comments