WordPress: pagebar 2.54

pagebar 2.54 removes a problem with the “Break comments into pages” setting which could not be deselected. Unfortunately I had to remove the “show all comments” feature since I have not found a different method to code this feature.

Additionally there are two more fixes:

  • Settings where not correctly inherited by multipagebar and commentbar.
  • Commentbar was displayed if only one page was present.

Download:

Hope I didn’t break anything else 😉

Hello Dolly 2010

Since 2 weeks there’s a voting on Digging into WordPress whether to keep the Hello Dolly plugin in the standard distribution or to chuck it out the house.

One of the most heard reasons for the existence of Hello Dolly that it should be used as a pattern for novice plugin developers. In my mind the problem with this argumentation is that the plugin hasn’t changed essentially since WordPress v1.21 (the version which introduced plugins in May 2004).

Since then the environment for plugins has changed a lot. The main difference is that there are typically ten or more plugins installed on a blog. Therefore it’s mor important than ever that the plugins don’t interfere with each other. This can most easily be achieved by encapsulation and this leads inevitable to object-oriented programming. Here’s my attempt to take Hello Dolly to the next decade:

< ?php
/**
 * @package Hello_Dolly
 * @author Matt Mullenweg
 * @version 1.5.1
 */
/*
Plugin Name: Hello Dolly
Plugin URI: http://wordpress.org/#
Description: This is not just a plugin, it symbolizes the hope and enthusiasm of an entire generation summed up in two words sung most famously by Louis Armstrong: Hello, Dolly. When activated you will randomly see a lyric from Hello, Dolly in the upper right of your admin screen on every page.
Author: Matt Mullenweg
Version: 1.5.1
Author URI: http://ma.tt/
*/

if (! class_exists('Hello Dolly')) {
	class HelloDolly { 

		function hello_dolly_get_lyric() {
			/** These are the lyrics to Hello Dolly */
			$lyrics = "Hello, Dolly
			Well, hello, Dolly
                        [...]
			It's so nice to have you back where you belong
			You're lookin' swell, Dolly

			Dolly'll never go away
			Dolly'll never go away again";

			// Here we split it into lines
			$lyrics = explode("n", $lyrics);

			// And then randomly choose a line
			return wptexturize( $lyrics[ mt_rand(0, count($lyrics) - 1) ] );
		}

		// This just echoes the chosen line, we'll position it later
		function hello_dolly() {
			$chosen = $this->hello_dolly_get_lyric();
			echo "

$chosen

"; } // We need some CSS to position the paragraph function dolly_css() { // This makes sure that the posinioning is also good for right-to-left languages $x = ( 'rtl' == get_bloginfo( 'text_direction' ) ) ? 'left' : 'right'; echo " #dolly { position: absolute; top: 4.5em; margin: 0; padding: 0; $x: 215px; font-size: 11px; } "; } //dolly_css() } //class }//if class_exists() $HelloDolly = new HelloDolly; if (isset($HelloDolly)) { add_action('admin_head', array(&$HelloDolly, 'dolly_css')); // Now we set that function up to execute when the admin_footer action is called add_action('admin_footer', array(&$HelloDolly, 'hello_dolly')); } ?>

As you can see all the code is encapsuled in the HelloDolly class and the only variable names visible to the rest of the system are class HelloDolly and $HelloDolly. It’s not very likely that there will be another plugin using the variables.
This may not be too important in this small plugin but it gives the user a good and up-to-date prototype for more complex code. Maybe this code will convince the 76% that this new Dolly is a cow that is not only sacred but also meaty.

WordPress: Überschriften mit Untertiteln

In vielen Zeitungen ist es üblich, unter die eigentliche Überschrift noch einen Untertitel zu setzen, um den folgenden Titel näher zu erläutern:

Durch diese Untertitel kann man den eigentlichen Titel etwas kreativer gestalten und anschließend erläutern. Leider bietet WordPress von Haus aus diese Funktion nicht an und so muss sie nachgerüstet werden. Als ersten Reflex würde der geneigte Programmierer eine Lösung per Plugin versuchen, allerdings gibt s auch eine Lösungmit Bordmitteln. Die Zauberworte lauten “Benutzerdefinierte Felder” (engl. “custom fields”).

Continue reading WordPress: Überschriften mit Untertiteln

WordPress: Überprüfen, ob ein Beitrag das more-Tag enthält

Manchmal möchte man einen Beitrag abhängig davon gestalten, ob er ein <!–more–>-Tag enthält oder nicht. Leider verfügt WordPress nicht über eine Funktion, um diese Prüfung vorzunehmen. Befindet sich der Beitrag innerhalb des Loops, so kann man aber folgende Funktion benutzen:

function hasMoreLink() {
	global $post;
	return strpos($post->post_content, '');
}

(Bitte “nore” mit “more” ersetzen, konnte ich aber nicht eingeben, weil sonst WordPress das Tag auswertet.)
Danke an MichaelH aus dem englischen WordPress Forum

WordPress Plugins übersetzen

Viele WordPress-Nutzer bevorzugen eine deutsche Oberfläche, weil sie der englischen Sprache nicht mächtig sind oder es einfach als angenehmer empfinden, sich mit ihrem Blogsystem in ihrer eigenen Muttersprache zu verständigen.
Für das Basissystem von WordPress wird mit großem Enthusiasmus vom wordpress-deutschland.org-Team eine Übersetzung bereitgestellt. Viele Plugins allerdings nicht nur in englischer Sprache verfügbar, was nicht nur den Nutzer verwirrt, wenn plötzlich Meldungen in einer anderen Sprache erscheinen, sondern auch ein uneinheitlichen und unprofessionelles Bild ergibt.

Zum Glück ist es in WordPress aber relativ einfach, Plugins in eine andere Sprache zu übersetzen. Sofern das Plugin es vorsieht und die Funktion __() (Doppelunterstrich) oder _e() für die Textausgaben benutzt. Diese Funktionen benutzen die gettext Bibliotheken und Werkzeuge.
Continue reading WordPress Plugins übersetzen

WordPress: Absprung im Plugin-Bereich v2.7

[English version]

Frank Bültge beschreibt in seinem Posting “WordPress Plugins bereichern“, wie man die Bedienungsfreundlichkeit seines Plugins steigern kann, indem man einen Link zu den Options-Seiten neben die Deaktivieren- und Bearbeiten-Links platziert. Mit Version 2.6 funktioniert das so:

function addConfigureLink($links, $file) {
  static $this_plugin;
  if (!$this_plugin) {
    $this_plugin = plugin_basename(__FILE__);
  }
  if ($file == $this_plugin) {
    $settings_link = '' . 
      __('Settings') . '';
    $links = array_merge( array($settings_link), $links);
  }
  return $links;
}

add_filter("plugin_action_links", "addConfigureLink", 10, 2);

Bei dieser Methode wird allerdings für jedes Plugin die Funktion addConfigureLink aufgerufen… und sehr übersichtlich sieht es auch nicht aus.

Das haben sich offensichtlich auch die WP-Entwickler gedacht und haben den Filter verbessert:

function addConfigureLink( $links ) { 
  $settings_link = 'Settings'; 
  array_unshift( $links, $settings_link ); 
  return $links; 
}

$plugin = plugin_basename(__FILE__); 
add_filter("plugin_action_links_$plugin", 'addConfigureLink' );

Jetzt muss die Funktion addConfigureLink nicht bei jedem installierten Plugins überprüfen, welche Plugindaten gerade aufgerufen werden und der Code wird übersichtlicher.

Abschließend bleibt wie immer die Überlegung, ob man solche “frischen” Filter sofort nutzen soll und damit die Kompatibilität zu vorherigen WordPress-Versionen zerstört oder ob man wartet, bis sich die neue Version ausreichend verbreitet hat. Meine Meinung dazu gibt’s bei identi.ca (schamlose Werbung!).

Update: There an English version of this posting available.

Using Komodo’s calltips with WordPress

Can you remember all the function parameters of the various WordPress API/actions and functions? Are you a regular visitor of the Codex for looking up the vaults of the zillion possibilities WordPress is giving you to code your plugins?

Well this will never change, I’m afraid, but you can make your life much easier if you’re coding your plugins with ActiveState’s Komodo Edit because it’s got the facility to extend the standard calltips with your own calltips, in this case the WordPress function calls:

Store the latest WordPress distribution on your machine. You do not need a web server being installed or any other second party software. Simply download the file and extract them into a directory.

Add the directory path to Komodo Edit: Edit/Preferences/Languages/PHP

komodo

In this case I inserted <code>z:/www/wp25</code>.

If you now enter a WordPress function (in this example add_action) Komodo will show you some informative inforamtion about it:

komodo2

Great, that was easy, wasn’t it?

WordPress Crazyhorse … no thanks!

Today I took a look and the new proposal for the next WordPress release. And I don’t like it … at all! It looks like the first incarnation of Google Reader and they changed it for good reasons.


(click to enlarge)

The interface looks totally clumsy, like a design from 2006. The left sidebar takes away a lot of the space for the text editor (about 12 columns on my screen). The editor looks somewhat lost inside the two sidebars.

The setting page is somewhat inconsistent. You select the option “Utilities/Settings” in the left sidebar but the next selections have to be made on the top of the window:


(click to enlarge)


The current (v2.5.1) design looks much lighter, much more today. If I want to have a menu structure like in Crazyhorse I better install WordPress Admin bar (which I actually have). Maybe this plugin should make it into the core?


(click to enlarge)