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-date.php

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

117 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Handle the item date 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 date 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_Date extends WPUPG_Template_Shortcode {
21 public static $shortcode = 'wpupg-item-date';
22
23 public static function init() {
24 $atts = array(
25 'date' => array(
26 'default' => 'published',
27 'type' => 'dropdown',
28 'options' => array(
29 'published' => 'Published Date',
30 'modified' => 'Modified Date',
31 ),
32 ),
33 'display' => array(
34 'default' => 'inline',
35 'type' => 'dropdown',
36 'options' => 'display_options',
37 ),
38 'align' => array(
39 'default' => 'left',
40 'type' => 'dropdown',
41 'options' => array(
42 'left' => 'Left',
43 'center' => 'Center',
44 'right' => 'Right',
45 ),
46 'dependency' => array(
47 'id' => 'display',
48 'value' => 'block',
49 ),
50 ),
51 'text_style' => array(
52 'default' => 'normal',
53 'type' => 'dropdown',
54 'options' => 'text_styles',
55 ),
56 'date_format' => array(
57 'default' => 'F j, Y',
58 'type' => 'text',
59 'help' => 'Use the PHP date format. Leave empty to use default WordPress date format from the Settings > General page.',
60 ),
61 );
62 $atts = array_merge( $atts, WPUPG_Template_Helper::get_label_container_atts() );
63
64 self::$attributes = $atts;
65 parent::init();
66 }
67
68 /**
69 * Output for the shortcode.
70 *
71 * @since 3.0.0
72 * @param array $atts Options passed along with the shortcode.
73 */
74 public static function shortcode( $atts ) {
75 $atts = parent::get_attributes( $atts );
76
77 $item = WPUPG_Template_Shortcodes::get_item();
78 if ( ! $item ) {
79 return '';
80 }
81
82 // Output.
83 $classes = array(
84 'wpupg-item-date',
85 'wpupg-block-text-' . $atts['text_style'],
86 );
87
88 // Alignment.
89 if ( 'block' === $atts['display'] && 'left' !== $atts['align'] ) {
90 $classes[] = 'wpupg-align-' . $atts['align'];
91 }
92
93 // Date format.
94 $format = $atts['date_format'];
95 if ( ! $format ) {
96 $format = get_option( 'date_format' );
97 }
98
99 // Date to use.
100 switch( $atts['date'] ) {
101 case 'modified':
102 $date = $item->date_modified();
103 break;
104 default:
105 $date = $item->date();
106 }
107
108 $formatted_date = date_i18n( $format, strtotime( $date ) );
109
110 $label_container = WPUPG_Template_Helper::get_label_container( $atts, 'date' );
111 $tag = 'block' === $atts['display'] ? 'div' : 'span';
112 $output = '<' . esc_attr( $tag ) . ' class="' . esc_attr( implode( ' ', $classes ) ) . '">' . $label_container . $formatted_date . '</' . esc_attr( $tag ) . '>';
113 return apply_filters( parent::get_hook(), $output, $atts, $item );
114 }
115 }
116
117 WPUPG_SC_Date::init();