Skip to content

Commit

Permalink
Bug #18, add [theme] shortcode plugin, for LD case-study [iet:7844079]
Browse files Browse the repository at this point in the history
  • Loading branch information
nfreear committed Jan 25, 2017
1 parent a93bfd1 commit 5c826ba
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions theme-shortcode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php namespace IET_OU\WP_Generic_Plugins;

/**
* Plugin Name: Theme shortcode
* Plugin URI:
* Description: Shortcode to insert images from a theme, via shortcode - ` [theme alt=".." src="example/image.png"] `
* Author: Nick Freear
* Author URI: https://github.com/nfreear
* Version: 1.0-alpha
*
* @copyright © 2017 The Open University (UK).
* @author Nick Freear, 24 January 2017.
*/

// http://wordpress.stackexchange.com/questions/66026/how-do-i-reference-the-theme-path-in-pages-for-images

class Theme_Shortcode_Plugin {

const SHORTCODE = 'theme';
const PATH = '/wp-content/themes/tttt-guide/images';
const TPL_IMAGE = '<img class="theme-sc x" src="%s/images/%s" alt="%s" />';

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();

0 comments on commit 5c826ba

Please sign in to comment.