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 / alerts.php

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

108 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Shortcode Alerts 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 * Alerts
16 */
17 add_action( 'init', function () {
18 powerkit_basic_shortcodes_register( array(
19 'name' => 'alerts',
20 'title' => esc_html__( 'Alerts', 'powerkit' ),
21 'priority' => 30,
22 'base' => 'powerkit_alert',
23 'autoregister' => true,
24 'fields' => array(
25 array(
26 'type' => 'section',
27 'label' => esc_html__( 'Options', 'powerkit' ),
28 ),
29 array(
30 'type' => 'radio',
31 'name' => 'type',
32 'label' => esc_html__( 'Type', 'powerkit' ),
33 'style' => 'vertical',
34 'default' => 'info',
35 'options' => array(
36 'danger' => esc_html__( 'Danger', 'powerkit' ),
37 'info' => esc_html__( 'Info', 'powerkit' ),
38 'link' => esc_html__( 'Link', 'powerkit' ),
39 'success' => esc_html__( 'Success', 'powerkit' ),
40 'warning' => esc_html__( 'Warning', 'powerkit' ),
41 ),
42 ),
43 array(
44 'type' => 'checkbox',
45 'name' => 'dismissible',
46 'label' => esc_html__( 'Display close button', 'powerkit' ),
47 'default' => false,
48 ),
49 array(
50 'type' => 'checkbox',
51 'name' => 'multiline',
52 'label' => esc_html__( 'Multiline', 'powerkit' ),
53 'default' => false,
54 ),
55 array(
56 'type' => 'section',
57 'label' => esc_html__( 'Content', 'powerkit' ),
58 ),
59 array(
60 'type' => 'content',
61 'name' => 'content',
62 'label' => esc_html__( 'Content', 'powerkit' ),
63 'default' => '',
64 'attrs' => array(
65 'class' => 'widefat',
66 'rows' => 6,
67 ),
68 ),
69 ),
70 ) );
71 } );
72
73 /**
74 * Alert Shortcode
75 *
76 * @param array $output Shortcode HTML.
77 * @param array $atts User defined attributes in shortcode tag.
78 * @param string $content Shorcode tag content.
79 * @return string Shortcode result HTML.
80 */
81 function powerkit_basic_shortcodes_alert( $output, $atts, $content ) {
82 $dm_class = __return_empty_string();
83 $dm_button = __return_empty_string();
84
85 if ( 'true' === $atts['dismissible'] ) {
86 $dm_class .= ' pk-alert-dismissible';
87 $dm_button .= '
88 <button type="button" class="pk-close" data-dismiss="alert" aria-label="' . esc_attr__( 'Close', 'powerkit' ) . '">
89 <i class="pk-icon-x"></i>
90 </button>';
91 }
92
93 if ( 'true' === $atts['multiline'] ) {
94 $dm_class .= ' pk-alert-multiline';
95 }
96
97 $output = sprintf(
98 '<div class="pk-alert pk-alert-%s%s" role="alert" >%s%s</div>',
99 esc_attr( $atts['type'] ),
100 esc_attr( $dm_class ),
101 wp_kses( $dm_button, 'post' ),
102 wp_kses( $content, 'post' )
103 );
104
105 return $output;
106 }
107 add_filter( 'powerkit_alert_shortcode', 'powerkit_basic_shortcodes_alert', 10, 3 );
108