-
-
Save wycks/4170788 to your computer and use it in GitHub Desktop.
WordPress Plugin for kitten placeholders. Defines an action and a shortcode.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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