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