| 1 |
<?php |
| 2 |
/** |
| 3 |
* Handle the item excerpt shortcode. |
| 4 |
* |
| 5 |
* @link https://bootstrapped.ventures |
| 6 |
* @since 3.0.0 |
| 7 |
* |
| 8 |
* @package WP_Ultimate_Post_Grid |
| 9 |
* @subpackage WP_Ultimate_Post_Grid/includes/public/shortcodes/item |
| 10 |
*/ |
| 11 |
|
| 12 |
/** |
| 13 |
* Handle the item excerpt shortcode. |
| 14 |
* |
| 15 |
* @since 3.0.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_Excerpt extends WPUPG_Template_Shortcode { |
| 21 |
public static $shortcode = 'wpupg-item-excerpt'; |
| 22 |
|
| 23 |
public static function init() { |
| 24 |
$atts = array( |
| 25 |
'display' => array( |
| 26 |
'default' => 'inline', |
| 27 |
'type' => 'dropdown', |
| 28 |
'options' => 'display_options', |
| 29 |
), |
| 30 |
'align' => array( |
| 31 |
'default' => 'left', |
| 32 |
'type' => 'dropdown', |
| 33 |
'options' => array( |
| 34 |
'left' => 'Left', |
| 35 |
'center' => 'Center', |
| 36 |
'right' => 'Right', |
| 37 |
), |
| 38 |
'dependency' => array( |
| 39 |
'id' => 'display', |
| 40 |
'value' => 'block', |
| 41 |
), |
| 42 |
), |
| 43 |
'text_style' => array( |
| 44 |
'default' => 'normal', |
| 45 |
'type' => 'dropdown', |
| 46 |
'options' => 'text_styles', |
| 47 |
), |
| 48 |
); |
| 49 |
$atts = array_merge( $atts, WPUPG_Template_Helper::get_label_container_atts() ); |
| 50 |
$atts = array_merge( $atts, WPUPG_Template_Helper::limit_text_atts() ); |
| 51 |
|
| 52 |
self::$attributes = $atts; |
| 53 |
parent::init(); |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* Output for the shortcode. |
| 58 |
* |
| 59 |
* @since 3.0.0 |
| 60 |
* @param array $atts Options passed along with the shortcode. |
| 61 |
*/ |
| 62 |
public static function shortcode( $atts ) { |
| 63 |
$atts = parent::get_attributes( $atts ); |
| 64 |
|
| 65 |
$item = WPUPG_Template_Shortcodes::get_item(); |
| 66 |
if ( ! $item ) { |
| 67 |
return ''; |
| 68 |
} |
| 69 |
|
| 70 |
// Output. |
| 71 |
$classes = array( |
| 72 |
'wpupg-item-excerpt', |
| 73 |
'wpupg-block-text-' . $atts['text_style'], |
| 74 |
); |
| 75 |
|
| 76 |
// Alignment. |
| 77 |
if ( 'block' === $atts['display'] && 'left' !== $atts['align'] ) { |
| 78 |
$classes[] = 'wpupg-align-' . $atts['align']; |
| 79 |
} |
| 80 |
|
| 81 |
$label_container = WPUPG_Template_Helper::get_label_container( $atts, 'excerpt' ); |
| 82 |
$tag = 'block' === $atts['display'] ? 'div' : 'span'; |
| 83 |
|
| 84 |
$text = WPUPG_Template_Helper::limit_text( $atts, $item->excerpt() ); |
| 85 |
|
| 86 |
$output = '<' . esc_attr( $tag ) . ' class="' . esc_attr( implode( ' ', $classes ) ) . '">' . $label_container . $text . '</' . esc_attr( $tag ) . '>'; |
| 87 |
return apply_filters( parent::get_hook(), $output, $atts, $item ); |
| 88 |
} |
| 89 |
} |
| 90 |
|
| 91 |
WPUPG_SC_Excerpt::init(); |