?

Log in

No account? Create an account

Peter Rogers's Blog
Artist-in-Residence at Chez Firth

Wednesday (3/6/13) 3:19am - ... wherein Peter makes his second WordPress plugin.

Here's another plugin -- it sets cases on enclosed text like so:
   

[SetCase type=upper]In WordPress, with the plugin activated, this would be upper-case text.[/SetCase]





<?php
/*
Plugin Name: SetCaser
Plugin URI: http://www.hujhax.com
Description: Changes the case of the enclosed content, using [SetCase] tags.
Version: 101
Author: Peter Rogers
Author URI: http://www.hujhax.com
*/

if (!class_exists("SetCaser")) {
    class SetCaser {
        function SetCaser()
        {
            add_shortcode('SetCase', array($this,'SetTextCase'));
        }

        // this alternate-caps-es strings -- lIkE ThIs
        function CrazyCase($string)
        {
            $characters = str_split(strtolower($string));
            foreach ($characters as $key => $character)
                if ($key % 2)
                    $characters[$key] = strtoupper($character);
            return implode("", $characters);
        }

        function SetTextCase( $atts, $content = null )
        {
            $attributes = shortcode_atts(array('type' => 'upper'), $atts);

            switch ($attributes['type']) {
                case 'upper':
                    return(strtoupper($content));
                case 'lower':
                    return(strtolower($content));
                case 'words':
                    return(ucwords($content));
                case 'crazy':
                    return($this->CrazyCase($content));
                default:
                    return($content);
            }
        }
    }
}

new SetCaser();

Tags: ,
Mood: [mood icon] amused · Music: none
Previous Entry Share Next Entry