PluginProbe
HurryTimer – An Scarcity and Urgency Countdown Timer for WordPress & WooCommerce / 2.2.18
HurryTimer – An Scarcity and Urgency Countdown Timer for WordPress & WooCommerce v2.2.18
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 / functions.php

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

222 lines 6.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 use Hurrytimer\Campaign;
4
5 if ( ! function_exists( 'hurryt_wc_stock_statuses' ) ) {
6 /**
7 * Returns WooCommerce stock status as array.
8 *
9 * @return array
10 */
11 function hurryt_wc_stock_statuses() {
12 return [
13 [
14 'name' => __( 'In stock', 'hurrytimer' ),
15 'id' => \Hurrytimer\C::WC_IN_STOCK,
16 ],
17 [
18 'name' => __( 'Out of stock', 'hurrytimer' ),
19 'id' => \Hurrytimer\C::WC_OUT_OF_STOCK,
20 ],
21 [
22 'name' => __( 'On backorder', 'hurrytimer' ),
23 'id' => \Hurrytimer\C::WC_ON_BACKORDER,
24 ],
25 ];
26 }
27 }
28
29 if ( ! function_exists( 'hurryt_wc_conditions' ) ) {
30
31 /**
32 * Returns supported conditions.
33 *
34 * @return array
35 */
36 function hurryt_wc_conditions() {
37 return ( new \Hurrytimer\ConditionalLogic() )->addRule( [
38 'key' => 'stock_status',
39 'name' => __( 'Stock status', 'hurrytimer' ),
40 'operators' => [ '==', '!=' ],
41 'values' => hurryt_wc_stock_statuses(),
42 'type' => 'string',
43 ] )->addRule( [
44 'key' => 'stock_quantity',
45 'name' => __( 'Stock quantity', 'hurrytimer' ),
46 'operators' => [ '==', '!=', '<', '>' ],
47 'values' => [],
48 'type' => 'number',
49 ] )->addRule( [
50 'key' => 'shipping_class',
51 'name' => __( 'Shipping class', 'hurrytimer' ),
52 'operators' => [ '==', '!=' ],
53 'values' => array_map( function ( $class ) {
54 return [
55 'name' => $class->name,
56 'id' => $class->term_id,
57 ];
58 }, \WC_Shipping::instance()->get_shipping_classes() ),
59 ] )->get();
60 }
61 }
62
63 if ( ! function_exists( 'hurryt_tz' ) ) {
64 /**
65 * Return WP timezone string/offset.
66 *
67 * @return mixed|string|void
68 */
69 function hurryt_tz() {
70 $tz_string = get_option( 'timezone_string' );
71 if ( ! empty( $tz_string ) ) {
72 return $tz_string;
73 }
74 $offset = get_option( 'gmt_offset' );
75 $hours = (int)$offset;
76 $minutes = abs( ( $offset - (int)$offset ) * 60 );
77 $offset = sprintf( '%+03d:%02d', $hours, $minutes );
78
79 return $offset;
80 }
81 }
82
83 if ( ! function_exists( 'hurryt_current_page_id' ) ) {
84
85 /**
86 * Get current page ID.
87 *
88 * @return int|mixed
89 */
90 function hurryt_current_page_id() {
91 $object_id = get_queried_object_id();
92 if ( ! hurryt_is_woocommerce_activated() ) {
93 return $object_id;
94 }
95 $wc_ids = [
96 'shop' => get_option( 'woocommerce_shop_page_id' ),
97 'cart' => get_option( 'woocommerce_cart_page_id' ),
98 'checkout' => get_option( 'woocommerce_checkout_page_id' ),
99 'checkout_pay' => get_option( 'woocommerce_pay_page_id' ),
100 'thanks' => get_option( 'woocommerce_thanks_page_id' ),
101 'myaccount' => get_option( 'woocommerce_myaccount_page_id' ),
102 'edit_address' => get_option( 'woocommerce_edit_address_page_id' ),
103 'view_order' => get_option( 'woocommerce_view_order_page_id' ),
104 'terms' => get_option( 'woocommerce_terms_page_id' ),
105 ];
106 if ( is_shop() ) {
107 $object_id = $wc_ids[ 'shop' ];
108 } elseif ( is_account_page() ) {
109 $object_id = $wc_ids[ 'myaccount' ];
110 } elseif ( is_checkout_pay_page() ) {
111 $object_id = $wc_ids[ 'checkout_pay' ];
112 } elseif ( is_checkout() ) {
113 $object_id = $wc_ids[ 'checkout' ];
114 } elseif ( is_cart() ) {
115 $object_id = $wc_ids[ 'cart' ];
116 } elseif ( is_view_order_page() ) {
117 $object_id = $wc_ids[ 'view_order' ];
118 } elseif ( is_view_order_page() ) {
119 $object_id = $wc_ids[ 'view_order' ];
120 } elseif ( is_view_order_page() ) {
121 $object_id = $wc_ids[ 'view_order' ];
122 } elseif ( is_view_order_page() ) {
123 $object_id = $wc_ids[ 'view_order' ];
124 }
125
126 return $object_id;
127 }
128 }
129
130 if ( ! function_exists( 'hurryt_is_woocommerce_activated' ) ) {
131 /**
132 * Returns true if WC is active.
133 *
134 * @return bool
135 */
136 function hurryt_is_woocommerce_activated() {
137 return class_exists( 'woocommerce' );
138 }
139 }
140
141 if ( ! function_exists( 'hurryt_settings' ) ) {
142 /**
143 * Returns plugin settings array.
144 *
145 * @return array
146 */
147 function hurryt_settings() {
148 $defaults = [ 'disable_actions' => 0 ];
149
150 return wp_parse_args( get_option( 'hurryt_settings', [] ), $defaults );
151 }
152 }
153
154 if ( ! function_exists( 'hurryt_get_campaign' ) ) {
155 /**
156 * Create a campaign instance with all props.
157 * @param $id
158 *
159 * @return Campaign
160 */
161 function hurryt_get_campaign( $id ) {
162 $campaign = new Campaign( $id );
163 $campaign->loadSettings();
164
165 return $campaign;
166 }
167 }
168
169 if ( ! function_exists( 'hurryt_is_admin_area' ) ) {
170 function hurryt_is_admin_area() {
171 global $wp;
172 wp_parse_str( $wp->query_string, $params );
173
174 return is_admin()
175 || is_preview()
176 || is_customize_preview()
177 || ! empty( $params[ 'preview' ] )
178 || ! empty( $params[ 'fl_builder' ] );
179 }
180 }
181
182 if ( ! function_exists( 'hurryt_parse_campaigns' ) ) {
183
184 /**
185 * Parse campaigns shortcodes in the given string content.
186 */
187 function hurryt_parse_campaigns( $content ) {
188 $pattern = get_shortcode_regex();
189 $tag = 'hurrytimer';
190 $ids = [];
191 if ( preg_match_all( '/' . $pattern . '/s', $content, $matches )
192 && array_key_exists( 2, $matches )
193 && in_array( $tag, $matches[ 2 ] )
194 ) {
195 foreach ( (array)$matches[ 2 ] as $key => $value ) {
196 if ( $tag === $value ) {
197 $ids[] = shortcode_parse_atts( $matches[ 3 ][ $key ] );
198 }
199 }
200 $ids = array_map( function ( $id ) {
201 return isset( $id[ 'id' ] ) ? absint( $id[ 'id' ] ) : null;
202 }, $ids );
203
204 return array_filter( $ids );
205 }
206
207 return [];
208 }
209 }
210
211 if ( ! function_exists( 'hurryt_count_active_campaigns' ) ) {
212 /**
213 * Returns published campaigns.
214 */
215 function hurryt_count_active_campaigns() {
216 $count = wp_count_posts( HURRYT_POST_TYPE );
217
218 return absint( $count->publish );
219 }
220 }
221
222