| 1 |
<?php |
| 2 |
/** |
| 3 |
* Shortcode Progress Bars config |
| 4 |
* |
| 5 |
* @package Powerkit |
| 6 |
* @subpackage Templates |
| 7 |
*/ |
| 8 |
|
| 9 |
/** |
| 10 |
* Progress Bars |
| 11 |
*/ |
| 12 |
powerkit_basic_shortcodes_register( array( |
| 13 |
'name' => 'progressbars', |
| 14 |
'title' => esc_html__( 'Progress Bars', 'powerkit' ), |
| 15 |
'priority' => 60, |
| 16 |
'base' => 'powerkit_progressbar', |
| 17 |
'autoregister' => true, |
| 18 |
'fields' => array( |
| 19 |
array( |
| 20 |
'type' => 'section', |
| 21 |
'label' => esc_html__( 'Options', 'powerkit' ), |
| 22 |
), |
| 23 |
array( |
| 24 |
'type' => 'input', |
| 25 |
'name' => 'value', |
| 26 |
'label' => esc_html__( 'Value', 'powerkit' ), |
| 27 |
'default' => '25', |
| 28 |
'suffix' => ' %', |
| 29 |
'desc' => '(0-100)', |
| 30 |
), |
| 31 |
array( |
| 32 |
'type' => 'section', |
| 33 |
'label' => esc_html__( 'Style', 'powerkit' ), |
| 34 |
), |
| 35 |
array( |
| 36 |
'type' => 'input', |
| 37 |
'name' => 'height', |
| 38 |
'label' => esc_html__( 'Height (thickness)', 'powerkit' ), |
| 39 |
'default' => '20', |
| 40 |
'suffix' => ' px', |
| 41 |
), |
| 42 |
array( |
| 43 |
'type' => 'radio', |
| 44 |
'name' => 'color', |
| 45 |
'label' => esc_html__( 'Color', 'powerkit' ), |
| 46 |
'style' => 'vertical', |
| 47 |
'default' => 'primary', |
| 48 |
'options' => array( |
| 49 |
'primary' => esc_html__( 'Primary', 'powerkit' ), |
| 50 |
'secondary' => esc_html__( 'Secondary', 'powerkit' ), |
| 51 |
'success' => esc_html__( 'Success', 'powerkit' ), |
| 52 |
'info' => esc_html__( 'Info', 'powerkit' ), |
| 53 |
'warning' => esc_html__( 'Warning', 'powerkit' ), |
| 54 |
'danger' => esc_html__( 'Danger', 'powerkit' ), |
| 55 |
), |
| 56 |
), |
| 57 |
array( |
| 58 |
'type' => 'checkbox', |
| 59 |
'name' => 'display_value', |
| 60 |
'label' => esc_html__( 'Display value', 'powerkit' ), |
| 61 |
'default' => false, |
| 62 |
), |
| 63 |
array( |
| 64 |
'type' => 'checkbox', |
| 65 |
'name' => 'striped', |
| 66 |
'label' => esc_html__( 'Striped', 'powerkit' ), |
| 67 |
'default' => false, |
| 68 |
), |
| 69 |
array( |
| 70 |
'type' => 'checkbox', |
| 71 |
'name' => 'animated', |
| 72 |
'label' => esc_html__( 'Animated', 'powerkit' ), |
| 73 |
'default' => false, |
| 74 |
), |
| 75 |
), |
| 76 |
) ); |
| 77 |
|
| 78 |
|
| 79 |
/** |
| 80 |
* Progress Bar Shortcode |
| 81 |
* |
| 82 |
* @param array $output Shortcode HTML. |
| 83 |
* @param array $atts User defined attributes in shortcode tag. |
| 84 |
* @param string $content Shorcode tag content. |
| 85 |
* @return string Shortcode result HTML. |
| 86 |
*/ |
| 87 |
function powerkit_basic_shortcodes_progressbar( $output, $atts, $content ) { |
| 88 |
|
| 89 |
// Value. |
| 90 |
$atts['value'] = $atts['value'] > 100 ? 100 : $atts['value']; |
| 91 |
|
| 92 |
// Display value. |
| 93 |
$display_value = ( 'true' === $atts['display_value'] ) ? $atts['value'] . '%' : ''; |
| 94 |
|
| 95 |
// Striped and animated. |
| 96 |
$class = 'pk-progress-bar'; |
| 97 |
$class .= ( 'true' === $atts['striped'] ) ? ' pk-progress-bar-striped' : ''; |
| 98 |
$class .= ( 'true' === $atts['animated'] ) ? ' pk-progress-bar-animated' : ''; |
| 99 |
|
| 100 |
// Color. |
| 101 |
$class .= sprintf( ' pk-bg-%s', $atts['color'] ); |
| 102 |
|
| 103 |
$output = sprintf( |
| 104 |
'<div class="pk-progress" style="height: %2$spx;"> |
| 105 |
<div class="%s" role="progressbar" style="width: %3$s%%;" aria-valuenow="%3$s" aria-valuemin="0" aria-valuemax="100">%4$s</div> |
| 106 |
</div>', |
| 107 |
$class, |
| 108 |
$atts['height'], |
| 109 |
$atts['value'], |
| 110 |
$display_value |
| 111 |
); |
| 112 |
|
| 113 |
return $output; |
| 114 |
} |
| 115 |
add_filter( 'powerkit_progressbar_shortcode', 'powerkit_basic_shortcodes_progressbar', 10, 3 ); |
| 116 |
|