PluginProbe
PostNL for WooCommerce / 3.1.7
PostNL for WooCommerce v3.1.7
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 3.1.7, at includes/compatibility/class-wc-core-compatibility.php

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