| 1 |
<?php |
| 2 |
/** |
| 3 |
* Handle the icon 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 icon 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_Icon extends WPUPG_Template_Shortcode { |
| 21 |
public static $shortcode = 'wpupg-icon'; |
| 22 |
|
| 23 |
public static function init() { |
| 24 |
self::$attributes = array( |
| 25 |
'icon' => array( |
| 26 |
'default' => '', |
| 27 |
'type' => 'icon', |
| 28 |
), |
| 29 |
'icon_color' => array( |
| 30 |
'default' => '#333333', |
| 31 |
'type' => 'color', |
| 32 |
'dependency' => array( |
| 33 |
'id' => 'icon', |
| 34 |
'value' => '', |
| 35 |
'type' => 'inverse', |
| 36 |
), |
| 37 |
), |
| 38 |
'icon_size' => array( |
| 39 |
'default' => '16px', |
| 40 |
'type' => 'size', |
| 41 |
'dependency' => array( |
| 42 |
'id' => 'icon', |
| 43 |
'value' => '', |
| 44 |
'type' => 'inverse', |
| 45 |
), |
| 46 |
), |
| 47 |
'style' => array( |
| 48 |
'default' => 'separate', |
| 49 |
'type' => 'dropdown', |
| 50 |
'options' => array( |
| 51 |
'inline' => 'Inline', |
| 52 |
'separate' => 'On its own line', |
| 53 |
), |
| 54 |
'dependency' => array( |
| 55 |
'id' => 'icon', |
| 56 |
'value' => '', |
| 57 |
'type' => 'inverse', |
| 58 |
), |
| 59 |
), |
| 60 |
'align' => array( |
| 61 |
'default' => 'center', |
| 62 |
'type' => 'dropdown', |
| 63 |
'options' => array( |
| 64 |
'left' => 'Left', |
| 65 |
'center' => 'Center', |
| 66 |
'right' => 'Right', |
| 67 |
), |
| 68 |
'dependency' => array( |
| 69 |
array( |
| 70 |
'id' => 'icon', |
| 71 |
'value' => '', |
| 72 |
'type' => 'inverse', |
| 73 |
), |
| 74 |
array( |
| 75 |
'id' => 'style', |
| 76 |
'value' => 'separate', |
| 77 |
), |
| 78 |
), |
| 79 |
), |
| 80 |
'decoration' => array( |
| 81 |
'default' => 'line', |
| 82 |
'type' => 'dropdown', |
| 83 |
'options' => array( |
| 84 |
'none' => 'None', |
| 85 |
'line' => 'Line', |
| 86 |
), |
| 87 |
'dependency' => array( |
| 88 |
array( |
| 89 |
'id' => 'icon', |
| 90 |
'value' => '', |
| 91 |
'type' => 'inverse', |
| 92 |
), |
| 93 |
array( |
| 94 |
'id' => 'style', |
| 95 |
'value' => 'separate', |
| 96 |
), |
| 97 |
), |
| 98 |
), |
| 99 |
'line_color' => array( |
| 100 |
'default' => '#9B9B9B', |
| 101 |
'type' => 'color', |
| 102 |
'dependency' => array( |
| 103 |
array( |
| 104 |
'id' => 'icon', |
| 105 |
'value' => '', |
| 106 |
'type' => 'inverse', |
| 107 |
), |
| 108 |
array( |
| 109 |
'id' => 'style', |
| 110 |
'value' => 'separate', |
| 111 |
), |
| 112 |
array( |
| 113 |
'id' => 'decoration', |
| 114 |
'value' => 'line', |
| 115 |
), |
| 116 |
), |
| 117 |
), |
| 118 |
); |
| 119 |
parent::init(); |
| 120 |
} |
| 121 |
|
| 122 |
/** |
| 123 |
* Output for the shortcode. |
| 124 |
* |
| 125 |
* @since 3.8.0 |
| 126 |
* @param array $atts Options passed along with the shortcode. |
| 127 |
*/ |
| 128 |
public static function shortcode( $atts ) { |
| 129 |
$atts = parent::get_attributes( $atts ); |
| 130 |
|
| 131 |
$icon = ''; |
| 132 |
if ( $atts['icon'] ) { |
| 133 |
$icon = WPUPG_Icon::get( $atts['icon'], $atts['icon_color'] ); |
| 134 |
|
| 135 |
if ( $icon ) { |
| 136 |
$icon = '<span class="wpupg-icon" aria-hidden="true">' . $icon . '</span> '; |
| 137 |
} |
| 138 |
} |
| 139 |
|
| 140 |
if ( ! $icon ) { |
| 141 |
return ''; |
| 142 |
} |
| 143 |
|
| 144 |
// Output. |
| 145 |
$classes = array( |
| 146 |
'wpupg-icon-shortcode', |
| 147 |
'wpupg-icon-shortcode-' . $atts['style'], |
| 148 |
); |
| 149 |
$before_icon = ''; |
| 150 |
$after_icon = ''; |
| 151 |
|
| 152 |
$style = ''; |
| 153 |
if ( '16px' !== $atts['icon_size'] ) { |
| 154 |
$style .= 'font-size: ' . $atts['icon_size'] . ';'; |
| 155 |
$style .= 'height: ' . $atts['icon_size'] . ';'; |
| 156 |
} |
| 157 |
|
| 158 |
if ( 'separate' === $atts['style'] ) { |
| 159 |
$classes[] = 'wpupg-align-' . $atts['align']; |
| 160 |
$classes[] = 'wpupg-icon-decoration-' . $atts['decoration']; |
| 161 |
|
| 162 |
if ( 'line' === $atts['decoration'] ) { |
| 163 |
if ( 'left' === $atts['align'] || 'center' === $atts['align'] ) { |
| 164 |
$after_icon = '<div class="wpupg-decoration-line" style="border-color: ' . esc_attr( $atts['line_color'] ) . '"></div>'; |
| 165 |
} |
| 166 |
if ( 'right' === $atts['align'] || 'center' === $atts['align'] ) { |
| 167 |
$before_icon = '<div class="wpupg-decoration-line" style="border-color: ' . esc_attr( $atts['line_color'] ) . '"></div>'; |
| 168 |
} |
| 169 |
} |
| 170 |
} |
| 171 |
|
| 172 |
$output = '<div class="' . esc_attr( implode( ' ', $classes ) ) . '" style="' . esc_attr( $style ) .'">' . $before_icon . $icon . $after_icon . '</div>'; |
| 173 |
return apply_filters( parent::get_hook(), $output, $atts ); |
| 174 |
} |
| 175 |
} |
| 176 |
|
| 177 |
WPUPG_SC_Icon::init(); |