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 +63 -55 2.1.22.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,37 +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);
19 + if(is_admin()){
20 + return '';
21 + }
20 22
21 - if ($id === null) {
23 + $id = $this->getId( $attrs );
24 +
25 + if ( $id === null ) {
22 26 return '';
23 27 }
24 - $campaign = new Campaign($id);
28 + $campaign = new Campaign( $id );
25 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 + ) {
26 37
27 - // Don't render the shortcode if the campaign's inactive.
28 - if ( ! $campaign->isActive() || $campaign->isScheduled()
29 - || ! $campaign->showStickyBarOn($this->getCurrentPageId())
30 - ) {
31 - return '';
38 + return apply_filters( 'hurryt_no_campaign', '', $campaign->getId() );
32 39 }
33 - // Run campaign's actions if expired.
34 - if ($campaign->isRegular() && $campaign->isExpired()) {
35 - $actionManager = new ActionManager($campaign);
40 + $isOneTimeCampaignExpired = $campaign->isRegular() && $campaign->isExpired();
41 + $isRecurringCampaignExpired = $campaign->isRecurring() && $campaign->isRecurringExpired();
42 +
43 + if ( $isRecurringCampaignExpired || $isOneTimeCampaignExpired ) {
44 + $actionManager = new ActionManager( $campaign );
36 45 $actionManager->run();
37 46 }
38 47
39 - $template = apply_filters('hurryt_campaign_template', $campaign->buildTemplate());
40 -
41 - return $template === '' ?: $campaign->wrapTemplate($template);
48 + $template = apply_filters( 'hurryt_campaign_template', $campaign->buildTemplate() );
42 49
50 + return $template === '' ? '' : $campaign->wrapTemplate( $template );
51 +
43 52 }
44 53
45 -
46 54 /**
47 55 * Returns campaign ID if set.
48 56 *
49 57 * @param $attrs
@@ -49,17 +57,17 @@
49 57 * @param $attrs
50 58 *
51 59 * @return int|null
52 60 */
53 - function getId($attrs)
61 + public function getId( $attrs )
54 62 {
55 - if ( ! $this->hasId($attrs)) {
63 + if ( ! $this->hasId( $attrs ) ) {
56 64 return null;
57 65 }
58 66
59 - $id = intval($attrs['id']);
67 + $id = intval( $attrs[ 'id' ] );
60 68
61 - if ( ! $this->campaignExists($id)) {
69 + if ( ! $this->campaignExists( $id ) ) {
62 70 return null;
63 71 }
64 72
65 73 return $id;
@@ -64,44 +72,44 @@
64 72
65 73 return $id;
66 74 }
67 75
68 - function getCurrentPageId()
76 + public function getCurrentPageId()
69 77 {
70 78
71 79 $objectId = get_queried_object_id();
72 - if(! Utils\Helpers::isWcActive()){
80 + if ( ! Utils\Helpers::isWcActive() ) {
73 81 return $objectId;
74 82 }
75 83 $wcIds = [
76 - 'shop' => get_option('woocommerce_shop_page_id'),
77 - 'cart' => get_option('woocommerce_cart_page_id'),
78 - 'checkout' => get_option('woocommerce_checkout_page_id'),
79 - 'checkout_pay' => get_option('woocommerce_pay_page_id'),
80 - 'thanks' => get_option('woocommerce_thanks_page_id'),
81 - 'myaccount' => get_option('woocommerce_myaccount_page_id'),
82 - 'edit_address' => get_option('woocommerce_edit_address_page_id'),
83 - 'view_order' => get_option('woocommerce_view_order_page_id'),
84 - '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' ),
85 93 ];
86 - if (is_shop()) {
87 - $objectId = $wcIds['shop'];
88 - } elseif (is_account_page()) {
89 - $objectId = $wcIds['myaccount'];
90 - } elseif (is_checkout_pay_page()) {
91 - $objectId = $wcIds['checkout_pay'];
92 - } elseif (is_checkout()) {
93 - $objectId = $wcIds['checkout'];
94 - } elseif (is_cart()) {
95 - $objectId = $wcIds['cart'];
96 - } elseif (is_view_order_page()) {
97 - $objectId = $wcIds['view_order'];
98 - } elseif (is_view_order_page()) {
99 - $objectId = $wcIds['view_order'];
100 - } elseif (is_view_order_page()) {
101 - $objectId = $wcIds['view_order'];
102 - } elseif (is_view_order_page()) {
103 - $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' ];
104 112 }
105 113
106 114 return $objectId;
107 115 }
@@ -112,11 +120,11 @@
112 120 * @param $attrs
113 121 *
114 122 * @return bool
115 123 */
116 - function hasId($attrs)
124 + public function hasId( $attrs )
117 125 {
118 - return isset($attrs['id']);
126 + return isset( $attrs[ 'id' ] );
119 127 }
120 128
121 129 /**
122 130 * Verify if the given campaign exists in database.
@@ -124,9 +132,9 @@
124 132 * @param $id
125 133 *
126 134 * @return boolean
127 135 */
128 - function campaignExists($id)
136 + public function campaignExists( $id )
129 137 {
130 - return get_post($id) instanceof WP_Post;
138 + return get_post( $id ) instanceof WP_Post;
131 139 }
132 -}
140 +}