elektroelch.net – blog

So your WordPress plugin kills the Theme Editor?

You’ve created a plugin that worked happily since version 2.5 of WordPress. Then came version 2.9 and the users of your plugin complain that the theme editor does not work anymore! What the theme editor? What have I to do with the theme editor?

That were my thoughts when I received bug reports for the pagebar plugin. I had absolutely no idea why and first checked the usual suspects; with no success. So I tried a different approach and disabled all initialisation code. The theme editor worked. I enabled the first disabled line and Eureka! The theme editor failed. This has to be the
erroneous line:

$dir = trailingslashit(WP_CONTENT [...]

The $dir variable is global and that seemed to be the problem. A short look at theme-editor.php shows that’s there a global variable called $dir. So I changed the variable name in my plugin to a more unique name and voilà, everything works as expected.

There are some lessons I learned from this incident:

  • Use a unique name for your global variables.
  • Better: Never use global variables at all.
  • Even better: encapsulate everythin inside a class.

I hope his short story helped you to debug your plugin and leave some happy users behind.

noteaser – The unknown WordPress tag

noteaserMost WordPress users will know the <!--more--> tag which allows you to create a teaser for your blog post. The text in front of the tag will be displayed on the main blog page and after clicking the “more” link the single post page containing the teaser and remaining part of the blog post will be displayed.

More often than not this is adequate but there may be situation where you want to create a separate teaser which isn’t displayed on the single post page. So it may be a good idea to create a collage as the teaser for a post containing various images. On the post page itself the collage would not be appropriate. Another situation could be a very striking teaser which does not fit into the main post but still is a good teaser to attract readers.

To hide these parts of the post you can use the lesser known <!--noteaser--> tag:

Teaser text
<! --more-><! --noteaser-->Post text.

The <!--noteaser--> necessarily has to follow directly after the <!--more--> tag otherwise it will not be evaluated.

However there are some issues using the tag:

  • After clicking the more tag the content of the post will be moved to the top of the browser window. This may be appropriate for a standard posting where the teaser text shall be hidden from the reader’s eyes. Using the noteaser tag there is no such text any more and the reader is wondering if there is anything above.
  • The text in front of the <!--more--><!--noteaser--> tags will not be shown on the preview page. So you have to write your post in two steps: first creating the text as usual and inserting the <!--noteaser--&gt in the final state.
  • All line breaks are preserved. To avoid an additional empty line at the top of the post you should insert the tags on a single line.

These issues may be solved by creating a plugin… maybe later. Nevertheless the tag is a nice tool to add a different view to your blog.

Accessing WordPress data from outside WordPress

(img by shindohd)

There are times when you want to access the data from your WordPress database from a webpage outside of your WordPress installation. This can be done by using the mysql_connect of PHP and selecting the data with some genuine SQL statements. This will work but it has the substantive disadvantage that the WordPress database is changed now and then and that the SQL statement will fail sooner or later.

There has to be a better solution and there is one! Simply use the function provided by WordPress itself to access the data. It’s as simple as this code:

include '../blog/wp-blog-header.php';

In this example WordPress is installed in the directory “../blog” relative to the directory of the current script. You have to adapt it to your installation, of course. Now you can access the database using the $wpdb-instance, i.e.

$post_id = 666;
$sql = "select post_title from $wpdb->posts where ID=$post_id";
$title = $wpdb->get_var($sql);

Ok, if Automattic decides to change the row names you’ve lost again. So you should completely avoid direct database calls and use the functions build into WordPress which are also available after including the above file:

$post_id = 666;
$title =  get_the_title($post_id);

This should be a safe call for a very long time!

First meeting for launching a hackerspace in Kassel/Germany

Kassel, a city located at the Fulda, population 200,000, is as ugly as sin but it’s got the <a href="Herkules, a pile of museums, a great hackerspace, a national theatre, a university

Wait, wait, wait! A hackerspace? In Kassel? No, of course there isn’t one. Not yet. But there could be soon. Some people thought they could change this state and create such a space in Kassel, whereby space does not exclusively has to be taken as a physical room.

So the call went out into the great wide open of the Internet and the initiators hoped for a small group of interested people. at the first meeting in a small pub this small group turned out to be a large group of 28 combatants.

Unfortunately the locality was quite unsuitable for such a large group. If only five or ten people had shown up it would have been a nice and cosy get-together but actually we had to make the best of the circumstances. Some verbal contributions could hardly be heard others not at all. But nobody could expect such an immense interest. Nonetheless everybody was concentrated and the discussion was quite constructive. After a short introduction to the basic ideas of hackerspaces everyone told a bit about his background, his intentions, ideas, and expectations. I think a lot of Blinkenlights will be created in the near future.

Obviously there is a great crowd of hardware freaks, programmers, and artistically interested men (yes, there wasn’t a single woman) having many ideas for new and/or interesting projects  and ideas how they can help others and how others can help them. The initiators presented a welled planned  concept and even looked after some affordable rooms with a good infrastructure. Next week we will have a go and see.

Hopefully everybody will keep at it and the new hackerspace will have a good substantial and financial foundation. It’s going to be interesting!

Links:

Botany Bay: Old Men with Ballpoint Pens

Botany Bay made a nice music clip about surveillance. You may not know the people in the clip (German politicians) but that does not matter at all.

Old Men With Ballpoint Pens

They know it is the worst thing
Not being in control
So they bring in all the big guns
To ease their troubled souls
You can see them in the tabloids
Where they smile their empty smiles
Selling tales of lawless chaos
And lies upon lies
They waste no time, they’re on the way
They’re quick to bend the laws
To abuse the ones who suffered
For their twisted cause

Old men with ballpoint pens
Old men with ballpoint pens
Old men with ballpoint pens
Old men with ballpoint pens

They know what you’ve been doing
They know where you have been
They read the words, both yours and mine
They’ve seen what you have seen
They’re here to protect you
All for the common good
Don’t you dare to get in their way
They just know what’s good for you
And if you’re feeling watched
And if you’re full of fear
Remember that, remember how
It was you who brought them here

Old men with ballpoint pens…