My First Plugin (that actually does something)
I have to say that if you've ever had the slightest inclination to write a WordPress plugin, Vladimir Prelovac's book is exactly what you need. I'll write a proper review once I've finished it, because (like reading the best erotica) I have to keep stopping. So if for no other reason than to amuse future-me at how basic I once was, here's what I wrote this afternoon. It translates blog posts into pig latin, and has no other use than to amuse me:
<?php
/*
Plugin Name: Ordpressway Luginpay
Version: 0.1
Description: translates the text of your blog into pig latin
Author: Sue Bailey
Author URI: http://blogmum.com
Plugin URI: http://blogmum.com/plugins
*/
global $wp_version;
//this particular plugin should work on any version of WP, I think; but I'm going to get into the habit of thinking about version compatibility right from the start
$exit_msg = 'This plugin requires WordPress 2.5 or higher. Please upgrade!';
if (version_compare($wp_version, "2.5", "<")) {
exit($exit_msg);
}
function translate_piglatin($text) {
$text = strtolower($text);
$text = strip_tags($text);
$text_array = explode(" ", $text);
foreach ($text_array as $word) {
$prefix = substr($word, 0, 1);
$suffix = substr($word, 1);
$piglatin = $suffix.$prefix."ay";
$output_string .= " ".$piglatin;
}
echo $output_string;
}
function piglatinise($content) {
return translate_piglatin($content);
}
//automatically apply the function to the content
add_filter('the_content', 'piglatinise');
?>
If by any mental chance you should want to install this, copy above, save as piglatin.php, upload to wp-content/plugins and enable from WP Admin. But, really, don't.
Tags: my plugins







