Emoticons
<?php
/*
Plugin Name: emoticons
Plugin URI: http://www.flatpress.org/
Description: Adds emoticons to FlatPress
Author: NoWhereMan
Version: 1.0
Author URI: http://www.nowhereland.it/
*/
/*
put your imgs in FP_CONTENT/emoticons/
(tipically FP_CONTENT is fp-content/ )
*/
define('EMOTICONS_DIR', BLOG_BASEURL . FP_CONTENT . 'emoticons/');
/* now please notice how I follow this naming convention: */
function plugin_emoticons_filter($string) {
static $EMOTICONS = array(
':)' => 'smile.gif', // of course format can be whatever; I use PNGs
':(' => 'sad.gif', // these are the images you have in fp-content/emoticons/
':-)' => 'smile.gif', // you can put multiple shortcuts for the same
// etc etc
);
$ed = EMOTICONS_DIR;
foreach ($EMOTICONS as $emo => $img) {
$string = str_replace(
" $emo ", /* replace one of the codes defined above,
when *sourrounded by spaces* */
"<img src=\"{$ed}{$img}\" class=\"emoticon\" alt=\"{$emo}\" />", /* with the <img> tag
.emoticon class can be styled as you prefer in your css */
$string
);
}
return $string;
}
/* and now, don't forget to register to the hook */
add_filter( 'the_content', 'plugin_emoticons_filter' );
/* if you want it in comments too */
add_filter( 'comment_text', 'plugin_emoticons_filter' );
?>