| 1 |
<?php |
| 2 |
/** |
| 3 |
* Handle the text 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 text 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_Text extends WPUPG_Template_Shortcode { |
| 21 |
public static $shortcode = 'wpupg-text'; |
| 22 |
|
| 23 |
public static function init() { |
| 24 |
self::$attributes = array( |
| 25 |
'text' => array( |
| 26 |
'default' => '', |
| 27 |
'type' => 'text', |
| 28 |
), |
| 29 |
'text_style' => array( |
| 30 |
'default' => 'normal', |
| 31 |
'type' => 'dropdown', |
| 32 |
'options' => 'text_styles', |
| 33 |
), |
| 34 |
'tag' => array( |
| 35 |
'default' => 'p', |
| 36 |
'type' => 'dropdown', |
| 37 |
'options' => array( |
| 38 |
'p' => 'p', |
| 39 |
'span' => 'span', |
| 40 |
'div' => 'div', |
| 41 |
'h1' => 'h1', |
| 42 |
'h2' => 'h2', |
| 43 |
'h3' => 'h3', |
| 44 |
'h4' => 'h4', |
| 45 |
'h5' => 'h5', |
| 46 |
'h6' => 'h6', |
| 47 |
), |
| 48 |
), |
| 49 |
'align' => array( |
| 50 |
'default' => 'left', |
| 51 |
'type' => 'dropdown', |
| 52 |
'options' => array( |
| 53 |
'left' => 'Left', |
| 54 |
'center' => 'Center', |
| 55 |
'right' => 'Right', |
| 56 |
), |
| 57 |
'dependency' => array( |
| 58 |
array( |
| 59 |
'id' => 'tag', |
| 60 |
'value' => 'span', |
| 61 |
'type' => 'inverse', |
| 62 |
), |
| 63 |
), |
| 64 |
), |
| 65 |
); |
| 66 |
parent::init(); |
| 67 |
} |
| 68 |
|
| 69 |
/** |
| 70 |
* Output for the shortcode. |
| 71 |
* |
| 72 |
* @since 3.8.0 |
| 73 |
* @param array $atts Options passed along with the shortcode. |
| 74 |
*/ |
| 75 |
public static function shortcode( $atts ) { |
| 76 |
$atts = parent::get_attributes( $atts ); |
| 77 |
|
| 78 |
$text = $atts['text']; |
| 79 |
if ( ! $text ) { |
| 80 |
return ''; |
| 81 |
} |
| 82 |
|
| 83 |
// Output. |
| 84 |
$classes = array( |
| 85 |
'wpupg-text', |
| 86 |
'wpupg-block-text-' . $atts['text_style'], |
| 87 |
); |
| 88 |
|
| 89 |
$output = ''; |
| 90 |
$tag = WPUPG_Shortcode::sanitize_html_element( $atts['tag'] ); |
| 91 |
|
| 92 |
// Alignment. |
| 93 |
if ( 'span' !== $tag && 'left' !== $atts['align'] ) { |
| 94 |
$classes[] = 'wpupg-align-' . esc_attr( $atts['align'] ); |
| 95 |
} |
| 96 |
|
| 97 |
$output .= '<' . esc_attr( $tag ) . ' class="' . esc_attr( implode( ' ', $classes ) ) . '">' . WPUPG_Shortcode::sanitize_html( $text ) . '</' . esc_attr( $tag ) . '>'; |
| 98 |
|
| 99 |
return apply_filters( parent::get_hook(), $output, $atts ); |
| 100 |
} |
| 101 |
} |
| 102 |
|
| 103 |
WPUPG_SC_Text::init(); |