PluginProbe
HurryTimer – An Scarcity and Urgency Countdown Timer for WordPress & WooCommerce / 2.1.5
HurryTimer – An Scarcity and Urgency Countdown Timer for WordPress & WooCommerce v2.1.5
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 / Utils / Helpers.php

Helpers.php in HurryTimer – An Scarcity and Urgency Countdown Timer for WordPress & WooCommerce 2.1.5, at includes/Utils/Helpers.php

184 lines 4.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Hurrytimer\Utils;
4
5 use DateTime;
6
7 class Helpers
8 {
9 public static function ip_address()
10 {
11 $ip = null;
12 if ( ! empty($_SERVER['HTTP_CLIENT_IP'])) {
13 $ip = $_SERVER['HTTP_CLIENT_IP'];
14 } elseif ( ! empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
15 $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
16 } else {
17 $ip = $_SERVER['REMOTE_ADDR'];
18 }
19
20 return $ip;
21 }
22
23 /**
24 * Get admin preferences' date format.
25 *
26 * @param string $date
27 *
28 * @return string
29 */
30 public static function format_date($date)
31 {
32 $date_format = get_option('date_format') ?: 'M d, Y';
33
34 return date($date_format, strtotime($date));
35 }
36
37 /**
38 * Check if WC's active.
39 *
40 * @return boolean
41 */
42 public static function isWcActive()
43 {
44 if ( ! is_admin()) {
45 include_once ABSPATH . 'wp-admin/includes/plugin.php';
46 }
47
48 return is_plugin_active('woocommerce/woocommerce.php');
49 }
50
51 /**
52 * Check if WC's active.
53 *
54 * @return boolean
55 */
56 public static function isPluginInstalled()
57 {
58 if ( ! is_admin()) {
59 include_once ABSPATH . 'wp-admin/includes/plugin.php';
60 }
61
62 return is_plugin_active('hurrytimer/hurrytimer.php');
63 }
64
65 /**
66 * Check if WC's active.
67 *
68 * @return boolean
69 */
70 public static function isPluginProInstalled()
71 {
72 if ( ! is_admin()) {
73 include_once ABSPATH . 'wp-admin/includes/plugin.php';
74 }
75
76 return is_plugin_active('hurrytimer-pro/hurrytimer.php');
77 }
78
79 public static function date_time($datetime)
80 {
81 return new DateTime($datetime);
82 }
83
84 public static function timezone_string()
85 {
86 if (($timezone = get_option('timezone_string'))) {
87 return $timezone;
88 }
89 if (0 === ($utc_offset = get_option('gmt_offset', 0))) {
90 return 'UTC';
91 }
92
93 return self::get_timezone_by_offset($utc_offset);
94 }
95
96 public static function get_timezone_by_offset($offset)
97 {
98 list($hours, $minutes) = explode(':', $offset);
99 $seconds = $hours * 60 * 60 + $minutes * 60;
100
101 return timezone_name_from_abbr(null, $seconds, true);
102 }
103
104 public static function date_later($seconds)
105 {
106 $now = current_time('mysql');
107
108 return date('Y-m-d H:i:s', strtotime($now) + $seconds);
109 }
110
111 public static function isNewPost($post_id)
112 {
113 return get_post_status($post_id) === "auto-draft";
114 }
115
116 public static function isPostActive($post_id)
117 {
118 return get_post_status($post_id) === "publish"
119 || get_post_status($post_id) === "future";
120 }
121
122 public static function activateUrl($post_id)
123 {
124 return wp_nonce_url(
125 add_query_arg(
126 array(
127 'hurrytimer_action' => 'activate-compaign',
128 'postid' => $post_id,
129 'post' => $post_id,
130 'action' => 'edit',
131 ),
132 network_admin_url('post.php')
133 ),
134 'activate-compaign'
135 );
136 }
137
138 public static function deactivateUrl($post_id)
139 {
140 return wp_nonce_url(
141 add_query_arg(
142 array(
143 'hurrytimer_action' => 'deactivate-compaign',
144 'postid' => $post_id,
145 'post' => $post_id,
146 'action' => 'edit',
147 ),
148 network_admin_url('post.php')
149 ),
150 'deactivate-compaign'
151 );
152 }
153
154 public static function camelToSnakeCase($str)
155 {
156 return strtolower(preg_replace('/(?<!^)[A-Z]/', '_$0', $str));
157 }
158
159 public static function snakeToCamelCase($str)
160 {
161 $arr = explode('_', $str);
162 $arr = array_map(function ($i, $word) {
163 if ($i === 0) {
164 return $word;
165 }
166
167 return ucfirst($word);
168 }, array_keys($arr), $arr);
169
170 return implode('', $arr);
171 }
172
173
174 public static function getCampaigns($args = [])
175 {
176 return get_posts(array_merge(
177 [
178 'post_type' => HURRYT_POST_TYPE,
179 'numberposts' => -1,
180 ],
181 $args));
182 }
183 }
184