Wordpress

Wordpress: qTranslate and Shopp Plugin II

Just a quick reminder: Shopp Plugin and qTranslate don’t play nice when it comes to Pretty Links / Permalinks. In this case the root of all evil seems to be Wordpress because with a typical setup bloginfo('url') displays http://mydomain.com/en i.e. the correct qTranslate URL, but get_bloginfo('url') returns http://mydomain.com.

One possible fix includes hacking shoppurl in the functions.php file of the Shopp plugin – simply replace get_bloginfo('url') with get_bloginfo('url', 'display').


Wordpress: qTranslate and Shopp Plugin

qTranslate is a lets say sufficient free plugin that enables multilingual wordpress setups. For a free plugin it is really feature rich, but when it comes to interact with the really nice shopp plugin, there are a few shortcommings. Especially, there is no way (besides writing qtranslate’s comments by hand) to translate the product summaries. This however can be resolved rather easy, because the product-summary field is more or less identical to wordpress own postexcerpt field. The later can be translated by qTranslate with qTranslates internal qtrans_modifyExcerpt() function.

So if we want to add translation für shopp product summaries, we simply have to take that function, adjust it to our needs and call it at the right spot. Without further ado – add the code below to your functions.php and you are done.

function tao_qtrans_modifyProductSummary() {
	global $q_config;
	echo "<script type="text/javascript">\n";
	echo "if(jQuery('#summary').size()>0) {";
	echo $q_config['js']['qtrans_is_array'];
	echo $q_config['js']['qtrans_xsplit'];
	echo $q_config['js']['qtrans_split'];
	echo $q_config['js']['qtrans_integrate'];
	echo $q_config['js']['qtrans_switch_postbox'];
	echo $q_config['js']['qtrans_use'];
	$el = qtrans_getSortedLanguages();
	foreach($el as $language) {
		echo qtrans_createTitlebarButton('product-summary', $language, 'summary', 'qtrans_switcher_product-summary_'.$language);
		echo qtrans_createTextArea('product-summary', $language, 'summary', 'qtrans_switcher_product-summary_'.$language);
	}
	echo "qtrans_switch_postbox('product-summary','summary','".$q_config['default_language']."');";
	echo "jQuery('#summary').hide();";
	echo "}";
	echo "\n</script>\n";
}

if( function_exists('qtrans_createTitlebarButton') &&
	function_exists('qtrans_createTextArea') ) {
	add_filter('admin_footer', 'tao_qtrans_modifyProductSummary');
}


Add custom post types to your wordpress feed

Most well-structured wordpress projects these days make heavy use of custom post types to cleanly separate different kinds of information.

Sadly by default, these post types are not available in your main wordpress RSS / ATOM feed, but luckily this can easily be fixed.

Just paste the following Code in your functions.php and all entries of all your custom post types are added to your RSS / ATOM feed.

add_filter('pre_get_posts',
	create_function('$query',
		'if ($query->is_feed) $query->set("post_type","any");
		return $query;'
	)
);

If you want to be more specific about what to add to your feed, simply change “any” to an array of post_types. For example:

add_filter('pre_get_posts',
	create_function('$query',
		'if ($query->is_feed)
			$query->set("post_type",array("post", "my_custom"));
		return $query;'
	)
);

As you are accessing the wordpress query object, the same technique can also be used to change the post order in your feed, or add custom category filters etc…


Enable iframes for wordpress posts

By default wordpress removes iframe tags from posts. This is not always the desired behavior as youtube, vimeo and other widgets are added via iframes.

The filtering of iframe tags is performed on the clientside by the javascript editor tinymce as well as on the serverside by the wordpress whitelist filter. Therefor, to disable iframe filtering, it is neccessary to add two hooks to either a plugin or the functions.php of your theme:

Disable iframe filtering in tinymce

Simply add the following code to your functions.php – this adds iframes as valid elements for tinymce:

add_filter('tiny_mce_before_init', create_function('$a', '$a["extended_valid_elements"] = "iframe[id|class|align|frameborder|height|name|scrolling|src|width|title|style]";return $a;'));

Disable server-side iframe filtering

Add this code to your functions.php – it adds iframes to the whitelist of wordpress:

global $allowedposttags;
$allowedposttags["iframe"] = array("id" => array(),"class" => array(), "align" => array(),"frameborder" => array(),"title" => array(),"style" => array(),"name" => array(),"scrolling" => array(),"src" => array(),"height" => array(),"width" => array());


Fixing Mailchimp Plugin translation

Translation / i18n of the mailchimp plugin does not work for me on Wordpress 3.0+. The cause of this seems to be the mailchimpSF_plugin_init function using ≤code>load_plugin_textdomain in the old and deprecated way (mailchimp.php, line 62):

load_plugin_textdomain( 'mailchimp_i18n', MCSF_DIR.'po/');

simply open mailchimp.php and change line 62 to:

load_plugin_textdomain( 'mailchimp_i18n', false, dirname(plugin_basename( __FILE__ )) . '/po');

and translation should work again.


Wordpress 3.0 update, custom post types and redirection

If you already used custom post types in wordpress 2.9, and wrote your own rewrite rules to access them you should be aware of a little problem with wordpress 3.0. If you did not explicitly set the rewrite parameter of register_post_type chances are good, that your rewrite rules will not work as expected, because the new custom post type rules will overwrite them and add quite a few 301 redirections to your page.

So in our case we needed to update:

register_post_type(array (
// unimportant setup code
'public' => false,
'publicly_queryable' => true,
'supports' => $supports
));

to

register_post_type(array (
// unimportant setup code
'public' => false,
'publicly_queryable' => true,
'supports' => $supports,
'rewrite' => false
));

to make urls behave nicely again.


Refine the Wordpress Admin Menu


This hacky plugin still does a magnificent Job in allowing you to customize Position, Title and Visibility of Wordpress Admin Menu Items. In case you want to provide your users an easy, stripped down interface, this plugin should be the perfect solution.

The only letdown is, that it has a small conflict with wordpress. It bundles another version of JSON.php that is not 100% compatible with the one Wordpress itself ships. If you need specific functions like Services_JSON::encodeUnsafe, you have to work around that by adding

function encodeUnsafe($var) { return $this->encode($var); }

to the plugins JSON.php

Admin Menu Editor For WordPress | W-Shadow.com


Wordpress TinyMCE configuration

TinyMCE, the preferred Text Editor of wordpress is surely lacking in the configurability department. Hence lot’s of Plugins (e.g. this extremely heavy one) that enable you to alter or extend its default settings exist.

Still i did not find a suitable plugin for my extremely simple task of changing a few init options. Luckily wordpress provides the tiny_mce_before_init action, that gives you full access to all init options. No need to hack the wordpress core files there!

A quick Example:

If you put this simple piece of code in your plugin file or functions.php, it switchs the default entity encoding of tinymce to ‘raw’.