As a WordPress lead developer, every time I see someone recommending editing a core WordPress file, a little bit of me dies.
You should always avoid editing the core files and put your modifications into a plugin so as to ensure you have a smooth upgrade experience to a future WordPress version.
Therefore inspired by the following forum post here is how to change one of the translatable strings in WordPress without hacking a core file using the filters available in the translation functions:
<?php
/*
Plugin Name: PJW Translation Mangler
Plugin URI: http://blog.ftwr.co.uk/#
Description: Example of how to mangle translated strings.
Author: Peter Westwood
Version: 0.01
Author URI: http://blog.ftwr.co.uk/
*/
class PJW_Translation_Mangler {
/**
* Filter the translation string before it is displayed.
*
* @param $translation The current translation
* @param $text The text being translated
* @param $context The context for the translation
* @param $domain The domain for the translation
* @return string The translated / filtered text.
*/
function filter_gettext($translation, $text, $domain) {
$translations = &get_translations_for_domain( $domain );
if ( $text == 'View all posts filed under %s' ) {
return $translations->translate( 'See all articles filed under %s' );
}
return $translation;
}
}
add_filter('gettext', array('PJW_Translation_Mangler', 'filter_gettext'), 10, 4);
?>
The filter used in this example gettext is one of a set of filters in the translation functions in wp-includes/l10n.php which also include gettext_with_context, ngettext, and ngettext_with_context.



A better meta API for WordPress
July 23rd, 2009
One of the things that we have being discussing for a very long time is extending WordPress with a comment meta api or even the idea of a generic meta api for WordPress and indeed this is something we are discussing at the moment and I thought I would jot down some thoughts on what I would like to see from an API point of view. Over the weekend at WordCamp UK we also heard about situations where some people are already adding comment meta tables for plugin usage and so the demand is definitely there.
I don’t really care how the data is stored, be it single table or multi table, all I care about is having a good stable API for plugins and the core to work with. If the API is good and well thought out they don’t need to care about the table structure and we can always change it later.
Therefore I thought I would summarise the features I would like to see in a generic meta api:
So I am thinking of an api like this:
/* * Register a new meta type. * If we have a table per meta this will create the table for you if required */ register_meta_type('cron'); /* * Returns the meta value for a particular key */ get_meta_value('cron', $key); /* * Sets the meta value for a particular key */ set_meta_value('cron', $key, $value); /* * Returns the meta values for a particular key based search */ get_meta_values('cron', $search_value, $search_type); /* * Deletes the meta value for a particular key */ delete_meta_value('cron', $key);I would envisage us enabling the use of the new api with wrapper functions for different meta types as required. These wrapper functions would only be included if required, for example we could create a comment_meta wrapper api around these generic meta api functions which would only be available if a plugin / theme called
enable_comment_meta_api()Posted in Development, WordPress | Read 10 Comments