PluginProbe
PostNL for WooCommerce / 4.4.1
PostNL for WooCommerce v4.4.1
5.9.12 5.9.11 5.9.10 5.9.9 5.9.8 5.9.7 5.9.6 trunk 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 3.1.4 3.1.5 3.1.6 3.1.7 4.0.0 4.0.1 4.0.2 4.3.2 4.3.3 4.4.0 4.4.1 All 72 releases
woo-postnl / includes / compatibility / class-wc-core-compatibility.php

class-wc-core-compatibility.php in PostNL for WooCommerce 4.4.1, at includes/compatibility/class-wc-core-compatibility.php

227 lines 6.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Derived from SkyVerge WooCommerce Plugin Framework https://github.com/skyverge/wc-plugin-framework/
4 */
5
6 namespace WPO\WC\PostNL\Compatibility;
7
8 use WC_Order;
9
10 defined('ABSPATH') or exit;
11
12 if (class_exists('\\WPO\\WC\\PostNL\\Compatibility\\WC_Core')) {
13 return;
14 }
15
16 /**
17 * WooCommerce Compatibility Utility Class
18 * The unfortunate purpose of this class is to provide a single point of
19 * compatibility functions for dealing with supporting multiple versions
20 * of WooCommerce and various extensions.
21 * The expected procedure is to remove methods from this class, using the
22 * latest ones directly in code, as support for older versions of WooCommerce
23 * are dropped.
24 * Current Compatibility
25 * + Core 2.5.5 - 3.0.x
26 *
27 * @since 2.0.0
28 */
29 class WC_Core
30 {
31
32 /**
33 * Backports wc_get_order() to pre-2.2.0
34 *
35 * @return WC_Order $order order object
36 * @since 4.3.0
37 */
38 public static function get_order($order_id)
39 {
40 if (function_exists('wc_get_order')) {
41 return wc_get_order($order_id);
42 } else {
43 return new WC_Order($order_id);
44 }
45 }
46
47 /**
48 * Backports wc_checkout_is_https() to 2.4.x
49 *
50 * @return bool
51 * @since 4.3.0
52 */
53 public static function wc_checkout_is_https()
54 {
55 if (self::is_wc_version_gte_2_5()) {
56 return wc_checkout_is_https();
57 } else {
58 return wc_site_is_https() || 'yes' === get_option('woocommerce_force_ssl_checkout')
59 || class_exists(
60 'WordPressHTTPS'
61 )
62 || strstr(wc_get_page_permalink('checkout'), 'https:');
63 }
64 }
65
66 /**
67 * Backports wc_help_tip() to WC 2.4.x
68 *
69 * @link https://github.com/woothemes/woocommerce/pull/9417
70 * @since 4.2.0
71 *
72 * @param string $tip help tip content, HTML allowed if $has_html is true
73 * @param bool $has_html false by default, true to indicate tip content has HTML
74 *
75 * @return string help tip HTML, a <span> in WC 2.5, <img> in WC 2.4
76 */
77 public static function wc_help_tip($tip, $has_html = false)
78 {
79 if (self::is_wc_version_gte_2_5()) {
80 return wc_help_tip($tip, $has_html);
81 } else {
82 $tip = $has_html ? wc_sanitize_tooltip($tip) : esc_attr($tip);
83
84 return sprintf(
85 '<img class="help_tip" data-tip="%1$s" src="%2$s" height="16" width="16" />',
86 $tip,
87 esc_url(WC()->plugin_url()) . '/assets/images/help.png'
88 );
89 }
90 }
91
92 /**
93 * Helper method to get the version of the currently installed WooCommerce
94 *
95 * @return string woocommerce version number or null
96 * @since 3.0.0
97 */
98 protected static function get_wc_version()
99 {
100 return defined('WC_VERSION') && WC_VERSION ? WC_VERSION : null;
101 }
102
103 /**
104 * Determines if the installed version of WooCommerce is 2.2.0 or greater.
105 *
106 * @return bool
107 * @since 4.2.0
108 */
109 public static function is_wc_version_gte_2_2()
110 {
111 return self::get_wc_version() && version_compare(self::get_wc_version(), '2.2', '>=');
112 }
113
114 /**
115 * Determines if the installed version of WooCommerce is less than 2.2.0
116 *
117 * @return bool
118 * @since 4.2.0
119 */
120 public static function is_wc_version_lt_2_2()
121 {
122 return self::get_wc_version() && version_compare(self::get_wc_version(), '2.2', '<');
123 }
124
125 /**
126 * Determines if the installed version of WooCommerce is 2.5.0 or greater.
127 *
128 * @return bool
129 * @since 4.2.0
130 */
131 public static function is_wc_version_gte_2_5()
132 {
133 return self::get_wc_version() && version_compare(self::get_wc_version(), '2.5', '>=');
134 }
135
136 /**
137 * Determines if the installed version of WooCommerce is less than 2.5.0
138 *
139 * @return bool
140 * @since 4.2.0
141 */
142 public static function is_wc_version_lt_2_5()
143 {
144 return self::get_wc_version() && version_compare(self::get_wc_version(), '2.5', '<');
145 }
146
147 /**
148 * Determines if the installed version of WooCommerce is 2.6.0 or greater.
149 *
150 * @return bool
151 * @since 4.4.0
152 */
153 public static function is_wc_version_gte_2_6()
154 {
155 return self::get_wc_version() && version_compare(self::get_wc_version(), '2.6', '>=');
156 }
157
158 /**
159 * Determines if the installed version of WooCommerce is less than 2.6.0
160 *
161 * @return bool
162 * @since 4.4.0
163 */
164 public static function is_wc_version_lt_2_6()
165 {
166 return self::get_wc_version() && version_compare(self::get_wc_version(), '2.6', '<');
167 }
168
169 /**
170 * Determines if the installed version of WooCommerce is 3.0.0 or greater.
171 *
172 * @return bool
173 * @since 4.6.0-dev
174 */
175 public static function is_wc_version_gte_3_0()
176 {
177 return self::get_wc_version() && version_compare(self::get_wc_version(), '3.0', '>=');
178 }
179
180 /**
181 * Determines if the installed version of WooCommerce is less than 3.0.0
182 *
183 * @return bool
184 * @since 4.6.0-dev
185 */
186 public static function is_wc_version_lt_3_0()
187 {
188 return self::get_wc_version() && version_compare(self::get_wc_version(), '3.0', '<');
189 }
190
191 /**
192 * Returns true if the installed version of WooCommerce is greater than $version
193 *
194 * @param string $version the version to compare
195 *
196 * @return bool true if the installed version of WooCommerce is > $version
197 * @since 2.0.0
198 */
199 public static function is_wc_version_gt($version)
200 {
201 return self::get_wc_version() && version_compare(self::get_wc_version(), $version, '>');
202 }
203
204
205 /** WordPress core ******************************************************/
206
207 /**
208 * Normalizes a WooCommerce page screen ID.
209 * Needed because WordPress uses a menu title (which is translatable), not slug, to generate screen ID.
210 * See details in: https://core.trac.wordpress.org/ticket/21454
211 * TODO: Add WP version check when https://core.trac.wordpress.org/ticket/18857 is addressed {BR 2016-12-12}
212 *
213 * @param string $slug The slug for the screen ID to normalize (minus `woocommerce_page_`).
214 *
215 * @return string Normalized screen ID.
216 * @since 4.6.0-dev
217 */
218 public static function normalize_wc_screen_id($slug = 'wc-settings')
219 {
220 // The text-domain usage is intentional here, we need to match the menu title.
221 $prefix = sanitize_title(__('WooCommerce', 'woocommerce'));
222
223 return $prefix . '_page_' . $slug;
224 }
225 }
226
227