| 1 |
<?php |
| 2 |
/** |
| 3 |
* Handle the link shortcode. |
| 4 |
* |
| 5 |
* @link https://bootstrapped.ventures |
| 6 |
* @since 3.8.0 |
| 7 |
* |
| 8 |
* @package WP_Ultimate_Post_Grid |
| 9 |
* @subpackage WP_Ultimate_Post_Grid/includes/public/shortcodes/item |
| 10 |
*/ |
| 11 |
|
| 12 |
/** |
| 13 |
* Handle the link shortcode. |
| 14 |
* |
| 15 |
* @since 3.8.0 |
| 16 |
* @package WP_Ultimate_Post_Grid |
| 17 |
* @subpackage WP_Ultimate_Post_Grid/includes/public/shortcodes/item |
| 18 |
* @author Brecht Vandersmissen <brecht@bootstrapped.ventures> |
| 19 |
*/ |
| 20 |
class WPUPG_SC_Link extends WPUPG_Template_Shortcode { |
| 21 |
public static $shortcode = 'wpupg-link'; |
| 22 |
|
| 23 |
public static function init() { |
| 24 |
self::$attributes = array( |
| 25 |
'link' => array( |
| 26 |
'default' => '', |
| 27 |
'type' => 'text', |
| 28 |
), |
| 29 |
'link_target' => array( |
| 30 |
'default' => '_blank', |
| 31 |
'type' => 'dropdown', |
| 32 |
'options' => array( |
| 33 |
'_self' => 'Open in same tab', |
| 34 |
'_blank' => 'Open in new tab', |
| 35 |
), |
| 36 |
'dependency' => array( |
| 37 |
'id' => 'link', |
| 38 |
'value' => '', |
| 39 |
'type' => 'inverse', |
| 40 |
), |
| 41 |
), |
| 42 |
'link_nofollow' => array( |
| 43 |
'default' => 'nofollow', |
| 44 |
'type' => 'dropdown', |
| 45 |
'options' => array( |
| 46 |
'dofollow' => 'Do not add nofollow attribute', |
| 47 |
'nofollow' => 'Add nofollow attribute', |
| 48 |
), |
| 49 |
'dependency' => array( |
| 50 |
'id' => 'link', |
| 51 |
'value' => '', |
| 52 |
'type' => 'inverse', |
| 53 |
), |
| 54 |
), |
| 55 |
'style' => array( |
| 56 |
'default' => 'text', |
| 57 |
'type' => 'dropdown', |
| 58 |
'options' => array( |
| 59 |
'text' => 'Text', |
| 60 |
'button' => 'Button', |
| 61 |
'inline-button' => 'Inline Button', |
| 62 |
'wide-button' => 'Full Width Button', |
| 63 |
), |
| 64 |
), |
| 65 |
'icon' => array( |
| 66 |
'default' => '', |
| 67 |
'type' => 'icon', |
| 68 |
), |
| 69 |
'text' => array( |
| 70 |
'default' => '', |
| 71 |
'type' => 'text', |
| 72 |
), |
| 73 |
'text_style' => array( |
| 74 |
'default' => 'normal', |
| 75 |
'type' => 'dropdown', |
| 76 |
'options' => 'text_styles', |
| 77 |
), |
| 78 |
'icon_color' => array( |
| 79 |
'default' => '#333333', |
| 80 |
'type' => 'color', |
| 81 |
'dependency' => array( |
| 82 |
'id' => 'icon', |
| 83 |
'value' => '', |
| 84 |
'type' => 'inverse', |
| 85 |
), |
| 86 |
), |
| 87 |
'text_color' => array( |
| 88 |
'default' => '#333333', |
| 89 |
'type' => 'color', |
| 90 |
), |
| 91 |
'horizontal_padding' => array( |
| 92 |
'default' => '5px', |
| 93 |
'type' => 'size', |
| 94 |
'dependency' => array( |
| 95 |
'id' => 'style', |
| 96 |
'value' => 'text', |
| 97 |
'type' => 'inverse', |
| 98 |
), |
| 99 |
), |
| 100 |
'vertical_padding' => array( |
| 101 |
'default' => '5px', |
| 102 |
'type' => 'size', |
| 103 |
'dependency' => array( |
| 104 |
'id' => 'style', |
| 105 |
'value' => 'text', |
| 106 |
'type' => 'inverse', |
| 107 |
), |
| 108 |
), |
| 109 |
'button_color' => array( |
| 110 |
'default' => '#ffffff', |
| 111 |
'type' => 'color', |
| 112 |
'dependency' => array( |
| 113 |
'id' => 'style', |
| 114 |
'value' => 'text', |
| 115 |
'type' => 'inverse', |
| 116 |
), |
| 117 |
), |
| 118 |
'border_color' => array( |
| 119 |
'default' => '#333333', |
| 120 |
'type' => 'color', |
| 121 |
'dependency' => array( |
| 122 |
'id' => 'style', |
| 123 |
'value' => 'text', |
| 124 |
'type' => 'inverse', |
| 125 |
), |
| 126 |
), |
| 127 |
'border_width' => array( |
| 128 |
'default' => '1px', |
| 129 |
'type' => 'size', |
| 130 |
'dependency' => array( |
| 131 |
'id' => 'style', |
| 132 |
'value' => 'text', |
| 133 |
'type' => 'inverse', |
| 134 |
), |
| 135 |
), |
| 136 |
'border_radius' => array( |
| 137 |
'default' => '0px', |
| 138 |
'type' => 'size', |
| 139 |
'dependency' => array( |
| 140 |
'id' => 'style', |
| 141 |
'value' => 'text', |
| 142 |
'type' => 'inverse', |
| 143 |
), |
| 144 |
), |
| 145 |
); |
| 146 |
parent::init(); |
| 147 |
} |
| 148 |
|
| 149 |
/** |
| 150 |
* Output for the shortcode. |
| 151 |
* |
| 152 |
* @since 3.8.0 |
| 153 |
* @param array $atts Options passed along with the shortcode. |
| 154 |
*/ |
| 155 |
public static function shortcode( $atts ) { |
| 156 |
$atts = parent::get_attributes( $atts ); |
| 157 |
|
| 158 |
$link = esc_url_raw( $atts['link'] ); |
| 159 |
if ( ! $link ) { |
| 160 |
return ''; |
| 161 |
} |
| 162 |
|
| 163 |
// Get optional icon. |
| 164 |
$icon = ''; |
| 165 |
if ( $atts['icon'] ) { |
| 166 |
$icon = WPUPG_Icon::get( $atts['icon'], $atts['icon_color'] ); |
| 167 |
|
| 168 |
if ( $icon ) { |
| 169 |
$icon = '<span class="wpupg-icon wpupg-link-icon">' . $icon . '</span> '; |
| 170 |
} |
| 171 |
} |
| 172 |
|
| 173 |
// Use link as default text. |
| 174 |
$text = $atts['text']; |
| 175 |
if ( ! $text ) { |
| 176 |
$text = $link; |
| 177 |
} |
| 178 |
|
| 179 |
// Output. |
| 180 |
$classes = array( |
| 181 |
'wpupg-link', |
| 182 |
'wpupg-block-text-' . $atts['text_style'], |
| 183 |
); |
| 184 |
|
| 185 |
$style = 'color: ' . $atts['text_color'] . ';'; |
| 186 |
if ( 'text' !== $atts['style'] ) { |
| 187 |
$classes[] = 'wpupg-link-' . $atts['style']; |
| 188 |
|
| 189 |
$style .= 'background-color: ' . $atts['button_color'] . ';'; |
| 190 |
$style .= 'border-width: ' . $atts['border_width'] . ';'; |
| 191 |
$style .= 'border-color: ' . $atts['border_color'] . ';'; |
| 192 |
$style .= 'border-radius: ' . $atts['border_radius'] . ';'; |
| 193 |
$style .= 'padding: ' . $atts['vertical_padding'] . ' ' . $atts['horizontal_padding'] . ';'; |
| 194 |
} |
| 195 |
|
| 196 |
$nofollow = 'nofollow' === $atts['link_nofollow'] ? ' rel="nofollow"' : ''; |
| 197 |
$output = '<a href="' . esc_attr( $link ) . '" target="' . esc_attr( $atts['link_target'] ) . '" class="' . esc_attr( implode( ' ', $classes ) ) . '"' . $nofollow . ' style="' . esc_attr( $style ) . '">' . $icon . WPUPG_Shortcode::sanitize_html( $text ) . '</a>'; |
| 198 |
return apply_filters( parent::get_hook(), $output, $atts ); |
| 199 |
} |
| 200 |
} |
| 201 |
|
| 202 |
WPUPG_SC_Link::init(); |