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

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

139 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Shortcode Buttons 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 * Buttons
16 */
17 add_action( 'init', function () {
18 powerkit_basic_shortcodes_register( array(
19 'name' => 'buttons',
20 'title' => esc_html__( 'Buttons', 'powerkit' ),
21 'priority' => 20,
22 'base' => 'powerkit_button',
23 'autoregister' => true,
24 'fields' => array(
25 array(
26 'type' => 'section',
27 'label' => esc_html__( 'Style Options', 'powerkit' ),
28 ),
29 array(
30 'type' => 'radio',
31 'name' => 'size',
32 'label' => esc_html__( 'Size', 'powerkit' ),
33 'style' => 'horizontal',
34 'default' => 'md',
35 'options' => array(
36 'sm' => esc_html__( 'Small', 'powerkit' ),
37 'md' => esc_html__( 'Default', 'powerkit' ),
38 'lg' => esc_html__( 'Large', 'powerkit' ),
39 ),
40 ),
41 array(
42 'type' => 'radio',
43 'name' => 'style',
44 'label' => esc_html__( 'Style', 'powerkit' ),
45 'style' => 'vertical',
46 'default' => 'primary',
47 'options' => array(
48 'primary' => esc_html__( 'Primary', 'powerkit' ),
49 'secondary' => esc_html__( 'Secondary', 'powerkit' ),
50 'success' => esc_html__( 'Success', 'powerkit' ),
51 'info' => esc_html__( 'Info', 'powerkit' ),
52 'warning' => esc_html__( 'Warning', 'powerkit' ),
53 'danger' => esc_html__( 'Danger', 'powerkit' ),
54 'link' => esc_html__( 'Link', 'powerkit' ),
55 ),
56 ),
57 array(
58 'type' => 'checkbox',
59 'name' => 'block',
60 'label' => esc_html__( 'Block', 'powerkit' ),
61 'default' => false,
62 ),
63 array(
64 'type' => 'section',
65 'label' => esc_html__( 'Link Options', 'powerkit' ),
66 ),
67 array(
68 'type' => 'input',
69 'name' => 'url',
70 'label' => esc_html__( 'URL', 'powerkit' ),
71 'default' => 'http://',
72 ),
73 array(
74 'type' => 'radio',
75 'name' => 'target',
76 'label' => esc_html__( 'Link target', 'powerkit' ),
77 'style' => 'vertical',
78 'default' => '_self',
79 'options' => array(
80 '_self' => esc_html__( 'Open in same window', 'powerkit' ),
81 '_blank' => esc_html__( 'Open in new window/tab', 'powerkit' ),
82 ),
83 ),
84 array(
85 'type' => 'content',
86 'name' => 'title',
87 'label' => esc_html__( 'Title', 'powerkit' ),
88 'default' => 'Button',
89 'attrs' => array(
90 'class' => 'widefat',
91 'rows' => 6,
92 ),
93 ),
94 array(
95 'type' => 'checkbox',
96 'name' => 'nofollow',
97 'label' => esc_html__( 'Apply "nofollow" attribute', 'powerkit' ),
98 'default' => false,
99 ),
100 ),
101 ) );
102 });
103
104 /**
105 * Button Shortcode
106 *
107 * @param array $output Shortcode HTML.
108 * @param array $atts User defined attributes in shortcode tag.
109 * @param string $content Shorcode tag content.
110 * @return string Shortcode result HTML.
111 */
112 function powerkit_basic_shortcodes_button( $output, $atts, $content ) {
113 $block = ( 'true' === $atts['block'] ) ? ' pk-button-block' : '';
114
115 if ( isset( $atts['title'] ) && $atts['title'] ) {
116 $title = $atts['title'];
117 }
118
119 if ( $content ) {
120 $title = $content;
121 }
122
123 $output = sprintf(
124 '<a class="pk-button pk-button-%s pk-button-%s%s pk-font-primary" href="%s" target="%s" %s>
125 %s
126 </a>',
127 esc_attr( $atts['size'] ),
128 esc_attr( $atts['style'] ),
129 esc_attr( $block ),
130 esc_url( $atts['url'] ),
131 esc_attr( $atts['target'] ),
132 ( ( 'true' === $atts['nofollow'] ) ? 'rel="nofollow"' : '' ),
133 wp_kses( $title, 'post' )
134 );
135
136 return $output;
137 }
138 add_filter( 'powerkit_button_shortcode', 'powerkit_basic_shortcodes_button', 10, 3 );
139