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

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

89 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Shortcode Separators 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 * Separators
16 */
17 add_action( 'init', function () {
18 powerkit_basic_shortcodes_register( array(
19 'name' => 'separators',
20 'title' => esc_html__( 'Separators', 'powerkit' ),
21 'priority' => 10,
22 'base' => 'powerkit_separator',
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' => 'style',
32 'label' => esc_html__( 'Style', 'powerkit' ),
33 'style' => 'vertical',
34 'default' => 'solid',
35 'options' => array(
36 'solid' => esc_html__( 'Solid', 'powerkit' ),
37 'double' => esc_html__( 'Double', 'powerkit' ),
38 'dotted' => esc_html__( 'Dotted', 'powerkit' ),
39 'dashed' => esc_html__( 'Dashed', 'powerkit' ),
40 'blank' => esc_html__( 'Blank (empty space)', 'powerkit' ),
41 ),
42 ),
43 array(
44 'type' => 'input',
45 'name' => 'height',
46 'label' => esc_html__( 'Height', 'powerkit' ),
47 'default' => '',
48 'suffix' => ' px',
49 ),
50 ),
51 ) );
52 });
53
54 /**
55 * Separator Shortcode
56 *
57 * @param array $output Shortcode HTML.
58 * @param array $atts User defined attributes in shortcode tag.
59 * @param string $content Shorcode tag content.
60 * @return string Shortcode result HTML.
61 */
62 function powerkit_basic_shortcodes_separator( $output, $atts, $content ) {
63
64 // Allowed CSS border-style keywords. The list is wider than the options the
65 // radio field offers, so a hand-written style="groove" keeps working. Any
66 // other value drops the declaration, which is how a browser already treats
67 // an invalid one.
68 $allowed_styles = array( 'none', 'hidden', 'dotted', 'dashed', 'solid', 'double', 'groove', 'ridge', 'inset', 'outset' );
69
70 if ( 'blank' === $atts['style'] ) {
71 $inl_css = sprintf( 'style="height: %dpx;"', absint( $atts['height'] ) );
72 } else {
73 $border_style = in_array( $atts['style'], $allowed_styles, true )
74 ? sprintf( ' border-bottom-style: %s;', $atts['style'] )
75 : '';
76
77 $inl_css = sprintf( 'style="border-bottom-width: %dpx;%s"', absint( $atts['height'] ), $border_style );
78 }
79
80 $output = sprintf(
81 '<div class="pk-separator" %s>%s</div>',
82 $inl_css,
83 wp_kses( $content, 'post' )
84 );
85
86 return $output;
87 }
88 add_filter( 'powerkit_separator_shortcode', 'powerkit_basic_shortcodes_separator', 10, 3 );
89