Created
May 15, 2017 18:30
-
-
Save ScaredStorm/da9cf86dd21a0ad4f17cd7980f009299 to your computer and use it in GitHub Desktop.
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 | |
/** | |
* Paste in functions.php | |
* | |
* Use this shortcode in the wordpress WYSIWYG editor like so: | |
* [progressbar current=70 color=success] | |
* [progressbar current=60 color=warning] | |
* [progressbar current=50 color=error] | |
* [progressbar current=40 color=info] | |
* [progressbar current=30] | |
* [progressbar current=90 text='Simple text'] | |
*/ | |
function sc_progress_bar($atts) { | |
$atts = shortcode_atts(array( | |
'min' => 0, | |
'max' => 100, | |
'current' => 0, | |
'text' => '', | |
'color' => '' | |
), $atts); | |
$percentage = 100 * (($atts['current'] - $atts['min'])/($atts['max']-$atts['min'])); | |
$color = ''; | |
if (!empty($atts['color'])) { | |
$color = 'progress-bar-'.$atts['color']; | |
} | |
ob_start(); | |
?> | |
<div class="progress"> | |
<div class="progress-bar <?= $color; ?>" role="progressbar" aria-valuenow="<?= $atts['current']; ?>" aria-valuemin="<?= $atts['min']; ?>" aria-valuemax="<?= $atts['max']; ?>" style="width: <?= $percentage; ?>%;"> | |
<?= $atts['text']; ?> | |
</div> | |
</div> | |
<?php | |
return ob_get_clean(); | |
} | |
add_shortcode('progressbar', 'sc_progress_bar'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment