PluginProbe
HurryTimer – An Scarcity and Urgency Countdown Timer for WordPress & WooCommerce / 2.0.2
HurryTimer – An Scarcity and Urgency Countdown Timer for WordPress & WooCommerce v2.0.2
2.15.0 trunk 1.0.0 1.0.1 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.1.2 2.1.3 2.1.5 2.1.6 2.1.7 2.1.8 2.10.0 All 62 releases
hurrytimer / includes / CampaignShortcode.php

CampaignShortcode.php in HurryTimer – An Scarcity and Urgency Countdown Timer for WordPress & WooCommerce 2.0.2, at includes/CampaignShortcode.php

87 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Hurrytimer;
4
5 use \WP_Post;
6
7 class CampaignShortcode
8 {
9
10 /**
11 * Return shortcode content.
12 *
13 * @param $attrs
14 *
15 * @return string
16 */
17 function content($attrs)
18 {
19 $id = $this->getId($attrs);
20
21 if ($id === null) {
22 return '';
23 }
24
25 $campaign = new Campaign($id);
26 $campaign->loadSettings();
27 // Don't render the shortcode if the campaign's inactive.
28 if ( ! $campaign->isActive() || $campaign->isScheduled()) {
29 return '';
30 }
31 // Run campaign's actions if expired.
32 if ($campaign->isRegular() && $campaign->isExpired()) {
33 $actionManager = new ActionManager($campaign);
34 $actionManager->run();
35 }
36
37 $template = apply_filters('hurryt_campaign_template', $campaign->buildTemplate());
38 return $campaign->wrapTemplate($template);
39
40 }
41
42 /**
43 * Returns campaign ID if set.
44 *
45 * @param $attrs
46 *
47 * @return int|null
48 */
49 function getId($attrs)
50 {
51 if ( ! $this->hasId($attrs)) {
52 return null;
53 }
54
55 $id = intval($attrs['id']);
56
57 if ( ! $this->campaignExists($id)) {
58 return null;
59 }
60
61 return $id;
62 }
63
64 /**
65 * Verify if the given attributes contain the campaign ID.
66 *
67 * @param $attrs
68 *
69 * @return bool
70 */
71 function hasId($attrs)
72 {
73 return isset($attrs['id']);
74 }
75
76 /**
77 * Verify if the given campaign exists in database.
78 *
79 * @param $id
80 *
81 * @return boolean
82 */
83 function campaignExists($id)
84 {
85 return get_post($id) instanceof WP_Post;
86 }
87 }