Completed
Branch BUG-10626-dst-unit-test (cc62a6)
by
unknown
37:15 queued 23:58
created

EspressoTicketSelector   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 84
rs 10
c 0
b 0
f 0
wmc 6
lcom 0
cbo 3

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getTag() 0 4 1
A cacheExpiration() 0 4 1
A initializeShortcode() 0 5 1
B processShortcode() 0 28 3
1
<?php
2
namespace EventEspresso\core\domain\entities\shortcodes;
3
4
use EE_Event;
5
use EE_Registry;
6
use EventEspresso\core\exceptions\ExceptionStackTraceDisplay;
7
use EventEspresso\core\services\shortcodes\EspressoShortcode;
8
use InvalidArgumentException;
9
10
defined('EVENT_ESPRESSO_VERSION') || exit;
11
12
13
14
/**
15
 * Class EspressoTicketSelector
16
 * ESPRESSO_TICKET_SELECTOR shortcode
17
 *
18
 * @package       Event Espresso
19
 * @author        Brent Christensen
20
 * @since         $VID:$
21
 */
22
class EspressoTicketSelector extends EspressoShortcode
23
{
24
25
26
27
    /**
28
     * the actual shortcode tag that gets registered with WordPress
29
     *
30
     * @return string
31
     */
32
    public function getTag()
33
    {
34
        return 'ESPRESSO_TICKET_SELECTOR';
35
    }
36
37
38
39
    /**
40
     * the time in seconds to cache the results of the processShortcode() method
41
     * 0 means the processShortcode() results will NOT be cached at all
42
     *
43
     * @return int
44
     */
45
    public function cacheExpiration()
46
    {
47
        return 0;
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
        add_filter('FHEE__EED_Ticket_Selector__load_tckt_slctr_assets', '__return_true');
61
        $this->shortcodeHasBeenInitialized();
62
    }
63
64
65
66
    /**
67
     * callback that runs when the shortcode is encountered in post content.
68
     * IMPORTANT !!!
69
     * remember that shortcode content should be RETURNED and NOT echoed out
70
     *
71
     * @param array $attributes
72
     * @return string
73
     * @throws InvalidArgumentException
74
     */
75
    public function processShortcode($attributes = array())
76
    {
77
        extract($attributes, EXTR_OVERWRITE);
78
        $event_id = isset($event_id) ? $event_id : 0;
79
        $event = EE_Registry::instance()->load_model('Event')->get_one_by_ID($event_id);
80
        if (! $event instanceof EE_Event) {
81
            new ExceptionStackTraceDisplay(
82
                new InvalidArgumentException(
83
                    sprintf(
84
                        esc_html__(
85
                            'A valid Event ID is required to use the "%1$s" shortcode.%4$sAn Event with an ID of "%2$s" could not be found.%4$sPlease verify that the shortcode added to this post\'s content includes an "%3$s" argument and that it\'s value corresponds to a valid Event ID.',
86
                            'event_espresso'
87
                        ),
88
                        $this->getTag(),
89
                        $event_id,
90
                        'event_id',
91
                        '<br />'
92
                    )
93
                )
94
            );
95
            return '';
96
        }
97
        ob_start();
98
        do_action('AHEE_event_details_before_post', $event_id);
99
        espresso_ticket_selector($event);
100
        do_action('AHEE_event_details_after_post');
101
        return ob_get_clean();
102
    }
103
104
105
}
106
// End of file EspressoTicketSelector.php
107
// Location: EventEspresso\core\domain\entities\shortcodes/EspressoTicketSelector.php