Skip to content
Snippets Groups Projects
Commit 2693a2a6 authored by Lauren's avatar Lauren
Browse files

Added ability for buttons to open in a new tab

parent fe32a80d
No related branches found
No related tags found
No related merge requests found
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
title : 'Insert a Button', title : 'Insert a Button',
body: [ body: [
{type: 'textbox', name: 'link', label: 'Link'}, {type: 'textbox', name: 'link', label: 'Link'},
{type: 'checkbox', name: 'new_tab', label: 'Open link in a new tab'},
{type: 'textbox', name: 'content', label: 'Button Text' }, {type: 'textbox', name: 'content', label: 'Button Text' },
{type: 'listbox', {type: 'listbox',
name: 'type', name: 'type',
...@@ -56,7 +57,10 @@ ...@@ -56,7 +57,10 @@
], ],
onsubmit: function(e) { onsubmit: function(e) {
ed.focus(); ed.focus();
ed.selection.setContent('[lbdesign_button link="' + e.data.link + '" type="' + e.data.type + '" size="' + e.data.size + '" style="' + e.data.styles + '" custom_class="' + e.data.custom_class + '"]' + e.data.content + '[/lbdesign_button]');
// build shortcode that gets inserted into the content when 'ok' is pressed on the modal
// [lbdesign_button link="" new_tab="" type="" size="" style="" custom_class=""][/lbdesign_button]
ed.selection.setContent('[lbdesign_button link="' + e.data.link + '" new_tab="' + e.data.new_tab + '" type="' + e.data.type + '" size="' + e.data.size + '" style="' + e.data.styles + '" custom_class="' + e.data.custom_class + '"]' + e.data.content + '[/lbdesign_button]');
} }
}); });
}); });
......
...@@ -13,8 +13,11 @@ function lbdesign_button_shortcode( $atts, $content = null ) { ...@@ -13,8 +13,11 @@ function lbdesign_button_shortcode( $atts, $content = null ) {
$classes[] = ''; $classes[] = '';
$target = '';
$atts = shortcode_atts(array( $atts = shortcode_atts(array(
'link' => null, 'link' => null,
'new_tab' => false,
'type' => 'default', 'type' => 'default',
'color' => 'default', 'color' => 'default',
'size' => 'default', 'size' => 'default',
...@@ -24,17 +27,21 @@ function lbdesign_button_shortcode( $atts, $content = null ) { ...@@ -24,17 +27,21 @@ function lbdesign_button_shortcode( $atts, $content = null ) {
foreach ( $atts as $key => $att ) { foreach ( $atts as $key => $att ) {
if( $key !== 'link' && $key !== 'custom_class' && $att !== null && $att !== '' && $att !== 'default' ) { if( $key !== 'link' && $key !== 'new_tab' && $key !== 'custom_class' && $att !== null && $att !== '' && $att !== 'default' ) {
$classes[] = 'lbdesign_' . esc_attr( $att ); $classes[] = 'lbdesign_' . strtolower( esc_attr( $att ) );
} }
if( $key == 'custom_class' ) { if( $key == 'custom_class' ) {
$classes[] = esc_attr( $att ); $classes[] = esc_attr( $att );
} }
if( $key == 'new_tab' && false !== $att && "false" !== $att ) {
$target = 'target="_blank"';
}
} }
return '<a class="lbdesign_button ' . implode( $classes, " " ) . '" href="' . esc_url( $atts['link'] ) . '">' . do_shortcode( $content ) . '</a>'; return '<a class="lbdesign_button ' . implode( $classes, " " ) . '" href="' . esc_url( $atts['link'] ) . '" ' . $target . '>' . do_shortcode( $content ) . '</a>';
} }
add_shortcode( 'lbdesign_button', 'lbdesign_button_shortcode' ); add_shortcode( 'lbdesign_button', 'lbdesign_button_shortcode' );
......
...@@ -34,6 +34,9 @@ This simple plugin allows you to add call-to-action buttons to post and page con ...@@ -34,6 +34,9 @@ This simple plugin allows you to add call-to-action buttons to post and page con
* Pill * Pill
* Block * Block
= Shortcode formatting: =
[lbdesign_button link="" type="" size="" style="" custom_class=""]Button text[/lbdesign_button]
== Installation == == Installation ==
1. Upload `lbdesign-button-shortcode` to the `/wp-content/plugins/` directory 1. Upload `lbdesign-button-shortcode` to the `/wp-content/plugins/` directory
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment