-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug #18, add
[theme]
shortcode plugin, for LD case-study [iet:7844079]
- Loading branch information
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
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
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(); |