Skip to content

Instantly share code, notes, and snippets.

@thefuxia
Created March 5, 2011 21:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save thefuxia/856749 to your computer and use it in GitHub Desktop.
Save thefuxia/856749 to your computer and use it in GitHub Desktop.
WordPress Plugin for kitten placeholders. Defines an action and a shortcode.
<?php
/*
Plugin Name: Placekitten
Description: Shortcode [placekitten w=100 h=300 g=1 alt=kitten] and action.
Version: 1.0
Author: Thomas Scholz
Author URI: http://toscho.de
License: GPL
*/
if ( ! function_exists( 'placekitten' ) )
{
/**
* Creates an image from placekitten.com. Shortcode handler.
*
* Usage: [placekitten w=100 h=300 g=1 alt=kitten]
*
* @param array $atts
* @return string
*/
function placekitten( $atts = array() )
{
$args = (object) array_merge( array ( 'w' => 300, 'h' => 200, 'alt' => 'Kitten', 'g' => 0 ), $atts );
return "<img src='http://placekitten.com/"
. ( 0 !== (int) $args->g ? 'g/' : '' )
. "$args->w/$args->h' alt='$args->alt'>";
}
/**
* Prints a placekitten.
*
* Usage: do_action( 'placekitten', array ( 'w' => 100 ) );
*
* @param array $args
* @return void
*/
function print_placekitten( $args )
{
print placekitten( $args );
}
add_shortcode( 'placekitten', 'placekitten' );
add_action( 'placekitten', 'print_placekitten', 10, 1 );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment