| @@ -7,9 +7,10 @@ | ||
| 7 | 7 | * Returns WooCommerce stock status as array. |
| 8 | 8 | * |
| 9 | 9 | * @return array |
| 10 | 10 | */ |
| 11 | - function hurryt_wc_stock_statuses() { | |
| 11 | + function hurryt_wc_stock_statuses() | |
| 12 | + { | |
| 12 | 13 | return [ |
| 13 | 14 | [ |
| 14 | 15 | 'name' => __('In stock', 'hurrytimer'), |
| 15 | 16 | 'id' => \Hurrytimer\C::WC_IN_STOCK, |
| @@ -32,9 +33,10 @@ | ||
| 32 | 33 | * Returns supported conditions. |
| 33 | 34 | * |
| 34 | 35 | * @return array |
| 35 | 36 | */ |
| 36 | - function hurryt_wc_conditions() { | |
| 37 | + function hurryt_wc_conditions() | |
| 38 | + { | |
| 37 | 39 | return (new \Hurrytimer\ConditionalLogic())->addRule([ |
| 38 | 40 | 'key' => 'stock_status', |
| 39 | 41 | 'name' => __('Stock status', 'hurrytimer'), |
| 40 | 42 | 'operators' => ['==', '!='], |
| @@ -68,47 +70,29 @@ | ||
| 68 | 70 | ])->get(); |
| 69 | 71 | } |
| 70 | 72 | } |
| 71 | 73 | |
| 72 | -if ( ! function_exists( 'hurryt_tz' ) ) { | |
| 73 | - function hurryt_tz( $tz = null ) { | |
| 74 | - | |
| 75 | - // If no saved timezone, fallback to WordPress setting. | |
| 76 | - if (empty($tz)) { | |
| 77 | - $current_offset = get_option('gmt_offset'); | |
| 78 | - $tzstring = get_option('timezone_string'); | |
| 79 | - | |
| 80 | - if (str_contains($tzstring, 'Etc/GMT')) { | |
| 81 | - $tzstring = ''; | |
| 82 | - } | |
| 83 | - | |
| 84 | - if (empty($tzstring)) { | |
| 85 | - if (0 === (int) $current_offset) { | |
| 86 | - $tzstring = 'UTC+0'; | |
| 87 | - } elseif ($current_offset < 0) { | |
| 88 | - $tzstring = 'UTC' . $current_offset; | |
| 89 | - } else { | |
| 90 | - $tzstring = 'UTC+' . $current_offset; | |
| 91 | - } | |
| 92 | - } | |
| 93 | - | |
| 94 | - $tz = $tzstring; | |
| 74 | +if (!function_exists('hurryt_tz')) { | |
| 75 | + /** | |
| 76 | + * Return WP timezone string/offset. | |
| 77 | + * | |
| 78 | + * @return mixed|string|void | |
| 79 | + */ | |
| 80 | + function hurryt_tz() | |
| 81 | + { | |
| 82 | + $tz_string = get_option('timezone_string'); | |
| 83 | + if (!empty($tz_string)) { | |
| 84 | + return $tz_string; | |
| 95 | 85 | } |
| 96 | - | |
| 97 | - // Convert UTC offsets like "UTC+2" into a valid timezone for PHP. | |
| 98 | - if (preg_match('/^UTC[+-]/', $tz)) { | |
| 99 | - $offset = (float)preg_replace( '/UTC\+?/', '', $tz ); | |
| 100 | - $hours = (int) $offset; | |
| 101 | - $minutes = ( $offset - $hours ); | |
| 102 | - $sign = ( $offset < 0 ) ? '-' : '+'; | |
| 103 | - $abs_hour = abs( $hours ); | |
| 104 | - $abs_mins = abs( $minutes * 60 ); | |
| 105 | - $tz = sprintf( '%s%02d:%02d', $sign, $abs_hour, $abs_mins ); | |
| 106 | - } | |
| 86 | + $offset = get_option('gmt_offset'); | |
| 87 | + $hours = (int)$offset; | |
| 88 | + $minutes = abs(($offset - (int)$offset) * 60); | |
| 89 | + $offset = sprintf('%+03d:%02d', $hours, $minutes); | |
| 107 | 90 | |
| 108 | - return $tz; | |
| 91 | + return $offset; | |
| 92 | + } | |
| 109 | 93 | } |
| 110 | -} | |
| 94 | + | |
| 111 | 95 | if (!function_exists('hurryt_current_page_id')) { |
| 112 | 96 | |
| 113 | 97 | /** |
| 114 | 98 | * Get current page ID. |
| @@ -114,9 +98,10 @@ | ||
| 114 | 98 | * Get current page ID. |
| 115 | 99 | * |
| 116 | 100 | * @return int|mixed |
| 117 | 101 | */ |
| 118 | - function hurryt_current_page_id() { | |
| 102 | + function hurryt_current_page_id() | |
| 103 | + { | |
| 119 | 104 | $object_id = get_queried_object_id(); |
| 120 | 105 | if (!hurryt_is_woocommerce_activated()) { |
| 121 | 106 | return $object_id; |
| 122 | 107 | } |
| @@ -160,9 +145,10 @@ | ||
| 160 | 145 | * Returns true if WC is active. |
| 161 | 146 | * |
| 162 | 147 | * @return bool |
| 163 | 148 | */ |
| 164 | - function hurryt_is_woocommerce_activated() { | |
| 149 | + function hurryt_is_woocommerce_activated() | |
| 150 | + { | |
| 165 | 151 | return class_exists('woocommerce'); |
| 166 | 152 | } |
| 167 | 153 | } |
| 168 | 154 | |
| @@ -171,9 +157,10 @@ | ||
| 171 | 157 | * Returns plugin settings array. |
| 172 | 158 | * |
| 173 | 159 | * @return array |
| 174 | 160 | */ |
| 175 | - function hurryt_settings() { | |
| 161 | + function hurryt_settings() | |
| 162 | + { | |
| 176 | 163 | $defaults = ['disable_actions' => 0]; |
| 177 | 164 | |
| 178 | 165 | return wp_parse_args(get_option('hurryt_settings', []), $defaults); |
| 179 | 166 | } |
| @@ -185,9 +172,10 @@ | ||
| 185 | 172 | * @param $id |
| 186 | 173 | * |
| 187 | 174 | * @return Campaign |
| 188 | 175 | */ |
| 189 | - function hurryt_get_campaign($id) { | |
| 176 | + function hurryt_get_campaign($id) | |
| 177 | + { | |
| 190 | 178 | $campaign = new Campaign($id); |
| 191 | 179 | $campaign->loadSettings(); |
| 192 | 180 | |
| 193 | 181 | return $campaign; |
| @@ -194,9 +182,10 @@ | ||
| 194 | 182 | } |
| 195 | 183 | } |
| 196 | 184 | |
| 197 | 185 | if (!function_exists('hurryt_is_admin_area')) { |
| 198 | - function hurryt_is_admin_area() { | |
| 186 | + function hurryt_is_admin_area() | |
| 187 | + { | |
| 199 | 188 | global $wp; |
| 200 | 189 | wp_parse_str($wp->query_string, $params); |
| 201 | 190 | |
| 202 | 191 | return is_admin() |
| @@ -213,9 +202,10 @@ | ||
| 213 | 202 | |
| 214 | 203 | /** |
| 215 | 204 | * Parse campaigns shortcodes in the given string content. |
| 216 | 205 | */ |
| 217 | - function hurryt_parse_campaigns($content) { | |
| 206 | + function hurryt_parse_campaigns($content) | |
| 207 | + { | |
| 218 | 208 | $pattern = get_shortcode_regex(); |
| 219 | 209 | $tag = 'hurrytimer'; |
| 220 | 210 | $ids = []; |
| 221 | 211 | if ( |
| @@ -242,9 +232,10 @@ | ||
| 242 | 232 | if (!function_exists('hurryt_count_active_campaigns')) { |
| 243 | 233 | /** |
| 244 | 234 | * Returns published campaigns. |
| 245 | 235 | */ |
| 246 | - function hurryt_count_active_campaigns() { | |
| 236 | + function hurryt_count_active_campaigns() | |
| 237 | + { | |
| 247 | 238 | |
| 248 | 239 | /** @var object $count */ |
| 249 | 240 | $count = wp_count_posts(HURRYT_POST_TYPE); |
| 250 | 241 | |
| @@ -255,24 +246,23 @@ | ||
| 255 | 246 | |
| 256 | 247 | /** |
| 257 | 248 | * Return all WooCommerce coupons. |
| 258 | 249 | * @param string $status |
| 259 | - * @access private | |
| 260 | - * @internal | |
| 261 | 250 | * @return array |
| 262 | 251 | */ |
| 263 | -function hurryt_get_wc_coupons($status = 'any') { | |
| 252 | +function hurryt_get_wc_coupons($status = 'publish') | |
| 253 | +{ | |
| 264 | 254 | |
| 265 | 255 | return get_posts([ |
| 266 | 256 | 'post_type' => 'shop_coupon', |
| 267 | 257 | 'post_status' => $status, |
| 268 | - 'no_found_rows' => true, | |
| 269 | - 'numberposts' => 30 | |
| 258 | + 'posts_per_page' => -1 | |
| 270 | 259 | ]); |
| 271 | 260 | } |
| 272 | 261 | |
| 273 | 262 | |
| 274 | -function hurryt_wc_coupon_name($coupon_id) { | |
| 263 | +function hurryt_wc_coupon_name($coupon_id) | |
| 264 | +{ | |
| 275 | 265 | if (!function_exists('wc_get_coupon_types')) { |
| 276 | 266 | return ''; |
| 277 | 267 | } |
| 278 | 268 | |
| @@ -286,9 +276,10 @@ | ||
| 286 | 276 | /** |
| 287 | 277 | * Return the current timezone string. |
| 288 | 278 | * @return string |
| 289 | 279 | */ |
| 290 | -function hurryt_current_timezone_string() { | |
| 280 | +function hurryt_current_timezone_string() | |
| 281 | +{ | |
| 291 | 282 | $current_offset = get_option('gmt_offset'); |
| 292 | 283 | $tzstring = get_option('timezone_string'); |
| 293 | 284 | |
| 294 | 285 | if (false !== strpos($tzstring, 'Etc/GMT')) { |
| @@ -307,9 +298,10 @@ | ||
| 307 | 298 | return $tzstring; |
| 308 | 299 | } |
| 309 | 300 | |
| 310 | 301 | |
| 311 | -function hurrytimer_is_elementor_edit_mode() { | |
| 302 | +function hurrytimer_is_elementor_edit_mode() | |
| 303 | +{ | |
| 312 | 304 | try { |
| 313 | 305 | return class_exists('\Elementor\Plugin') && \Elementor\Plugin::$instance->editor->is_edit_mode(); |
| 314 | 306 | } catch (\Exception $e) { |
| 315 | 307 | return false; |
| @@ -315,9 +307,10 @@ | ||
| 315 | 307 | return false; |
| 316 | 308 | } |
| 317 | 309 | } |
| 318 | 310 | |
| 319 | -function hurrytimer_is_elementor_preview_mode() { | |
| 311 | +function hurrytimer_is_elementor_preview_mode() | |
| 312 | +{ | |
| 320 | 313 | try { |
| 321 | 314 | return class_exists('\Elementor\Plugin') && \Elementor\Plugin::$instance->preview->is_preview_mode(); |
| 322 | 315 | } catch (\Exception $e) { |
| 323 | 316 | return false; |
| @@ -322,21 +315,4 @@ | ||
| 322 | 315 | } catch (\Exception $e) { |
| 323 | 316 | return false; |
| 324 | 317 | } |
| 325 | 318 | } |
| 326 | - | |
| 327 | - | |
| 328 | -function hurrytimer_allow_unfiltered_html() { | |
| 329 | - | |
| 330 | - $allow_unfiltered_html = current_user_can('unfiltered_html'); | |
| 331 | - | |
| 332 | - /** | |
| 333 | - * Filters whether the current user is allowed to save unfiltered HTML. | |
| 334 | - * | |
| 335 | - * @param bool allow_unfiltered_html The result. | |
| 336 | - */ | |
| 337 | - return apply_filters( 'hurrytimer/allow_unfiltered_html', $allow_unfiltered_html ); | |
| 338 | -} | |
| 339 | - | |
| 340 | -function hurrytimer_is_pro(){ | |
| 341 | - return defined( 'HURRYT_IS_PRO' ) && HURRYT_IS_PRO; | |
| 342 | -} | |