Fixing the Upload section when using Podpress

November 16th, 2007 by Henrik Melin

PodPress introduces a bug whereby the Upload file browser no longer recognizes image fiiles as images, and therefore does not produce the <img> tag needed to display the image in a post.

Luckily, this can be fixed from within another WP Plugin, using the following snippet:

/*
**    Fix podpress' bug that affects WP's upload field
*/
function dsc_pp_attached_file_bug ($file, $id='') {
   if (preg_match("/upload\.php/", $_SERVER['PHP_SELF']))
      remove_filter('get_attached_file',
         'podPress_get_attached_file');
   return $file;
}
function dsc_pp_get_attachment_metadata_bug ($data, $id='') {
   if (preg_match("/upload\.php/", $_SERVER['PHP_SELF']))
      remove_filter('wp_get_attachment_metadata',
         'podPress_wp_get_attachment_metadata');
   return $data;
}
add_filter('wp_get_attachment_metadata',
   'dsc_pp_get_attachment_metadata_bug', 9, 2);
add_filter('get_attached_file',
   'dsc_pp_attached_file_bug', 9, 2);

The above code removes the filters introduced by PodPress when we’re in WP’s own Upload field.

PodPress is showing more and more annoying little features/bugs - it’s a pretty code rich plugin that does alot.

Translating plugins - the $domain parameter

November 16th, 2007 by Henrik Melin

Any half descent Wordpress plugin should be able to handle different languages. The gettext translation system that Wordpress uses is really easy to use, once one has the right tools, namely POEdit.

The function that loads the translation file is declared in WP as follows:

function load_plugin_textdomain($domain, $path = false)

Where $domain is the second parameter called in __($en_US_text, $domain) and _e($en_US_text, $domain). The difference between these two functions is that the _e() echoes the text, whereas __() just returns it. So, the $domain parameter defines the namespace within which the translation file (.mo) is valid, and this namespace must be specified for each translatable entity.

We load the .mo file in the plugin using the ‘init’ hook:

function p2m_translate(){
	load_plugin_textdomain('p2m-links', PLUGINDIR
            . '/' . dirname(plugin_basename (__FILE__)) );
}
add_action('init', 'p2m_translate');

In this example, the domain is ‘p2m-links’, which mean that translatable text should be expressed as:

__('Gobbledygook', 'p2m-links');
_e('Gobbledygook', 'p2m-links');

If no domain is specified in a plugin then Wordpress will look for translations in the .mo file contained in the wp-includes/languages directory.

Removing the podPress footer completely

November 14th, 2007 by Henrik Melin

Even when the ‘Show PodPress footer’ is unticked in the PodPress admin, the plugin still cranks out html code in a div with the style ‘display: none’. The following bit of code, placed in a Wordpress plugin, will remove that pesky bit of promotional code.

function p2m_remove_podpress_footer () {
        remove_action('wp_footer','podPress_wp_footer');
}
add_action('wp_footer','p2m_remove_podpress_footer', 9);

Nothing spectacular, of course. Worth noting might be that the default priority of an action is 10, so giving our removal action a priority of 9 ensures that this code runs before that of Podpress’.

Grepping for files with byte order marks (BOM)

November 13th, 2007 by Henrik Melin

Finding offending php files with UTF8 byte order marks (BOM):

grep $'\xEF\xBB\xBF' * -rl | grep .php

Having byte order marks present in any of the Wordpress or bbPress files causes the content not to validate to XHTML 1.0 Strict.

dagensskiva.com 4.1

November 12th, 2007 by Henrik Melin

Back in early November we sat down and upgraded dagensskiva.com to version 4.1. Features in this release include:

  • Upgrade to Wordpress 2.3.1
  • Upgrade to BBPress 0.8.3
  • Migration to WP internal tag handling (and leaving Ultimate Tag Warrior behind).
  • For the ‘Relaterat’ field we now use a modified version of WP 2.3 Related Posts , which matches posts based on tags. The changes made formats the title to include information stored in custom fields.
  • JQuery feature in BBPress that shows who tagged what (and how many times).
  • The last.fm radio based on tracks submitted to the dagensskiva group.

Hello world, development blog.

November 12th, 2007 by Henrik Melin

Welcome to the Peter2Meter development blog. Here, we will document - and release to the community - the custom components developed for the Wordpress platform that enable the smooth running of dagensskiva.com (and soon dagensbok.com).