PluginProbe
WP Ultimate Post Grid / 4.0.1
WP Ultimate Post Grid v4.0.1
4.1.1 trunk 1.5 1.6 1.7 1.7.1 1.7.2 1.8 1.9 2.0 2.1 2.2 2.3 2.4.0 2.5.0 2.6.0 2.7.0 2.8.0 2.8.2 3.0.0 3.3.0 3.4.0 3.5.0 3.6.0 3.7.0 All 32 releases
wp-ultimate-post-grid / includes / public / shortcodes / item / class-wpupg-sc-permalink.php

class-wpupg-sc-permalink.php in WP Ultimate Post Grid 4.0.1, at includes/public/shortcodes/item/class-wpupg-sc-permalink.php

184 lines 4.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Handle the permalink 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 permalink 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 <[email protected]>
19 */
20 class WPUPG_SC_Permalink extends WPUPG_Template_Shortcode {
21 public static $shortcode = 'wpupg-item-link';
22
23 public static function init() {
24 self::$attributes = array(
25 'link_target' => array(
26 'default' => '_self',
27 'type' => 'dropdown',
28 'options' => array(
29 '_self' => 'Open in same tab',
30 '_blank' => 'Open in new tab',
31 ),
32 ),
33 'style' => array(
34 'default' => 'text',
35 'type' => 'dropdown',
36 'options' => array(
37 'text' => 'Text',
38 'button' => 'Button',
39 'inline-button' => 'Inline Button',
40 'wide-button' => 'Full Width Button',
41 ),
42 ),
43 'icon' => array(
44 'default' => '',
45 'type' => 'icon',
46 ),
47 'text' => array(
48 'default' => '',
49 'type' => 'text',
50 ),
51 'text_style' => array(
52 'default' => 'normal',
53 'type' => 'dropdown',
54 'options' => 'text_styles',
55 ),
56 'icon_color' => array(
57 'default' => '#333333',
58 'type' => 'color',
59 'dependency' => array(
60 'id' => 'icon',
61 'value' => '',
62 'type' => 'inverse',
63 ),
64 ),
65 'text_color' => array(
66 'default' => '#333333',
67 'type' => 'color',
68 ),
69 'horizontal_padding' => array(
70 'default' => '5px',
71 'type' => 'size',
72 'dependency' => array(
73 'id' => 'style',
74 'value' => 'text',
75 'type' => 'inverse',
76 ),
77 ),
78 'vertical_padding' => array(
79 'default' => '5px',
80 'type' => 'size',
81 'dependency' => array(
82 'id' => 'style',
83 'value' => 'text',
84 'type' => 'inverse',
85 ),
86 ),
87 'button_color' => array(
88 'default' => '#ffffff',
89 'type' => 'color',
90 'dependency' => array(
91 'id' => 'style',
92 'value' => 'text',
93 'type' => 'inverse',
94 ),
95 ),
96 'border_color' => array(
97 'default' => '#333333',
98 'type' => 'color',
99 'dependency' => array(
100 'id' => 'style',
101 'value' => 'text',
102 'type' => 'inverse',
103 ),
104 ),
105 'border_width' => array(
106 'default' => '1px',
107 'type' => 'size',
108 'dependency' => array(
109 'id' => 'style',
110 'value' => 'text',
111 'type' => 'inverse',
112 ),
113 ),
114 'border_radius' => array(
115 'default' => '0px',
116 'type' => 'size',
117 'dependency' => array(
118 'id' => 'style',
119 'value' => 'text',
120 'type' => 'inverse',
121 ),
122 ),
123 );
124 parent::init();
125 }
126
127 /**
128 * Output for the shortcode.
129 *
130 * @since 3.8.0
131 * @param array $atts Options passed along with the shortcode.
132 */
133 public static function shortcode( $atts ) {
134 $atts = parent::get_attributes( $atts );
135
136 $item = WPUPG_Template_Shortcodes::get_item();
137 if ( ! $item ) {
138 return '';
139 }
140
141 $link = $item->url();
142 if ( ! $link ) {
143 return '';
144 }
145
146 // Get optional icon.
147 $icon = '';
148 if ( $atts['icon'] ) {
149 $icon = WPUPG_Icon::get( $atts['icon'], $atts['icon_color'] );
150
151 if ( $icon ) {
152 $icon = '<span class="wpupg-icon wpupg-link-icon">' . $icon . '</span> ';
153 }
154 }
155
156 // Use link as default text.
157 $text = $atts['text'];
158 if ( ! $text ) {
159 $text = $link;
160 }
161
162 // Output.
163 $classes = array(
164 'wpupg-link',
165 'wpupg-block-text-' . $atts['text_style'],
166 );
167
168 $style = 'color: ' . $atts['text_color'] . ';';
169 if ( 'text' !== $atts['style'] ) {
170 $classes[] = 'wpupg-link-' . $atts['style'];
171
172 $style .= 'background-color: ' . $atts['button_color'] . ';';
173 $style .= 'border-width: ' . $atts['border_width'] . ';';
174 $style .= 'border-color: ' . $atts['border_color'] . ';';
175 $style .= 'border-radius: ' . $atts['border_radius'] . ';';
176 $style .= 'padding: ' . $atts['vertical_padding'] . ' ' . $atts['horizontal_padding'] . ';';
177 }
178
179 $output = '<a href="' . esc_attr( $link ) . '" target="' . esc_attr( $atts['link_target'] ) . '" class="' . esc_attr( implode( ' ', $classes ) ) . '" style="' . esc_attr( $style ) . '">' . $icon . WPUPG_Shortcode::sanitize_html( $text ) . '</a>';
180 return apply_filters( parent::get_hook(), $output, $atts );
181 }
182 }
183
184 WPUPG_SC_Permalink::init();