From 5c826ba57c3b8a7df906d11efd0e5d85480c2385 Mon Sep 17 00:00:00 2001 From: Nick Freear Date: Wed, 25 Jan 2017 10:57:18 +0000 Subject: [PATCH] Bug #18, add `[theme]` shortcode plugin, for LD case-study [iet:7844079] --- theme-shortcode.php | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 theme-shortcode.php diff --git a/theme-shortcode.php b/theme-shortcode.php new file mode 100644 index 0000000..b5a8626 --- /dev/null +++ b/theme-shortcode.php @@ -0,0 +1,40 @@ +'; + + public function __construct() { + add_shortcode( self::SHORTCODE, [ &$this, 'shortcode' ] ); + } + + public function shortcode( $attrs = [], $content = null ) { + $inp = (object) shortcode_atts( [ + 'src' => null, + 'alt' => null, + ], $attrs ); + + $theme_uri = is_child_theme() + ? get_stylesheet_directory_uri() + : get_template_directory_uri(); + + return sprintf( self::TPL_IMAGE, $theme_uri, $inp->src, $inp->alt ); + } +} +$plugin = new Theme_Shortcode_Plugin();