public
Last active

WordPress Plugin for kitten placeholders. Defines an action and a shortcode.

  • Download Gist
placekitten.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
<?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 );
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.