Completed
Branch BUG-10381-asset-loading (2d15a5)
by
unknown
127:00 queued 116:19
created

EspressoEvents::cacheExpiration()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
namespace EventEspresso\core\domain\entities\shortcodes;
3
4
use EED_Events_Archive;
5
use EEH_Template;
6
use EventEspresso\core\domain\services\wp_queries\EventListQuery;
7
use EventEspresso\core\services\shortcodes\EspressoShortcode;
8
9
defined('EVENT_ESPRESSO_VERSION') || exit;
10
11
12
13
/**
14
 * Class EspressoEvents
15
 * ESPRESSO_EVENTS shortcode
16
 *
17
 * @package       Event Espresso
18
 * @author        Brent Christensen
19
 * @since         4.9.26
20
 */
21
class EspressoEvents extends EspressoShortcode
22
{
23
24
25
26
    /**
27
     * the actual shortcode tag that gets registered with WordPress
28
     *
29
     * @return string
30
     */
31
    public function getTag()
32
    {
33
        return 'ESPRESSO_EVENTS';
34
    }
35
36
37
38
    /**
39
     * the time in seconds to cache the results of the processShortcode() method
40
     * 0 means the processShortcode() results will NOT be cached at all
41
     *
42
     * @return int
43
     */
44
    public function cacheExpiration()
45
    {
46
        return MINUTE_IN_SECONDS * 15;
47
    }
48
49
50
51
    /**
52
     * a place for adding any initialization code that needs to run prior to wp_header().
53
     * this may be required for shortcodes that utilize a corresponding module,
54
     * and need to enqueue assets for that module
55
     *
56
     * @return void
57
     */
58
    public function initializeShortcode()
59
    {
60
        EED_Events_Archive::instance()->event_list();
61
    }
62
63
64
65
    /**
66
     * callback that runs when the shortcode is encountered in post content.
67
     * IMPORTANT !!!
68
     * remember that shortcode content should be RETURNED and NOT echoed out
69
     *
70
     * @param array $attributes
71
     * @return string
72
     */
73
    public function processShortcode($attributes = array())
74
    {
75
        // grab attributes and merge with defaults
76
        $attributes = $this->getAttributes((array)$attributes);
77
        // make sure we use the_excerpt()
78
        add_filter('FHEE__EES_Espresso_Events__process_shortcode__true', '__return_true');
79
        // apply query filters
80
        add_filter('FHEE__EEH_Event_Query__apply_query_filters', '__return_true');
81
        // run the query
82
        global $wp_query;
83
        // yes we have to overwrite the main wp query, but it's ok...
84
        // we're going to reset it again below, so everything will be Hunky Dory (amazing album)
85
        $wp_query = new EventListQuery($attributes);
86
        // check what template is loaded and load filters accordingly
87
        EED_Events_Archive::instance()->template_include('loop-espresso_events.php');
88
        // load our template
89
        $event_list = EEH_Template::locate_template('loop-espresso_events.php', array(), true, true);
90
        // now reset the query and postdata
91
        wp_reset_query();
92
        wp_reset_postdata();
93
        EED_Events_Archive::remove_all_events_archive_filters();
94
        // remove query filters
95
        remove_filter('FHEE__EEH_Event_Query__apply_query_filters', '__return_true');
96
        // pull our content from the output buffer and return it
97
        return $event_list;
98
    }
99
100
101
102
    /**
103
     * merge incoming attributes with filtered defaults
104
     *
105
     * @param array $attributes
106
     * @return array
107
     */
108
    private function getAttributes(array $attributes)
109
    {
110
        return array_merge(
111
            (array)apply_filters(
112
                'EES_Espresso_Events__process_shortcode__default_espresso_events_shortcode_atts',
113
                array(
114
                    'title'         => null,
115
                    'limit'         => 10,
116
                    'css_class'     => null,
117
                    'show_expired'  => false,
118
                    'month'         => null,
119
                    'category_slug' => null,
120
                    'order_by'      => 'start_date',
121
                    'sort'          => 'ASC',
122
                )
123
            ),
124
            $attributes
125
        );
126
    }
127
128
129
}
130
// End of file EspressoEvents.php
131
// Location: EventEspresso\core\domain\entities\shortcodes/EspressoEvents.php