PluginProbe
HurryTimer – An Scarcity and Urgency Countdown Timer for WordPress & WooCommerce / 2.2.16
HurryTimer – An Scarcity and Urgency Countdown Timer for WordPress & WooCommerce v2.2.16
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
← All changes | includes/CampaignShortcode.php +59 -61 2.1.52.2.16 View file →
@@ -2,9 +2,9 @@
2 2
3 3 namespace Hurrytimer;
4 4
5 5 use \WP_Post;
6 -
6 +use \Hurrytimer\Utils\Helpers;
7 7 class CampaignShortcode
8 8 {
9 9
10 10 /**
@@ -13,47 +13,45 @@
13 13 * @param $attrs
14 14 *
15 15 * @return string
16 16 */
17 - function content($attrs)
17 + public function content( $attrs )
18 18 {
19 - $id = $this->getId($attrs);
20 -
21 - if ($id === null) {
19 + if(is_admin()){
22 20 return '';
23 21 }
24 - $campaign = new Campaign($id);
25 22
26 - $campaign->loadSettings();
23 + $id = $this->getId( $attrs );
27 24
28 - // Don't render the shortcode if the campaign's inactive.
29 - if ( ! $campaign->isActive() || $campaign->isScheduled()
30 - || ! $campaign->showStickyBarOn($this->getCurrentPageId())
31 - ) {
25 + if ( $id === null ) {
32 26 return '';
33 27 }
28 + $campaign = new Campaign( $id );
29 + $campaign->loadSettings();
30 + if ( ! $campaign->isActive()
31 + || $campaign->isScheduled()
32 + || ! $campaign->showStickyBarOn( $this->getCurrentPageId() )
33 + || $campaign->isStickyDismissed()
34 + || ( $campaign->isRecurring() && ! $campaign->canRecurToday() )
35 + || ( $campaign->isRecurring() && $campaign->getRecurringDeadline() === null )
36 + ) {
34 37
35 - // We must check if the campaign is sticky
36 - // If yes, we don't need to run actions as the campaign is no longer active.
37 - // Running actions for dismissed campaigns is bad for UX, so we avoid it.
38 - if($campaign->isDismissed()){
39 - return '';
38 + return apply_filters( 'hurryt_no_campaign', '', $campaign->getId() );
40 39 }
40 + $isOneTimeCampaignExpired = $campaign->isRegular() && $campaign->isExpired();
41 + $isRecurringCampaignExpired = $campaign->isRecurring() && $campaign->isRecurringExpired();
41 42
42 - // If it's a regular campaign and expired, run selected actions.
43 - if ($campaign->isRegular() && $campaign->isExpired()) {
44 - $actionManager = new ActionManager($campaign);
43 + if ( $isRecurringCampaignExpired || $isOneTimeCampaignExpired ) {
44 + $actionManager = new ActionManager( $campaign );
45 45 $actionManager->run();
46 46 }
47 47
48 + $template = apply_filters( 'hurryt_campaign_template', $campaign->buildTemplate() );
48 49
49 - $template = apply_filters('hurryt_campaign_template', $campaign->buildTemplate());
50 -
51 - return $template === '' ? '': $campaign->wrapTemplate($template);
50 + return $template === '' ? '' : $campaign->wrapTemplate( $template );
52 51
53 52 }
54 53
55 -
56 54 /**
57 55 * Returns campaign ID if set.
58 56 *
59 57 * @param $attrs
@@ -59,17 +57,17 @@
59 57 * @param $attrs
60 58 *
61 59 * @return int|null
62 60 */
63 - function getId($attrs)
61 + public function getId( $attrs )
64 62 {
65 - if ( ! $this->hasId($attrs)) {
63 + if ( ! $this->hasId( $attrs ) ) {
66 64 return null;
67 65 }
68 66
69 - $id = intval($attrs['id']);
67 + $id = intval( $attrs[ 'id' ] );
70 68
71 - if ( ! $this->campaignExists($id)) {
69 + if ( ! $this->campaignExists( $id ) ) {
72 70 return null;
73 71 }
74 72
75 73 return $id;
@@ -74,44 +72,44 @@
74 72
75 73 return $id;
76 74 }
77 75
78 - function getCurrentPageId()
76 + public function getCurrentPageId()
79 77 {
80 78
81 79 $objectId = get_queried_object_id();
82 - if(! Utils\Helpers::isWcActive()){
80 + if ( ! Utils\Helpers::isWcActive() ) {
83 81 return $objectId;
84 82 }
85 83 $wcIds = [
86 - 'shop' => get_option('woocommerce_shop_page_id'),
87 - 'cart' => get_option('woocommerce_cart_page_id'),
88 - 'checkout' => get_option('woocommerce_checkout_page_id'),
89 - 'checkout_pay' => get_option('woocommerce_pay_page_id'),
90 - 'thanks' => get_option('woocommerce_thanks_page_id'),
91 - 'myaccount' => get_option('woocommerce_myaccount_page_id'),
92 - 'edit_address' => get_option('woocommerce_edit_address_page_id'),
93 - 'view_order' => get_option('woocommerce_view_order_page_id'),
94 - 'terms' => get_option('woocommerce_terms_page_id'),
84 + 'shop' => get_option( 'woocommerce_shop_page_id' ),
85 + 'cart' => get_option( 'woocommerce_cart_page_id' ),
86 + 'checkout' => get_option( 'woocommerce_checkout_page_id' ),
87 + 'checkout_pay' => get_option( 'woocommerce_pay_page_id' ),
88 + 'thanks' => get_option( 'woocommerce_thanks_page_id' ),
89 + 'myaccount' => get_option( 'woocommerce_myaccount_page_id' ),
90 + 'edit_address' => get_option( 'woocommerce_edit_address_page_id' ),
91 + 'view_order' => get_option( 'woocommerce_view_order_page_id' ),
92 + 'terms' => get_option( 'woocommerce_terms_page_id' ),
95 93 ];
96 - if (is_shop()) {
97 - $objectId = $wcIds['shop'];
98 - } elseif (is_account_page()) {
99 - $objectId = $wcIds['myaccount'];
100 - } elseif (is_checkout_pay_page()) {
101 - $objectId = $wcIds['checkout_pay'];
102 - } elseif (is_checkout()) {
103 - $objectId = $wcIds['checkout'];
104 - } elseif (is_cart()) {
105 - $objectId = $wcIds['cart'];
106 - } elseif (is_view_order_page()) {
107 - $objectId = $wcIds['view_order'];
108 - } elseif (is_view_order_page()) {
109 - $objectId = $wcIds['view_order'];
110 - } elseif (is_view_order_page()) {
111 - $objectId = $wcIds['view_order'];
112 - } elseif (is_view_order_page()) {
113 - $objectId = $wcIds['view_order'];
94 + if ( is_shop() ) {
95 + $objectId = $wcIds[ 'shop' ];
96 + } elseif ( is_account_page() ) {
97 + $objectId = $wcIds[ 'myaccount' ];
98 + } elseif ( is_checkout_pay_page() ) {
99 + $objectId = $wcIds[ 'checkout_pay' ];
100 + } elseif ( is_checkout() ) {
101 + $objectId = $wcIds[ 'checkout' ];
102 + } elseif ( is_cart() ) {
103 + $objectId = $wcIds[ 'cart' ];
104 + } elseif ( is_view_order_page() ) {
105 + $objectId = $wcIds[ 'view_order' ];
106 + } elseif ( is_view_order_page() ) {
107 + $objectId = $wcIds[ 'view_order' ];
108 + } elseif ( is_view_order_page() ) {
109 + $objectId = $wcIds[ 'view_order' ];
110 + } elseif ( is_view_order_page() ) {
111 + $objectId = $wcIds[ 'view_order' ];
114 112 }
115 113
116 114 return $objectId;
117 115 }
@@ -122,11 +120,11 @@
122 120 * @param $attrs
123 121 *
124 122 * @return bool
125 123 */
126 - function hasId($attrs)
124 + public function hasId( $attrs )
127 125 {
128 - return isset($attrs['id']);
126 + return isset( $attrs[ 'id' ] );
129 127 }
130 128
131 129 /**
132 130 * Verify if the given campaign exists in database.
@@ -134,9 +132,9 @@
134 132 * @param $id
135 133 *
136 134 * @return boolean
137 135 */
138 - function campaignExists($id)
136 + public function campaignExists( $id )
139 137 {
140 - return get_post($id) instanceof WP_Post;
138 + return get_post( $id ) instanceof WP_Post;
141 139 }
142 -}
140 +}