Posts Tagged ‘plugin’

Locale dependent actions in WordPress

Wednesday, April 2nd, 2008

For some reason or other there are actions in WordPress that have translatable fields in them, so when these actions are used on other languages than English, they change. They are actions involving the $page_hook variable., e.g. admin_head-$page_hook. I ran into this problem when updating More Fields. The problem in the context of plugins is that the language is not loaded when the plugins are loaded, so that the needed translation is not available. To get around this, the actions requiring translation are called at the ‘admin_init’ action instead.

function mf_pre_queue_js () {
    add_action('load-' . sanitize_title(__('Settings')) . '_page_more-fields', 'mf_queue_js');
}
add_action('admin_init', 'mf_pre_queue_js');

I got help with this on the wp-hackers mailng list - a great source for WordPress insights.

>Try adding your actions on the init hook, I think that runs after
>the translatable stuff has been loaded and setup.

Correct.

Everything related to languages should be done at init or later, so that everything is loaded and any plugins that modify the content are loaded.

So, at the init/admin_init hook, we’re safe to assume that the appropriate language has been loaded.

Setting the template for individual posts

Thursday, March 20th, 2008

I hashed together a plugin that enables authors to specify a specific template file to be used for a post (this functionality is already built in for pages, but not for posts).

<?php
/*
Plugin Name: Template for posts
Plugin URI: http://labs.dagensskiva.com
Description: Set the template file for a post by setting the Custom Field 'dsc_template' to the filename of the template
Version: 0.1
Author: Henrik
*/
?>

function dsc_post_template() {
  global $post, $wp_query;

  if (count($wp_query->posts) == 1) {
    $id = $wp_query->posts[0]->ID;
    if ($temp = get_post_meta($id, 'dsc_template', true)) {
      include( TEMPLATEPATH . '/' .$temp );
      exit(0);
    }
  }
}
add_filter('template_redirect', 'dsc_post_template', 9);

Usage: a Custom Field called ‘dsc_template’ is set to equal the basename of the file, e.g. ‘interview.php’, placed inside your theme folder. Simple as that. It only applies the template file if $wp_query contains only one post, i.e. where the template file ’single.php’ would normally be applied.

The ‘Post Links’ plugin released on WordPress.org

Friday, January 25th, 2008

I’ve put up the latest in the string of plugins derived from the development work of dagensskiva.com into the WordPress Plugin repository. It is called ‘Post Links’, and is a system to add links to a post (as many as you want), and then easily display them in templates.

More information about the plugin can be found here, and it can be downloaded from WordPress.org.

The plugin can be seen in action on e.g. this review, under ‘Externa Länkar’.

We release the ‘Ad-minister’ Wordpress plugin!

Sunday, January 20th, 2008

We have now released our ad management WordPress plugin developed for dagensskiva.com. More info about the plugin can be found here.

The plugin can be downloaded from Wordpress.org.

As usual, this is beta software, and it’s licensed under the GPL:

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see .

Do enjoy, and I appreciate any feedback.

We release the ‘More Fields’ Wordpress plugin!

Thursday, January 10th, 2008

Finally, having uhhmm’d and ahhrree’d about implementation, I’ve decided submit the 0.4 beta version of the ‘More Fields’ plugin to the Wordpress Plugins CVS server, else it might never happen.

You can find more information about the plugin here. I’m hoping to update the examples to reflect the current look of the plugin, albeit I’m still hoping for a redesign of the ‘More Fields’ admin for some future version.

You can download the plugin from Wordpress.org.

The plugin is a beta, which means it might be riddled with bugs and oddities that might sink your particular Wordpress ship. It is released under the GPL license.

As always, feedback and comments are always very much appreciated.

I’m quite exited to see this one out the door. There are another two proprietary plugins that we currently run on dagensskiva.com - one that handles the external links associated with posts, and one (sizable) ad-management system. I’m hoping that these will also be released shortly.

Removing the podPress footer completely

Wednesday, November 14th, 2007

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’.