PluginProbe
Powerkit – Supercharge your WordPress Site / trunk
Powerkit – Supercharge your WordPress Site vtrunk
3.1.1 3.1.0 3.0.9 3.0.8 trunk 2.2.6 2.2.7 2.2.8 2.2.9 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.3.8 2.3.9 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 All 87 releases
powerkit / modules / basic-elements / templates / progressbars.php

progressbars.php in Powerkit – Supercharge your WordPress Site trunk, at modules/basic-elements/templates/progressbars.php

129 lines 3.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Shortcode Progress Bars config
4 *
5 * @package Powerkit
6 * @subpackage Templates
7 */
8
9 // Exit if accessed directly.
10 if ( ! defined( 'ABSPATH' ) ) {
11 exit;
12 }
13
14 /**
15 * Progress Bars
16 */
17 add_action( 'init', function () {
18 powerkit_basic_shortcodes_register( array(
19 'name' => 'progressbars',
20 'title' => esc_html__( 'Progress Bars', 'powerkit' ),
21 'priority' => 60,
22 'base' => 'powerkit_progressbar',
23 'autoregister' => true,
24 'fields' => array(
25 array(
26 'type' => 'section',
27 'label' => esc_html__( 'Options', 'powerkit' ),
28 ),
29 array(
30 'type' => 'input',
31 'name' => 'value',
32 'label' => esc_html__( 'Value', 'powerkit' ),
33 'default' => '25',
34 'suffix' => ' %',
35 'desc' => '(0-100)',
36 ),
37 array(
38 'type' => 'section',
39 'label' => esc_html__( 'Style', 'powerkit' ),
40 ),
41 array(
42 'type' => 'input',
43 'name' => 'height',
44 'label' => esc_html__( 'Height (thickness)', 'powerkit' ),
45 'default' => '20',
46 'suffix' => ' px',
47 ),
48 array(
49 'type' => 'radio',
50 'name' => 'color',
51 'label' => esc_html__( 'Color', 'powerkit' ),
52 'style' => 'vertical',
53 'default' => 'primary',
54 'options' => array(
55 'primary' => esc_html__( 'Primary', 'powerkit' ),
56 'secondary' => esc_html__( 'Secondary', 'powerkit' ),
57 'success' => esc_html__( 'Success', 'powerkit' ),
58 'info' => esc_html__( 'Info', 'powerkit' ),
59 'warning' => esc_html__( 'Warning', 'powerkit' ),
60 'danger' => esc_html__( 'Danger', 'powerkit' ),
61 ),
62 ),
63 array(
64 'type' => 'checkbox',
65 'name' => 'display_value',
66 'label' => esc_html__( 'Display value', 'powerkit' ),
67 'default' => false,
68 ),
69 array(
70 'type' => 'checkbox',
71 'name' => 'striped',
72 'label' => esc_html__( 'Striped', 'powerkit' ),
73 'default' => false,
74 ),
75 array(
76 'type' => 'checkbox',
77 'name' => 'animated',
78 'label' => esc_html__( 'Animated', 'powerkit' ),
79 'default' => false,
80 ),
81 ),
82 ) );
83 });
84
85 /**
86 * Progress Bar Shortcode
87 *
88 * @param array $output Shortcode HTML.
89 * @param array $atts User defined attributes in shortcode tag.
90 * @param string $content Shorcode tag content.
91 * @return string Shortcode result HTML.
92 */
93 function powerkit_basic_shortcodes_progressbar( $output, $atts, $content ) {
94
95 // Value.
96 $atts['value'] = ( is_numeric( $atts['value'] ) && $atts['value'] > 100 ) ? 100 : $atts['value'];
97
98 // Display value.
99 $display_value = ( 'true' === $atts['display_value'] ) ? esc_html( $atts['value'] ) . '%' : '';
100
101 // Striped and animated.
102 $class = 'pk-progress-bar';
103 $class .= ( 'true' === $atts['striped'] ) ? ' pk-progress-bar-striped' : '';
104 $class .= ( 'true' === $atts['animated'] ) ? ' pk-progress-bar-animated' : '';
105
106 // Color.
107 $class .= ' pk-bg-' . sanitize_html_class( $atts['color'] );
108
109 // Dimensions. Both are cast to a number so they can never break out of the
110 // style attribute. A non-numeric value drops the declaration, which is how
111 // a browser already treats an invalid one.
112 $height_css = is_numeric( $atts['height'] ) ? sprintf( 'height: %spx;', (float) $atts['height'] ) : '';
113 $width_css = is_numeric( $atts['value'] ) ? sprintf( 'width: %s%%;', (float) $atts['value'] ) : '';
114
115 $output = sprintf(
116 '<div class="pk-progress" style="%2$s">
117 <div class="%1$s" role="progressbar" style="%3$s" aria-valuenow="%4$s" aria-valuemin="0" aria-valuemax="100">%5$s</div>
118 </div>',
119 esc_attr( $class ),
120 esc_attr( $height_css ),
121 esc_attr( $width_css ),
122 esc_attr( $atts['value'] ),
123 $display_value
124 );
125
126 return $output;
127 }
128 add_filter( 'powerkit_progressbar_shortcode', 'powerkit_basic_shortcodes_progressbar', 10, 3 );
129