PluginProbe
HurryTimer – An Scarcity and Urgency Countdown Timer for WordPress & WooCommerce / 2.0.0
HurryTimer – An Scarcity and Urgency Countdown Timer for WordPress & WooCommerce v2.0.0
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.0.0, at includes/Utils/Helpers.php

172 lines 4.0 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 * Check if WC's active.
66 *
67 * @return boolean
68 */
69 public static function isPluginProInstalled()
70 {
71 if (!is_admin()) {
72 include_once ABSPATH . 'wp-admin/includes/plugin.php';
73 }
74
75 return is_plugin_active('hurrytimer-pro/hurrytimer.php');
76 }
77
78 public static function date_time($datetime)
79 {
80 return new DateTime($datetime);
81 }
82
83 public static function timezone_string()
84 {
85 if (($timezone = get_option('timezone_string'))) {
86 return $timezone;
87 }
88 if (0 === ($utc_offset = get_option('gmt_offset', 0))) {
89 return 'UTC';
90 }
91
92 return self::get_timezone_by_offset($utc_offset);
93 }
94
95 public static function get_timezone_by_offset($offset)
96 {
97 list($hours, $minutes) = explode(':', $offset);
98 $seconds = $hours * 60 * 60 + $minutes * 60;
99
100 return timezone_name_from_abbr(null, $seconds, true);
101 }
102
103 public static function date_later($seconds)
104 {
105 $now = current_time('mysql');
106
107 return date('Y-m-d H:i:s', strtotime($now) + $seconds);
108 }
109
110 public static function isNewPost($post_id)
111 {
112 return get_post_status($post_id) === "auto-draft";
113 }
114
115 public static function isPostActive($post_id)
116 {
117 return get_post_status($post_id) === "publish"
118 || get_post_status($post_id) === "future";
119 }
120
121 public static function activateUrl($post_id)
122 {
123 return wp_nonce_url(
124 add_query_arg(
125 array(
126 'hurrytimer_action' => 'activate-compaign',
127 'postid' => $post_id,
128 'post' => $post_id,
129 'action' => 'edit',
130 ),
131 network_admin_url('post.php')
132 ),
133 'activate-compaign'
134 );
135 }
136
137 public static function deactivateUrl($post_id)
138 {
139 return wp_nonce_url(
140 add_query_arg(
141 array(
142 'hurrytimer_action' => 'deactivate-compaign',
143 'postid' => $post_id,
144 'post' => $post_id,
145 'action' => 'edit',
146 ),
147 network_admin_url('post.php')
148 ),
149 'deactivate-compaign'
150 );
151 }
152
153 public static function camelToSnakeCase($str)
154 {
155 return strtolower(preg_replace('/(?<!^)[A-Z]/', '_$0', $str));
156 }
157
158 public static function snakeToCamelCase($str)
159 {
160 $arr = explode('_', $str);
161 $arr = array_map(function ($i, $word) {
162 if ($i === 0) {
163 return $word;
164 }
165
166 return ucfirst($word);
167 }, array_keys($arr), $arr);
168
169 return implode('', $arr);
170 }
171 }
172